Class: VagrantPlugins::ProviderZone::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-zones/provider.rb

Overview

This is a module to assist in managing, creating bhyve, kvm, and lx zones

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ Provider

Returns a new instance of Provider.



12
13
14
15
16
# File 'lib/vagrant-zones/provider.rb', line 12

def initialize(machine)
  @logger = Log4r::Logger.new('vagrant::provider::zone')
  @machine = machine
  super(machine)
end

Instance Method Details

#action(name) ⇒ Object

This should return an action callable for the given name.

Parameters:

  • name (Symbol)

    Name of the action.

Returns:

  • (Object)

    A callable action sequence object, whether it is a proc, object, etc.



46
47
48
49
50
51
52
53
54
# File 'lib/vagrant-zones/provider.rb', line 46

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

#driverObject



18
19
20
21
22
# File 'lib/vagrant-zones/provider.rb', line 18

def driver
  return @driver if @driver

  @driver = Driver.new(@machine)
end

#machine_id_changedObject

This method is called if the underying machine ID changes. Providers can use this method to load in new data for the actual backing machine or to realize that the machine is now gone (the ID can become ‘nil`). No parameters are given, since the underlying machine is simply the machine instance given to this object. And no return value is necessary.



62
63
64
# File 'lib/vagrant-zones/provider.rb', line 62

def machine_id_changed
  nil
end

#ssh_infoObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vagrant-zones/provider.rb', line 24

def ssh_info
  # We just return nil if were not able to identify the VM's IP and
  # let Vagrant core deal with it like docker provider does
  return nil if state.id != :running
  return nil unless driver.get_ip_address('ssh_info')

  passwordauth = 'passwordauth'
  ssh_info = {
    host: driver.get_ip_address('ssh_info'),
    port: driver.sshport(@machine).to_s,
    password: driver.vagrantuserpass(@machine).to_s,
    username: driver.user(@machine),
    private_key_path: driver.userprivatekeypath(@machine).to_s,
    PasswordAuthentication: passwordauth
  }
  ssh_info unless ssh_info.nil?
end

#stateObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/vagrant-zones/provider.rb', line 66

def state
  state_id = nil
  state_id = :not_created unless @machine.id
  state_id = driver.state(@machine) if @machine.id && !state_id
  # This is a special pseudo-state so that we don't set the
  # NOT_CREATED_ID while we're setting up the machine. This avoids
  # clearing the data dir.
  state_id = :preparing if @machine.id == 'preparing'
  # Get the short and long description
  short = state_id.to_s.tr('_', ' ')
  # If we're not created, then specify the special ID flag
  state_id = Vagrant::MachineState::NOT_CREATED_ID if state_id == :not_created
  # Return the MachineState object
  Vagrant::MachineState.new(state_id, short, short)
end