class NodeUpdate::NodeUpdateFromFile
Public Instance Methods
loader()
click to toggle source
# File lib/chef/knife/update_from_file.rb, line 30 def loader @loader ||= ::Chef::Knife::Core::ObjectLoader.new(Chef::Node, ui) end
run()
click to toggle source
# File lib/chef/knife/update_from_file.rb, line 46 def run file_path = @name_args[0] updated = loader.load_from("nodes", file_path) node_name = updated.name ui.info("Looking for #{node_name}") result = searcher.search(:node, "name:#{node_name}") node = result.first.first if node.nil? ui.warn("Could not find a node named #{node_name}") result = ui.ask_question("Create a new one? (Y/N)", :default => "y").upcase if ['Y', 'YES'].include?(result) system( *%W{knife node from file #{file_path}}) else ui.info("Exiting to system") exit 1 end else update_node(node, updated) ui.info("Saving the updated node #{@node_name}") node.save end end
searcher()
click to toggle source
# File lib/chef/knife/update_from_file.rb, line 34 def searcher @searcher ||= ::Chef::Search::Query.new end
update_node(node, updated)
click to toggle source
# File lib/chef/knife/update_from_file.rb, line 38 def update_node(node, updated) node.normal_attrs = Chef::Mixin::DeepMerge.merge(node.normal_attrs, updated.normal_attrs) node.override_attrs = Chef::Mixin::DeepMerge.merge(node.override_attrs, updated.override_attrs) node.run_list(updated.run_list) node.chef_environment(updated.chef_environment) node end