Class: VagrantPlugins::VMM::Provider

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ Provider

Returns a new instance of Provider.



32
33
34
35
36
37
38
# File 'lib/vagrant-vmm/provider.rb', line 32

def initialize(machine)
  @machine = machine
  @state_id = nil
  # This method will load in our driver, so we call it now to
  # initialize it.
  machine_id_changed
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



12
13
14
# File 'lib/vagrant-vmm/provider.rb', line 12

def driver
  @driver
end

Class Method Details

.usable?(raise_error = false) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vagrant-vmm/provider.rb', line 14

def self.usable?(raise_error=false)
  if !Vagrant::Util::Platform.windows?
    raise Errors::WindowsRequired
    return false
  end

  if !Vagrant::Util::Platform.windows_admin?
    raise Errors::AdminRequired
  end

  if !Vagrant::Util::PowerShell.available?
    raise Errors::PowerShellRequired
    return false
  end

  true
end

Instance Method Details

#action(name) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/vagrant-vmm/provider.rb', line 40

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

#current_stateObject



53
54
55
# File 'lib/vagrant-vmm/provider.rb', line 53

def current_state
  @state_id
end

#machine_id_changedObject



49
50
51
# File 'lib/vagrant-vmm/provider.rb', line 49

def machine_id_changed
  @driver = Driver.new(@machine)
end

#reset_stateObject



57
58
59
# File 'lib/vagrant-vmm/provider.rb', line 57

def reset_state
  @state_id = nil
end

#ssh_infoObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/vagrant-vmm/provider.rb', line 87

def ssh_info
  # We can only SSH into a running machine
  return nil if state.id != :running
  address = @machine.provider_config.vm_address || @machine.config.winrm.host
  if !address
    #TODO: call wait_for_ip_address
    return nil
  end

  {
    host: address,
    port: 22,
  }
end

#stateObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/vagrant-vmm/provider.rb', line 61

def state
  @state_id = :not_created if !@machine.id

  if !@state_id || @state_id == :not_created
    env = @machine.action(:read_state)
    @state_id = env[:machine_state_id]
  end

  # Get the short and long description
  short = @state_id.to_s
  long  = ""

  # If we're not created, then specify the special ID flag
  if @state_id == :not_created
    @state_id = Vagrant::MachineState::NOT_CREATED_ID
  end

  # Return the MachineState object
  Vagrant::MachineState.new(@state_id, short, long)
end

#to_sObject



82
83
84
85
# File 'lib/vagrant-vmm/provider.rb', line 82

def to_s
  id = @machine.id.nil? ? "new" : @machine.id
  "VMM (#{id})"
end