Class: Chef::Knife::RightscaleImageList

Inherits:
Chef::Knife show all
Includes:
RightscaleBase
Defined in:
lib/chef/knife/rightscale_image_list.rb

Instance Method Summary collapse

Methods included from RightscaleBase

#connection, included, #locate_config_value, #msg_pair, #right_api_client, #set_log_level

Instance Method Details

#runObject



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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/chef/knife/rightscale_image_list.rb', line 53

def run
  $stdout.sync = true

  validate!
  
  # fail if the requested cloud is not registered with RightScale account
  puts(ui.color('Looking up cloud...', :magenta)) 
  @cloud = connection.find_cloud_by_name(config[:cloud_name])
  raise "ERROR: cannot find a cloud named: '#{config[:cloud_name]}'. " +
        "See 'knife rightscale cloud list' command for a list of clouds" +
        " registered with your RightScale account" unless  @cloud

  puts(ui.color('Looking up ServerTemplate...', :magenta)) 
  @st = connection.find_servertemplate(config[:server_template])
  raise "ERROR: cannot find ServerTemplate '#{config[:server_template]}'. Did you import it?\n" + 
        "Visit http://bit.ly/VnOiA7 for more info.\n\n" unless  @st

  image_list = [
    ui.color('Image', :bold),
    ui.color('Instance Type (default)', :bold)
  ].flatten.compact

  output_column_count = image_list.length
  
  puts(ui.color('Looking up supported multi-cloud images...', :magenta)) 
  @multi_cloud_images = connection.list_multi_cloud_images(@st, :by_name, config[:image_name])

  print(ui.color('Inspecting ServerTemplate images...', :magenta)) 
  @multi_cloud_images.each do |multi_cloud_image|
    multi_cloud_image.settings.index.each do |cloud_setting|
      print(ui.color(".", :magenta)) 
      STDOUT.flush
      next unless registered_cloud?(cloud_setting.cloud)
      image_list << multi_cloud_image.name
      image_list << instance_type(cloud_setting.show)
    end
  end
  puts
  puts ui.list(image_list, :uneven_columns_across, output_column_count)
end