Class: Chef::Knife::XapiGuestDelete
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::XapiGuestDelete
- Includes:
- XapiBase
- Defined in:
- lib/chef/knife/xapi_guest_delete.rb
Instance Attribute Summary
Attributes included from XapiBase
Instance Method Summary collapse
Methods included from XapiBase
#add_vif_by_name, #cleanup, #clear_vm_vifs, #color_kv, #create_vbd, #create_vdi, defaults, #destroy_vdi, #detach_vdi, #fail, #find_default_sr, #find_template, #generate_mac, #get_all_vdis, get_default, #get_guest_ip, #get_host_ref, #get_sr_by_name, #get_sr_by_uuid, #get_task_ref, #get_template, #get_vbd_by_uuid, #get_vbds_from_vdi, #get_vdi_by_name_label, #get_vdi_by_uuid, #h, included, #input_to_bytes, #is_uuid?, #locate_config_value, #print_record, #print_vdi_info, set_defaults, #start, #stop, #user_select, #wait_on_task, #xapi, #yes_no?
Instance Method Details
#run ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/chef/knife/xapi_guest_delete.rb', line 50 def run server_name = @name_args[0] if server_name.nil? puts 'Error: No VM Name specified...' puts 'Usage: ' + exit 1 end name = server_name if config[:uuid] name = get_name_label(vm) end vms = [] if config[:uuid] vms << xapi.VM.get_by_uuid(server_name) else vms << xapi.VM.get_by_name_label(server_name) end vms.flatten! if vms.empty? puts "VM not found: #{h.color server_name, :red}" exit 1 elsif vms.length > 1 puts 'Multiple VM matches found use guest list if you are unsure' vm = user_select(vms) else vm = vms.first end # Cleanup the VM if vm == :all vms.each { |vm| cleanup(vm) } else cleanup(vm) end ############################################# # Delete client and node on the chef server # ############################################# unless config[:keep_client] client_list = Chef::ApiClient.list if client_list.key?(name) ui.msg "Removing client #{h.color name, :cyan} from chef" delete_object(Chef::ApiClient, name) else puts 'Client not found on the chef server.. Nothing to delete..' end end unless config[:keep_node] env = Chef::Config[:environment] node_list = env ? Chef::Node.list_by_environment(env) : Chef::Node.list if node_list.key?(name) ui.msg "Removing node #{h.color name, :cyan} from chef " delete_object(Chef::Node, name) else puts 'Node not found on the chef server.. Nothing to delete..' end end end |