Class: Fog::AWS::EC2

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/aws/ec2.rb,
lib/fog/aws/models/ec2/image.rb,
lib/fog/aws/models/ec2/flavor.rb,
lib/fog/aws/models/ec2/images.rb,
lib/fog/aws/models/ec2/server.rb,
lib/fog/aws/models/ec2/volume.rb,
lib/fog/aws/models/ec2/address.rb,
lib/fog/aws/models/ec2/flavors.rb,
lib/fog/aws/models/ec2/servers.rb,
lib/fog/aws/models/ec2/volumes.rb,
lib/fog/aws/models/ec2/key_pair.rb,
lib/fog/aws/models/ec2/snapshot.rb,
lib/fog/aws/models/ec2/addresses.rb,
lib/fog/aws/models/ec2/key_pairs.rb,
lib/fog/aws/models/ec2/snapshots.rb,
lib/fog/aws/models/ec2/security_group.rb,
lib/fog/aws/models/ec2/security_groups.rb,
lib/fog/aws/requests/ec2/attach_volume.rb,
lib/fog/aws/requests/ec2/attach_volume.rb,
lib/fog/aws/requests/ec2/create_volume.rb,
lib/fog/aws/requests/ec2/create_volume.rb,
lib/fog/aws/requests/ec2/delete_volume.rb,
lib/fog/aws/requests/ec2/delete_volume.rb,
lib/fog/aws/requests/ec2/detach_volume.rb,
lib/fog/aws/requests/ec2/detach_volume.rb,
lib/fog/aws/requests/ec2/run_instances.rb,
lib/fog/aws/requests/ec2/run_instances.rb,
lib/fog/aws/requests/ec2/create_key_pair.rb,
lib/fog/aws/requests/ec2/create_key_pair.rb,
lib/fog/aws/requests/ec2/create_snapshot.rb,
lib/fog/aws/requests/ec2/create_snapshot.rb,
lib/fog/aws/requests/ec2/delete_key_pair.rb,
lib/fog/aws/requests/ec2/delete_key_pair.rb,
lib/fog/aws/requests/ec2/delete_snapshot.rb,
lib/fog/aws/requests/ec2/delete_snapshot.rb,
lib/fog/aws/requests/ec2/describe_images.rb,
lib/fog/aws/requests/ec2/describe_images.rb,
lib/fog/aws/requests/ec2/release_address.rb,
lib/fog/aws/requests/ec2/release_address.rb,
lib/fog/aws/requests/ec2/allocate_address.rb,
lib/fog/aws/requests/ec2/allocate_address.rb,
lib/fog/aws/requests/ec2/describe_regions.rb,
lib/fog/aws/requests/ec2/describe_regions.rb,
lib/fog/aws/requests/ec2/describe_volumes.rb,
lib/fog/aws/requests/ec2/describe_volumes.rb,
lib/fog/aws/requests/ec2/reboot_instances.rb,
lib/fog/aws/requests/ec2/reboot_instances.rb,
lib/fog/aws/requests/ec2/associate_address.rb,
lib/fog/aws/requests/ec2/associate_address.rb,
lib/fog/aws/requests/ec2/describe_addresses.rb,
lib/fog/aws/requests/ec2/describe_addresses.rb,
lib/fog/aws/requests/ec2/describe_instances.rb,
lib/fog/aws/requests/ec2/describe_instances.rb,
lib/fog/aws/requests/ec2/describe_key_pairs.rb,
lib/fog/aws/requests/ec2/describe_key_pairs.rb,
lib/fog/aws/requests/ec2/describe_snapshots.rb,
lib/fog/aws/requests/ec2/describe_snapshots.rb,
lib/fog/aws/requests/ec2/get_console_output.rb,
lib/fog/aws/requests/ec2/get_console_output.rb,
lib/fog/aws/requests/ec2/terminate_instances.rb,
lib/fog/aws/requests/ec2/terminate_instances.rb,
lib/fog/aws/requests/ec2/disassociate_address.rb,
lib/fog/aws/requests/ec2/disassociate_address.rb,
lib/fog/aws/requests/ec2/create_security_group.rb,
lib/fog/aws/requests/ec2/create_security_group.rb,
lib/fog/aws/requests/ec2/delete_security_group.rb,
lib/fog/aws/requests/ec2/delete_security_group.rb,
lib/fog/aws/requests/ec2/describe_security_groups.rb,
lib/fog/aws/requests/ec2/describe_security_groups.rb,
lib/fog/aws/requests/ec2/describe_availability_zones.rb,
lib/fog/aws/requests/ec2/describe_availability_zones.rb,
lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb,
lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb,
lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb,
lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb

Defined Under Namespace

Classes: Address, Addresses, Flavor, Flavors, Image, Images, KeyPair, KeyPairs, SecurityGroup, SecurityGroups, Server, Servers, Snapshot, Snapshots, Volume, Volumes

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ EC2

Initialize connection to EC2

Notes

options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection

Examples

sdb = SimpleDB.new(
 :aws_access_key_id => your_aws_access_key_id,
 :aws_secret_access_key => your_aws_secret_access_key
)

Parameters

  • options<~Hash> - config arguments for connection. Defaults to {}.

Returns

  • EC2 object with connection to aws.



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/fog/aws/ec2.rb', line 129

def initialize(options={})
  unless @aws_access_key_id = options[:aws_access_key_id]
    raise ArgumentError.new('aws_access_key_id is required to access ec2')
  end
  unless @aws_secret_access_key = options[:aws_secret_access_key]
    raise ArgumentError.new('aws_secret_access_key is required to access ec2')
  end
  @hmac       = HMAC::SHA256.new(@aws_secret_access_key)
  @host       = options[:host]      || 'ec2.amazonaws.com'
  @port       = options[:port]      || 443
  @scheme     = options[:scheme]    || 'https'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
end

Class Method Details

.dataObject



6
7
8
# File 'lib/fog/aws/ec2.rb', line 6

def self.data
  @data
end

.reloadObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fog/aws/ec2.rb', line 22

def self.reload
  load "fog/aws/models/ec2/address.rb"
  load "fog/aws/models/ec2/addresses.rb"
  load "fog/aws/models/ec2/flavor.rb"
  load "fog/aws/models/ec2/flavors.rb"
  load "fog/aws/models/ec2/image.rb"
  load "fog/aws/models/ec2/images.rb"
  load "fog/aws/models/ec2/key_pair.rb"
  load "fog/aws/models/ec2/key_pairs.rb"
  load "fog/aws/models/ec2/security_group.rb"
  load "fog/aws/models/ec2/security_groups.rb"
  load "fog/aws/models/ec2/server.rb"
  load "fog/aws/models/ec2/servers.rb"
  load "fog/aws/models/ec2/snapshot.rb"
  load "fog/aws/models/ec2/snapshots.rb"
  load "fog/aws/models/ec2/volume.rb"
  load "fog/aws/models/ec2/volumes.rb"

  load "fog/aws/parsers/ec2/allocate_address.rb"
  load "fog/aws/parsers/ec2/attach_volume.rb"
  load "fog/aws/parsers/ec2/basic.rb"
  load "fog/aws/parsers/ec2/create_key_pair.rb"
  load "fog/aws/parsers/ec2/create_snapshot.rb"
  load "fog/aws/parsers/ec2/create_volume.rb"
  load "fog/aws/parsers/ec2/describe_addresses.rb"
  load "fog/aws/parsers/ec2/describe_availability_zones.rb"
  load "fog/aws/parsers/ec2/describe_images.rb"
  load "fog/aws/parsers/ec2/describe_instances.rb"
  load "fog/aws/parsers/ec2/describe_key_pairs.rb"
  load "fog/aws/parsers/ec2/describe_regions.rb"
  load "fog/aws/parsers/ec2/describe_security_groups.rb"
  load "fog/aws/parsers/ec2/describe_snapshots.rb"
  load "fog/aws/parsers/ec2/describe_volumes.rb"
  load "fog/aws/parsers/ec2/detach_volume.rb"
  load "fog/aws/parsers/ec2/get_console_output.rb"
  load "fog/aws/parsers/ec2/run_instances.rb"
  load "fog/aws/parsers/ec2/terminate_instances.rb"

  load "fog/aws/requests/ec2/allocate_address.rb"
  load "fog/aws/requests/ec2/associate_address.rb"
  load "fog/aws/requests/ec2/attach_volume.rb"
  load "fog/aws/requests/ec2/authorize_security_group_ingress.rb"
  # TODO: require "fog/aws/requests/ec2/bundle_instance.rb"
  # TODO: require "fog/aws/requests/ec2/cancel_bundle_task.rb"
  # TODO: require "fog/aws/requests/ec2/confirm_product_instance.rb"
  load "fog/aws/requests/ec2/create_key_pair.rb"
  load "fog/aws/requests/ec2/create_security_group.rb"
  load "fog/aws/requests/ec2/create_snapshot.rb"
  load "fog/aws/requests/ec2/create_volume.rb"
  load "fog/aws/requests/ec2/delete_key_pair.rb"
  load "fog/aws/requests/ec2/delete_security_group.rb"
  load "fog/aws/requests/ec2/delete_snapshot.rb"
  load "fog/aws/requests/ec2/delete_volume.rb"
  # TODO: require "fog/aws/requests/ec2/deregister_image.rb"
  load "fog/aws/requests/ec2/describe_addresses.rb"
  load "fog/aws/requests/ec2/describe_availability_zones.rb"
  # TODO: require "fog/aws/requests/ec2/describe_bundle_tasks.rb"
  # TODO: require "fog/aws/requests/ec2/describe_image_attribute.rb"
  load "fog/aws/requests/ec2/describe_images.rb"
  load "fog/aws/requests/ec2/describe_instances.rb"
  load "fog/aws/requests/ec2/describe_key_pairs.rb"
  load "fog/aws/requests/ec2/describe_regions.rb"
  # TODO: require "fog/aws/requests/ec2/describe_reserved_instances.rb"
  # TODO: require "fog/aws/requests/ec2/describe_reserved_instances_offerings.rb"
  load "fog/aws/requests/ec2/describe_security_groups.rb"
  load "fog/aws/requests/ec2/describe_snapshots.rb"
  load "fog/aws/requests/ec2/describe_volumes.rb"
  load "fog/aws/requests/ec2/detach_volume.rb"
  load "fog/aws/requests/ec2/disassociate_address.rb"
  load "fog/aws/requests/ec2/get_console_output.rb"
  # TODO: require "fog/aws/requests/ec2/modify_image_attribute.rb"
  # TODO: require "fog/aws/requests/ec2/modify_snapshot_attribute.rb"
  # TODO: require "fog/aws/requests/ec2/monitor_instances.rb"
  # TODO: require "fog/aws/requests/ec2/purchase_reserved_instances_offering.rb"
  load "fog/aws/requests/ec2/reboot_instances.rb"
  # TODO: require "fog/aws/requests/ec2/register_image.rb"
  load "fog/aws/requests/ec2/release_address.rb"
  # TODO: require "fog/aws/requests/ec2/reset_image_attributes.rb"
  # TODO: require "fog/aws/requests/ec2/reset_snapshot_attributes.rb"
  load "fog/aws/requests/ec2/revoke_security_group_ingress.rb"
  load "fog/aws/requests/ec2/run_instances.rb"
  load "fog/aws/requests/ec2/terminate_instances.rb"
  # TODO: require "fog/aws/requests/ec2/unmonitor_instances.rb"

  if Fog.mocking?
    reset_data
  end

end

.reset_dataObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/aws/ec2.rb', line 9

def self.reset_data
  @data = {
    :deleted_at => {},
    :addresses => {},
    :instances => {},
    :key_pairs => {},
    :security_groups => {},
    :snapshots => {},
    :volumes => {}
  }
end

Instance Method Details

#addresses(attributes = {}) ⇒ Object



5
6
7
8
9
# File 'lib/fog/aws/models/ec2/addresses.rb', line 5

def addresses(attributes = {})
  Fog::AWS::EC2::Addresses.new({
    :connection => self
  }.merge!(attributes))
end

#allocate_addressObject

Acquire an elastic IP address.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘publicIp’<~String> - The acquired address

      • ‘requestId’<~String> - Id of the request



14
15
16
17
18
# File 'lib/fog/aws/requests/ec2/allocate_address.rb', line 14

def allocate_address
  request({
    'Action' => 'AllocateAddress'
  }, Fog::Parsers::AWS::EC2::AllocateAddress.new)
end

#associate_address(instance_id, public_ip) ⇒ Object

Associate an elastic IP address with an instance

Parameters

  • instance_id<~String> - Id of instance to associate address with

  • public_ip<~String> - Public ip to assign to instance

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘return’<~Boolean> - success?



18
19
20
21
22
23
24
# File 'lib/fog/aws/requests/ec2/associate_address.rb', line 18

def associate_address(instance_id, public_ip)
  request({
    'Action' => 'AssociateAddress',
    'InstanceId' => instance_id,
    'PublicIp' => public_ip
  }, Fog::Parsers::AWS::EC2::Basic.new)
end

#attach_volume(instance_id, volume_id, device) ⇒ Object

Attach an Amazon EBS volume with a running instance, exposing as specified device

Parameters

  • instance_id<~String> - Id of instance to associate volume with

  • volume_id<~String> - Id of amazon EBS volume to associate with instance

  • device<~String> - Specifies how the device is exposed to the instance (e.g. “/dev/sdh”)

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘attachTime’<~Time> - Time of attachment was initiated at

      • ‘device’<~String> - Device as it is exposed to the instance

      • ‘instanceId’<~String> - Id of instance for volume

      • ‘requestId’<~String> - Id of request

      • ‘status’<~String> - Status of volume

      • ‘volumeId’<~String> - Reference to volume



23
24
25
26
27
28
29
30
# File 'lib/fog/aws/requests/ec2/attach_volume.rb', line 23

def attach_volume(instance_id, volume_id, device)
  request({
    'Action' => 'AttachVolume',
    'VolumeId' => volume_id,
    'InstanceId' => instance_id,
    'Device' => device
  }, Fog::Parsers::AWS::EC2::AttachVolume.new)
end

#authorize_security_group_ingress(options = {}) ⇒ Object

TODO: handle the GroupName/Source/Source case



26
27
28
29
30
# File 'lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb', line 26

def authorize_security_group_ingress(options = {})
  request({
    'Action' => 'AuthorizeSecurityGroupIngress'
  }.merge!(options), Fog::Parsers::AWS::EC2::Basic.new)
end

#create_key_pair(key_name) ⇒ Object

Create a new key pair

Parameters

  • key_name<~String> - Unique name for key pair.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘keyFingerprint’<~String> - SHA-1 digest of DER encoded private key

      • ‘keyMaterial’<~String> - Unencrypted encoded PEM private key

      • ‘keyName’<~String> - Name of key

      • ‘requestId’<~String> - Id of request



19
20
21
22
23
24
# File 'lib/fog/aws/requests/ec2/create_key_pair.rb', line 19

def create_key_pair(key_name)
  request({
    'Action' => 'CreateKeyPair',
    'KeyName' => key_name
  }, Fog::Parsers::AWS::EC2::CreateKeyPair.new)
end

#create_security_group(name, description) ⇒ Object

Create a new security group

Parameters

  • group_name<~String> - Name of the security group.

  • group_description<~String> - Description of group.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘return’<~Boolean> - success?



18
19
20
21
22
23
24
# File 'lib/fog/aws/requests/ec2/create_security_group.rb', line 18

def create_security_group(name, description)
  request({
    'Action' => 'CreateSecurityGroup',
    'GroupName' => name,
    'GroupDescription' => CGI.escape(description)
  }, Fog::Parsers::AWS::EC2::Basic.new)
end

#create_snapshot(volume_id) ⇒ Object

Create a snapshot of an EBS volume and store it in S3

Parameters

  • volume_id<~String> - Id of EBS volume to snapshot

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘progress’<~String> - The percentage progress of the snapshot

      • ‘requestId’<~String> - id of request

      • ‘snapshotId’<~String> - id of snapshot

      • ‘startTime’<~Time> - timestamp when snapshot was initiated

      • ‘status’<~String> - state of snapshot

      • ‘volumeId’<~String> - id of volume snapshot targets



21
22
23
24
25
26
# File 'lib/fog/aws/requests/ec2/create_snapshot.rb', line 21

def create_snapshot(volume_id)
  request({
    'Action' => 'CreateSnapshot',
    'VolumeId' => volume_id
  }, Fog::Parsers::AWS::EC2::CreateSnapshot.new)
end

#create_volume(availability_zone, size, snapshot_id = nil) ⇒ Object

Create an EBS volume

Parameters

  • availability_zone<~String> - availability zone to create volume in

  • size<~Integer> - Size in GiBs for volume. Must be between 1 and 1024.

  • snapshot_id<~String> - Optional, snapshot to create volume from

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘availabilityZone’<~String> - Availability zone for volume

      • ‘createTime’<~Time> - Timestamp for creation

      • ‘size’<~Integer> - Size in GiBs for volume

      • ‘snapshotId’<~String> - Snapshot volume was created from, if any

      • ‘status’s<~String> - State of volume

      • ‘volumeId’<~String> - Reference to volume



23
24
25
26
27
28
29
30
# File 'lib/fog/aws/requests/ec2/create_volume.rb', line 23

def create_volume(availability_zone, size, snapshot_id = nil)
  request({
    'Action' => 'CreateVolume',
    'AvailabilityZone' => availability_zone,
    'Size' => size,
    'SnapshotId' => snapshot_id
  }, Fog::Parsers::AWS::EC2::CreateVolume.new)
end

#delete_key_pair(key_name) ⇒ Object

Delete a key pair that you own

Parameters

  • key_name<~String> - Name of the key pair.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> id of request

      • ‘return’<~Boolean> - success?



17
18
19
20
21
22
# File 'lib/fog/aws/requests/ec2/delete_key_pair.rb', line 17

def delete_key_pair(key_name)
  request({
    'Action' => 'DeleteKeyPair',
    'KeyName' => key_name
  }, Fog::Parsers::AWS::EC2::Basic.new)
end

#delete_security_group(name) ⇒ Object

Delete a security group that you own

Parameters

  • group_name<~String> - Name of the security group.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘return’<~Boolean> - success?



17
18
19
20
21
22
# File 'lib/fog/aws/requests/ec2/delete_security_group.rb', line 17

def delete_security_group(name)
  request({
    'Action' => 'DeleteSecurityGroup',
    'GroupName' => name
  }, Fog::Parsers::AWS::EC2::Basic.new)
end

#delete_snapshot(snapshot_id) ⇒ Object

Delete a snapshot of an EBS volume that you own

Parameters

  • snapshot_id<~String> - ID of snapshot to delete

Returns

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘return’<~Boolean> - success?



17
18
19
20
21
22
# File 'lib/fog/aws/requests/ec2/delete_snapshot.rb', line 17

def delete_snapshot(snapshot_id)
  request({
    'Action' => 'DeleteSnapshot',
    'SnapshotId' => snapshot_id
  }, Fog::Parsers::AWS::EC2::Basic.new)
end

#delete_volume(volume_id) ⇒ Object

Delete an EBS volume

Parameters

  • volume_id<~String> - Id of volume to delete.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘return’<~Boolean> - success?



17
18
19
20
21
22
# File 'lib/fog/aws/requests/ec2/delete_volume.rb', line 17

def delete_volume(volume_id)
  request({
    'Action' => 'DeleteVolume',
    'VolumeId' => volume_id
  }, Fog::Parsers::AWS::EC2::Basic.new)
end

#describe_addresses(public_ip = []) ⇒ Object

Describe all or specified IP addresses.

Parameters

  • public_ip<~Array> - List of ips to describe, defaults to all

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘addressesSet’<~Array>:

        • ‘instanceId’<~String> - instance for ip address

        • ‘publicIp’<~String> - ip address for instance



19
20
21
22
23
24
# File 'lib/fog/aws/requests/ec2/describe_addresses.rb', line 19

def describe_addresses(public_ip = [])
  params = indexed_params('PublicIp', public_ip)
  request({
    'Action' => 'DescribeAddresses'
  }.merge!(params), Fog::Parsers::AWS::EC2::DescribeAddresses.new)
end

#describe_availability_zones(zone_name = []) ⇒ Object

Describe all or specified availability zones

Params

  • zone_name<~String> - List of availability zones to describe, defaults to all

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘availabilityZoneInfo’<~Array>:

        • ‘regionName’<~String> - Name of region

        • ‘zoneName’<~String> - Name of zone

        • ‘zoneState’<~String> - State of zone



20
21
22
23
24
25
# File 'lib/fog/aws/requests/ec2/describe_availability_zones.rb', line 20

def describe_availability_zones(zone_name = [])
  params = indexed_params('ZoneName', zone_name)
  request({
    'Action' => 'DescribeAvailabilityZones'
  }.merge!(params), Fog::Parsers::AWS::EC2::DescribeAvailabilityZones.new)
end

#describe_images(options = {}) ⇒ Object

Describe all or specified images.

Params

  • options<~Hash> - Optional params

    • ‘ExecutableBy’<~String> - Only return images that the executable_by user has explicit permission to launch

    • ‘ImageId’<~Array> - Ids of images to describe

    • ‘Owner’<~String> - Only return images belonging to owner.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘imagesSet’<~Array>:

        • ‘architecture’<~String> - Architecture of the image

        • ‘imageId’<~String> - Id of the image

        • ‘imageLocation’<~String> - Location of the image

        • ‘imageOwnerId’<~String> - Id of the owner of the image

        • ‘imageState’<~String> - State of the image

        • ‘imageType’<~String> - Type of the image

        • ‘isPublic’<~Boolean> - Whether or not the image is public

        • ‘kernelId’<~String> - Kernel id associated with image, if any

        • ‘platform’<~String> - Operating platform of the image

        • ‘productCodes’<~Array> - Product codes for the image

        • ‘ramdiskId’<~String> - Ramdisk id associated with image, if any



32
33
34
35
36
37
38
39
# File 'lib/fog/aws/requests/ec2/describe_images.rb', line 32

def describe_images(options = {})
  if image_id = options.delete('ImageId')
    options.merge!(indexed_params('ImageId', image_id))
  end
  request({
    'Action' => 'DescribeImages'
  }.merge!(options), Fog::Parsers::AWS::EC2::DescribeImages.new)
end

#describe_instances(instance_id = {}) ⇒ Object

Describe all or specified instances

Parameters

  • instance_id<~Array> - List of instance ids to describe, defaults to all

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘reservationSet’<~Array>:

        • ‘groupSet’<~Array> - Group names for reservation

        • ‘ownerId’<~String> - AWS Access Key ID of reservation owner

        • ‘reservationId’<~String> - Id of the reservation

        • ‘instancesSet’<~Array>:

          • instance<~Hash>:

            • ‘amiLaunchIndex’<~Integer> - reference to instance in launch group

            • ‘dnsName’<~String> - public dns name, blank until instance is running

            • ‘imageId’<~String> - image id of ami used to launch instance

            • ‘instanceId’<~String> - id of the instance

            • ‘instanceState’<~Hash>:

              • ‘code’<~Integer> - current status code

              • ‘name’<~String> - current status name

            • ‘instanceType’<~String> - type of instance

            • ‘kernelId’<~String> - Id of kernel used to launch instance

            • ‘keyName’<~String> - name of key used launch instances or blank

            • ‘launchTime’<~Time> - time instance was launched

            • ‘monitoring’<~Hash>:

              • ‘state’<~Boolean - state of monitoring

            • ‘placement’<~Hash>:

              • ‘availabilityZone’<~String> - Availability zone of the instance

            • ‘productCodes’<~Array> - Product codes for the instance

            • ‘privateDnsName’<~String> - private dns name, blank until instance is running

            • ‘ramdiskId’<~String> - Id of ramdisk used to launch instance

            • ‘reason’<~String> - reason for most recent state transition, or blank



41
42
43
44
45
46
# File 'lib/fog/aws/requests/ec2/describe_instances.rb', line 41

def describe_instances(instance_id = [])
  params = indexed_params('InstanceId', instance_id)
  request({
    'Action' => 'DescribeInstances'
  }.merge!(params), Fog::Parsers::AWS::EC2::DescribeInstances.new)
end

#describe_key_pairs(key_name = []) ⇒ Object

Describe all or specified key pairs

Parameters

  • key_name<~Array>

    List of key names to describe, defaults to all

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘keySet’<~Array>:

        • ‘keyName’<~String> - Name of key

        • ‘keyFingerprint’<~String> - Fingerprint of key



19
20
21
22
23
24
# File 'lib/fog/aws/requests/ec2/describe_key_pairs.rb', line 19

def describe_key_pairs(key_name = [])
  params = indexed_params('KeyName', key_name)
  request({
    'Action' => 'DescribeKeyPairs'
  }.merge!(params), Fog::Parsers::AWS::EC2::DescribeKeyPairs.new)
end

#describe_regions(region_name = []) ⇒ Object

Describe all or specified regions

Params

  • region_name<~String> - List of regions to describe, defaults to all

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘regionInfo’<~Array>:

        • ‘regionName’<~String> - Name of region

        • ‘regionEndpoint’<~String> - Service endpoint for region



19
20
21
22
23
24
# File 'lib/fog/aws/requests/ec2/describe_regions.rb', line 19

def describe_regions(region_name = [])
  params = indexed_params('RegionName', region_name)
  request({
    'Action' => 'DescribeRegions'
  }.merge!(params), Fog::Parsers::AWS::EC2::DescribeRegions.new)
end

#describe_security_groups(group_name = []) ⇒ Object

Describe all or specified security groups

Parameters

  • group_name<~Array> - List of groups to describe, defaults to all

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘securityGroupInfo’<~Array>:

        • ‘groupDescription’<~String> - Description of security group

        • ‘groupName’<~String> - Name of security group

        • ‘ipPermissions’<~Array>:

          • ‘fromPort’<~Integer> - Start of port range (or -1 for ICMP wildcard)

          • ‘groups’<~Array>:

            • ‘groupName’<~String> - Name of security group

            • ‘userId’<~String> - AWS User Id of account

          • ‘ipProtocol’<~String> - Ip protocol, must be in [‘tcp’, ‘udp’, ‘icmp’]

          • ‘ipRanges’<~Array>:

            • ‘cidrIp’<~String> - CIDR range

          • ‘toPort’<~Integer> - End of port range (or -1 for ICMP wildcard)

        • ‘ownerId’<~String> - AWS Access Key Id of the owner of the security group



29
30
31
32
33
34
# File 'lib/fog/aws/requests/ec2/describe_security_groups.rb', line 29

def describe_security_groups(group_name = [])
  params = indexed_params('GroupName', group_name)
  request({
    'Action' => 'DescribeSecurityGroups',
  }.merge!(params), Fog::Parsers::AWS::EC2::DescribeSecurityGroups.new)
end

#describe_snapshots(snapshot_id = []) ⇒ Object

Describe all or specified snapshots

Parameters

  • snapshot_id<~Array> - List of snapshots to describe, defaults to all

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘snapshotSet’<~Array>:

        • ‘progress’<~String>: The percentage progress of the snapshot

        • ‘snapshotId’<~String>: Id of the snapshot

        • ‘startTime’<~Time>: Timestamp of when snapshot was initiated

        • ‘status’<~String>: Snapshot state, in [‘pending’, ‘completed’]

        • ‘volumeId’<~String>: Id of volume that snapshot contains



22
23
24
25
26
27
# File 'lib/fog/aws/requests/ec2/describe_snapshots.rb', line 22

def describe_snapshots(snapshot_id = [])
  params = indexed_params('SnapshotId', snapshot_id)
  request({
    'Action' => 'DescribeSnapshots'
  }.merge!(params), Fog::Parsers::AWS::EC2::DescribeSnapshots.new)
end

#describe_volumes(volume_id = []) ⇒ Object

Describe all or specified volumes.

Parameters

  • volume_id<~Array> - List of volumes to describe, defaults to all

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘volumeSet’<~Array>:

        • ‘availabilityZone’<~String> - Availability zone for volume

        • ‘createTime’<~Time> - Timestamp for creation

        • ‘size’<~Integer> - Size in GiBs for volume

        • ‘snapshotId’<~String> - Snapshot volume was created from, if any

        • ‘status’<~String> - State of volume

        • ‘volumeId’<~String> - Reference to volume

        • ‘attachmentSet’<~Array>:

          • ‘attachmentTime’<~Time> - Timestamp for attachment

          • ‘device’<~String> - How value is exposed to instance

          • ‘instanceId’<~String> - Reference to attached instance

          • ‘status’<~String> - Attachment state

          • ‘volumeId’<~String> - Reference to volume



28
29
30
31
32
33
# File 'lib/fog/aws/requests/ec2/describe_volumes.rb', line 28

def describe_volumes(volume_id = [])
  params = indexed_params('VolumeId', volume_id)
  request({
    'Action' => 'DescribeVolumes'
  }.merge!(params), Fog::Parsers::AWS::EC2::DescribeVolumes.new)
end

#detach_volume(volume_id, options = {}) ⇒ Object

Detach an Amazon EBS volume from a running instance

Parameters

  • volume_id<~String> - Id of amazon EBS volume to associate with instance

  • options<~Hash>:

    • ‘Device’<~String> - Specifies how the device is exposed to the instance (e.g. “/dev/sdh”)

    • ‘Force’<~Boolean> - If true forces detach, can cause data loss/corruption

    • ‘InstanceId’<~String> - Id of instance to associate volume with

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘attachTime’<~Time> - Time of attachment was initiated at

      • ‘device’<~String> - Device as it is exposed to the instance

      • ‘instanceId’<~String> - Id of instance for volume

      • ‘requestId’<~String> - Id of request

      • ‘status’<~String> - Status of volume

      • ‘volumeId’<~String> - Reference to volume



25
26
27
28
29
30
# File 'lib/fog/aws/requests/ec2/detach_volume.rb', line 25

def detach_volume(volume_id, options = {})
  request({
    'Action' => 'DetachVolume',
    'VolumeId' => volume_id
  }.merge!(options), Fog::Parsers::AWS::EC2::DetachVolume.new)
end

#disassociate_address(public_ip) ⇒ Object

Disassociate an elastic IP address from its instance (if any)

Parameters

  • public_ip<~String> - Public ip to assign to instance

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘return’<~Boolean> - success?



17
18
19
20
21
22
# File 'lib/fog/aws/requests/ec2/disassociate_address.rb', line 17

def disassociate_address(public_ip)
  request({
    'Action' => 'DisassociateAddress',
    'PublicIp' => public_ip
  }, Fog::Parsers::AWS::EC2::Basic.new)
end

#flavorsObject



5
6
7
# File 'lib/fog/aws/models/ec2/flavors.rb', line 5

def flavors
  Fog::AWS::EC2::Flavors.new(:connection => self)
end

#get_console_output(instance_id) ⇒ Object

Retrieve console output for specified instance

Parameters

  • instance_id<~String> - Id of instance to get console output from

Returns

# * response<~Excon::Response>:

* body<~Hash>:
  * 'instanceId'<~String> - Id of instance
  * 'output'<~String> - Console output
  * 'requestId'<~String> - Id of request
  * 'timestamp'<~Time> - Timestamp of last update to output


19
20
21
22
23
24
# File 'lib/fog/aws/requests/ec2/get_console_output.rb', line 19

def get_console_output(instance_id)
  request({
    'Action' => 'GetConsoleOutput',
    'InstanceId' => instance_id
  }, Fog::Parsers::AWS::EC2::GetConsoleOutput.new)
end

#imagesObject



5
6
7
# File 'lib/fog/aws/models/ec2/images.rb', line 5

def images
  Fog::AWS::EC2::Images.new(:connection => self)
end

#key_pairsObject



5
6
7
# File 'lib/fog/aws/models/ec2/key_pairs.rb', line 5

def key_pairs
  Fog::AWS::EC2::KeyPairs.new(:connection => self)
end

#reboot_instances(instance_id = []) ⇒ Object

Reboot specified instances

Parameters

  • instance_id<~Array> - Ids of instances to reboot

Returns

# * response<~Excon::Response>:

* body<~Hash>:
  * 'requestId'<~String> - Id of request
  * 'return'<~Boolean> - success?


17
18
19
20
21
22
# File 'lib/fog/aws/requests/ec2/reboot_instances.rb', line 17

def reboot_instances(instance_id = [])
  params = indexed_params('InstanceId', instance_id)
  request({
    'Action' => 'RebootInstances'
  }.merge!(params), Fog::Parsers::AWS::EC2::Basic.new)
end

#release_address(public_ip) ⇒ Object

Release an elastic IP address.

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘requestId’<~String> - Id of request

      • ‘return’<~Boolean> - success?



14
15
16
17
18
19
# File 'lib/fog/aws/requests/ec2/release_address.rb', line 14

def release_address(public_ip)
  request({
    'Action' => 'ReleaseAddress',
    'PublicIp' => public_ip
  }, Fog::Parsers::AWS::EC2::Basic.new)
end

#revoke_security_group_ingress(options = {}) ⇒ Object

TODO: handle the GroupName/Source/Source case



26
27
28
29
30
# File 'lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb', line 26

def revoke_security_group_ingress(options = {})
  request({
    'Action' => 'RevokeSecurityGroupIngress'
  }.merge!(options), Fog::Parsers::AWS::EC2::Basic.new)
end

#run_instances(image_id, min_count, max_count, options = {}) ⇒ Object

Launch specified instances

Parameters

  • image_id<~String> - Id of machine image to load on instances

  • min_count<~Integer> - Minimum number of instances to launch. If this exceeds the count of available instances, no instances will be launched. Must be between 1 and maximum allowed for your account (by default the maximum for an account is 20)

  • max_count<~Integer> - Maximum number of instances to launch. If this exceeds the number of available instances, the largest possible number of instances above min_count will be launched instead. Must be between 1 and maximum allowed for you account (by default the maximum for an account is 20)

  • options<~Hash>:

    • ‘Placement.AvailabilityZone’<~String> - Placement constraint for instances

    • ‘DeviceName’<~String> - ?

    • ‘Encoding’<~String> - ?

    • ‘SecurityGroup.n’<~String> - Indexed names of security groups for instances

    • ‘InstanceType’<~String> - Type of instance to boot. Valid options in [‘m1.small’, ‘m1.large’, ‘m1.xlarge’, ‘c1.medium’, ‘c1.xlarge’, ‘m2.2xlarge’, ‘m2.4xlarge’] default is ‘m1.small’

    • ‘KernelId’<~String> - Id of kernel with which to launch

    • ‘KeyName’<~String> - Name of a keypair to add to booting instances

    • ‘Monitoring.Enabled’<~Boolean> - Enables monitoring, defaults to disabled

    • ‘RamdiskId’<~String> - Id of ramdisk with which to launch

    • ‘UserData’<~String> - Additional data to provide to booting instances

    • ‘Version’<~String> - ?

    • ‘VirtualName’<~String> - ?

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘groupSet’<~Array>: groups the instances are members in

        • ‘groupName’<~String> - Name of group

      • ‘instancesSet’<~Array>: returned instances

        • instance<~Hash>:

          • ‘amiLaunchIndex’<~Integer> - reference to instance in launch group

          • ‘dnsName’<~String> - public dns name, blank until instance is running

          • ‘imageId’<~String> - image id of ami used to launch instance

          • ‘instanceId’<~String> - id of the instance

          • ‘instanceState’<~Hash>:

            • ‘code’<~Integer> - current status code

            • ‘name’<~String> - current status name

          • ‘instanceType’<~String> - type of instance

          • ‘kernelId’<~String> - Id of kernel used to launch instance

          • ‘keyName’<~String> - name of key used launch instances or blank

          • ‘launchTime’<~Time> - time instance was launched

          • ‘monitoring’<~Hash>:

            • ‘state’<~Boolean - state of monitoring

          • ‘placement’<~Hash>:

            • ‘availabilityZone’<~String> - Availability zone of the instance

          • ‘privateDnsName’<~String> - private dns name, blank until instance is running

          • ‘productCodes’<~Array> - Product codes for the instance

          • ‘ramdiskId’<~String> - Id of ramdisk used to launch instance

          • ‘reason’<~String> - reason for most recent state transition, or blank

      • ‘ownerId’<~String> - Id of owner

      • ‘requestId’<~String> - Id of request

      • ‘reservationId’<~String> - Id of reservation



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fog/aws/requests/ec2/run_instances.rb', line 66

def run_instances(image_id, min_count, max_count, options = {})
  if options['UserData']
    options['UserData'] = Base64.encode64(options['UserData'])
  end
  request({
    'Action' => 'RunInstances',
    'ImageId' => image_id,
    'MinCount' => min_count,
    'MaxCount' => max_count
  }.merge!(options), Fog::Parsers::AWS::EC2::RunInstances.new)
end

#security_groupsObject



5
6
7
# File 'lib/fog/aws/models/ec2/security_groups.rb', line 5

def security_groups
  Fog::AWS::EC2::SecurityGroups.new(:connection => self)
end

#serversObject



5
6
7
# File 'lib/fog/aws/models/ec2/servers.rb', line 5

def servers
  Fog::AWS::EC2::Servers.new(:connection => self)
end

#snapshots(attributes = {}) ⇒ Object



5
6
7
8
9
# File 'lib/fog/aws/models/ec2/snapshots.rb', line 5

def snapshots(attributes = {})
  Fog::AWS::EC2::Snapshots.new({
    :connection => self
  }.merge!(attributes))
end

#terminate_instances(instance_id) ⇒ Object

Terminate specified instances

Parameters

  • instance_id<~Array> - Ids of instances to terminates

Returns

# * response<~Excon::Response>:

* body<~Hash>:
  * 'requestId'<~String> - Id of request
  * 'instancesSet'<~Array>:
    * 'instanceId'<~String> - id of the terminated instance
    * 'previousState'<~Hash>: previous state of instance
      * 'code'<~Integer> - previous status code
      * 'name'<~String> - name of previous state
    * 'shutdownState'<~Hash>: shutdown state of instance
      * 'code'<~Integer> - current status code
      * 'name'<~String> - name of current state


24
25
26
27
28
29
# File 'lib/fog/aws/requests/ec2/terminate_instances.rb', line 24

def terminate_instances(instance_id)
  params = indexed_params('InstanceId', instance_id)
  request({
    'Action' => 'TerminateInstances'
  }.merge!(params), Fog::Parsers::AWS::EC2::TerminateInstances.new)
end

#volumes(attributes = {}) ⇒ Object



5
6
7
8
9
# File 'lib/fog/aws/models/ec2/volumes.rb', line 5

def volumes(attributes = {})
  Fog::AWS::EC2::Volumes.new({
    :connection => self
  }.merge!(attributes))
end