diff options
author | elijah <elijah@riseup.net> | 2013-06-11 09:41:26 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-06-11 09:41:26 -0700 |
commit | 404353dcf345122c0f04555a572efc5417f1b661 (patch) | |
tree | 322ed07b40d02da27d41a00bc46d09dbd9259011 /lib/leap_cli/commands/node.rb | |
parent | 34a8237d7172c19547b74bd972bfe908c272c4ab (diff) |
added --ip and --port override flags to deploy and init.
Diffstat (limited to 'lib/leap_cli/commands/node.rb')
-rw-r--r-- | lib/leap_cli/commands/node.rb | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/leap_cli/commands/node.rb b/lib/leap_cli/commands/node.rb index 12c9500..4b5ea9e 100644 --- a/lib/leap_cli/commands/node.rb +++ b/lib/leap_cli/commands/node.rb @@ -51,14 +51,19 @@ module LeapCli; module Commands node.arg_name 'FILTER' #, :optional => false, :multiple => false node.command :init do |init| init.switch 'echo', :desc => 'If set, passwords are visible as you type them (default is hidden)', :negatable => false + init.switch 'noping', :desc => 'If set, skip initial ping of node (in case ICMP is being blocked).', :negatable => false + init.flag :port, :desc => 'Override the default SSH port.', :arg_name => 'PORT' + init.flag :ip, :desc => 'Override the default SSH IP address.', :arg_name => 'IPADDRESS' + init.action do |global,options,args| assert! args.any?, 'You must specify a FILTER' finished = [] manager.filter!(args).each_node do |node| - ping_node(node) - save_public_host_key(node, global) + ping_node(node, options) unless options[:noping] + save_public_host_key(node, global, options) update_compiled_ssh_configs - ssh_connect(node, :bootstrap => true, :echo => options[:echo]) do |ssh| + ssh_connect_options = connect_options(options).merge({:bootstrap => true, :echo => options[:echo]}) + ssh_connect(node, ssh_connect_options) do |ssh| ssh.install_authorized_keys ssh.install_prerequisites ssh.leap.capture(facter_cmd) do |response| @@ -148,9 +153,11 @@ module LeapCli; module Commands # # see `man sshd` for the format of known_hosts # - def save_public_host_key(node, global) + def save_public_host_key(node, global, options) log :fetching, "public SSH host key for #{node.name}" - public_key = get_public_key_for_ip(node.ip_address, node.ssh.port) + address = options[:ip] || node.ip_address + port = options[:port] || node.ssh.port + public_key = get_public_key_for_ip(address, port) pub_key_path = Path.named_path([:node_ssh_pub_key, node.name]) if Path.exists?(pub_key_path) if public_key == SshKey.load_from_file(pub_key_path) @@ -187,9 +194,10 @@ module LeapCli; module Commands return SshKey.load(public_key, key_type) end - def ping_node(node) + def ping_node(node, options) + ip = options[:ip] || node.ip_address log :pinging, node.name - assert_run!("ping -W 1 -c 1 #{node.ip_address}", "Could not ping #{node.name} (address #{node.ip_address}). Try again, we only send a single ping.") + assert_run!("ping -W 1 -c 1 #{ip}", "Could not ping #{node.name} (address #{ip}). Try again, we only send a single ping.") end def seed_node_data(node, args) |