Class: Vagrant::Hostmaster::VM
- Inherits:
-
Object
- Object
- Vagrant::Hostmaster::VM
- Extended by:
- Forwardable
- Defined in:
- lib/vagrant/hostmaster/vm.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(options = {}) ⇒ Object
- #hosts_path ⇒ Object
-
#initialize(vm) ⇒ VM
constructor
A new instance of VM.
- #list(options = {}) ⇒ Object
- #remove(options = {}) ⇒ Object
- #update(options = {}) ⇒ Object
Constructor Details
#initialize(vm) ⇒ VM
Returns a new instance of VM.
20 21 22 |
# File 'lib/vagrant/hostmaster/vm.rb', line 20 def initialize(vm) @vm = vm end |
Class Method Details
.expand_path(relative_path, relative_to) ⇒ Object
11 12 13 |
# File 'lib/vagrant/hostmaster/vm.rb', line 11 def (relative_path, relative_to) File.(relative_path, relative_to) end |
.hosts_path ⇒ Object
15 16 17 |
# File 'lib/vagrant/hostmaster/vm.rb', line 15 def hosts_path Util::Platform.windows? ? ('system32/drivers/etc/hosts', ENV['SYSTEMROOT']) : '/etc/hosts' end |
Instance Method Details
#add(options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/vagrant/hostmaster/vm.rb', line 24 def add( = {}) .merge! config_to_h if process_local?() env.ui.info("Adding host entry for #{name} VM. Administrator privileges will be required...") unless [:quiet] sudo add_command end with_other_vms { |vm| channel.sudo vm.add_command(:uuid => uuid, :hosts_path => hosts_path) } if process_guests?() end |
#hosts_path ⇒ Object
34 35 36 37 |
# File 'lib/vagrant/hostmaster/vm.rb', line 34 def hosts_path # TODO: if windows guests are supported, this will need to be smarter "/etc/hosts" end |
#list(options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vagrant/hostmaster/vm.rb', line 39 def list( = {}) .merge! config_to_h if process_local?() output = `#{list_command}`.chomp env.ui.info("[local] #{output}\n\n", :prefix => false) unless output.empty? end if process_guests?() entries = "" with_other_vms do |vm| channel.execute(vm.list_command(:uuid => uuid, :hosts_path => hosts_path), :error_check => false) do |type, data| entries << data if type == :stdout end end entries = entries.split($/).collect { |entry| "[#{name}] #{entry}" }.join("\n") env.ui.info("#{entries}\n\n", :prefix => false) unless entries.empty? end end |
#remove(options = {}) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/vagrant/hostmaster/vm.rb', line 58 def remove( = {}) .merge! config_to_h if process_local?() env.ui.info("Removing host entry for #{name} VM. Administrator privileges will be required...") unless [:quiet] sudo remove_command end with_other_vms { |vm| channel.sudo vm.remove_command(:uuid => uuid, :hosts_path => hosts_path) } if process_guests?() end |
#update(options = {}) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/vagrant/hostmaster/vm.rb', line 67 def update( = {}) .merge! config_to_h if process_local?() env.ui.info("Updating host entry for #{name} VM. Administrator privileges will be required...") unless [:quiet] sudo(remove_command) && sudo(add_command) end with_other_vms { |vm| channel.sudo(vm.remove_command(:uuid => uuid, :hosts_path => hosts_path)) && channel.sudo(vm.add_command(:uuid => uuid, :hosts_path => hosts_path)) } if process_guests?() end |