fog 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +98 -0
- data/VERSION +1 -0
- data/benchs/fog_vs.rb +135 -0
- data/benchs/headers_split_vs_match.rb +18 -0
- data/benchs/params.rb +43 -0
- data/benchs/parse_vs_push.rb +60 -0
- data/benchs/stripping.rb +26 -0
- data/lib/fog.rb +21 -0
- data/lib/fog/aws.rb +145 -0
- data/lib/fog/aws/ec2.rb +173 -0
- data/lib/fog/aws/models/ec2/address.rb +31 -0
- data/lib/fog/aws/models/ec2/addresses.rb +36 -0
- data/lib/fog/aws/models/ec2/key_pair.rb +35 -0
- data/lib/fog/aws/models/ec2/key_pairs.rb +36 -0
- data/lib/fog/aws/models/ec2/volume.rb +47 -0
- data/lib/fog/aws/models/ec2/volumes.rb +36 -0
- data/lib/fog/aws/models/s3/bucket.rb +77 -0
- data/lib/fog/aws/models/s3/buckets.rb +83 -0
- data/lib/fog/aws/models/s3/object.rb +76 -0
- data/lib/fog/aws/models/s3/objects.rb +97 -0
- data/lib/fog/aws/models/s3/owner.rb +18 -0
- data/lib/fog/aws/parsers/ec2/allocate_address.rb +19 -0
- data/lib/fog/aws/parsers/ec2/attach_volume.rb +22 -0
- data/lib/fog/aws/parsers/ec2/basic.rb +25 -0
- data/lib/fog/aws/parsers/ec2/create_key_pair.rb +20 -0
- data/lib/fog/aws/parsers/ec2/create_snapshot.rb +22 -0
- data/lib/fog/aws/parsers/ec2/create_volume.rb +24 -0
- data/lib/fog/aws/parsers/ec2/describe_addresses.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_availability_zones.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_images.rb +49 -0
- data/lib/fog/aws/parsers/ec2/describe_instances.rb +73 -0
- data/lib/fog/aws/parsers/ec2/describe_key_pairs.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_regions.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_security_groups.rb +75 -0
- data/lib/fog/aws/parsers/ec2/describe_snapshots.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_volumes.rb +57 -0
- data/lib/fog/aws/parsers/ec2/detach_volume.rb +22 -0
- data/lib/fog/aws/parsers/ec2/get_console_output.rb +28 -0
- data/lib/fog/aws/parsers/ec2/run_instances.rb +65 -0
- data/lib/fog/aws/parsers/ec2/terminate_instances.rb +55 -0
- data/lib/fog/aws/parsers/s3/copy_object.rb +22 -0
- data/lib/fog/aws/parsers/s3/get_bucket.rb +46 -0
- data/lib/fog/aws/parsers/s3/get_bucket_location.rb +20 -0
- data/lib/fog/aws/parsers/s3/get_request_payment.rb +20 -0
- data/lib/fog/aws/parsers/s3/get_service.rb +32 -0
- data/lib/fog/aws/parsers/simpledb/basic.rb +31 -0
- data/lib/fog/aws/parsers/simpledb/domain_metadata.rb +30 -0
- data/lib/fog/aws/parsers/simpledb/get_attributes.rb +34 -0
- data/lib/fog/aws/parsers/simpledb/list_domains.rb +28 -0
- data/lib/fog/aws/parsers/simpledb/select.rb +39 -0
- data/lib/fog/aws/requests/ec2/allocate_address.rb +50 -0
- data/lib/fog/aws/requests/ec2/associate_address.rb +59 -0
- data/lib/fog/aws/requests/ec2/attach_volume.rb +71 -0
- data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +32 -0
- data/lib/fog/aws/requests/ec2/create_key_pair.rb +60 -0
- data/lib/fog/aws/requests/ec2/create_security_group.rb +61 -0
- data/lib/fog/aws/requests/ec2/create_snapshot.rb +65 -0
- data/lib/fog/aws/requests/ec2/create_volume.rb +66 -0
- data/lib/fog/aws/requests/ec2/delete_key_pair.rb +49 -0
- data/lib/fog/aws/requests/ec2/delete_security_group.rb +52 -0
- data/lib/fog/aws/requests/ec2/delete_snapshot.rb +53 -0
- data/lib/fog/aws/requests/ec2/delete_volume.rb +55 -0
- data/lib/fog/aws/requests/ec2/describe_addresses.rb +61 -0
- data/lib/fog/aws/requests/ec2/describe_availability_zones.rb +64 -0
- data/lib/fog/aws/requests/ec2/describe_images.rb +41 -0
- data/lib/fog/aws/requests/ec2/describe_instances.rb +114 -0
- data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +63 -0
- data/lib/fog/aws/requests/ec2/describe_regions.rb +61 -0
- data/lib/fog/aws/requests/ec2/describe_security_groups.rb +71 -0
- data/lib/fog/aws/requests/ec2/describe_snapshots.rb +78 -0
- data/lib/fog/aws/requests/ec2/describe_volumes.rb +85 -0
- data/lib/fog/aws/requests/ec2/detach_volume.rb +62 -0
- data/lib/fog/aws/requests/ec2/disassociate_address.rb +55 -0
- data/lib/fog/aws/requests/ec2/get_console_output.rb +26 -0
- data/lib/fog/aws/requests/ec2/reboot_instances.rb +24 -0
- data/lib/fog/aws/requests/ec2/release_address.rb +50 -0
- data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +32 -0
- data/lib/fog/aws/requests/ec2/run_instances.rb +134 -0
- data/lib/fog/aws/requests/ec2/terminate_instances.rb +80 -0
- data/lib/fog/aws/requests/s3/copy_object.rb +79 -0
- data/lib/fog/aws/requests/s3/delete_bucket.rb +53 -0
- data/lib/fog/aws/requests/s3/delete_object.rb +52 -0
- data/lib/fog/aws/requests/s3/get_bucket.rb +100 -0
- data/lib/fog/aws/requests/s3/get_bucket_location.rb +53 -0
- data/lib/fog/aws/requests/s3/get_object.rb +82 -0
- data/lib/fog/aws/requests/s3/get_request_payment.rb +53 -0
- data/lib/fog/aws/requests/s3/get_service.rb +58 -0
- data/lib/fog/aws/requests/s3/head_object.rb +61 -0
- data/lib/fog/aws/requests/s3/put_bucket.rb +69 -0
- data/lib/fog/aws/requests/s3/put_object.rb +76 -0
- data/lib/fog/aws/requests/s3/put_request_payment.rb +56 -0
- data/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +31 -0
- data/lib/fog/aws/requests/simpledb/create_domain.rb +25 -0
- data/lib/fog/aws/requests/simpledb/delete_attributes.rb +34 -0
- data/lib/fog/aws/requests/simpledb/delete_domain.rb +25 -0
- data/lib/fog/aws/requests/simpledb/domain_metadata.rb +30 -0
- data/lib/fog/aws/requests/simpledb/get_attributes.rb +35 -0
- data/lib/fog/aws/requests/simpledb/list_domains.rb +30 -0
- data/lib/fog/aws/requests/simpledb/put_attributes.rb +29 -0
- data/lib/fog/aws/requests/simpledb/select.rb +29 -0
- data/lib/fog/aws/s3.rb +157 -0
- data/lib/fog/aws/simpledb.rb +157 -0
- data/lib/fog/collection.rb +77 -0
- data/lib/fog/connection.rb +130 -0
- data/lib/fog/errors.rb +145 -0
- data/lib/fog/model.rb +72 -0
- data/lib/fog/parser.rb +30 -0
- data/lib/fog/response.rb +12 -0
- data/spec/aws/models/s3/bucket_spec.rb +130 -0
- data/spec/aws/models/s3/buckets_spec.rb +79 -0
- data/spec/aws/models/s3/object_spec.rb +121 -0
- data/spec/aws/models/s3/objects_spec.rb +112 -0
- data/spec/aws/models/s3/owner_spec.rb +18 -0
- data/spec/aws/requests/ec2/allocate_address_spec.rb +18 -0
- data/spec/aws/requests/ec2/associate_address_spec.rb +42 -0
- data/spec/aws/requests/ec2/attach_volume_spec.rb +53 -0
- data/spec/aws/requests/ec2/authorize_security_group_ingress_spec.rb +26 -0
- data/spec/aws/requests/ec2/create_key_pair_spec.rb +36 -0
- data/spec/aws/requests/ec2/create_security_group_spec.rb +34 -0
- data/spec/aws/requests/ec2/create_snapshot_spec.rb +37 -0
- data/spec/aws/requests/ec2/create_volume_spec.rb +23 -0
- data/spec/aws/requests/ec2/delete_key_pair_spec.rb +21 -0
- data/spec/aws/requests/ec2/delete_security_group_spec.rb +26 -0
- data/spec/aws/requests/ec2/delete_snapshot_spec.rb +35 -0
- data/spec/aws/requests/ec2/delete_volume_spec.rb +26 -0
- data/spec/aws/requests/ec2/describe_addresses_spec.rb +38 -0
- data/spec/aws/requests/ec2/describe_availability_zones_spec.rb +23 -0
- data/spec/aws/requests/ec2/describe_images_spec.rb +39 -0
- data/spec/aws/requests/ec2/describe_instances_spec.rb +86 -0
- data/spec/aws/requests/ec2/describe_key_pairs_spec.rb +42 -0
- data/spec/aws/requests/ec2/describe_regions_spec.rb +21 -0
- data/spec/aws/requests/ec2/describe_security_groups_spec.rb +51 -0
- data/spec/aws/requests/ec2/describe_snapshots_spec.rb +54 -0
- data/spec/aws/requests/ec2/describe_volumes_spec.rb +50 -0
- data/spec/aws/requests/ec2/detach_volume_spec.rb +43 -0
- data/spec/aws/requests/ec2/disassociate_address_spec.rb +35 -0
- data/spec/aws/requests/ec2/get_console_output_spec.rb +23 -0
- data/spec/aws/requests/ec2/reboot_instances_spec.rb +21 -0
- data/spec/aws/requests/ec2/release_address_spec.rb +26 -0
- data/spec/aws/requests/ec2/revoke_security_group_ingress_spec.rb +32 -0
- data/spec/aws/requests/ec2/run_instances_spec.rb +41 -0
- data/spec/aws/requests/ec2/terminate_instances_spec.rb +35 -0
- data/spec/aws/requests/s3/copy_object_spec.rb +62 -0
- data/spec/aws/requests/s3/delete_bucket_spec.rb +36 -0
- data/spec/aws/requests/s3/delete_object_spec.rb +37 -0
- data/spec/aws/requests/s3/get_bucket_location_spec.rb +30 -0
- data/spec/aws/requests/s3/get_bucket_spec.rb +110 -0
- data/spec/aws/requests/s3/get_object_spec.rb +45 -0
- data/spec/aws/requests/s3/get_request_payment_spec.rb +30 -0
- data/spec/aws/requests/s3/get_service_spec.rb +33 -0
- data/spec/aws/requests/s3/head_object_spec.rb +28 -0
- data/spec/aws/requests/s3/put_bucket_spec.rb +19 -0
- data/spec/aws/requests/s3/put_object_spec.rb +38 -0
- data/spec/aws/requests/s3/put_request_payment_spec.rb +29 -0
- data/spec/aws/requests/simpledb/batch_put_attributes_spec.rb +22 -0
- data/spec/aws/requests/simpledb/create_domain_spec.rb +21 -0
- data/spec/aws/requests/simpledb/delete_attributes_spec.rb +22 -0
- data/spec/aws/requests/simpledb/delete_domain_spec.rb +21 -0
- data/spec/aws/requests/simpledb/domain_metadata_spec.rb +43 -0
- data/spec/aws/requests/simpledb/get_attributes_spec.rb +31 -0
- data/spec/aws/requests/simpledb/list_domains_spec.rb +30 -0
- data/spec/aws/requests/simpledb/put_attributes_spec.rb +22 -0
- data/spec/aws/requests/simpledb/select_spec.rb +9 -0
- data/spec/lorem.txt +1 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +66 -0
- metadata +309 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
unless Fog.mocking?
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module AWS
|
5
|
+
class EC2
|
6
|
+
|
7
|
+
# Detach an Amazon EBS volume from a running instance
|
8
|
+
#
|
9
|
+
# ==== Parameters
|
10
|
+
# * volume_id<~String> - Id of amazon EBS volume to associate with instance
|
11
|
+
# * options<~Hash>:
|
12
|
+
# * 'Device'<~String> - Specifies how the device is exposed to the instance (e.g. "/dev/sdh")
|
13
|
+
# * 'Force'<~Boolean> - If true forces detach, can cause data loss/corruption
|
14
|
+
# * 'InstanceId'<~String> - Id of instance to associate volume with
|
15
|
+
#
|
16
|
+
# ==== Returns
|
17
|
+
# * response<~Fog::AWS::Response>:
|
18
|
+
# * body<~Hash>:
|
19
|
+
# * 'attachTime'<~Time> - Time of attachment was initiated at
|
20
|
+
# * 'device'<~String> - Device as it is exposed to the instance
|
21
|
+
# * 'instanceId'<~String> - Id of instance for volume
|
22
|
+
# * 'requestId'<~String> - Id of request
|
23
|
+
# * 'status'<~String> - Status of volume
|
24
|
+
# * 'volumeId'<~String> - Reference to volume
|
25
|
+
def detach_volume(volume_id, options = {})
|
26
|
+
request({
|
27
|
+
'Action' => 'DetachVolume',
|
28
|
+
'VolumeId' => volume_id
|
29
|
+
}.merge!(options), Fog::Parsers::AWS::EC2::DetachVolume.new)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
else
|
37
|
+
|
38
|
+
module Fog
|
39
|
+
module AWS
|
40
|
+
class EC2
|
41
|
+
|
42
|
+
def detach_volume(volume_id, options = {})
|
43
|
+
response = Fog::Response.new
|
44
|
+
response.status = 200
|
45
|
+
if volume = Fog::AWS::EC2.data[:volumes][volume_id]
|
46
|
+
data = volume['attachmentSet'].pop
|
47
|
+
response.status = 200
|
48
|
+
response.body = {
|
49
|
+
'requestId' => Fog::AWS::Mock.request_id
|
50
|
+
}.merge!(data)
|
51
|
+
else
|
52
|
+
response.status = 400
|
53
|
+
raise(Fog::Errors.status_error(200, 400, response))
|
54
|
+
end
|
55
|
+
response
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
unless Fog.mocking?
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module AWS
|
5
|
+
class EC2
|
6
|
+
|
7
|
+
# Disassociate an elastic IP address from its instance (if any)
|
8
|
+
#
|
9
|
+
# ==== Parameters
|
10
|
+
# * public_ip<~String> - Public ip to assign to instance
|
11
|
+
#
|
12
|
+
# ==== Returns
|
13
|
+
# * response<~Fog::AWS::Response>:
|
14
|
+
# * body<~Hash>:
|
15
|
+
# * 'requestId'<~String> - Id of request
|
16
|
+
# * 'return'<~Boolean> - success?
|
17
|
+
def disassociate_address(public_ip)
|
18
|
+
request({
|
19
|
+
'Action' => 'DisassociateAddress',
|
20
|
+
'PublicIp' => public_ip
|
21
|
+
}, Fog::Parsers::AWS::EC2::Basic.new)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
else
|
29
|
+
|
30
|
+
module Fog
|
31
|
+
module AWS
|
32
|
+
class EC2
|
33
|
+
|
34
|
+
def disassociate_address(public_ip)
|
35
|
+
response = Fog::Response.new
|
36
|
+
response.status = 200
|
37
|
+
if address = Fog::AWS::EC2.data[:addresses][public_ip]
|
38
|
+
address['instanceId'] = ''
|
39
|
+
response.status = 200
|
40
|
+
response.body = {
|
41
|
+
'requestId' => Fog::AWS::Mock.request_id,
|
42
|
+
'return' => true
|
43
|
+
}
|
44
|
+
else
|
45
|
+
response.status = 400
|
46
|
+
raise(Fog::Errors.status_error(200, 400, response))
|
47
|
+
end
|
48
|
+
response
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class EC2
|
4
|
+
|
5
|
+
# Retrieve console output for specified instance
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * instance_id<~String> - Id of instance to get console output from
|
9
|
+
#
|
10
|
+
# ==== Returns
|
11
|
+
# # * response<~Fog::AWS::Response>:
|
12
|
+
# * body<~Hash>:
|
13
|
+
# * 'instanceId'<~String> - Id of instance
|
14
|
+
# * 'output'<~String> - Console output
|
15
|
+
# * 'requestId'<~String> - Id of request
|
16
|
+
# * 'timestamp'<~Time> - Timestamp of last update to output
|
17
|
+
def get_console_output(instance_id)
|
18
|
+
request({
|
19
|
+
'Action' => 'GetConsoleOutput',
|
20
|
+
'InstanceId' => instance_id
|
21
|
+
}, Fog::Parsers::AWS::EC2::GetConsoleOutput.new)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class EC2
|
4
|
+
|
5
|
+
# Reboot specified instances
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * instance_id<~Array> - Ids of instances to reboot
|
9
|
+
#
|
10
|
+
# ==== Returns
|
11
|
+
# # * response<~Fog::AWS::Response>:
|
12
|
+
# * body<~Hash>:
|
13
|
+
# * 'requestId'<~String> - Id of request
|
14
|
+
# * 'return'<~Boolean> - success?
|
15
|
+
def reboot_instances(instance_id = [])
|
16
|
+
params = indexed_params('InstanceId', instance_id)
|
17
|
+
request({
|
18
|
+
'Action' => 'RebootInstances'
|
19
|
+
}.merge!(params), Fog::Parsers::AWS::EC2::Basic.new)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
unless Fog.mocking?
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module AWS
|
5
|
+
class EC2
|
6
|
+
|
7
|
+
# Release an elastic IP address.
|
8
|
+
#
|
9
|
+
# ==== Returns
|
10
|
+
# * response<~Fog::AWS::Response>:
|
11
|
+
# * body<~Hash>:
|
12
|
+
# * 'requestId'<~String> - Id of request
|
13
|
+
# * 'return'<~Boolean> - success?
|
14
|
+
def release_address(public_ip)
|
15
|
+
request({
|
16
|
+
'Action' => 'ReleaseAddress',
|
17
|
+
'PublicIp' => public_ip
|
18
|
+
}, Fog::Parsers::AWS::EC2::Basic.new)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
else
|
26
|
+
|
27
|
+
module Fog
|
28
|
+
module AWS
|
29
|
+
class EC2
|
30
|
+
|
31
|
+
def release_address(public_ip)
|
32
|
+
response = Fog::Response.new
|
33
|
+
if (address = Fog::AWS::EC2.data[:addresses].delete(public_ip))
|
34
|
+
response.status = 200
|
35
|
+
response.body = {
|
36
|
+
'requestId' => Fog::AWS::Mock.request_id,
|
37
|
+
'return' => true
|
38
|
+
}
|
39
|
+
else
|
40
|
+
response.status = 400
|
41
|
+
raise(Fog::Errors.status_error(200, 400, response))
|
42
|
+
end
|
43
|
+
response
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class EC2
|
4
|
+
|
5
|
+
# Remove permissions from a security group
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * options<~Hash>:
|
9
|
+
# * 'GroupName'<~String> - Name of group
|
10
|
+
# * 'SourceSecurityGroupName'<~String> - Name of security group to authorize
|
11
|
+
# * 'SourceSecurityGroupOwnerId'<~String> - Name of owner to authorize
|
12
|
+
# or
|
13
|
+
# * 'CidrIp' - CIDR range
|
14
|
+
# * 'FromPort' - Start of port range (or -1 for ICMP wildcard)
|
15
|
+
# * 'GroupName' - Name of group to modify
|
16
|
+
# * 'IpProtocol' - Ip protocol, must be in ['tcp', 'udp', 'icmp']
|
17
|
+
# * 'ToPort' - End of port range (or -1 for ICMP wildcard)
|
18
|
+
#
|
19
|
+
# === Returns
|
20
|
+
# * response<~Fog::AWS::Response>:
|
21
|
+
# * body<~Hash>:
|
22
|
+
# * 'requestId'<~String> - Id of request
|
23
|
+
# * 'return'<~Boolean> - success?
|
24
|
+
def revoke_security_group_ingress(options = {})
|
25
|
+
request({
|
26
|
+
'Action' => 'RevokeSecurityGroupIngress'
|
27
|
+
}.merge!(options), Fog::Parsers::AWS::EC2::Basic.new)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
unless Fog.mocking?
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module AWS
|
5
|
+
class EC2
|
6
|
+
|
7
|
+
# Launch specified instances
|
8
|
+
#
|
9
|
+
# ==== Parameters
|
10
|
+
# * image_id<~String> - Id of machine image to load on instances
|
11
|
+
# * min_count<~Integer> - Minimum number of instances to launch. If this
|
12
|
+
# exceeds the count of available instances, no instances will be
|
13
|
+
# launched. Must be between 1 and maximum allowed for your account
|
14
|
+
# (by default the maximum for an account is 20)
|
15
|
+
# * max_count<~Integer> - Maximum number of instances to launch. If this
|
16
|
+
# exceeds the number of available instances, the largest possible
|
17
|
+
# number of instances above min_count will be launched instead. Must
|
18
|
+
# be between 1 and maximum allowed for you account
|
19
|
+
# (by default the maximum for an account is 20)
|
20
|
+
# * options<~Hash>:
|
21
|
+
# * 'Placement.AvailabilityZone'<~String> - Placement constraint for instances
|
22
|
+
# * 'DeviceName'<~String> - ?
|
23
|
+
# * 'Encoding'<~String> - ?
|
24
|
+
# * 'GroupId'<~String> - Name of security group for instances
|
25
|
+
# * 'InstanceType'<~String> - Type of instance to boot. Valid options
|
26
|
+
# in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge']
|
27
|
+
# default is 'm1.small'
|
28
|
+
# * 'KernelId'<~String> - Id of kernel with which to launch
|
29
|
+
# * 'KeyName'<~String> - Name of a keypair to add to booting instances
|
30
|
+
# * 'Monitoring.Enabled'<~Boolean> - Enables monitoring, defaults to
|
31
|
+
# disabled
|
32
|
+
# * 'RamdiskId'<~String> - Id of ramdisk with which to launch
|
33
|
+
# * 'UserData'<~String> - Additional data to provide to booting instances
|
34
|
+
# * 'Version'<~String> - ?
|
35
|
+
# * 'VirtualName'<~String> - ?
|
36
|
+
#
|
37
|
+
# ==== Returns
|
38
|
+
# * response<~Fog::AWS::Response>:
|
39
|
+
# * body<~Hash>:
|
40
|
+
# * 'groupSet'<~Array>: groups the instances are members in
|
41
|
+
# * 'groupName'<~String> - Name of group
|
42
|
+
# * 'instancesSet'<~Array>: returned instances
|
43
|
+
# * instance<~Hash>:
|
44
|
+
# * 'amiLaunchIndex'<~Integer> - reference to instance in launch group
|
45
|
+
# * 'dnsName'<~String> - public dns name, blank until instance is running
|
46
|
+
# * 'imageId'<~String> - image id of ami used to launch instance
|
47
|
+
# * 'instanceId'<~String> - id of the instance
|
48
|
+
# * 'instanceState'<~Hash>:
|
49
|
+
# * 'code'<~Integer> - current status code
|
50
|
+
# * 'name'<~String> - current status name
|
51
|
+
# * 'instanceType'<~String> - type of instance
|
52
|
+
# * 'kernelId'<~String> - Id of kernel used to launch instance
|
53
|
+
# * 'keyName'<~String> - name of key used launch instances or blank
|
54
|
+
# * 'launchTime'<~Time> - time instance was launched
|
55
|
+
# * 'monitoring'<~Hash>:
|
56
|
+
# * 'state'<~Boolean - state of monitoring
|
57
|
+
# * 'placement'<~Hash>:
|
58
|
+
# * 'availabilityZone'<~String> - Availability zone of the instance
|
59
|
+
# * 'privateDnsName'<~String> - private dns name, blank until instance is running
|
60
|
+
# * 'productCodes'<~Array> - Product codes for the instance
|
61
|
+
# * 'ramdiskId'<~String> - Id of ramdisk used to launch instance
|
62
|
+
# * 'reason'<~String> - reason for most recent state transition, or blank
|
63
|
+
# * 'ownerId'<~String> - Id of owner
|
64
|
+
# * 'requestId'<~String> - Id of request
|
65
|
+
# * 'reservationId'<~String> - Id of reservation
|
66
|
+
def run_instances(image_id, min_count, max_count, options = {})
|
67
|
+
request({
|
68
|
+
'Action' => 'RunInstances',
|
69
|
+
'ImageId' => image_id,
|
70
|
+
'MinCount' => min_count,
|
71
|
+
'MaxCount' => max_count
|
72
|
+
}.merge!(options), Fog::Parsers::AWS::EC2::RunInstances.new)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
else
|
80
|
+
|
81
|
+
module Fog
|
82
|
+
module AWS
|
83
|
+
class EC2
|
84
|
+
|
85
|
+
def run_instances(image_id, min_count, max_count, options = {})
|
86
|
+
response = Fog::Response.new
|
87
|
+
response.status = 200
|
88
|
+
|
89
|
+
group_set = [ (options['GroupId'] || 'default') ]
|
90
|
+
instances_set = []
|
91
|
+
owner_id = Fog::AWS::Mock.owner_id
|
92
|
+
reservation_id = Fog::AWS::Mock.reservation_id
|
93
|
+
|
94
|
+
min_count.times do |i|
|
95
|
+
instance_id = Fog::AWS::Mock.instance_id
|
96
|
+
data = {
|
97
|
+
'amiLaunchIndex' => i,
|
98
|
+
'dnsName' => '',
|
99
|
+
'groupSet' => group_set,
|
100
|
+
'imageId' => image_id,
|
101
|
+
'instanceId' => instance_id,
|
102
|
+
'instanceState' => { 'code' => 0, 'name' => 'pending' },
|
103
|
+
'instanceType' => options['InstanceType'] || 'm1.small',
|
104
|
+
'kernelId' => options['KernelId'] || Fog::AWS::Mock.kernel_id,
|
105
|
+
'keyName' => options['KeyName'] || '',
|
106
|
+
'launchTime' => Time.now,
|
107
|
+
'monitoring' => { 'state' => options['Monitoring.Enabled'] || false },
|
108
|
+
'ownerId' => owner_id,
|
109
|
+
'placement' => { 'availabilityZone' => options['Placement.AvailabilityZone'] || Fog::AWS::Mock.availability_zone },
|
110
|
+
'privateDnsName' => '',
|
111
|
+
'productCodes' => [],
|
112
|
+
'ramdiskId' => options['RamdiskId'] || Fog::AWS::Mock.ramdisk_id,
|
113
|
+
'reason' => '',
|
114
|
+
'reservationId' => reservation_id,
|
115
|
+
'state' => 'pending'
|
116
|
+
}
|
117
|
+
Fog::AWS::EC2.data[:instances][instance_id] = data
|
118
|
+
instances_set << data.reject{|key,value| !['amiLaunchIndex', 'dnsName', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'placement', 'privateDnsName', 'productCodes', 'ramdiskId', 'reason'].include?(key)}
|
119
|
+
end
|
120
|
+
response.body = {
|
121
|
+
'groupSet' => group_set,
|
122
|
+
'instancesSet' => instances_set,
|
123
|
+
'ownerId' => owner_id,
|
124
|
+
'requestId' => Fog::AWS::Mock.request_id,
|
125
|
+
'reservationId' => reservation_id
|
126
|
+
}
|
127
|
+
response
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
unless Fog.mocking?
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module AWS
|
5
|
+
class EC2
|
6
|
+
|
7
|
+
# Terminate specified instances
|
8
|
+
#
|
9
|
+
# ==== Parameters
|
10
|
+
# * instance_id<~Array> - Ids of instances to terminates
|
11
|
+
#
|
12
|
+
# ==== Returns
|
13
|
+
# # * response<~Fog::AWS::Response>:
|
14
|
+
# * body<~Hash>:
|
15
|
+
# * 'requestId'<~String> - Id of request
|
16
|
+
# * 'instancesSet'<~Array>:
|
17
|
+
# * 'instanceId'<~String> - id of the terminated instance
|
18
|
+
# * 'previousState'<~Hash>: previous state of instance
|
19
|
+
# * 'code'<~Integer> - previous status code
|
20
|
+
# * 'name'<~String> - name of previous state
|
21
|
+
# * 'shutdownState'<~Hash>: shutdown state of instance
|
22
|
+
# * 'code'<~Integer> - current status code
|
23
|
+
# * 'name'<~String> - name of current state
|
24
|
+
def terminate_instances(instance_id)
|
25
|
+
params = indexed_params('InstanceId', instance_id)
|
26
|
+
request({
|
27
|
+
'Action' => 'TerminateInstances'
|
28
|
+
}.merge!(params), Fog::Parsers::AWS::EC2::TerminateInstances.new)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
else
|
36
|
+
|
37
|
+
module Fog
|
38
|
+
module AWS
|
39
|
+
class EC2
|
40
|
+
|
41
|
+
def terminate_instances(instance_id)
|
42
|
+
instance_id = [*instance_id]
|
43
|
+
response = Fog::Response.new
|
44
|
+
instance_id.each do |instance_id|
|
45
|
+
response.body = {
|
46
|
+
'requestId' => Fog::AWS::Mock.request_id,
|
47
|
+
'instancesSet' => []
|
48
|
+
}
|
49
|
+
if instance = Fog::AWS::EC2.data[:instances][instance_id]
|
50
|
+
Fog::AWS::EC2.data[:deleted_at][instance_id] = Time.now
|
51
|
+
instance['status'] = 'deleting'
|
52
|
+
response.status = 200
|
53
|
+
code = case instance['state']
|
54
|
+
when 'pending'
|
55
|
+
0
|
56
|
+
when 'running'
|
57
|
+
16
|
58
|
+
when 'shutting-down'
|
59
|
+
32
|
60
|
+
when 'terminated'
|
61
|
+
64
|
62
|
+
end
|
63
|
+
response.body['instancesSet'] << {
|
64
|
+
'instanceId' => instance_id,
|
65
|
+
'previousState' => { 'name' => instance['state'], 'code' => code },
|
66
|
+
'shutdownState' => { 'name' => 'shutting-down', 'code' => 32}
|
67
|
+
}
|
68
|
+
else
|
69
|
+
response.status = 400
|
70
|
+
raise(Fog::Errors.status_error(200, 400, response))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
response
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|