summaryrefslogtreecommitdiff
path: root/lib/chef/node.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2015-09-09 18:17:48 -0700
committerdanielsdeleo <dan@chef.io>2015-09-17 14:29:49 -0700
commit01be9b1e91e515eb76de43a1e448e5476bd56574 (patch)
tree0d63197047ef25996a909f86c69e2aa178d02db0 /lib/chef/node.rb
parenta59b1992cabd063bdcf1494a1a3d0edf48ffa0d5 (diff)
downloadchef-01be9b1e91e515eb76de43a1e448e5476bd56574.tar.gz
Add policy_name and policy_group attrs to Node class
Diffstat (limited to 'lib/chef/node.rb')
-rw-r--r--lib/chef/node.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 22c7d5bd8e..65ed21a442 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -63,6 +63,8 @@ class Chef
include Chef::Mixin::ParamsValidate
+ NULL_ARG = Object.new
+
# Create a new Chef::Node object.
def initialize(chef_server_rest: nil)
@chef_server_rest = chef_server_rest
@@ -72,6 +74,9 @@ class Chef
@primary_runlist = Chef::RunList.new
@override_runlist = Chef::RunList.new
+ @policy_name = nil
+ @policy_group = nil
+
@attributes = Chef::Node::Attribute.new({}, {}, {}, {})
@run_state = {}
@@ -132,6 +137,50 @@ class Chef
alias :environment :chef_environment
+ # The `policy_name` for this node. Setting this to a non-nil value will
+ # enable policyfile mode when `chef-client` is run. If set in the config
+ # file or in node json, running `chef-client` will update this value.
+ #
+ # @see Chef::PolicyBuilder::Dynamic
+ # @see Chef::PolicyBuilder::Policyfile
+ #
+ # @param arg [String] the new policy_name value
+ # @return [String] the current policy_name, or the one you just set
+ def policy_name(arg=NULL_ARG)
+ return @policy_name if arg.equal?(NULL_ARG)
+ validate({policy_name: arg}, { policy_name: { kind_of: [ String, NilClass ], regex: /^[\-:.[:alnum:]_]+$/ } })
+ @policy_name = arg
+ end
+
+ # A "non-DSL-style" setter for `policy_name`
+ #
+ # @see #policy_name
+ def policy_name=(policy_name)
+ policy_name(policy_name)
+ end
+
+ # The `policy_group` for this node. Setting this to a non-nil value will
+ # enable policyfile mode when `chef-client` is run. If set in the config
+ # file or in node json, running `chef-client` will update this value.
+ #
+ # @see Chef::PolicyBuilder::Dynamic
+ # @see Chef::PolicyBuilder::Policyfile
+ #
+ # @param arg [String] the new policy_group value
+ # @return [String] the current policy_group, or the one you just set
+ def policy_group(arg=NULL_ARG)
+ return @policy_group if arg.equal?(NULL_ARG)
+ validate({policy_group: arg}, { policy_group: { kind_of: [ String, NilClass ], regex: /^[\-:.[:alnum:]_]+$/ } })
+ @policy_group = arg
+ end
+
+ # A "non-DSL-style" setter for `policy_group`
+ #
+ # @see #policy_group
+ def policy_group=(policy_group)
+ policy_group(policy_group)
+ end
+
def attributes
@attributes
end