diff options
author | John Keiser <jkeiser@opscode.com> | 2014-06-30 10:33:48 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2014-07-07 10:04:59 -0700 |
commit | c5956378e9035af7f05e1be1c7741b50de7eb84c (patch) | |
tree | 33feaf826e9dd3126b7515d5b4a7b9cd339dc1c5 /lib/chef | |
parent | b536215ece2183584188c3a304c2322de2f2a4ff (diff) | |
download | chef-c5956378e9035af7f05e1be1c7741b50de7eb84c.tar.gz |
Support --chef-zero-port=A-B,C,D-E syntax for finding ports
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/application.rb | 25 | ||||
-rw-r--r-- | lib/chef/application/client.rb | 2 | ||||
-rw-r--r-- | lib/chef/application/knife.rb | 2 | ||||
-rw-r--r-- | lib/chef/config.rb | 2 |
4 files changed, 27 insertions, 4 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb index ca610480d0..c77fcd5ee7 100644 --- a/lib/chef/application.rb +++ b/lib/chef/application.rb @@ -199,10 +199,11 @@ class Chef::Application server_options[:data_store] = data_store server_options[:log_level] = Chef::Log.level server_options[:host] = Chef::Config.chef_zero.host - server_options[:port] = Chef::Config.chef_zero.port + server_options[:port] = Chef::Application.parse_port(Chef::Config.chef_zero.port) Chef::Log.info("Starting chef-zero on host #{Chef::Config.chef_zero.host}, port #{Chef::Config.chef_zero.port} with repository at #{chef_fs.fs_description}") @chef_zero_server = ChefZero::Server.new(server_options) @chef_zero_server.start_background + Chef::Log.info("chef-zero started at #{@chef_zero_server.url}") Chef::Config.chef_server_url = @chef_zero_server.url end end @@ -240,6 +241,28 @@ class Chef::Application Chef::Application.destroy_server_connectivity end + def self.parse_port(port) + if port.is_a?(String) + parts = port.split(',') + if parts.size == 1 + a,b = parts[0].split('-',2) + if b + a.to_i.upto(b.to_i) + else + [ a.to_i ] + end + else + array = [] + parts.each do |part| + array += parse_port(part).to_a + end + array + end + else + port + end + end + private def apply_config(config_content, config_file_path) diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index e9973a1131..c581bb0da0 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -217,7 +217,7 @@ class Chef::Application::Client < Chef::Application option :chef_zero_port, :long => "--chef-zero-port PORT", - :description => "Port to start chef-zero on" + :description => "Port (or port range) to start chef-zero on. Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works." option :config_file_jail, :long => "--config-file-jail PATH", diff --git a/lib/chef/application/knife.rb b/lib/chef/application/knife.rb index e838e44632..d3e2f55757 100644 --- a/lib/chef/application/knife.rb +++ b/lib/chef/application/knife.rb @@ -120,7 +120,7 @@ class Chef::Application::Knife < Chef::Application option :chef_zero_port, :long => "--chef-zero-port PORT", - :description => "Port to start chef-zero on" + :description => "Port (or port range) to start chef-zero on. Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works." option :version, :short => "-v", diff --git a/lib/chef/config.rb b/lib/chef/config.rb index 0ac82cc5ac..65952b8cf7 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -325,7 +325,7 @@ class Chef config_strict_mode true default(:enabled) { Chef::Config.local_mode } default :host, 'localhost' - default :port, 8889 + default :port, 8889.upto(9999) # Will try ports from 8889-9999 until one works end default :chef_server_url, "https://localhost:443" |