Class: Chef::Knife::XenserverSrList
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::XenserverSrList
- Includes:
- XenserverBase
- Defined in:
- lib/chef/knife/xenserver_sr_list.rb
Instance Method Summary collapse
Methods included from XenserverBase
#bytes_to_megabytes, #connection, included, #locate_config_value
Instance Method Details
#run ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/chef/knife/xenserver_sr_list.rb', line 39 def run # Finding the current host (the one we used to get the connection) #xshost = config[:xenserver_host] || Chef::Config[:knife][:xenserver_host] #address = Resolv.getaddress xshost #host = connection.hosts.find { |h| h.address == address } # Storage Repositories belong to the pool, # There's no way to list host storage repositories AFAIK repositories = connection.storage_repositories table = table do |t| t.headings = %w{NAME TYPE UTILISATION UUID} valid_types = config[:sr_type].split(',').map { |t| t.strip } repositories.each do |sr| # we only list LVM and EXT repositories by default next unless valid_types.include? sr.type if config[:numeric_utilisation] utilisation = sr.physical_utilisation else if sr.physical_size.to_i > 0 utilisation = (sr.physical_utilisation.to_i * 100)/sr.physical_size.to_f * 100 utilisation = "%.2f%" % utilisation else utilisation = "100%" end end t << [sr.name, sr.type, utilisation, sr.uuid] end end puts table if !repositories.empty? end |