Class: Vagabond::Knife

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions, Helpers
Defined in:
lib/vagabond/knife.rb

Instance Method Summary collapse

Methods included from Helpers

included

Constructor Details

#initialize(*args) ⇒ Knife

Returns a new instance of Knife.



18
19
20
# File 'lib/vagabond/knife.rb', line 18

def initialize(*args)
  super
end

Instance Method Details

#knife(command, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vagabond/knife.rb', line 23

def knife(command, *args)
  @options = options.dup
  @vagabondfile = Vagabondfile.new(options[:vagabond_file])
  options[:disable_solo] = true
  options[:sudo] = sudo
  Lxc.use_sudo = @vagabondfile[:sudo].nil? ? true : @vagabondfile[:sudo]
  @internal_config = InternalConfiguration.new(@vagabondfile, nil, options)
  unless(options[:local_server])
    if(@vagabondfile[:local_chef_server] && @vagabondfile[:local_chef_server][:enabled])
      srv = Lxc.new(@internal_config[:mappings][:server])
      if(srv.running?)
        proto = @vagabondfile[:local_chef_server][:zero] ? 'http' : 'https'
        options[:knife_opts] = " --server-url #{proto}://#{srv.container_ip(10, true)}"
      else
        options[:knife_opts] = ' -s https://no-local-server'
      end
    end
  end
  command_string = [command, args.map{|s| "'#{s}'"}].flatten.compact.join(' ')
  if(ENV['VAGABOND_KNIFE_DEBUG'])
    puts "knife #{command_string} #{options[:knife_opts]}"
  end
  exec("knife #{command_string} #{options[:knife_opts]}")
end