class Chef::Knife::SceImageDescribe

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/sce_image_describe.rb, line 28
def run

  validate!

  @name_args.each do |image_id|
      
    begin
      @image = connection.images.get(image_id)
    rescue Excon::Errors::InternalServerError => e
      if image_id.is_number?
        ui.error e.inspect
        exit 1
      end
      # is not a number and we received an error, ignore, API likes numbers only, we try to fetch the image by the name
    end
    
    if @image.nil?
      connection.images.all.each do |i|
        if i.name.to_s == image_id
          @image = i
        end
      end
    end
    
    msg_pair("Image ID", @image.id.to_s)
    msg_pair("Name", @image.name.to_s)
    msg_pair("Location", connection.locations.get(@image.location).name.to_s)
    msg_pair("Description", @image.description.to_s)
    msg_pair("Visbility", @image.visibility.to_s)
    msg_pair("Platform", @image.platform.to_s)
    msg_pair("Architecture", @image.architecture.to_s)
    msg_pair("Owner", @image.owner.to_s)
    msg_pair("State", @image.state.to_s)
    msg_pair("Manifest", @image.manifest.to_s)
    msg_pair("Product codes", ":")
    @image.product_codes.each do |pc|
      msg_pair("  -> ", pc)
    end
    msg_pair("Supported instance types", ":")
    @image.supported_instance_types.each do |sit|
      msg_pair("  -> ", sit.id.to_s)
      msg_pair("     ", sit.label.to_s)
      msg_pair("     ", sit.detail.to_s)
      msg_pair("     ", "Price: #{sit.price['rate']}#{sit.price['currencyCode']}/#{sit.price['pricePerQuantity']}#{sit.price['unitOfMeasure']}")
    end
    msg_pair("Documentation", @image.documentation.to_s)
    
    puts "\n"

  end
end