class Knife::Clc::Bootstrap::Methods::SyncLinuxSsh
Attributes
cloud_adapter[R]
config[R]
connectivity_helper[R]
subcommand_loader[R]
Public Class Methods
new(params)
click to toggle source
# File lib/knife-clc/bootstrap/methods/sync_linux_ssh.rb, line 8 def initialize(params) @cloud_adapter = params.fetch(:cloud_adapter) @config = params.fetch(:config) @connectivity_helper = params.fetch(:connectivity_helper) @subcommand_loader = params.fetch(:subcommand_loader) end
Public Instance Methods
execute(server)
click to toggle source
# File lib/knife-clc/bootstrap/methods/sync_linux_ssh.rb, line 15 def execute(server) cloud_adapter.ensure_server_powered_on(server) fqdn = get_server_fqdn(server) wait_for_sshd(fqdn) command = subcommand_loader.load(:class => Chef::Knife::Bootstrap, :config => config) username, password = config.values_at(:ssh_user, :ssh_password) unless username && password creds = cloud_adapter.get_server_credentials(server) command.config.merge!(:ssh_user => creds['userName'], :ssh_password => creds['password']) end command.name_args = [fqdn] command.config[:chef_node_name] ||= server['name'] command.run end
Private Instance Methods
get_server_fqdn(server)
click to toggle source
# File lib/knife-clc/bootstrap/methods/sync_linux_ssh.rb, line 52 def get_server_fqdn(server) if indirect_bootstrap? cloud_adapter.get_private_ip(server) else cloud_adapter.get_public_ip(server) end end
indirect_bootstrap?()
click to toggle source
# File lib/knife-clc/bootstrap/methods/sync_linux_ssh.rb, line 60 def indirect_bootstrap? config[:clc_bootstrap_private] || config[:ssh_gateway] end
wait_for_sshd(hostname)
click to toggle source
# File lib/knife-clc/bootstrap/methods/sync_linux_ssh.rb, line 37 def wait_for_sshd(hostname) expire_at = Time.now + 30 port = config[:ssh_port] || 22 if gateway = config[:ssh_gateway] until connectivity_helper.test_ssh_tunnel(:host => hostname, :port => port, :gateway => gateway) raise 'Could not establish tunneled SSH connection with the server' if Time.now > expire_at end else until connectivity_helper.test_tcp(:host => hostname, :port => port) raise 'Could not establish SSH connection with the server' if Time.now > expire_at end end end