Class: ChefMetalSsh::SshDriver
- Inherits:
-
ChefMetal::Driver
- Object
- ChefMetal::Driver
- ChefMetalSsh::SshDriver
- Includes:
- MachineRegistry
- Defined in:
- lib/chef_metal_ssh/ssh_driver.rb
Overview
Provisions machines with ssh.
Instance Attribute Summary collapse
-
#cluster_path ⇒ Object
readonly
Returns the value of attribute cluster_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#allocate_machine(action_handler, machine_spec, machine_options) ⇒ Object
Acquire a machine, generally by provisioning it.
- #connect_to_machine(machine_spec, machine_options) ⇒ Object
-
#driver_url ⇒ Object
def reload_machine(action_handler, node) # Use ‘kexec` here to skip POST and BIOS and all that noise.
-
#initialize(driver_url, config) ⇒ SshDriver
constructor
Create a new ssh driver.
- #ready_machine(action_handler, machine_spec, machine_options) ⇒ Object
Methods included from MachineRegistry
#create_registration_file, #delete_provider_registration_file, #match_machine_options_to_registered, #registered_machine_is_available?, #validate_machine_options
Constructor Details
#initialize(driver_url, config) ⇒ SshDriver
Create a new ssh driver.
## Parameters cluster_path - path to the directory containing the vagrant files, which
should have been created with the vagrant_cluster resource.
28 29 30 31 32 |
# File 'lib/chef_metal_ssh/ssh_driver.rb', line 28 def initialize(driver_url, config) super scheme, cluster_path = driver_url.split(':', 2) @cluster_path = cluster_path end |
Instance Attribute Details
#cluster_path ⇒ Object (readonly)
Returns the value of attribute cluster_path.
34 35 36 |
# File 'lib/chef_metal_ssh/ssh_driver.rb', line 34 def cluster_path @cluster_path end |
Class Method Details
.canonicalize_url(driver_url, config) ⇒ Object
40 41 42 43 44 |
# File 'lib/chef_metal_ssh/ssh_driver.rb', line 40 def self.canonicalize_url(driver_url, config) scheme, cluster_path = driver_url.split(':', 2) cluster_path = File.(cluster_path || File.join(Chef::Config.config_dir, 'metal_ssh')) "ssh:#{cluster_path}" 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. 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 provides context. 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 this format:
-- provisioner_url: ssh:<@target_host>
-- target_ip: the IP address of the target machine - IP or FQDN is required
-- target_fqdn: The Resolvable name of the target machine - IP or FQDN is required
-- ssh_user: the user to ssh as
-- ssh_options: options to pass the ssh command. available options are here - https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh.rb#L61
node['normal']['provisioner_output'] will be populated with information
about the created machine. For ssh, it is a hash with this
format:
-- provisioner_url: ssh:<@target_host>
-- name: container name
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/chef_metal_ssh/ssh_driver.rb', line 73 def allocate_machine(action_handler, machine_spec, ) # TODO verify that the existing provisioner_url in the node is the same as ours ensure_ssh_cluster(action_handler) target_name = machine_spec.name target_file_path = File.join(cluster_path, "#{machine_spec.name}.json") # Chef::Log.debug("======================================>") # Chef::Log.debug("acquire_machine - provisioner_options.inspect: #{provisioner_options.inspect}") # Chef::Log.debug("======================================>") @target_host = get_target_connection_method() # Chef::Log.debug("======================================>") # Chef::Log.debug("acquire_machine - target_host: #{@target_host}") # Chef::Log.debug("======================================>") # Set up Provisioner Output # TODO - make url the chef server url path? maybe disk path if zero? machine_spec.location = { 'driver_url' => driver_url, 'driver_version' => ChefMetalSsh::VERSION, 'target_name' => target_name, 'target_file_path' => target_file_path, 'allocated_at' => Time.now.utc.to_s } # Chef::Log.debug("======================================>") # Chef::Log.debug("acquire_machine - machine_spec.inspect: #{machine_spec.inspect}") # Chef::Log.debug("======================================>") end |
#connect_to_machine(machine_spec, machine_options) ⇒ Object
111 112 113 |
# File 'lib/chef_metal_ssh/ssh_driver.rb', line 111 def connect_to_machine(machine_spec, ) machine_for(machine_spec, ) end |
#driver_url ⇒ Object
def reload_machine(action_handler, node)
# Use `kexec` here to skip POST and BIOS and all that noise.
end
159 160 161 |
# File 'lib/chef_metal_ssh/ssh_driver.rb', line 159 def driver_url "ssh:#{cluster_path}" end |
#ready_machine(action_handler, machine_spec, machine_options) ⇒ Object
107 108 109 |
# File 'lib/chef_metal_ssh/ssh_driver.rb', line 107 def ready_machine(action_handler, machine_spec, ) machine_for(machine_spec, ) end |