Class: Awscli::EC2::Ami

Inherits:
Object
  • Object
show all
Defined in:
lib/awscli/ec2.rb

Overview

> Eip

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Ami

Returns a new instance of Ami.



423
424
425
# File 'lib/awscli/ec2.rb', line 423

def initialize(connection)
  @conn = connection
end

Instance Method Details

#create_image_from_instance(options) ⇒ Object



479
480
481
482
483
484
485
486
487
488
# File 'lib/awscli/ec2.rb', line 479

def create_image_from_instance(options)
  abort "Invalid Instace: #{options[:instance_id]}" unless @conn.servers.get(options[:instance_id])
  @conn.create_image(
      options[:instance_id],
      options[:name],
      options[:desc],
      options[:no_reboot]
    )
  puts "Created image from instance: #{options[:instance_id]}"
end

#deregister(image_id) ⇒ Object



490
491
492
493
494
495
# File 'lib/awscli/ec2.rb', line 490

def deregister(image_id)
  image = @conn.images.get(image_id)
  abort "Cannot find image with id: #{image_id}" unless image
  @conn.deregister_image(image_id)
  say "De-registerd image: <%= color('#{image_id}', :green) %>"
end

#list(filter) ⇒ Object



427
428
429
430
431
432
433
434
435
# File 'lib/awscli/ec2.rb', line 427

def list(filter)
  puts filter
  if filter.nil?
    @conn.images.all.table([:architecture, :id, :is_public, :platform, :root_device_type, :state])
  else
    data = @conn.images.all(filter)
    data.empty? ? puts("No AMI's found for provided filters") : data.table([:architecture, :id, :is_public, :platform, :root_device_type, :state])
  end
end

#list_amazonObject



470
471
472
# File 'lib/awscli/ec2.rb', line 470

def list_amazon
  @conn.images.all('owner-alias' => 'amazon').table([:architecture, :id, :is_public, :platform, :root_device_type, :state])
end

#list_selfObject



474
475
476
477
# File 'lib/awscli/ec2.rb', line 474

def list_self
  response = @conn.describe_images({'Owner' => 'self'}).body['imagesSet']
  Formatador.display_table(response, ['architecture', 'imageId', 'isPublic', 'name', 'imageState', 'rootDeviceType', 'imageType'])
end

#show_filtersObject



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/awscli/ec2.rb', line 437

def show_filters
  filters =
    [
      {:filter_name => "architecture", :desc => "Image Architecture"},
      {:filter_name => "block-device-mapping.delete-on-termination", :desc => "Whether the Amazon EBS volume is deleted on instance termination"},
      {:filter_name => "block-device-mapping.device-name", :desc => "Device name (e.g., /dev/sdh) for an Amazon EBS volume mapped to the image"},
      {:filter_name => "block-device-mapping.snapshot-id", :desc => "Snapshot ID for an Amazon EBS volume mapped to the image"},
      {:filter_name => "block-device-mapping.volume-size", :desc => "Volume size for an Amazon EBS volume mapped to the image"},
      {:filter_name => "description", :desc => "Description of the AMI (provided during image creation)"},
      {:filter_name => "image-id", :desc => "ID of the image" },
      {:filter_name => "imgae-type", :desc => "Type of image" },
      {:filter_name => "is-public", :desc => "Whether the image is public" },
      {:filter_name => "kernel-id", :desc => "Kernel ID" },
      {:filter_name => "manifest-location", :desc => "Location of the image manifest" },
      {:filter_name => "name", :desc => "Name of the AMI (provided during image creation)" },
      {:filter_name => "owner-alias", :desc => "AWS account alias (e.g., amazon or self) or AWS account ID that owns the AMI" },
      {:filter_name => "owner-id", :desc => "AWS account ID of the image owner" },
      {:filter_name => "platform", :desc => "Use windows if you have Windows based AMIs; otherwise leave blank" },
      {:filter_name => "product-code", :desc => "Product code associated with the AMI" },
      {:filter_name => "ramdisk-id", :desc => "RAM disk ID" },
      {:filter_name => "root-device-name", :desc => "Root device name of the AMI (e.g., /dev/sda1)" },
      {:filter_name => "root-device-type", :desc => "Root device type the AMI uses" },
      {:filter_name => "state", :desc => "State of the image" },
      {:filter_name => "state-reason-code", :desc => "Reason code for the state change" },
      {:filter_name => "state-reason-message", :desc => "Message for the state change" },
      {:filter_name => "tag-key", :desc => "Key of a tag assigned to the resource. This filter is independent of the tag-value filter" },
      {:filter_name => "tag-value", :desc => "Value of a tag assigned to the resource. This filter is independent of the tag-key filter." },
      {:filter_name => "virtualization-type", :desc => "Virtualization type of the image" },
      {:filter_name => "hypervisor", :desc => "Hypervisor type of the image" }
    ]
  Formatador.display_table(filters, [:filter_name, :desc])
end