Class: ChefMetal::Provisioner

Inherits:
Object
  • Object
show all
Defined in:
lib/chef_metal/provisioner.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inflate(node) ⇒ Object

Inflate a provisioner from node information; we don’t want to force the driver to figure out what the provisioner really needs, since it varies from provisioner to provisioner.

## Parameters node - node to inflate the provisioner for

returns a should return a Privisoner from the information provided



13
14
15
# File 'lib/chef_metal/provisioner.rb', line 13

def self.inflate(node)
  raise "#{self.class} does not override self.inflate"
end

Instance Method Details

#acquire_machine(action_handler, node) ⇒ 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. The Machine object will have a “node” property which must be saved to the server (if it is any different from the original node object).

## Parameters action_handler - the action_handler object that is calling this method; this

is generally a provider, but could be anything that can support the
interface (i.e., in the case of the test kitchen metal driver for
acquiring and destroying VMs).

node - node object (deserialized json) representing this machine. If

the node has a provisioner_options hash in it, these will be used
instead of options provided by the provisioner.  TODO compare and
fail if different?
node will have node['normal']['provisioner_options'] in it with any
options. It is a hash with at least these options:

   -- provisioner_url: <provisioner url>

node['normal']['provisioner_output'] will be populated with
information about the created machine.  For vagrant, it is a hash
with at least these options:

   -- provisioner_url: <provisioner url>


43
44
45
# File 'lib/chef_metal/provisioner.rb', line 43

def acquire_machine(action_handler, node)
  raise "#{self.class} does not override acquire_machine"
end

#acquire_machines(action_handler, nodes_json, parallelizer) ⇒ Object

Acquire machines in batch, in parallel if possible.



81
82
83
84
85
86
87
# File 'lib/chef_metal/provisioner.rb', line 81

def acquire_machines(action_handler, nodes_json, parallelizer)
  parallelizer.parallelize(nodes_json) do |node_json|
    machine = acquire_machine(add_prefix(node_json, action_handler), node_json)
    yield node_json, machine if block_given?
    machine
  end.to_a
end

#connect_to_machine(node) ⇒ Object

Connect to a machine without acquiring it. This method will NOT make any changes to anything.

## Parameters node - node object (deserialized json) representing this machine. The

node may have normal attributes "provisioner_options" and
"provisioner_output" in it, representing the input and output of
any prior "acquire_machine" process (if any).


56
57
58
# File 'lib/chef_metal/provisioner.rb', line 56

def connect_to_machine(node)
  raise "#{self.class} does not override connect_to_machine"
end

#delete_machine(action_handler, node) ⇒ Object

Delete the given machine (idempotent). Should destroy the machine, returning things to the state before acquire_machine was called.



62
63
64
# File 'lib/chef_metal/provisioner.rb', line 62

def delete_machine(action_handler, node)
  raise "#{self.class} does not override delete_machine"
end

#delete_machines(action_handler, nodes_json, parallelizer) ⇒ Object

Delete machines in batch, in parallel if possible.



98
99
100
101
102
103
# File 'lib/chef_metal/provisioner.rb', line 98

def delete_machines(action_handler, nodes_json, parallelizer)
  parallelizer.parallelize(nodes_json) do |node_json|
    delete_machine(add_prefix(node_json, action_handler), node_json)
    yield node_json if block_given?
  end.to_a
end

#resource_created(machine) ⇒ Object

Provider notification that happens at the point a resource is declared (after all properties have been set on it)



73
74
# File 'lib/chef_metal/provisioner.rb', line 73

def resource_created(machine)
end

#stop_machine(action_handler, node) ⇒ Object

Stop the given machine.



67
68
69
# File 'lib/chef_metal/provisioner.rb', line 67

def stop_machine(action_handler, node)
  raise "#{self.class} does not override stop_machine"
end

#stop_machines(action_handler, nodes_json, parallelizer) ⇒ Object

Stop machines in batch, in parallel if possible.



90
91
92
93
94
95
# File 'lib/chef_metal/provisioner.rb', line 90

def stop_machines(action_handler, nodes_json, parallelizer)
  parallelizer.parallelize(nodes_json) do |node_json|
    stop_machine(add_prefix(node_json, action_handler), node_json)
    yield node_json if block_given?
  end.to_a
end