summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam Jacob <adam@hjksolutions.com>2008-05-09 14:29:29 -0700
committerAdam Jacob <adam@hjksolutions.com>2008-05-09 14:29:29 -0700
commita125c8a450c4368bfdb1668679dd7153d53757c6 (patch)
tree4e44d0c46bd20099c1d93f84c5b449363f30300b /lib
parent2f1c4c662c3b1d999258796152273eac7b7b9ae8 (diff)
downloadchef-a125c8a450c4368bfdb1668679dd7153d53757c6.tar.gz
Factoring out find_file instead of just find for nodes
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/node.rb31
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index c5be016ec8..f8adf5983f 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -50,18 +50,9 @@ class Chef
#
# Raises an ArgumentError if it cannot find the node.
def self.find(fqdn)
- node_file = nil
- host_parts = fqdn.split(".")
- hostname = host_parts[0]
-
- if File.exists?(File.join(Chef::Config[:node_path], "#{fqdn}.rb"))
- node_file = File.join(Chef::Config[:node_path], "#{fqdn}.rb")
- elsif File.exists?(File.join(Chef::Config[:node_path], "#{hostname}.rb"))
- node_file = File.join(Chef::Config[:node_path], "#{hostname}.rb")
- elsif File.exists?(File.join(Chef::Config[:node_path], "default.rb"))
- node_file = File.join(Chef::Config[:node_path], "default.rb")
- else
- raise ArgumentError, "Cannot find a node matching #{fqdn}, not even with default.rb!"
+ node_file = self.find_file(fqdn)
+ unless node_file
+ raise ArgumentError, "Cannot find a node matching #{fqdn}, not even with default.rb!"
end
chef_node = Chef::Node.new()
chef_node.from_file(node_file)
@@ -79,6 +70,22 @@ class Chef
results
end
+ # Returns the file name we would use to build a node. Returns nil if it cannot find
+ # a file for this node.
+ def self.find_file(fqdn)
+ node_file = nil
+ host_parts = fqdn.split(".")
+ hostname = host_parts[0]
+
+ if File.exists?(File.join(Chef::Config[:node_path], "#{fqdn}.rb"))
+ node_file = File.join(Chef::Config[:node_path], "#{fqdn}.rb")
+ elsif File.exists?(File.join(Chef::Config[:node_path], "#{hostname}.rb"))
+ node_file = File.join(Chef::Config[:node_path], "#{hostname}.rb")
+ elsif File.exists?(File.join(Chef::Config[:node_path], "default.rb"))
+ node_file = File.join(Chef::Config[:node_path], "default.rb")
+ end
+ end
+
# Set the name of this Node, or return the current name.
def name(arg=nil)
if arg != nil