class Capacity

Constants

CAPACITY_TYPES

Public Instance Methods

capacity_to_s(capacity, entity) click to toggle source
   # File lib/cloudstack-cli/commands/capacity.rb
52 def capacity_to_s(capacity, entity)
53   value = CAPACITY_TYPES[capacity['type']][:divider] ?
54     (capacity[entity] / CAPACITY_TYPES[capacity['type']][:divider]).round(1) :
55     capacity[entity]
56   CAPACITY_TYPES[capacity['type']][:unit] ?
57     "#{value} #{CAPACITY_TYPES[capacity['type']][:unit]}" :
58     value.to_s
59 end
list() click to toggle source
   # File lib/cloudstack-cli/commands/capacity.rb
19 def list
20   resolve_zone
21   resolve_cluster
22   capacities = client.list_capacity(options)
23   table = []
24   header = ["Zone", "Type", "Capacity Used", "Capacity Total", "Used"]
25   header[0] = "Cluster" if options[:cluster_id]
26   capacities.each do |c|
27     if CAPACITY_TYPES.include? c['type']
28       table << [
29         c['clustername'] || c['zonename'],
30         CAPACITY_TYPES[c['type']][:name],
31         capacity_to_s(c, 'capacityused'),
32         capacity_to_s(c, 'capacitytotal'),
33         "#{c['percentused']}%"
34       ]
35     end
36   end
37   table = table.sort {|a, b| [a[0], a[1]] <=> [b[0], b[1]]}
38   print_table table.insert(0, header)
39 end
types() click to toggle source
   # File lib/cloudstack-cli/commands/capacity.rb
42 def types
43   table = [['type', 'name']]
44   CAPACITY_TYPES.each_pair do |type, data|
45     table << [type, data[:name]]
46   end
47   print_table table
48 end