class ResourceLimit

Constants

RESOURCE_TYPES

Public Instance Methods

list() click to toggle source
   # File lib/cloudstack-cli/commands/resource_limit.rb
23 def list
24   resolve_account
25   resolve_project
26   limits = client.list_resource_limits(options)
27   table = []
28   header = options[:project] ? ["Project"] : ["Account"]
29   header += ["Type", "Resource Name", "Max"]
30   limits.each do |limit|
31     limit['resourcetype'] = limit['resourcetype'].to_i
32     table << [
33       options[:project] ? limit['project'] : limit['account'],
34       limit['resourcetype'],
35       RESOURCE_TYPES[limit['resourcetype']][:name],
36       resource_to_s(limit, 'max')
37     ]
38   end
39 
40   case options[:format].to_sym
41   when :yaml
42     puts({resource_limits: limits}.to_yaml)
43   when :json
44     puts JSON.pretty_generate(resource_limits: limits)
45   else
46     table = table.insert(0, header)
47     print_table table
48   end
49 end
refresh() click to toggle source
   # File lib/cloudstack-cli/commands/resource_limit.rb
56 def refresh
57   resolve_domain
58   resolve_account
59   resolve_project
60   options[:resource_type] = options[:type] if options[:type]
61 
62   unless ['domain_id', 'account', 'project'].any? {|k| options.key?(k)}
63     say "Error: Please provide domain, account or project.", :red
64     exit 1
65   end
66 
67   if resource_count = client.update_resource_count(options)
68     say "Sucessfully refreshed resource limits.", :green
69   else
70     say "Error refreshing resource limits.", :red
71     exit 1
72   end
73 end
resource_to_s(limit, entity) click to toggle source
    # File lib/cloudstack-cli/commands/resource_limit.rb
115 def resource_to_s(limit, entity)
116   return '-1 (unlimited)' if limit['max'] == -1
117   value = RESOURCE_TYPES[limit['resourcetype']][:divider] ?
118   (limit[entity] / RESOURCE_TYPES[limit['resourcetype']][:divider]).round(1) :
119   limit[entity]
120   RESOURCE_TYPES[limit['resourcetype']][:unit] ?
121   "#{value} #{RESOURCE_TYPES[limit['resourcetype']][:unit]}" :
122   value.to_s
123 end
types() click to toggle source
    # File lib/cloudstack-cli/commands/resource_limit.rb
105 def types
106   table = [['type', 'name']]
107   RESOURCE_TYPES.each_pair do |type, data|
108     table << [type, data[:name]]
109   end
110   print_table table
111 end
update() click to toggle source
    # File lib/cloudstack-cli/commands/resource_limit.rb
 85 def update
 86   resolve_domain
 87   resolve_account
 88   resolve_project
 89   options[:resource_type] = options[:type]
 90 
 91   unless ['domain_id', 'account', 'project'].any? {|k| options.key?(k)}
 92     say "Error: Please provide domain, account or project.", :red
 93     exit 1
 94   end
 95 
 96   if resource_count = client.update_resource_limit(options)
 97     say "Sucessfully updated resource limits.", :green
 98   else
 99     say "Error updating resource limits.", :red
100     exit 1
101   end
102 end