Class: KnifeCloudstack::CsProductList

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/cs_product_list.rb

Instance Method Summary collapse

Instance Method Details

#locate_config_value(key) ⇒ Object



64
65
66
67
# File 'lib/chef/knife/cs_product_list.rb', line 64

def locate_config_value(key)
  key = key.to_sym
  Chef::Config[:knife][key] || config[key]
end

#runObject



30
31
32
33
34
35
36
37
38
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/cs_product_list.rb', line 30

def run

  connection = CloudstackClient::Connection.new(
      locate_config_value(:cloudstack_url),
      locate_config_value(:cloudstack_api_key),
      locate_config_value(:cloudstack_secret_key)
  )

  product_list = [
      ui.color('id', :bold),
      ui.color('serviceid', :bold),
      ui.color('desc', :bold),
      ui.color('diskid', :bold),
      ui.color('desc', :bold),
      ui.color('templateid', :bold),
      ui.color('desc', :bold),
      ui.color('zoneid', :bold),
      ui.color('desc', :bold)
  ]
  products = connection.list_products
  products.each do |product| 
      product_list << product['productid']
      product_list << product['serviceofferingid']
      product_list << product['serviceofferingdesc']
      product_list << product['diskofferingid']
      product_list << product['diskofferingdesc']
      product_list << product['templateid']
      product_list << product['templatedesc']
      product_list << product['zoneid']
      product_list << product['zonedesc']
  end
  puts ui.list(product_list, :columns_across, 9)
end