Sha256: 8fe64fe523a05763114aa8cea0bb7ddd6a9c08841ebdcc7a9ffce39f13b72d78

Contents?: true

Size: 1.8 KB

Versions: 27

Compression:

Stored size: 1.8 KB

Contents

class Capacity < CloudstackCli::Base
  CAPACITY_TYPES = {
    0 => {name: "Memory", unit: "GB", divider: 1024.0**3},
    1 => {name: "CPU", unit: "GHz", divider: 1000.0},
    2 => {name: "Storage", unit: "TB", divider: 1024.0**4},
    3 => {name: "Primary Storage", unit: "TB", divider: 1024.0**4},
    4 => {name: "Public IP's"},
    5 => {name: "Private IP's"},
    6 => {name: "Secondary Storage", unit: "TB", divider: 1024.0**4},
    7 => {name: "VLAN"},
    8 => {name: "Direct Attached Public IP's"},
    9 => {name: "Local Storage", unit: "TB", divider: 1024.0**4}
  }

  desc "list", "list system capacity"
  option :zone, desc: "lists clusters by zone"
  option :type, desc: "specify type, see types for a list of types"
  def list
    resolve_zone if options[:zone]
    capacities = client.list_capacity(options)
    table = []
    header = ["Zone", "Type", "Capacity Used", "Capacity Total", "Used"]
    capacities.each do |c|
      table << [
        c['zonename'],
         CAPACITY_TYPES[c['type']][:name],
         capacity_to_s(c, 'capacityused'),
         capacity_to_s(c, 'capacitytotal'),
         "#{c['percentused']}%"
      ]
    end
    table = table.sort {|a, b|  [a[0], a[1]] <=> [b[0], b[1]]}.insert(0, header)
    print_table table
  end

  desc "types", "show capacity types"
  def types
    table = [['type', 'name']]
    CAPACITY_TYPES.each_pair do |type, data|
      table << [type, data[:name]]
    end
    print_table table
  end

  no_commands do

    def capacity_to_s(capacity, entity)
      value = CAPACITY_TYPES[capacity['type']][:divider] ?
        (capacity[entity] / CAPACITY_TYPES[capacity['type']][:divider]).round(1) :
        capacity[entity]
      CAPACITY_TYPES[capacity['type']][:unit] ?
        "#{value} #{CAPACITY_TYPES[capacity['type']][:unit]}" :
        value.to_s
    end

  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
cloudstack-cli-1.4.1 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.4.0 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.3.3 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.3.2 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.3.1 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.3.0 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.2.7 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.2.6 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.2.5 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.2.4 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.2.3 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.2.1 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.2.0 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.1.0 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.0.8 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.0.7 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.0.6 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.0.5 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.0.4 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.0.3 lib/cloudstack-cli/commands/capacity.rb