From 1646ceb6b92aac327efac8ec0cc71ae92f284337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 10 Feb 2015 14:45:02 +0100 Subject: [PATCH] Allow to configure the ssh port to connect to when creating a new server It can be useful, for example when using snapshots of load balancers that run SSH on a different port. --- README.rdoc | 2 ++ lib/chef/knife/brightbox_server_create.rb | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 6f07439..de7697e 100644 --- a/README.rdoc +++ b/README.rdoc @@ -68,6 +68,8 @@ Provisions a new server in the Brightbox Cloud and then perform a Chef bootstrap You can specify the Brightbox zone your new server will use using the `--zone` switch. By default it is `gb1-a`. It can also be `gb1-b` at the time of this writing. See `knife brightbox zone list` to request a current list from the API. +You can specify the ssh port to connect to using the `--ssh-port` switch. By default it is `22`. + == knife brightbox server delete Deletes an existing server in the currently configured Brightbox Cloud account by the server/instance id. You can find the instance id by entering 'knife brightbox server list'. You can specify the `--purge` flag to delete the associated node and client objects from the Chef server along with the cloup ip. diff --git a/lib/chef/knife/brightbox_server_create.rb b/lib/chef/knife/brightbox_server_create.rb index d2f0318..21a18ce 100644 --- a/lib/chef/knife/brightbox_server_create.rb +++ b/lib/chef/knife/brightbox_server_create.rb @@ -110,6 +110,13 @@ class BrightboxServerCreate < Knife :description => "The ssh username; default is 'root'", :default => "root" + option :ssh_port, + :short => "-p PORT", + :long => "--ssh-port PORT", + :description => "The ssh port", + :default => 22, + :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key.to_i } + option :first_boot_attributes, :short => "-j JSON_ATTRIBS", :long => "--json-attributes", @@ -136,7 +143,7 @@ class BrightboxServerCreate < Knife :proc => Proc.new { |z| Chef::Config[:zone] = z } def tcp_test_ssh(hostname) - tcp_socket = TCPSocket.new(hostname, 22) + tcp_socket = TCPSocket.new(hostname, config[:ssh_port]) readable = IO.select([tcp_socket], nil, nil, 5) if readable Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}") @@ -222,6 +229,7 @@ def bootstrap_for_node(server) bootstrap.name_args = [server.cloud_ips.first['public_ip']] bootstrap.config[:run_list] = config[:run_list] bootstrap.config[:ssh_user] = config[:ssh_user] || "root" + bootstrap.config[:ssh_port] = config[:ssh_port] bootstrap.config[:identity_file] = config[:identity_file] bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.name || server.id bootstrap.config[:bootstrap_version] = locate_config_value(:bootstrap_version)