Included modules
Public class methods
from_hash
(h)
imageOwnerId: “203338247012” kernelId: aki-a71cf9ce ramdiskId: ari-a51cf9cc imageState: available imageId: ami-dd34d3b4 architecture: i386 isPublic: “false” imageLocation: solutious-rudy-us/debian-squeeze-m1.small-v5.manifest.xml imageType: machine
[show source]
# File lib/rudy/aws/ec2/image.rb, line 118 118: def Images.from_hash(h) 119: img = Rudy::AWS::EC2::Image.new 120: img.owner = h['imageOwnerId'] 121: img.aki = h['kernelId'] 122: img.ari = h['ramdiskId'] 123: img.state = h['imageState'] 124: img.awsid = h['imageId'] 125: img.arch = h['architecture'] 126: img.visibility = h['isPublic'] == 'true' ? 'public' : 'private' 127: img.location = h['imageLocation'] 128: img.kind = h['imageType'] 129: img 130: end
Public instance methods
deregister
(id)
id AMI ID to deregister (ami-XXXXXXX) Returns true when successful. Otherwise throws an exception.
[show source]
# File lib/rudy/aws/ec2/image.rb, line 76 76: def deregister(id) 77: opts = { 78: :image_id => id 79: } 80: ret = @@ec2.deregister_image(opts) 81: return false unless ret && ret.is_a?(Hash) 82: true 83: end
list
(owner=[], image_ids=[], executable_by=[], &each_image)
[show source]
# File lib/rudy/aws/ec2/image.rb, line 33 33: def list(owner=[], image_ids=[], executable_by=[], &each_image) 34: images = list_as_hash(owner, image_ids, executable_by) 35: images &&= images.values 36: images 37: end
list_as_hash
(owner=[], image_ids=[], executable_by=[], &each_image)
[show source]
# File lib/rudy/aws/ec2/image.rb, line 39 39: def list_as_hash(owner=[], image_ids=[], executable_by=[], &each_image) 40: owner &&= [owner].flatten.compact 41: image_ids &&= [image_ids].flatten.compact 42: executable_by &&= [executable_by].flatten.compact 43: 44: # Remove dashes from aws account numbers 45: owner &&= owner.collect { |o| o.tr('-', '') } 46: # If we got Image objects, we want just the IDs. 47: # This method always returns an Array. 48: image_ids = objects_to_image_ids(image_ids) 49: 50: opts = { 51: :owner_id => owner || [], 52: :image_id => image_ids || [], 53: :executable_by => executable_by || [] 54: } 55: 56: response = Rudy::AWS::EC2.execute_request({}) { @@ec2.describe_images(opts) } 57: 58: return nil unless response['imagesSet'].is_a?(Hash) # No instances 59: 60: resids = [] 61: images = {} 62: response['imagesSet']['item'].each do |res| 63: resids << res['reservationId'] 64: img = Images.from_hash(res) 65: images[img.awsid] = img 66: end 67: 68: images.each_value { |image| each_image.call(image) } if each_image 69: 70: images = nil if images.empty? # Don't return an empty hash 71: images 72: end
register
(opts)
opts can be the S3 path to the manifest (bucket/file.manifest.xml) or a hash containing the following options:
- optional, String
- :image_location (“”) S3 URL for the XML manifest
- optional, String
- :name (“”) Name of EBS image
- optional, String
- :description (“”) Description of EBS image
- optional, String
- :architecture (“”) Architecture of EBS image, currently ‘i386’ or ‘x86_64‘
- optional, String
- :kernel_id (“”) Kernel ID of EBS image
- optional, String
- :ramdisk_id (“”) Ramdisk ID of EBS image
- optional, String
- :root_device_name (“”) Root device name of EBS image, eg ‘/dev/sda1‘
- optional, Array
- :block_device_mapping ([]) An array of Hashes representing the elements of
the block device mapping. e.g. [{:device_name => ‘/dev/sdh’,
:virtual_name => ’’, :ebs_snapshot_id => ’’,
:ebs_volume_size => ’’, :ebs_delete_on_termination =>
’’},{},…]
i.e. :block_device_mapping => [{ :device_name => "/dev/sda1", :ebs_snapshot_id => "snap-01234567", :ebs_delete_on_termination => true, }]
[show source]
# File lib/rudy/aws/ec2/image.rb, line 102 102: def register(opts) 103: opts = Hash === opts ? opts : { :image_location => opts } 104: ret = @@ec2.register_image(opts) 105: return nil unless ret && ret.is_a?(Hash) 106: ret['imageId'] 107: end