Class: Chef::Knife::SceImageDescribe

Inherits:
Chef::Knife show all
Includes:
SceBase
Defined in:
lib/chef/knife/sce_image_describe.rb

Instance Method Summary collapse

Methods included from SceBase

#connection, #connection_storage, #datacenter_id, included, #locate_config_value, #msg_pair, #validate!

Instance Method Details

#runObject



28
29
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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