]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
added --ip and --port override flags to deploy and init.
authorelijah <elijah@riseup.net>
Tue, 11 Jun 2013 16:41:26 +0000 (09:41 -0700)
committerelijah <elijah@riseup.net>
Tue, 11 Jun 2013 16:41:26 +0000 (09:41 -0700)
lib/leap_cli/commands/deploy.rb
lib/leap_cli/commands/node.rb
lib/leap_cli/commands/shell.rb
lib/leap_cli/util/remote_command.rb

index 12e829458b931b64cc4c45a0b277e5944103e93d..8130111c99d1b7effdb72248bbf78901483b60fb 100644 (file)
@@ -18,6 +18,12 @@ module LeapCli
       c.flag :tags, :desc => 'Specify tags to pass through to puppet (overriding the default).',
                     :default_value => DEFAULT_TAGS.join(','), :arg_name => 'TAG[,TAG]'
 
+      c.flag :port, :desc => 'Override the default SSH port.',
+                    :arg_name => 'PORT'
+
+      c.flag :ip,   :desc => 'Override the default SSH IP address.',
+                    :arg_name => 'IPADDRESS'
+
       c.action do |global,options,args|
         init_submodules
 
@@ -31,7 +37,7 @@ module LeapCli
 
         compile_hiera_files(nodes)
 
-        ssh_connect(nodes) do |ssh|
+        ssh_connect(nodes, connect_options(options)) do |ssh|
           ssh.leap.log :checking, 'node' do
             ssh.leap.assert_initialized
           end
index 12c95005278c4f4d3abf911144c8dec268ea98e6..4b5ea9eec1b3468608be33a6ede2c3ba601615c5 100644 (file)
@@ -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)
index 2822481e5fe60695baa979a97e98f8f4bc57a93e..822ef05593bd3c8165f59ebc9a75a11506844db0 100644 (file)
@@ -16,6 +16,22 @@ module LeapCli; module Commands
     end
   end
 
+  protected
+
+  #
+  # allow for ssh overrides of all commands that use ssh_connect
+  #
+  def connect_options(options)
+    connect_options = {:ssh_options=>{}}
+    if options[:port]
+      connect_options[:ssh_options][:port] = options[:port]
+    end
+    if options[:ip]
+      connect_options[:ssh_options][:host_name] = options[:ip]
+    end
+    return connect_options
+  end
+
   private
 
   def exec_ssh(cmd, args)
index db020379a2aa621e55716cf0eea00a3c1597fecb..2c77196abff2359b1ded90998027e72deae55c55 100644 (file)
@@ -9,6 +9,7 @@ module LeapCli; module Util; module RemoteCommand
   #  Capistrano::Logger::TRACE     = 3
   #
   def ssh_connect(nodes, options={}, &block)
+    options ||= {}
     node_list = parse_node_list(nodes)
 
     cap = new_capistrano
@@ -30,7 +31,7 @@ module LeapCli; module Util; module RemoteCommand
     end
 
     node_list.each do |name, node|
-      cap.server node.name, :dummy_arg, node_options(node)
+      cap.server node.name, :dummy_arg, node_options(node, options[:ssh_options])
     end
 
     yield cap
@@ -58,13 +59,14 @@ module LeapCli; module Util; module RemoteCommand
   #  password_proc = Proc.new {Capistrano::CLI.password_prompt "Root SSH password for #{node.name}"}
   #  return {:password => password_proc}
   #
-  def node_options(node)
+  def node_options(node, ssh_options_override=nil)
+    ssh_options_override ||= {}
     {
       :ssh_options => {
         :host_key_alias => node.name,
         :host_name => node.ip_address,
         :port => node.ssh.port
-      }.merge(contingent_ssh_options_for_node(node))
+      }.merge(contingent_ssh_options_for_node(node)).merge(ssh_options_override)
     }
   end