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



77
78
79
80
# File 'lib/chef/knife/cs_product_list.rb', line 77

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

#runObject



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
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/chef/knife/cs_product_list.rb', line 38

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

  if config[:output_type].eql? "table"
    puts ui.list(product_list, :columns_across, 9)
  else
    puts products.to_json
  end
end