Class: Knifecosmic::CosmicTemplateList
Instance Method Summary
collapse
included, #list_object, #list_object_fields, #output_format
Instance Method Details
#human_file_size(n) ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/chef/knife/cosmic_template_list.rb', line 78
def human_file_size n
count = 0
while n >= 1024 and count < 4
n /= 1024.0
count += 1
end
format("%.0f", n) + %w(B KB MB GB TB)[count]
end
|
#run ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/chef/knife/cosmic_template_list.rb', line 46
def run
validate_base_options
columns = [
'Name :name',
'Size :size',
'Zone :zonename',
'Public :ispublic',
'Created :created'
]
params = { 'command' => "listTemplates" }
params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
params['name'] = locate_config_value(:name) if locate_config_value(:name)
if ['all','featured','self','selfexecutable','sharedexecutable','executable','community'].include?(locate_config_value(:templatefilter))
params['templatefilter'] = locate_config_value(:templatefilter)
else
params['templatefilter'] = 'featured'
end
result = connection.list_object(params, "template")
result.each do |r|
r['size'] = human_file_size(r['size']) if r['size']
end
list_object(columns, result)
end
|