Class: ResourceLimit

Inherits:
CloudstackCli::Base show all
Defined in:
lib/cloudstack-cli/commands/resource_limit.rb

Constant Summary collapse

RESOURCE_TYPES =
{
  0  => {name: "Instances"},
  1  => {name: "IP Addresses"},
  2  => {name: "Volumes"},
  3  => {name: "Snapshots"},
  4  => {name: "Templates"},
  5  => {name: "Projects"},
  6  => {name: "Networks"},
  7  => {name: "VPC's"},
  8  => {name: "CPU's"},
  9  => {name: "Memory", unit: "GB", divider: 1024.0},
  10 => {name: "Primary Storage", unit: "TB", divider: 1024.0},
  11 => {name: "Secondary Storage", unit: "TB", divider: 1024.0}
}

Constants included from CloudstackCli::Helper

CloudstackCli::Helper::ASYNC_STATES

Instance Attribute Summary

Attributes inherited from CloudstackCli::Base

#config

Instance Method Summary collapse

Methods inherited from CloudstackCli::Base

exit_on_failure?

Methods included from CloudstackCli::Helper

#ask_number, #bootstrap_server, #bootstrap_server_interactive, #create_port_rules, #create_server, #print_job_status, #print_options, #update_job_status, #watch_jobs

Instance Method Details

#listObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cloudstack-cli/commands/resource_limit.rb', line 21

def list
  limits = client.list_resource_limits(options)
  table = []
  header = options[:project] ? ["Project"] : ["Account"]
  header += ["Type", "Resource Name", "Max"]
  limits.each do |limit|
    limit['resourcetype'] = limit['resourcetype'].to_i
    table << [
      options[:project] ? limit['project'] : limit['account'],
      limit['resourcetype'],
      RESOURCE_TYPES[limit['resourcetype']][:name],
      resource_to_s(limit, 'max')
    ]
  end
  table = table.insert(0, header)
  print_table table
end

#refreshObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cloudstack-cli/commands/resource_limit.rb', line 44

def refresh
  set_domain_id if options[:domain]
  options[:resource_type] = options[:type] if options[:type]

  unless ['domain_id', 'account', 'project'].any? {|k| options.key?(k)}
    say "Error: Please provide domain, account or project.", :red
    exit 1
  end

  if resource_count = client.update_resource_count(options)
    say "Sucessfully refreshed resource limits.", :green
  else
    say "Error refreshing resource limits.", :red
    exit 1
  end
end

#typesObject



89
90
91
92
93
94
95
# File 'lib/cloudstack-cli/commands/resource_limit.rb', line 89

def types
  table = [['type', 'name']]
  RESOURCE_TYPES.each_pair do |type, data|
    table << [type, data[:name]]
  end
  print_table table
end

#updateObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cloudstack-cli/commands/resource_limit.rb', line 71

def update
  set_domain_id if options[:domain]
  options[:resource_type] = options[:type]

  unless ['domain_id', 'account', 'project'].any? {|k| options.key?(k)}
    say "Error: Please provide domain, account or project.", :red
    exit 1
  end

  if resource_count = client.update_resource_limit(options)
    say "Sucessfully updated resource limits.", :green
  else
    say "Error updating resource limits.", :red
    exit 1
  end
end