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?, start

Methods included from CloudstackCli::OptionResolver

#resolve_account, #resolve_cluster, #resolve_compute_offering, #resolve_disk_offering, #resolve_domain, #resolve_host, #resolve_ip_network_list, #resolve_iso, #resolve_iso_for_vm_deployment, #resolve_networks, #resolve_project, #resolve_snapshot, #resolve_template, #resolve_virtual_machine, #resolve_zone, #vm_options_to_params

Methods included from CloudstackCli::Helper

#ask_number, #bootstrap_server, #bootstrap_server_interactive, #create_port_rules, #create_server, #get_server_default_nic, #pf_rule_to_object, #print_job_status, #print_options, #run_background_jobs, #update_job_status, #update_jobs, #watch_jobs

Methods inherited from Thor

banner, basename2, old_subcommand, subcommand

Instance Method Details

#listObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cloudstack-cli/commands/resource_limit.rb', line 23

def list
  
  resolve_project
  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

  case options[:format].to_sym
  when :yaml
    puts({resource_limits: limits}.to_yaml)
  when :json
    puts JSON.pretty_generate(resource_limits: limits)
  else
    table = table.insert(0, header)
    print_table table
  end
end

#refreshObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cloudstack-cli/commands/resource_limit.rb', line 56

def refresh
  resolve_domain
  
  resolve_project
  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



105
106
107
108
109
110
111
# File 'lib/cloudstack-cli/commands/resource_limit.rb', line 105

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

#updateObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cloudstack-cli/commands/resource_limit.rb', line 85

def update
  resolve_domain
  
  resolve_project
  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