summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Jacob <adam@opscode.com>2010-04-15 22:30:30 -0700
committerAdam Jacob <adam@opscode.com>2010-04-15 22:30:30 -0700
commit782320c6198f12e04f2b49a0808a732513107023 (patch)
treea7d8cd8572d0257ca9ba22c8db7ee0477863b2ca
parent583c5b3668da7c14d94d61dc8edeabdb1390998a (diff)
downloadchef-782320c6198f12e04f2b49a0808a732513107023.tar.gz
Fixing node webui for 3 attrs
-rw-r--r--chef-server-api/app/controllers/nodes.rb2
-rw-r--r--chef-server-webui/app/controllers/nodes.rb6
-rw-r--r--chef-server-webui/app/views/nodes/_form.html.haml2
-rw-r--r--chef-server-webui/app/views/nodes/show.html.haml2
-rw-r--r--chef/lib/chef/node.rb23
-rw-r--r--chef/spec/unit/node_spec.rb6
6 files changed, 24 insertions, 17 deletions
diff --git a/chef-server-api/app/controllers/nodes.rb b/chef-server-api/app/controllers/nodes.rb
index 72128868ec..4243d3e2e8 100644
--- a/chef-server-api/app/controllers/nodes.rb
+++ b/chef-server-api/app/controllers/nodes.rb
@@ -67,7 +67,7 @@ class ChefServerApi::Nodes < ChefServerApi::Application
updated = params['inflated_object']
@node.run_list.reset!(updated.run_list)
- @node.attribute = updated.attribute
+ @node.normal_attrs = updated.normal_attrs
@node.override_attrs = updated.override_attrs
@node.default_attrs = updated.default_attrs
@node.cdb_save
diff --git a/chef-server-webui/app/controllers/nodes.rb b/chef-server-webui/app/controllers/nodes.rb
index 408884efd5..726cf6df78 100644
--- a/chef-server-webui/app/controllers/nodes.rb
+++ b/chef-server-webui/app/controllers/nodes.rb
@@ -86,14 +86,14 @@ class ChefServerWebui::Nodes < ChefServerWebui::Application
begin
@node = Chef::Node.new
@node.name params[:name]
- @node.attribute = JSON.parse(params[:attributes])
+ @node.normal_attrs = JSON.parse(params[:attributes])
@node.run_list.reset!(params[:for_node] ? params[:for_node] : [])
raise ArgumentError, "Node name cannot be blank" if (params[:name].nil? || params[:name].length==0)
@node.create
redirect(slice_url(:nodes), :message => { :notice => "Created Node #{@node.name}" })
rescue => e
Chef::Log.error("#{e}\n#{e.backtrace.join("\n")}")
- @node.attribute = JSON.parse(params[:attributes])
+ @node.normal_attrs = JSON.parse(params[:attributes])
@available_recipes = get_available_recipes
@available_roles = Chef::Role.list.keys.sort
@node.run_list params[:for_node]
@@ -107,7 +107,7 @@ class ChefServerWebui::Nodes < ChefServerWebui::Application
begin
@node = Chef::Node.load(params[:id])
@node.run_list.reset!(params[:for_node] ? params[:for_node] : [])
- @node.attribute = JSON.parse(params[:attributes])
+ @node.normal_attrs = JSON.parse(params[:attributes])
@node.save
@_message = { :notice => "Updated Node" }
render :show
diff --git a/chef-server-webui/app/views/nodes/_form.html.haml b/chef-server-webui/app/views/nodes/_form.html.haml
index 0e6abc6d5a..7407e8e971 100644
--- a/chef-server-webui/app/views/nodes/_form.html.haml
+++ b/chef-server-webui/app/views/nodes/_form.html.haml
@@ -42,7 +42,7 @@
%div.group.form{:style => "position:relative;"}
%label.label Attributes
- = partial '../layout/jsonedit', :json =>@node.attribute.to_json
+ = partial '../layout/jsonedit', :json =>@node.normal_attrs.to_json
%div.group.form
%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.
diff --git a/chef-server-webui/app/views/nodes/show.html.haml b/chef-server-webui/app/views/nodes/show.html.haml
index 4e94551adf..6a732ce85a 100644
--- a/chef-server-webui/app/views/nodes/show.html.haml
+++ b/chef-server-webui/app/views/nodes/show.html.haml
@@ -56,5 +56,5 @@
.left
%h3 Attributes
- = build_tree('attrs', @node.attribute, default_attrs, override_attrs)
+ = build_tree('attrs', @node.normal_attrs, default_attrs, override_attrs)
diff --git a/chef/lib/chef/node.rb b/chef/lib/chef/node.rb
index d63bcf7b64..516e743163 100644
--- a/chef/lib/chef/node.rb
+++ b/chef/lib/chef/node.rb
@@ -195,6 +195,10 @@ class Chef
def attribute
Chef::Node::Attribute.new(@normal_attrs, @default_attrs, @override_attrs)
end
+
+ def attribute=(value)
+ @normal_attrs = value
+ end
# Return an attribute of this node. Returns nil if the attribute is not found.
def [](attrib)
@@ -212,25 +216,25 @@ class Chef
# Set a normal attribute of this node, but auto-vivifiy any Mashes that
# might be missing
- def set
+ def normal
attrs = Chef::Node::Attribute.new(@normal_attrs, @default_attrs, @override_attrs)
attrs.set_type = :normal
attrs.auto_vivifiy_on_read = true
attrs
end
- alias_method :normal, :set
+ alias_method :set, :normal
# Set a normal attribute of this node, auto-vivifiying any mashes that are
# missing, but if the final value already exists, don't set it
- def set_unless
+ def normal_unless
attrs = Chef::Node::Attribute.new(@normal_attrs, @default_attrs, @override_attrs)
attrs.set_type = :normal
attrs.auto_vivifiy_on_read = true
attrs.set_unless_value_present = true
attrs
end
- alias_method :normal_unless, :set_unless
+ alias_method :set_unless, :normal_unless
# Set a default of this node, but auto-vivifiy any Mashes that might
# be missing
@@ -293,7 +297,10 @@ class Chef
# to set the attribute values. Otherwise, we'll wind up just returning the attributes
# value.
def method_missing(symbol, *args)
- Chef::Node::Attribute.new(@normal_attrs, @default_attrs, @override_attrs).send(symbol, *args)
+ attrs = Chef::Node::Attribute.new(@normal_attrs, @default_attrs, @override_attrs)
+ attrs.set_type = :normal
+ attrs.auto_vivify_on_read = true
+ attrs.send(symbol, *args)
end
# Returns true if this Node expects a given recipe, false if not.
@@ -342,9 +349,9 @@ class Chef
index_hash = Hash.new
index_hash["chef_type"] = "node"
index_hash["name"] = @name
- index_hash["normal"] = @normal_attrs
- index_hash["default"] = @default_attrs
- index_hash["override"] = @override_attrs
+ attribute.each do |key, value|
+ index_hash[key] = value
+ end
index_hash["recipe"] = @run_list.recipes if @run_list.recipes.length > 0
index_hash["role"] = @run_list.roles if @run_list.roles.length > 0
index_hash["run_list"] = @run_list.run_list if @run_list.run_list.length > 0
diff --git a/chef/spec/unit/node_spec.rb b/chef/spec/unit/node_spec.rb
index d271c0f5be..0e9980c1c1 100644
--- a/chef/spec/unit/node_spec.rb
+++ b/chef/spec/unit/node_spec.rb
@@ -327,9 +327,9 @@ describe Chef::Node do
@node.run_list << "role[leninist]"
@node.run_list << "recipe[stalinist]"
h = @node.to_hash
- h["default"].should == @node.default_attrs
- h["override"].should == @node.override_attrs
- h["normal"].should == @node.normal_attrs
+ h["one"]["two"].should == "three"
+ h["one"]["four"].should == "six"
+ h["one"]["eight"].should == "nine"
h["role"].should be_include("marxist")
h["role"].should be_include("leninist")
h["run_list"].should be_include("role[marxist]")