Class: VagrantPlugins::ProviderKvm::Provider
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderKvm::Provider
- Defined in:
- lib/vagrant-kvm/provider.rb
Instance Attribute Summary collapse
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
Instance Method Summary collapse
- #action(name) ⇒ Object
-
#initialize(machine) ⇒ Provider
constructor
A new instance of Provider.
-
#machine_id_changed ⇒ Object
If the machine ID changed, then we need to rebuild our underlying driver.
-
#read_machine_ip ⇒ String
XXX duplicated from prepare_nfs_settings Returns the IP address of the guest by looking at the first enabled host only network.
-
#ssh_info ⇒ Object
Returns the SSH info for accessing the VM.
-
#state ⇒ Symbol
Return the state of the VM.
-
#to_s ⇒ String
Returns a human-friendly string version of this provider which includes the machine’s ID that this provider represents, if it has one.
Constructor Details
#initialize(machine) ⇒ Provider
Returns a new instance of Provider.
9 10 11 12 13 14 15 16 |
# File 'lib/vagrant-kvm/provider.rb', line 9 def initialize(machine) @logger = Log4r::Logger.new("vagrant_kvm") @machine = machine # This method will load in our driver, so we call it now to # initialize it. machine_id_changed end |
Instance Attribute Details
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
7 8 9 |
# File 'lib/vagrant-kvm/provider.rb', line 7 def driver @driver end |
Instance Method Details
#action(name) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/vagrant-kvm/provider.rb', line 18 def action(name) # Attempt to get the action method from the Action class if it # exists, otherwise return nil to show that we don't support the # given action. action_method = "action_#{name}" return Action.send(action_method) if Action.respond_to?(action_method) nil end |
#machine_id_changed ⇒ Object
If the machine ID changed, then we need to rebuild our underlying driver.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vagrant-kvm/provider.rb', line 29 def machine_id_changed id = @machine.id begin @logger.debug("Instantiating the driver for machine ID: #{@machine.id.inspect}") @driver = Driver::Driver.new(id) rescue Driver::Driver::VMNotFound # The virtual machine doesn't exist, so we probably have a stale # ID. Just clear the id out of the machine and reload it. @logger.debug("VM not found! Clearing saved machine ID and reloading.") id = nil retry end end |
#read_machine_ip ⇒ String
XXX duplicated from prepare_nfs_settings Returns the IP address of the guest by looking at the first enabled host only network.
62 63 64 65 66 67 68 69 70 |
# File 'lib/vagrant-kvm/provider.rb', line 62 def read_machine_ip @machine.config.vm.networks.each do |type, | if type == :private_network && [:ip].is_a?(String) return [:ip] end end nil end |
#ssh_info ⇒ Object
Returns the SSH info for accessing the VM.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vagrant-kvm/provider.rb', line 45 def ssh_info # If the VM is not created then we cannot possibly SSH into it, so # we return nil. return nil if state == :not_created #ip_addr = @driver.read_ip(@machine.config.vm.base_mac) return { :host => read_machine_ip, :port => "22" # XXX should be somewhere in default config } end |
#state ⇒ Symbol
Return the state of the VM
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/vagrant-kvm/provider.rb', line 75 def state # XXX: What happens if we destroy the VM but the UUID is still # set here? # Determine the ID of the state here. state_id = nil state_id = :not_created if !@driver.uuid state_id = @driver.read_state if !state_id state_id = :unknown if !state_id # TODO Translate into short/long descriptions short = state_id long = I18n.t("vagrant.commands.status.#{state_id}") # Return the state Vagrant::MachineState.new(state_id, short, long) end |
#to_s ⇒ String
Returns a human-friendly string version of this provider which includes the machine’s ID that this provider represents, if it has one.
98 99 100 101 |
# File 'lib/vagrant-kvm/provider.rb', line 98 def to_s id = @machine.id ? @machine.id : "new VM" "QEMU/KVM (#{id})" end |