Class: Vagabond::Server

Inherits:
Vagabond show all
Defined in:
lib/vagabond/server.rb

Constant Summary

Constants included from Vagabond

COLORS, VERSION

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Server

Returns a new instance of Server.



18
19
20
21
22
23
# File 'lib/vagabond/server.rb', line 18

def initialize(*args)
  super
  @name = 'server'
  @base_template = 'ubuntu_1204' # TODO: Make this dynamic
  setup('status')
end

Class Method Details

.basenameObject



11
12
13
# File 'lib/vagabond/server.rb', line 11

def basename
  'vagabond server'
end

Instance Method Details

#auto_uploadObject



41
42
43
44
45
46
47
48
# File 'lib/vagabond/server.rb', line 41

def auto_upload
  ui.info 'Auto uploading all assets to local Chef server...'
  upload_roles
  upload_databags
  upload_environments
  upload_cookbooks
  ui.info ui.color('  -> All assets uploaded!', :green)
end

#stopObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vagabond/server.rb', line 26

def stop
  if(lxc.exists?)
    if(lxc.running?)
      ui.info 'Shutting down Chef server container...'
      lxc.shutdown
      ui.info 'Chef server container shut down!'
    else
      ui.error 'Chef server container not currently running'
    end
  else
    ui.error 'Chef server container has not been created'
  end
end

#upload_cookbooksObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/vagabond/server.rb', line 98

def upload_cookbooks
  am_uploading('cookbooks') do
    if(vagabondfile[:local_chef_server][:librarian])
      librarian_upload
    elsif(vagabondfile[:local_chef_server][:berkshelf])
      berks_upload
    else
      if(File.exists?(File.join(vagabondfile.directory, 'Cheffile')))
        librarian_upload
      elsif(File.exists?(File.join(vagabondfile.directory, 'Berksfile')))
        berks_upload
      else
        raw_upload
      end
    end
  end
end

#upload_databagsObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vagabond/server.rb', line 65

def upload_databags
  am_uploading('data bags') do
    if(File.directory?(File.join(base_dir, 'data_bags')))
      Dir.glob(File.join(base_dir, "data_bags/*")).each do |b|
        next if %w(. ..).include?(b) || !File.directory?(b)
        coms = [
          "data bag create #{File.basename(b)}",
          "data bag from file #{File.basename(b)} --all"
        ].each do |com|
          cmd = knife_command(com)
          cmd.run_command
          cmd.error!
        end
      end
    end
  end
end

#upload_environmentsObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/vagabond/server.rb', line 84

def upload_environments
  am_uploading('environments') do
    if(File.directory?(File.join(base_dir, 'environments')))
      %w(rb json js).each do |ext|
        next if Dir.glob(File.join(base_dir, "environments", "*.#{ext}")).size == 0
        cmd = knife_command("environment from file #{File.join(base_dir, "environments/*.#{ext}")}")
        cmd.run_command
        cmd.error!
      end
    end
  end
end

#upload_rolesObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vagabond/server.rb', line 51

def upload_roles
  am_uploading('roles') do
    if(File.directory?(File.join(base_dir, 'roles')))
      %w(rb json js).each do |ext|
        next if Dir.glob(File.join(base_dir, "roles", "*.#{ext}")).size == 0
        cmd = knife_command("role from file #{File.join(base_dir, "roles/*.#{ext}")}")
        cmd.run_command
        cmd.error!
      end
    end
  end
end