summaryrefslogtreecommitdiff
path: root/lib/chef/cookbook_version.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-08-01 12:29:12 -0700
committerdanielsdeleo <dan@opscode.com>2013-08-02 09:29:05 -0700
commite4fd4f0e00bc64abb5acf6517593063e2666ea7e (patch)
treef666cde81ea63c59dae13d9361ac8c1684aadec9 /lib/chef/cookbook_version.rb
parentf3262fc1d1ba12bf31de6dff421c8e77d6692bc7 (diff)
downloadchef-e4fd4f0e00bc64abb5acf6517593063e2666ea7e.tar.gz
Add methods to query for template/file existence in run context
- Convenience methods added to CookbookVersion to query if a cookbook file or template is available for a given node in that cookbook - Convenience methods added to RunContext to query the existence of cookbook files or templates
Diffstat (limited to 'lib/chef/cookbook_version.rb')
-rw-r--r--lib/chef/cookbook_version.rb32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 4e8b2a048e..5bd0ca064c 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -265,6 +265,18 @@ class Chef
end
end
+ # Query whether a template file +template_filename+ is available. File
+ # specificity for the given +node+ is obeyed in the lookup.
+ def has_template_for_node?(node, template_filename)
+ !!find_preferred_manifest_record(node, :templates, template_filename)
+ end
+
+ # Query whether a cookbook_file file +cookbook_filename+ is available. File
+ # specificity for the given +node+ is obeyed in the lookup.
+ def has_cookbook_file_for_node?(node, cookbook_filename)
+ !!find_preferred_manifest_record(node, :files, cookbook_filename)
+ end
+
# Determine the most specific manifest record for the given
# segment/filename, given information in the node. Throws
# FileNotFound if there is no such segment and filename in the
@@ -278,14 +290,7 @@ class Chef
# :checksum => "1234"
# }
def preferred_manifest_record(node, segment, filename)
- preferences = preferences_for_path(node, segment, filename)
-
- # ensure that we generate the manifest, which will also generate
- # @manifest_records_by_path
- manifest
-
- # in order of prefernce, look for the filename in the manifest
- found_pref = preferences.find {|preferred_filename| @manifest_records_by_path[preferred_filename] }
+ found_pref = find_preferred_manifest_record(node, segment, filename)
if found_pref
@manifest_records_by_path[found_pref]
else
@@ -567,6 +572,17 @@ class Chef
private
+ def find_preferred_manifest_record(node, segment, filename)
+ preferences = preferences_for_path(node, segment, filename)
+
+ # ensure that we generate the manifest, which will also generate
+ # @manifest_records_by_path
+ manifest
+
+ # in order of prefernce, look for the filename in the manifest
+ preferences.find {|preferred_filename| @manifest_records_by_path[preferred_filename] }
+ end
+
# For each filename, produce a mapping of base filename (i.e. recipe name
# or attribute file) to on disk location
def filenames_by_name(filenames)