Skip to content

Commit 7d6c0fb

Browse files
committed
Adding node name override to chef-client
1 parent d03717e commit 7d6c0fb

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

chef-server/lib/controllers/openid_register.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,15 @@ def create
5454
@registered_node = Chef::OpenIDRegistration.new
5555
@registered_node.name = params[:id]
5656
@registered_node.set_password(params[:password])
57-
if params[:validation_token] == Chef::Config[:validation_token]
58-
@registered_node.validated = true
59-
end
57+
if Chef::Config[:validation_token]
58+
if params[:validation_token] == Chef::Config[:validation_token]
59+
@registered_node.validated = true
60+
else
61+
@registered_node.validated = false
62+
end
63+
else
64+
@registered_node.validated = false
65+
end
6066
@registered_node.save
6167
display @registered_node
6268
end

chef/bin/chef-client

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ config = {
2929
:log_level => :info,
3030
:json_attribs => nil,
3131
:noop => false,
32-
:validation_token => nil
32+
:validation_token => nil,
33+
:node_name => nil
3334
}
3435
opts = OptionParser.new do |opts|
3536
opts.banner = "Usage: #{$0} [-d DIR|-r FILE] (options)"
@@ -39,6 +40,9 @@ opts = OptionParser.new do |opts|
3940
opts.on("-j JSON_ATTRIBS", "--json-attributes JSON_ATTRIBS", "Load attributes from a JSON file") do |j|
4041
config[:json_attribs] = j
4142
end
43+
opts.on("-N NODE_NAME", "--node-name NODE_NAME", "The node name for this client") do |n|
44+
config[:node_name] = n
45+
end
4246
opts.on("-n", "--noop", "Print what you would do, but don't actually do it.") do
4347
config[:noop] = true
4448
end
@@ -70,8 +74,6 @@ if config[:json_attribs]
7074
config[:json_attribs] = JSON.parse(IO.read(config[:json_attribs]))
7175
end
7276

73-
74-
7577
# Load our config file
7678
Chef::Config.from_file(config[:config_file])
7779
if config[:log_level]
@@ -81,4 +83,5 @@ end
8183
c = Chef::Client.new
8284
c.json_attribs = config[:json_attribs]
8385
c.validation_token = config[:validation_token]
86+
c.node_name = config[:node_name]
8487
c.run

chef/lib/chef/client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Client
2828
include Chef::Mixin::GenerateURL
2929
include Chef::Mixin::Checksum
3030

31-
attr_accessor :node, :registration, :safe_name, :json_attribs, :validation_token
31+
attr_accessor :node, :registration, :safe_name, :json_attribs, :validation_token, :node_name
3232

3333
# Creates a new Chef::Client.
3434
def initialize()
@@ -37,6 +37,7 @@ def initialize()
3737
@validation_token = nil
3838
@registration = nil
3939
@json_attribs = nil
40+
@node_name = nil
4041
@rest = Chef::REST.new(Chef::Config[:registration_url])
4142
end
4243

@@ -58,7 +59,7 @@ def run
5859
start_time = Time.now
5960
Chef::Log.info("Starting Chef Run")
6061

61-
build_node
62+
build_node(@node_name)
6263
register
6364
authenticate
6465
sync_library_files

chef/lib/chef/config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Config
5656
:openid_store_path => "/var/chef/openid/db",
5757
:openid_cstore_path => "/var/chef/openid/cstore",
5858
:file_cache_path => "/var/chef/cache",
59+
:node_name => nil,
5960
:executable_path => ENV['PATH'] ? ENV['PATH'].split(File::PATH_SEPARATOR) : []
6061
}
6162

chef/spec/unit/provider/template_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ def do_action_create
133133
end
134134

135135
describe Chef::Provider::Template, "generate_url" do
136-
137136
before(:each) do
138137
@resource = Chef::Resource::Template.new("seattle")
139138
@resource.cookbook_name = "daft"

0 commit comments

Comments
 (0)