Class: Chef::Knife::GandiImageList
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::GandiImageList
- Defined in:
- lib/chef/knife/gandi_image_list.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
57 58 59 |
# File 'lib/chef/knife/gandi_image_list.rb', line 57 def api_key @api_key end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
57 58 59 |
# File 'lib/chef/knife/gandi_image_list.rb', line 57 def connection @connection end |
Instance Method Details
#run ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/chef/knife/gandi_image_list.rb', line 59 def run # Unsual to extend here but enables 'plugin_helper' to be require'd lazily extend KnifeGandi::PluginHelper $stdout.sync = true # Necessary changes to xmlrpc's defaults, prevent warnings from showing up in prompt suppress_warnings do XMLRPC::Config.const_set(:ENABLE_NIL_PARSER, true) XMLRPC::Config.const_set(:ENABLE_NIL_CREATE, true) end @connection = XMLRPC::Client.new2(KnifeGandi::API_ENDPOINT_URL) @api_key = Chef::Config[:knife][:gandi_api_key] || config[:gandi_api_key] || raise("No Gandi API key was specified") image_list = [ ui.color('ID', :bold), ui.color('Name', :bold), ui.color('Arch', :bold), ui.color('Datacenter_id', :bold) ] # Filter the result set filters = { :sort_by => 'label', :datacenter_id => Chef::Config[:knife][:gandi_datacenter_id] || nil, :os_arch => Chef::Config[:knife][:gandi_os_arch] || nil } connection.call('image.list', api_key, filters).each do |image| image_list << image['id'].to_s image_list << ui.color(image['label'], :bold) image_list << image['os_arch'] image_list << image['datacenter_id'].to_s end puts ui.list(image_list, :columns_across, 4) end |