Class: Vagabond::Server

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

Constant Summary

Constants included from Vagabond

BASE_TEMPLATES, COLORS, VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Vagabond

get_bytes

Constructor Details

#initialize(*args) ⇒ Server

Returns a new instance of Server.



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

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

Class Method Details

.basenameObject



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

def basename
  'vagabond server'
end

Instance Method Details

#auto_uploadObject



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

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



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

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



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/vagabond/server.rb', line 96

def upload_cookbooks
  am_uploading('cookbooks') do
    if(vagabondfile[:local_chef_server][:librarian])
      librarian_upload
    elsif(vagabondfile[:local_chef_server][:berkshelf])
      berks_upload
    else
      raw_upload
    end
  end
end

#upload_databagsObject



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

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)
        coms = [
          "knife data bag create #{File.basename(b)} #{options[:knife_opts]}",
          "knife data bag from file #{File.basename(b)} #{options[:knife_opts]} --all"
        ].each do |com|
          debug(com)
          cmd = Mixlib::ShellOut.new(com, :live_stream => options[:debug])
          cmd.run_command
          cmd.error!
        end
      end
    end
  end
end

#upload_environmentsObject



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

def upload_environments
  am_uploading('environments') do
    if(File.directory?(File.join(base_dir, 'environments')))
      com = "knife environment from file #{File.join(base_dir, 'environments/*')} #{options[:knife_opts]}"
      debug(com)
      cmd = Mixlib::ShellOut.new(com, :live_stream => options[:debug])
      cmd.run_command
      cmd.error!
    end
  end
end

#upload_rolesObject



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

def upload_roles
  am_uploading('roles') do
    if(File.directory?(File.join(base_dir, 'roles')))
      com = "knife role from file #{File.join(base_dir, 'roles/*')} #{options[:knife_opts]}"
      debug(com)
      cmd = Mixlib::ShellOut.new(com, :live_stream => options[:debug])
      cmd.run_command
      cmd.error!
    end
  end
end