Class: ChefMetalCrowbar::CrowbarDriver

Inherits:
ChefMetal::Driver
  • Object
show all
Defined in:
lib/chef_metal_crowbar/crowbar_driver.rb

Direct Known Subclasses

Providers::Core

Constant Summary collapse

AVAILABLE_DEPLOYMENT =
'available'
RESERVED_DEPLOYMENT =
'reserved'
TARGET_NODE_ROLE =
"crowbar-managed-node"
KEY_ATTRIB =
"chef-server_admin_client_key"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver_url, config) ⇒ CrowbarDriver

Returns a new instance of CrowbarDriver.



45
46
47
# File 'lib/chef_metal_crowbar/crowbar_driver.rb', line 45

def initialize(driver_url, config)
  super(driver_url, config)
end

Class Method Details

.from_url(driver_url, config) ⇒ Object

Passed in a driver_url, and a config in the format of Driver.config.



41
42
43
# File 'lib/chef_metal_crowbar/crowbar_driver.rb', line 41

def self.from_url(driver_url, config)
  CrowbarDriver.new(driver_url, config)
end

Instance Method Details

#allocate_machine(action_handler, machine_spec, machine_options) ⇒ Object

Acquire a machine, generally by provisioning it. Returns a Machine object pointing at the machine, allowing useful actions like setup, converge, execute, file and directory.



58
59
60
61
62
63
64
# File 'lib/chef_metal_crowbar/crowbar_driver.rb', line 58

def allocate_machine(action_handler, machine_spec, machine_options)
  Core.connect crowbar_url

  # If the server does not exist, create it
  create_servers(action_handler, { machine_spec => machine_options }, Chef::ChefFS::Parallelizer.new(0))
  machine_spec
end

#crowbar_apiObject



49
50
51
52
53
# File 'lib/chef_metal_crowbar/crowbar_driver.rb', line 49

def crowbar_api
  # relies on url & driver_config from Driver superclass
  scheme, crowbar_url = url.split(':', 2)
  Crowbar::Core.connect crowbar_url, driver_config
end

#machine_for(machine_spec, machine_options) ⇒ Object



106
107
108
109
110
111
112
113
114
115
# File 'lib/chef_metal_crowbar/crowbar_driver.rb', line 106

def machine_for(machine_spec, machine_options)
  server_id = machine_spec.location['server_id']
  ssh_options = {
    :auth_methods => ['publickey'],
    :keys => [ get_key('bootstrapkey') ],
  }
  transport = ChefMetal::Transport::SSHTransport.new(server_id, ssh_options, {}, config)
  convergence_strategy = ChefMetal::ConvergenceStrategy::InstallCached.new(machine_options[:convergence_options])
  ChefMetal::Machine::UnixMachine.new(machine_spec, transport, convergence_strategy)
end

#ready_machine(action_handler, machine_spec, machine_options) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/chef_metal_crowbar/crowbar_driver.rb', line 87

def ready_machine(action_handler, machine_spec, machine_options)
  server_id = machine_spec.location['server_id']
  server = crowbar_api.node(server_id)
  if server["alive"] == 'false'
    action_handler.perform_action "Powering up machine #{server_id}" do
      crowbar_api.power(server_id, "on")
    end
  end

  if server["state"] != 0
    action_handler.perform_action "wait for machine #{server_id}" do
      crowbar_api.wait_for_machine_to_have_status(server_id, 0)
    end
  end

  # Return the Machine object
  machine_for(machine_spec, machine_options)
end