Class: Knifecosmic::CosmicServiceList
Instance Method Summary
collapse
included, #list_object, #list_object_fields, #output_format
Instance Method Details
#human_memory(n) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/chef/knife/cosmic_service_list.rb', line 64
def human_memory n
count = 0
while n >= 1024 and count < 2
n /= 1024.0
count += 1
end
format("%.0f", n) + %w(MB GB TB)[count]
end
|
#run ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/chef/knife/cosmic_service_list.rb', line 39
def run
validate_base_options
columns = [
'Name :name',
'Memory :memory',
'CPUs :cpunumber',
'CPU Speed :cpuspeed',
'Created :created'
]
params = { 'command' => "listServiceOfferings" }
params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
params['name'] = locate_config_value(:name) if locate_config_value(:name)
result = connection.list_object(params, "serviceoffering")
result.each do |r|
r['memory'] = human_memory(r['memory']) if r['memory']
end
list_object(columns, result)
end
|