class StoragePool

Public Instance Methods

list() click to toggle source
   # File lib/cloudstack-cli/commands/storage_pool.rb
10 def list
11   resolve_zone
12   storage_pools = client.list_storage_pools(options)
13   if storage_pools.size < 1
14     say "No storage pools found."
15   else
16     case options[:format].to_sym
17     when :yaml
18       puts({storage_pools: storage_pools}.to_yaml)
19     when :json
20       puts JSON.pretty_generate(storage_pools: storage_pools)
21     else
22       storage_pools = filter_by(storage_pools, "state", options[:state]) if options[:state]
23       table = [%w(Name Pod State Zone)]
24       table[0] << "Size [GB]"
25       table[0] << "Used [GB]"
26       table[0] << "Used [%]"
27       table[0] << "Alocated [GB]"
28       table[0] << "Alocated [%]"
29       table[0] << "Type"
30       storage_pools.each do |storage_pool|
31         total = storage_pool['disksizetotal'] / 1024**3
32         used = (storage_pool['disksizeused'] / 1024**3) rescue 0
33         allocated = (storage_pool['disksizeallocated'] / 1024**3) rescue 0
34         table << [
35               storage_pool['name'], storage_pool['podname'],
36           storage_pool['state'], storage_pool['zonename'],
37           total, used, (100.0 / total * used).round(0),
38           allocated, (100.0 / total * allocated).round(0),
39           storage_pool['type']
40         ]
41       end
42       print_table table
43       say "Total number of storage_pools: #{storage_pools.size}"
44     end
45   end
46 end