Class: Vagrant::Hostmaster::VM

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vagrant/hostmaster/vm.rb

Instance Method Summary collapse

Constructor Details

#initialize(vm) ⇒ VM

Returns a new instance of VM.



10
11
12
# File 'lib/vagrant/hostmaster/vm.rb', line 10

def initialize(vm)
  @vm = vm
end

Instance Method Details

#add(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/vagrant/hostmaster/vm.rb', line 14

def add(options = {})
  if process_local?(options)
    env.ui.info("Adding host entry for #{name} VM. Administrator privileges will be required...") unless options[:quiet]
    sudo add_command
  end

  with_other_vms { |vm| channel.sudo vm.add_command(uuid) } if process_guests?(options)
end

#list(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant/hostmaster/vm.rb', line 23

def list(options = {})
  if process_local?(options)
    output = `#{list_command}`.chomp
    env.ui.info("Local host entry for #{name}...\n#{output}\n\n", :prefix => false) unless output.empty?
  end

  if process_guests?(options)
    entries = []
    with_other_vms do |vm|
      entry = ""
      channel.execute(vm.list_command(uuid), :error_check => false) do |type, data|
        entry << data if type == :stdout
      end
      entry.chomp!
      entries << entry unless entry.empty?
    end
    env.ui.info("Guest host #{entries.size > 1 ? 'entries' : 'entry'} on #{name}...\n#{entries.join("\n")}\n\n", :prefix => false) unless entries.empty?
  end
end

#remove(options = {}) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/vagrant/hostmaster/vm.rb', line 43

def remove(options = {})
  if process_local?(options)
    env.ui.info("Removing host entry for #{name} VM. Administrator privileges will be required...") unless options[:quiet]
    sudo remove_command
  end
  with_other_vms { |vm| channel.sudo vm.remove_command(uuid) } if process_guests?(options)
end

#update(options = {}) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/vagrant/hostmaster/vm.rb', line 51

def update(options = {})
  if process_local?(options)
    env.ui.info("Updating host entry for #{name} VM. Administrator privileges will be required...") unless options[:quiet]
    sudo(remove_command) && sudo(add_command)
  end
  with_other_vms { |vm| channel.sudo(vm.remove_command(uuid)) && channel.sudo(vm.add_command(uuid)) } if process_guests?(options)
end