Class: Chef::Knife::LparDelete
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::LparDelete
- Includes:
- LparBase
- Defined in:
- lib/chef/knife/lpar_delete.rb
Instance Method Summary collapse
- #delete_lpar ⇒ Object
-
#read_and_validate_params ⇒ Object
Reads the input parameters and validates them.
-
#run ⇒ Object
Run the plugin.
Methods included from LparBase
#get_password, #print_with_output, #run_remote_command
Instance Method Details
#delete_lpar ⇒ Object
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/chef/knife/lpar_delete.rb', line 73 def delete_lpar Net::SSH.start(@name_args[0], "hscroot", :password => @password) do |ssh| # some background checks # check for existing lpar with name ui.info "Verifying #{config[:name]} exists" command = "lssyscfg -m #{config[:virtual_server]} -F name -r lpar --filter \"lpar_names=#{config[:name]}\"" output = run_remote_command(ssh, command) unless output.eql? config[:name] ui.fatal output Kernel.exit(1) end # Check to see if it's running ui.info "Verifying #{config[:name]} is not running" command = "lssyscfg -m #{config[:virtual_server]} -F state -r lpar --filter \"lpar_names=#{config[:name]}\"" output = run_remote_command(ssh, command) unless output.eql? "Not Activated" ui.fatal output Kernel.exit(1) end # first let's find the host mapping ui.info "Searching for host mapping" command = "lssyscfg -m #{config[:virtual_server]} --filter \"lpar_names=#{config[:name]}\" -F lpar_id -r lpar" output = run_remote_command(ssh, command) # and of course it doesn't match, 0 based vs 1 based counting vhost = output.to_i - 1 vhost_name = "vhost#{vhost}" print_with_output("Found host id of #{output} - mapping to #{vhost_name}", nil) # mapping for the drive ui.info "Searching for vscsi mapping" command = "lssyscfg -m #{config[:virtual_server]} -r prof --filter \"lpar_names=#{config[:name]}\" -F virtual_scsi_adapters" output = run_remote_command(ssh, command) vscsi_id = output.match('.*\/.*\/.*\/.*\/(.*)\/.*')[1] print_with_output("Found vscsi mapping #{vscsi_id}", output) # find the mapping for the vopt ui.info "Searching for vtopt mapping" command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"lsmap -vadapter #{vhost_name} -type file_opt -field vtd -fmt \\\":\\\"\"" vtopt_id = run_remote_command(ssh, command) print_with_output("Found vtopt mapping #{vtopt_id}", output) # find lv mapping ui.info "Searching for logical volume mapping" command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"lsmap -vadapter #{vhost_name} -type lv -field vtd -fmt \\\":\\\"\"" lv_id = run_remote_command(ssh, command) print_with_output("Found lv mapping #{lv_id}", output) # find lv backing device ui.info "Searching for lv backing device" command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"lsmap -vadapter #{vhost_name} -type lv -field backing -fmt \\\":\\\"\"" backing_device = run_remote_command(ssh, command) print_with_output("Found device #{backing_device}") # now delete the file backed optical drive mapping ui.info "Removing #{vtopt_id}" command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"rmvdev -vtd #{vtopt_id}\"" output = run_remote_command(ssh, command) print_with_output("#{vtopt_id} Removed", output) # now delete the vtscsi device ui.info "Removing vscsi #{lv_id}" command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"rmvdev -vtd #{lv_id}\"" output = run_remote_command(ssh, command) print_with_output("#{lv_id} Removed", output) # now delete the logical volume ui.info "Removing lv #{backing_device}" command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"rmlv -f #{backing_device}\"" output = run_remote_command(ssh, command) print_with_output("#{backing_device} Removed", output) # now that we know the id, let's remove it from the virtual io server ui.info "Removing vtscsi mapping from vios" command = "chhwres -r virtualio -m #{config[:virtual_server]} -o r -p #{config[:vios]} --rsubtype scsi -s #{vscsi_id}" output = run_remote_command(ssh, command) print_with_output("Mapping Removed", output) # save the virtual io server profile ui.info "Saving updated vios profile on #{config[:vios]}" command = "mksyscfg -r prof -m #{config[:virtual_server]} -o save -p #{config[:vios]} -n `lssyscfg -r lpar -m #{config[:virtual_server]} --filter \"lpar_names=#{config[:vios]}\" -F curr_profile` --force" output = run_remote_command(ssh, command) print_with_output("Profile Saved", output) # now remove the lpar completely ui.info "Removing #{config[:name]} completely" command = "rmsyscfg -r lpar -m #{config[:virtual_server]} -n #{config[:name]}" output = run_remote_command(ssh, command) print_with_output("#{config[:name]} Terminated", output) end end |
#read_and_validate_params ⇒ Object
Reads the input parameters and validates them. Will exit if it encounters an error
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chef/knife/lpar_delete.rb', line 59 def read_and_validate_params if @name_args.length < 1 show_usage exit 1 end if config[:name].nil? || config[:vios].nil? || config[:virtual_server].nil? show_usage exit 1 end end |
#run ⇒ Object
Run the plugin
49 50 51 52 53 |
# File 'lib/chef/knife/lpar_delete.rb', line 49 def run read_and_validate_params @password = get_password delete_lpar end |