Sha256: 125f02a1140bb9a5de32eaf5c41ee0a360dd1701ce687e03d9877fd669d73571

Contents?: true

Size: 1.98 KB

Versions: 17

Compression:

Stored size: 1.98 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: "list capacity by zone"
  option :cluster, desc: "list capacity by cluster"
  option :type, desc: "specify type, see types for a list of types"
  def list
    resolve_zone
    resolve_cluster
    capacities = client.list_capacity(options)
    table = []
    header = ["Zone", "Type", "Capacity Used", "Capacity Total", "Used"]
    header[0] = "Cluster" if options[:cluster_id]
    capacities.each do |c|
      if CAPACITY_TYPES.include? c['type']
        table << [
          c['clustername'] || c['zonename'],
          CAPACITY_TYPES[c['type']][:name],
          capacity_to_s(c, 'capacityused'),
          capacity_to_s(c, 'capacitytotal'),
          "#{c['percentused']}%"
        ]
      end
    end
    table = table.sort {|a, b| [a[0], a[1]] <=> [b[0], b[1]]}
    print_table table.insert(0, header)
  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

17 entries across 17 versions & 1 rubygems

Version Path
cloudstack-cli-1.6.10 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.6.9 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.6.8 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.6.7 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.6.6 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.6.5 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.6.4 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.6.3 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.6.2 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.6.1 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.6.0 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.5.13 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.5.12 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.5.10 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.5.9 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.5.8 lib/cloudstack-cli/commands/capacity.rb
cloudstack-cli-1.5.7 lib/cloudstack-cli/commands/capacity.rb