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.



401
402
403
# File 'lib/awscli/ec2.rb', line 401

def initialize(connection)
  @conn = connection
end

Instance Method Details

#create_image_from_instance(options) ⇒ Object



457
458
459
460
461
462
463
464
465
466
# File 'lib/awscli/ec2.rb', line 457

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



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

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



405
406
407
408
409
410
411
412
413
# File 'lib/awscli/ec2.rb', line 405

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



448
449
450
# File 'lib/awscli/ec2.rb', line 448

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

#list_selfObject



452
453
454
455
# File 'lib/awscli/ec2.rb', line 452

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



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/awscli/ec2.rb', line 415

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