-
-
Save meineerde/7580432 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NodeUpdateFromFile < ::Chef::Knife | |
deps do | |
require "chef/node" | |
require "chef/json_compat" | |
require "chef/knife/core/object_loader" | |
end | |
banner "knife node update from file FILE (options)" | |
def loader | |
@loader ||= ::Chef::Knife::Core::ObjectLoader.new(Chef::Node, ui) | |
end | |
def run | |
update = loader.load_from("nodes", @name_args[0]) | |
begin | |
node = ::Chef::Node.load(update.name) | |
rescue Net::HTTPServerException | |
ui.info("Could not load existing node #{update.name}, assuming new node.") | |
node = ::Chef::Node.new | |
node.name(update.name) | |
end | |
# Replace attributes, run_list, and chef_environment from the new node | |
# definition. | |
node.normal_attrs = update.normal_attrs | |
node.override_attrs = update.override_attrs | |
node.default_attrs = update.default_attrs | |
node.run_list.reset!(update.run_list) | |
node.chef_environment(update.chef_environment) | |
# Expand the run_list in case it has changed | |
node.expand! | |
node.save | |
output(format_for_display(node)) if config[:print_after] | |
ui.info("Updated Node #{update.name}!") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment