Class: Knifecosmic::CosmicIsoList

Inherits:
Chef::Knife show all
Includes:
Chef::Knife::KnifecosmicBaseList
Defined in:
lib/chef/knife/cosmic_iso_list.rb

Instance Method Summary collapse

Methods included from Chef::Knife::KnifecosmicBaseList

included, #list_object, #list_object_fields, #output_format

Instance Method Details

#human_file_size(n) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/chef/knife/cosmic_iso_list.rb', line 79

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

#runObject



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
77
# File 'lib/chef/knife/cosmic_iso_list.rb', line 47

def run
  validate_base_options

  columns = [
    'Name    :name',
    'Account :account',
    'Domain  :domain',
    'Public  :ispublic',
    'Size    :size',
    'OS      :ostypename'
  ]

  params = { 'command' => "listIsos" }
  params['filter']  = locate_config_value(:filter)  if locate_config_value(:filter)
  params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
  params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
  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['isofilter'] = locate_config_value(:isofilter)
  else
    params['isofilter'] = 'featured'
  end
 
  result = connection.list_object(params, "iso")
  result.each do |r|
    r['size'] = human_file_size(r['size']) if r['size']
  end

  list_object(columns, result)
end