Module: Chef::Provisioning::VboxDriver

Defined in:
lib/chef/provisioning/vbox_driver/driver.rb,
lib/chef/provisioning/vbox_driver/version.rb

Defined Under Namespace

Classes: Driver

Constant Summary collapse

VERSION =
'0.1.9'

Instance Method Summary collapse

Instance Method Details

#connect_to_machine(machine_spec, machine_options) ⇒ Object



124
125
126
# File 'lib/chef/provisioning/vbox_driver/driver.rb', line 124

def connect_to_machine(machine_spec, machine_options)
  machine_for(machine_spec, machine_options)
end

#destroy_machine(action_handler, machine_spec, machine_options) ⇒ Object



104
105
106
107
108
109
110
111
112
113
# File 'lib/chef/provisioning/vbox_driver/driver.rb', line 104

def destroy_machine(action_handler, machine_spec, machine_options)
  if machine_spec.reference
    server_id = machine_spec.reference['server_id']
    action_handler.perform_action "Destroy machine #{server_id}" do
      vbox.power_off(server_id)
      vbox.destroy_machine(server_id)
      machine_spec.reference = nil
    end
  end
end

#machine_for(machine_spec, machine_options) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/chef/provisioning/vbox_driver/driver.rb', line 91

def machine_for(machine_spec, machine_options)
  server_id = machine_spec.reference['server_id']
  hostname = vbox.get_hostname()
  username = 'root'
  ssh_options = {
    :auth_methods => ['publickey'],
    :keys => [ get_key('bootstrapkey') ],
  }
  transport = Chef::Provisioning::Transport::SSH.new(vbox.get_hostname(server_id), username, ssh_options, {}, config)
  convergence_strategy = Chef::Provisioning::ConvergenceStrategy::InstallCached.new(machine_options[:convergence_options], {})
  Chef::Provisioning::Machine::UnixMachine.new(machine_spec, transport, convergence_strategy)
end

#ready_machine(action_handler, machine_spec, machine_options) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/chef/provisioning/vbox_driver/driver.rb', line 74

def ready_machine(action_handler, machine_spec, machine_options)
 server_id = machine_spec.reference['server_id']
 if vbox.machine_status(server_id) == 'stopped'
   action_handler.perform_action "Powering up machine #{server_id}" do
     vbox.power_on(server_id)
   end
 end

 if vbox.machine_status(server_id) != 'ready'
   action_handler.perform_action "wait for machine #{server_id}" do
     vbox.wait_for_machine_to_have_status(server_id, 'ready')
   end
 end
 # Return the Machine object
 machine_for(machine_spec, machine_options)
end

#stop_machine(action_handler, machine_spec, machine_options) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/chef/provisioning/vbox_driver/driver.rb', line 115

def stop_machine(action_handler, machine_spec, machine_options)
  if machine_spec.reference
    server_id = machine_spec.reference['server_id']
    action_handler.perform_action "Power off machine #{server_id}" do
      vbox.power_off(server_id)
    end
  end
end