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.



413
414
415
# File 'lib/awscli/ec2.rb', line 413

def initialize(connection)
  @conn = connection
end

Instance Method Details

#create_image_from_instance(options) ⇒ Object



469
470
471
472
473
474
475
476
477
478
# File 'lib/awscli/ec2.rb', line 469

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



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

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



417
418
419
420
421
422
423
424
425
# File 'lib/awscli/ec2.rb', line 417

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



460
461
462
# File 'lib/awscli/ec2.rb', line 460

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

#list_selfObject



464
465
466
467
# File 'lib/awscli/ec2.rb', line 464

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



427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/awscli/ec2.rb', line 427

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