summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Amdor <luke.amdor@gmail.com>2014-04-16 15:25:40 -0700
committerBryan McLellan <btm@getchef.com>2014-06-05 12:19:41 -0700
commitb88db29b5ab1e388cd8f03f2aa8ce2c3018ff1a5 (patch)
tree00cb2d4064e1e648a9c09ac4eb53e2d283073001
parent5c6492da1466048eb259a523fbf38345c1018567 (diff)
downloadchef-b88db29b5ab1e388cd8f03f2aa8ce2c3018ff1a5.tar.gz
making the chef-zero host configurable for knife and chef-client
-rw-r--r--lib/chef/application.rb4
-rw-r--r--lib/chef/application/client.rb5
-rw-r--r--lib/chef/application/knife.rb4
-rw-r--r--lib/chef/config.rb1
-rw-r--r--lib/chef/knife.rb1
-rw-r--r--spec/integration/knife/common_options_spec.rb9
6 files changed, 22 insertions, 2 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index bf19a53c8b..ca610480d0 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -198,9 +198,9 @@ class Chef::Application
server_options = {}
server_options[:data_store] = data_store
server_options[:log_level] = Chef::Log.level
- server_options[:port] = Chef::Config.chef_zero.port
server_options[:host] = Chef::Config.chef_zero.host
- Chef::Log.info("Starting chef-zero on port #{Chef::Config.chef_zero.port} with repository at #{chef_fs.fs_description}")
+ server_options[: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::Config.chef_server_url = @chef_zero_server.url
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb
index 5772c9c32e..e9973a1131 100644
--- a/lib/chef/application/client.rb
+++ b/lib/chef/application/client.rb
@@ -211,6 +211,10 @@ class Chef::Application::Client < Chef::Application
:description => "Point chef-client at local repository",
:boolean => true
+ option :chef_zero_host,
+ :long => "--chef-zero-host HOST",
+ :description => "Host to start chef-zero on"
+
option :chef_zero_port,
:long => "--chef-zero-port PORT",
:description => "Port to start chef-zero on"
@@ -250,6 +254,7 @@ class Chef::Application::Client < Chef::Application
if Chef::Config.local_mode && !Chef::Config.has_key?(:cookbook_path) && !Chef::Config.has_key?(:chef_repo_path)
Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
end
+ Chef::Config.chef_zero.host = config[:chef_zero_host] if config[:chef_zero_host]
Chef::Config.chef_zero.port = config[:chef_zero_port] if config[:chef_zero_port]
if Chef::Config[:daemonize]
diff --git a/lib/chef/application/knife.rb b/lib/chef/application/knife.rb
index 5f2456311c..6b5105a4f4 100644
--- a/lib/chef/application/knife.rb
+++ b/lib/chef/application/knife.rb
@@ -114,6 +114,10 @@ class Chef::Application::Knife < Chef::Application
:description => "Point knife commands at local repository instead of server",
:boolean => true
+ option :chef_zero_host,
+ :long => "--chef-zero-host HOST",
+ :description => "Host to start chef-zero on"
+
option :chef_zero_port,
:long => "--chef-zero-port PORT",
:description => "Port to start chef-zero on"
diff --git a/lib/chef/config.rb b/lib/chef/config.rb
index a797f0a542..dd1b44661b 100644
--- a/lib/chef/config.rb
+++ b/lib/chef/config.rb
@@ -324,6 +324,7 @@ class Chef
config_context :chef_zero do
config_strict_mode true
default(:enabled) { Chef::Config.local_mode }
+ default :host, '127.0.0.1'
default :port, 8889
default :host, 'localhost'
end
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb
index 5cbc968980..f8622975e8 100644
--- a/lib/chef/knife.rb
+++ b/lib/chef/knife.rb
@@ -394,6 +394,7 @@ class Chef
if Chef::Config.local_mode && !Chef::Config.has_key?(:cookbook_path) && !Chef::Config.has_key?(:chef_repo_path)
Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
end
+ Chef::Config.chef_zero.host = config[:chef_zero_host] if config[:chef_zero_host]
Chef::Config.chef_zero.port = config[:chef_zero_port] if config[:chef_zero_port]
# Expand a relative path from the config directory. Config from command
diff --git a/spec/integration/knife/common_options_spec.rb b/spec/integration/knife/common_options_spec.rb
index 00e3131ed4..c9b16d50c0 100644
--- a/spec/integration/knife/common_options_spec.rb
+++ b/spec/integration/knife/common_options_spec.rb
@@ -50,6 +50,15 @@ describe 'knife common options' do
end
end
+ context 'And chef_zero.host is 0.0.0.0' do
+ before(:each) { Chef::Config.chef_zero.host = '0.0.0.0' }
+
+ it 'knife raw /nodes/x should retrieve the role' do
+ knife('raw /nodes/x').should_succeed /"name": "x"/
+ Chef::Config.chef_server_url.should == 'http://0.0.0.0:8889'
+ end
+ end
+
context 'and there is a private key' do
file 'mykey.pem', <<EOM
-----BEGIN RSA PRIVATE KEY-----