Class: Chef::Knife::HmcDiskList
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::HmcDiskList
- Includes:
- HmcBase
- Defined in:
- lib/chef/knife/hmc_disk_list.rb
Instance Method Summary collapse
-
#print_header ⇒ Object
print_header => Prints table header for disk list.
-
#print_line(vio1_disk, vio2_disk) ⇒ Object
print_line => Prints a single line of the output table given two Lun objects representing the same disk on a pair of VIOs.
- #run ⇒ Object
Methods included from HmcBase
#get_config, included, #tcp_ssh_alive, #validate, #validate!
Instance Method Details
#print_header ⇒ Object
print_header
> Prints table header for disk list
147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/chef/knife/hmc_disk_list.rb', line 147 def print_header if validate([:lpar]) puts "Listing information on all disks attached to #{get_config(:lpar)}\n" elsif get_config(:only_available) puts "Listing only available disks on this VIO Pair\n" elsif get_config(:only_used) puts "Listing only used disks on this VIO Pair\n" else puts "Listing all disks on this VIO Pair\n" end printf "%-20s %10s %20s %20s\n", "PVID", "Size (MB)", "Name (on #{get_config(:primary_vio)})", "Name (on #{get_config(:secondary_vio)})" printf "-----------------------------------------------------------------------------------------\n" end |
#print_line(vio1_disk, vio2_disk) ⇒ Object
print_line
> Prints a single line of the output table
given two Lun objects representing the same
disk on a pair of VIOs
168 169 170 |
# File 'lib/chef/knife/hmc_disk_list.rb', line 168 def print_line(vio1_disk,vio2_disk) printf "%-20s %10s %20s %20s\n", vio1_disk.pvid, "#{vio1_disk.size_in_mb} MB", vio1_disk.name, vio2_disk.name end |
#run ⇒ Object
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 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 |
# File 'lib/chef/knife/hmc_disk_list.rb', line 54 def run Chef::Log.debug("Listing disks...") validate! hmc = Hmc.new(get_config(:hmc_host), get_config(:hmc_username) , {:password => get_config(:hmc_password)}) hmc.connect validate!([:primary_vio,:secondary_vio,:frame]) frame = get_config(:frame) primary_vio_name = get_config(:primary_vio) secondary_vio_name = get_config(:secondary_vio) #Make Vio objects for the two VIOs primary_vio = Vio.new(hmc,frame,primary_vio_name) secondary_vio = Vio.new(hmc,frame,secondary_vio_name) #Arrays that will hold the disks to list vio1_disks = [] vio2_disks = [] if validate([:lpar]) #Show only disks attached to the specified LPAR lpar_name = get_config(:lpar) = hmc.(frame,lpar_name) lpar = Lpar.new() #Get the vSCSIs from this LPAR and determine the virtual adapter #slots used by each VIO vscsi_adapters = lpar.get_vscsi_adapters primary_vio_slot = nil secondary_vio_slot = nil adapter_cnt=0 vscsi_adapters.each do |adapter| if adapter.remote_lpar_name == primary_vio.name primary_vio_slot = adapter.remote_slot_num adapter_cnt += 1 elsif adapter.remote_lpar_name == secondary_vio.name secondary_vio_slot = adapter.remote_slot_num adapter_cnt += 1 end end if primary_vio_slot.nil? or secondary_vio_slot.nil? or adapter_cnt != 2 #Could not determine which vSCSIs to use error = "Unable to determine which vSCSI adapters have storage attached to it from #{primary_vio_name} and #{secondary_vio_name}\n" + "Cannot list disks attached to #{lpar_name}" puts "#{error}" ui.error(error) exit 1 end #Find the vhosts that hold this LPARs disks primary_vhost = primary_vio.find_vhost_given_virtual_slot(primary_vio_slot) secondary_vhost = secondary_vio.find_vhost_given_virtual_slot(secondary_vio_slot) #Get the names (known to the VIOs) of the disks attached to the LPAR vio1_disks = primary_vio.get_attached_disks(primary_vhost) vio2_disks = secondary_vio.get_attached_disks(secondary_vhost) elsif get_config(:only_available) #Show only available disks vio1_disks = primary_vio.available_disks vio2_disks = secondary_vio.available_disks elsif get_config(:only_used) #Show only used disks vio1_disks = primary_vio.used_disks vio2_disks = secondary_vio.used_disks else #None of :lpar, :only_available, and :only_used options were specified. #Show used *and* available disks vio1_disks = primary_vio.available_disks + primary_vio.used_disks vio2_disks = secondary_vio.available_disks + secondary_vio.used_disks end #List the disks populated in vio1_disks and vio2_disks print_header vio1_disks.each do |v1_disk| vio2_disks.each do |v2_disk| if v1_disk == v2_disk print_line(v1_disk,v2_disk) end end end hmc.disconnect end |