Skip to content

Commit 782320c

Browse files
committed
Fixing node webui for 3 attrs
1 parent 583c5b3 commit 782320c

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

‎chef-server-api/app/controllers/nodes.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def update
6767

6868
updated=params['inflated_object']
6969
@node.run_list.reset!(updated.run_list)
70-
@node.attribute=updated.attribute
70+
@node.normal_attrs=updated.normal_attrs
7171
@node.override_attrs=updated.override_attrs
7272
@node.default_attrs=updated.default_attrs
7373
@node.cdb_save

‎chef-server-webui/app/controllers/nodes.rb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ def create
8686
begin
8787
@node=Chef::Node.new
8888
@node.nameparams[:name]
89-
@node.attribute=JSON.parse(params[:attributes])
89+
@node.normal_attrs=JSON.parse(params[:attributes])
9090
@node.run_list.reset!(params[:for_node] ? params[:for_node] : [])
9191
raiseArgumentError,"Node name cannot be blank"if(params[:name].nil? || params[:name].length==0)
9292
@node.create
9393
redirect(slice_url(:nodes),:message=>{:notice=>"Created Node #{@node.name}"})
9494
rescue=>e
9595
Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
96-
@node.attribute=JSON.parse(params[:attributes])
96+
@node.normal_attrs=JSON.parse(params[:attributes])
9797
@available_recipes=get_available_recipes
9898
@available_roles=Chef::Role.list.keys.sort
9999
@node.run_listparams[:for_node]
@@ -107,7 +107,7 @@ def update
107107
begin
108108
@node=Chef::Node.load(params[:id])
109109
@node.run_list.reset!(params[:for_node] ? params[:for_node] : [])
110-
@node.attribute=JSON.parse(params[:attributes])
110+
@node.normal_attrs=JSON.parse(params[:attributes])
111111
@node.save
112112
@_message={:notice=>"Updated Node"}
113113
render:show

‎chef-server-webui/app/views/nodes/_form.html.haml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
%div.group.form{:style => "position:relative;"}
4444
%label.label Attributes
45-
= partial '../layout/jsonedit', :json =>@node.attribute.to_json
45+
= partial '../layout/jsonedit', :json =>@node.normal_attrs.to_json
4646
%div.group.form
4747
%span.description A JSON hash for default attributes for nodes of this node. These attributes will only be applied if the node does not already have a value for the attributes.
4848

‎chef-server-webui/app/views/nodes/show.html.haml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@
5656

5757
.left
5858
%h3 Attributes
59-
= build_tree('attrs', @node.attribute, default_attrs, override_attrs)
59+
= build_tree('attrs', @node.normal_attrs, default_attrs, override_attrs)
6060

‎chef/lib/chef/node.rb‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ def name(arg=nil)
195195
defattribute
196196
Chef::Node::Attribute.new(@normal_attrs,@default_attrs,@override_attrs)
197197
end
198+
199+
defattribute=(value)
200+
@normal_attrs=value
201+
end
198202

199203
# Return an attribute of this node. Returns nil if the attribute is not found.
200204
def [](attrib)
@@ -212,25 +216,25 @@ def store(attrib, value)
212216

213217
# Set a normal attribute of this node, but auto-vivifiy any Mashes that
214218
# might be missing
215-
defset
219+
defnormal
216220
attrs=Chef::Node::Attribute.new(@normal_attrs,@default_attrs,@override_attrs)
217221
attrs.set_type=:normal
218222
attrs.auto_vivifiy_on_read=true
219223
attrs
220224
end
221225

222-
alias_method:normal,:set
226+
alias_method:set,:normal
223227

224228
# Set a normal attribute of this node, auto-vivifiying any mashes that are
225229
# missing, but if the final value already exists, don't set it
226-
defset_unless
230+
defnormal_unless
227231
attrs=Chef::Node::Attribute.new(@normal_attrs,@default_attrs,@override_attrs)
228232
attrs.set_type=:normal
229233
attrs.auto_vivifiy_on_read=true
230234
attrs.set_unless_value_present=true
231235
attrs
232236
end
233-
alias_method:normal_unless,:set_unless
237+
alias_method:set_unless,:normal_unless
234238

235239
# Set a default of this node, but auto-vivifiy any Mashes that might
236240
# be missing
@@ -293,7 +297,10 @@ def each_attribute(&block)
293297
# to set the attribute values. Otherwise, we'll wind up just returning the attributes
294298
# value.
295299
defmethod_missing(symbol, *args)
296-
Chef::Node::Attribute.new(@normal_attrs,@default_attrs,@override_attrs).send(symbol, *args)
300+
attrs=Chef::Node::Attribute.new(@normal_attrs,@default_attrs,@override_attrs)
301+
attrs.set_type=:normal
302+
attrs.auto_vivify_on_read=true
303+
attrs.send(symbol, *args)
297304
end
298305

299306
# Returns true if this Node expects a given recipe, false if not.
@@ -342,9 +349,9 @@ def to_hash
342349
index_hash=Hash.new
343350
index_hash["chef_type"]="node"
344351
index_hash["name"]=@name
345-
index_hash["normal"]=@normal_attrs
346-
index_hash["default"]=@default_attrs
347-
index_hash["override"]=@override_attrs
352+
attribute.eachdo |key,value|
353+
index_hash[key]=value
354+
end
348355
index_hash["recipe"]=@run_list.recipesif@run_list.recipes.length > 0
349356
index_hash["role"]=@run_list.rolesif@run_list.roles.length > 0
350357
index_hash["run_list"]=@run_list.run_listif@run_list.run_list.length > 0

‎chef/spec/unit/node_spec.rb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@
327327
@node.run_list << "role[leninist]"
328328
@node.run_list << "recipe[stalinist]"
329329
h=@node.to_hash
330-
h["default"].should == @node.default_attrs
331-
h["override"].should == @node.override_attrs
332-
h["normal"].should == @node.normal_attrs
330+
h["one"]["two"].should == "three"
331+
h["one"]["four"].should == "six"
332+
h["one"]["eight"].should == "nine"
333333
h["role"].shouldbe_include("marxist")
334334
h["role"].shouldbe_include("leninist")
335335
h["run_list"].shouldbe_include("role[marxist]")

0 commit comments

Comments
(0)