Class: KnifeTopo::TopoDelete
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- KnifeTopo::TopoDelete
- Includes:
- CommandHelper, Loader
- Defined in:
- lib/chef/knife/topo_delete.rb
Overview
knife topo delete
Instance Attribute Summary
Attributes included from Loader
Instance Method Summary collapse
- #confirm_and_delete_nodes ⇒ Object
- #delete_topo ⇒ Object
-
#remove_node_from_topology(node_name) ⇒ Object
Remove the topo name attribute from all nodes, so topo search knows they are not in the topology.
- #run ⇒ Object
- #validate_args ⇒ Object
Methods included from Loader
#auto_detect_format, #check_file, #create_topo_bag, #get_local_topo_path, #list_topo_bag, #load_local_topo_or_exit, #load_node_data, #load_topo_from_file_or_exit, #load_topo_from_server, #load_topo_from_server_or_exit, #priority_attrs, #topo_bag_name, #topologies_path
Methods included from CommandHelper
#check_chef_env, #initialize_cmd_args, #most_common, #resource_exists?, #run_cmd
Instance Method Details
#confirm_and_delete_nodes ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/chef/knife/topo_delete.rb', line 67 def confirm_and_delete_nodes confirm("Do you want to delete topology #{@topo_name} - " \ 'this does not delete nodes') @topo['nodes'].each do |node| remove_node_from_topology(node['name']) end if @topo['nodes'] end |
#delete_topo ⇒ Object
75 76 77 78 |
# File 'lib/chef/knife/topo_delete.rb', line 75 def delete_topo @topo.destroy(topo_bag_name, @topo_name) ui.info "Deleted topology #{@topo_name}" end |
#remove_node_from_topology(node_name) ⇒ Object
Remove the topo name attribute from all nodes, so topo search knows they are not in the topology
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/chef/knife/topo_delete.rb', line 82 def remove_node_from_topology(node_name) # load then update and save the node node = Chef::Node.load(node_name) if node['topo'] && node['topo']['name'] == @topo_name node.rm('topo', 'name') ui.info "Removing node #{node.name} from topology" node.save end node rescue Net::HTTPServerException => e raise unless e.to_s =~ /^404/ # Node has not been created end |
#run ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chef/knife/topo_delete.rb', line 42 def run validate_args config[:disable_editing] = true # remove each node @topo = load_topo_from_server(@topo_name) unless @topo ui.info "Topology #{topo_bag_name}/#{@topo_name} does not " \ 'exist on server' exit(0) end confirm_and_delete_nodes delete_topo end |
#validate_args ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/chef/knife/topo_delete.rb', line 58 def validate_args unless @name_args[0] show_usage ui.fatal('You must specify the name of a topology') exit 1 end @topo_name = @name_args[0] end |