fog 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +79 -2
- data/VERSION +1 -1
- data/fog.gemspec +28 -6
- data/lib/fog.rb +10 -7
- data/lib/fog/aws.rb +35 -9
- data/lib/fog/aws/ec2.rb +82 -69
- data/lib/fog/aws/models/ec2/address.rb +23 -1
- data/lib/fog/aws/models/ec2/addresses.rb +26 -2
- data/lib/fog/aws/models/ec2/instance.rb +135 -0
- data/lib/fog/aws/models/ec2/instances.rb +56 -0
- data/lib/fog/aws/models/ec2/key_pair.rb +17 -2
- data/lib/fog/aws/models/ec2/key_pairs.rb +29 -3
- data/lib/fog/aws/models/ec2/security_group.rb +41 -0
- data/lib/fog/aws/models/ec2/security_groups.rb +62 -0
- data/lib/fog/aws/models/ec2/snapshot.rb +12 -12
- data/lib/fog/aws/models/ec2/snapshots.rb +43 -21
- data/lib/fog/aws/models/ec2/volume.rb +21 -10
- data/lib/fog/aws/models/ec2/volumes.rb +30 -4
- data/lib/fog/aws/models/s3/buckets.rb +5 -8
- data/lib/fog/aws/models/s3/objects.rb +4 -7
- data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +63 -27
- data/lib/fog/aws/requests/ec2/create_security_group.rb +3 -3
- data/lib/fog/aws/requests/ec2/describe_images.rb +65 -35
- data/lib/fog/aws/requests/ec2/describe_instances.rb +2 -0
- data/lib/fog/aws/requests/ec2/get_console_output.rb +52 -21
- data/lib/fog/aws/requests/ec2/reboot_instances.rb +52 -19
- data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +63 -27
- data/lib/fog/aws/requests/ec2/run_instances.rb +1 -1
- data/lib/fog/aws/requests/ec2/terminate_instances.rb +14 -10
- data/lib/fog/aws/s3.rb +31 -35
- data/lib/fog/aws/simpledb.rb +19 -22
- data/lib/fog/collection.rb +3 -3
- data/lib/fog/connection.rb +2 -2
- data/lib/fog/errors.rb +1 -1
- data/lib/fog/model.rb +3 -3
- data/spec/aws/models/ec2/address_spec.rb +84 -0
- data/spec/aws/models/ec2/addresses_spec.rb +70 -0
- data/spec/aws/models/ec2/key_pair_spec.rb +84 -0
- data/spec/aws/models/ec2/key_pairs_spec.rb +71 -0
- data/spec/aws/models/ec2/security_group_spec.rb +84 -0
- data/spec/aws/models/ec2/security_groups_spec.rb +71 -0
- data/spec/aws/models/ec2/snapshot_spec.rb +93 -0
- data/spec/aws/models/ec2/snapshots_spec.rb +74 -0
- data/spec/aws/models/ec2/volume_spec.rb +84 -0
- data/spec/aws/models/ec2/volumes_spec.rb +70 -0
- data/spec/aws/models/s3/bucket_spec.rb +0 -1
- data/spec/aws/models/s3/buckets_spec.rb +2 -11
- data/spec/aws/requests/ec2/describe_security_groups_spec.rb +1 -1
- data/spec/aws/requests/ec2/get_console_output_spec.rb +9 -0
- data/spec/aws/requests/ec2/reboot_instances_spec.rb +11 -2
- data/spec/aws/requests/ec2/run_instances_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +26 -4
- data/LICENSE +0 -20
@@ -2,45 +2,67 @@ module Fog
|
|
2
2
|
module AWS
|
3
3
|
class EC2
|
4
4
|
|
5
|
-
def snapshots
|
6
|
-
Fog::AWS::EC2::Snapshots.new(
|
5
|
+
def snapshots(attributes = {})
|
6
|
+
Fog::AWS::EC2::Snapshots.new({
|
7
|
+
:connection => self
|
8
|
+
}.merge!(attributes))
|
7
9
|
end
|
8
10
|
|
9
11
|
class Snapshots < Fog::Collection
|
10
12
|
|
13
|
+
attribute :snapshot_id
|
14
|
+
attribute :volume_id
|
15
|
+
|
16
|
+
def initialize(attributes)
|
17
|
+
@snapshot_id ||= []
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
11
21
|
def all(snapshot_id = [])
|
12
|
-
data = connection.describe_snapshots(snapshot_id)
|
13
|
-
snapshots = Fog::AWS::EC2::Snapshots.new(
|
14
|
-
|
22
|
+
data = connection.describe_snapshots(snapshot_id).body
|
23
|
+
snapshots = Fog::AWS::EC2::Snapshots.new({
|
24
|
+
:connection => connection,
|
25
|
+
:snapshot_id => snapshot_id
|
26
|
+
}.merge!(attributes))
|
27
|
+
data['snapshotSet'].each do |snapshot|
|
15
28
|
snapshots << Fog::AWS::EC2::Snapshot.new({
|
16
|
-
:connection => connection
|
29
|
+
:connection => connection,
|
30
|
+
:snapshots => self
|
17
31
|
}.merge!(snapshot))
|
18
32
|
end
|
33
|
+
if volume_id
|
34
|
+
snapshots = snapshots.select {|snapshot| snapshot.volume_id == volume_id}
|
35
|
+
end
|
19
36
|
snapshots
|
20
37
|
end
|
21
38
|
|
22
39
|
def create(attributes = {})
|
23
|
-
|
24
|
-
|
25
|
-
|
40
|
+
snapshot = new(attributes)
|
41
|
+
snapshot.save
|
42
|
+
snapshot
|
26
43
|
end
|
27
44
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
:snapshots => self
|
33
|
-
}.merge!(attributes))
|
45
|
+
def get(snapshot_id)
|
46
|
+
all(snapshot_id).first
|
47
|
+
rescue Fog::Errors::BadRequest
|
48
|
+
nil
|
34
49
|
end
|
35
50
|
|
36
|
-
def
|
37
|
-
|
51
|
+
def new(attributes = {})
|
52
|
+
snapshot = Fog::AWS::EC2::Snapshot.new(
|
53
|
+
attributes.merge!(
|
54
|
+
:connection => connection,
|
55
|
+
:snapshots => self
|
56
|
+
)
|
57
|
+
)
|
58
|
+
if volume_id
|
59
|
+
snapshot.volume_id = volume_id
|
60
|
+
end
|
61
|
+
snapshot
|
38
62
|
end
|
39
63
|
|
40
|
-
|
41
|
-
|
42
|
-
def volume=(new_volume)
|
43
|
-
@volume = new_volume
|
64
|
+
def reload
|
65
|
+
all(snapshot_id)
|
44
66
|
end
|
45
67
|
|
46
68
|
end
|
@@ -6,7 +6,8 @@ module Fog
|
|
6
6
|
|
7
7
|
attribute :attachment_time, 'attachmentTime'
|
8
8
|
attribute :availability_zone, 'availabilityZone'
|
9
|
-
attribute :
|
9
|
+
attribute :create_time, 'createTime'
|
10
|
+
attribute :device
|
10
11
|
attribute :instance_id, 'instanceId'
|
11
12
|
attribute :size
|
12
13
|
attribute :snapshot_id, 'snapshotId'
|
@@ -15,30 +16,40 @@ module Fog
|
|
15
16
|
|
16
17
|
def initialize(attributes = {})
|
17
18
|
if attributes['attachmentSet']
|
18
|
-
attributes.merge!(attributes.delete('attachmentSet'))
|
19
|
+
attributes.merge!(attributes.delete('attachmentSet').first || {})
|
19
20
|
end
|
20
21
|
super
|
21
22
|
end
|
22
23
|
|
23
|
-
def
|
24
|
+
def destroy
|
24
25
|
connection.delete_volume(@volume_id)
|
25
26
|
true
|
26
27
|
end
|
27
28
|
|
29
|
+
def reload
|
30
|
+
new_attributes = volumes.get(@volume_id).attributes
|
31
|
+
merge_attributes(new_attributes)
|
32
|
+
end
|
33
|
+
|
28
34
|
def save
|
29
35
|
data = connection.create_volume(@availability_zone, @size, @snapshot_id).body
|
30
36
|
new_attributes = data.reject {|key,value| key == 'requestId'}
|
31
|
-
|
37
|
+
merge_attributes(new_attributes)
|
32
38
|
true
|
33
39
|
end
|
34
40
|
|
35
41
|
def snapshots
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
connection.snapshots(:volume_id => volume_id)
|
43
|
+
end
|
44
|
+
|
45
|
+
def volumes
|
46
|
+
@volumes
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def volumes=(new_volumes)
|
52
|
+
@volumes = new_volumes
|
42
53
|
end
|
43
54
|
|
44
55
|
end
|
@@ -8,12 +8,23 @@ module Fog
|
|
8
8
|
|
9
9
|
class Volumes < Fog::Collection
|
10
10
|
|
11
|
+
attribute :volume_id
|
12
|
+
|
13
|
+
def initialize(attributes)
|
14
|
+
@volume_id ||= []
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
11
18
|
def all(volume_id = [])
|
12
|
-
data = connection.describe_volumes(volume_id)
|
13
|
-
volumes = Fog::AWS::EC2::Volumes.new(
|
19
|
+
data = connection.describe_volumes(volume_id).body
|
20
|
+
volumes = Fog::AWS::EC2::Volumes.new({
|
21
|
+
:connection => connection,
|
22
|
+
:volume_id => volume_id
|
23
|
+
}.merge!(attributes))
|
14
24
|
data['volumeSet'].each do |volume|
|
15
25
|
volumes << Fog::AWS::EC2::Volume.new({
|
16
|
-
:connection => connection
|
26
|
+
:connection => connection,
|
27
|
+
:volumes => self
|
17
28
|
}.merge!(volume))
|
18
29
|
end
|
19
30
|
volumes
|
@@ -25,8 +36,23 @@ module Fog
|
|
25
36
|
volume
|
26
37
|
end
|
27
38
|
|
39
|
+
def get(volume_id)
|
40
|
+
all(volume_id).first
|
41
|
+
rescue Fog::Errors::BadRequest
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
28
45
|
def new(attributes = {})
|
29
|
-
Fog::AWS::EC2::Volume.new(
|
46
|
+
Fog::AWS::EC2::Volume.new(
|
47
|
+
attributes.merge!(
|
48
|
+
:connection => connection,
|
49
|
+
:volumes => self
|
50
|
+
)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def reload
|
55
|
+
all(volume_id)
|
30
56
|
end
|
31
57
|
|
32
58
|
end
|
@@ -30,10 +30,7 @@ module Fog
|
|
30
30
|
|
31
31
|
def get(name, options = {})
|
32
32
|
remap_attributes(options, {
|
33
|
-
:
|
34
|
-
:marker => 'Marker',
|
35
|
-
:max_keys => 'MaxKeys',
|
36
|
-
:prefix => 'Prefix'
|
33
|
+
:max_keys => 'max-keys',
|
37
34
|
})
|
38
35
|
data = connection.get_bucket(name, options).body
|
39
36
|
bucket = Fog::AWS::S3::Bucket.new({
|
@@ -41,13 +38,13 @@ module Fog
|
|
41
38
|
:connection => connection,
|
42
39
|
:name => data['Name']
|
43
40
|
})
|
44
|
-
|
41
|
+
options = {}
|
45
42
|
for key, value in data
|
46
|
-
if ['IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
|
47
|
-
|
43
|
+
if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
|
44
|
+
options[key] = value
|
48
45
|
end
|
49
46
|
end
|
50
|
-
bucket.objects.merge_attributes(
|
47
|
+
bucket.objects.merge_attributes(:options => options)
|
51
48
|
data['Contents'].each do |object|
|
52
49
|
owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection))
|
53
50
|
bucket.objects << Fog::AWS::S3::Object.new({
|
@@ -4,14 +4,11 @@ module Fog
|
|
4
4
|
|
5
5
|
class Objects < Fog::Collection
|
6
6
|
|
7
|
-
attribute :
|
8
|
-
attribute :marker, 'Marker'
|
9
|
-
attribute :max_keys, 'MaxKeys'
|
10
|
-
attribute :prefix, 'Prefix'
|
7
|
+
attribute :options
|
11
8
|
|
12
9
|
def all(options = {})
|
13
|
-
merge_attributes(options)
|
14
|
-
bucket.buckets.get(bucket.name,
|
10
|
+
merge_attributes(:options => options)
|
11
|
+
bucket.buckets.get(bucket.name, @options).objects
|
15
12
|
end
|
16
13
|
|
17
14
|
def bucket
|
@@ -74,7 +71,7 @@ module Fog
|
|
74
71
|
end
|
75
72
|
|
76
73
|
def reload
|
77
|
-
all
|
74
|
+
all(@options)
|
78
75
|
end
|
79
76
|
|
80
77
|
private
|
@@ -1,32 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
1
|
+
unless Fog.mocking?
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module AWS
|
5
|
+
class EC2
|
6
|
+
|
7
|
+
# Add permissions to a security group
|
8
|
+
#
|
9
|
+
# ==== Parameters
|
10
|
+
# * options<~Hash>:
|
11
|
+
# * 'GroupName'<~String> - Name of group
|
12
|
+
# * 'SourceSecurityGroupName'<~String> - Name of security group to authorize
|
13
|
+
# * 'SourceSecurityGroupOwnerId'<~String> - Name of owner to authorize
|
14
|
+
# or
|
15
|
+
# * 'CidrIp' - CIDR range
|
16
|
+
# * 'FromPort' - Start of port range (or -1 for ICMP wildcard)
|
17
|
+
# * 'GroupName' - Name of group to modify
|
18
|
+
# * 'IpProtocol' - Ip protocol, must be in ['tcp', 'udp', 'icmp']
|
19
|
+
# * 'ToPort' - End of port range (or -1 for ICMP wildcard)
|
20
|
+
#
|
21
|
+
# === Returns
|
22
|
+
# * response<~Fog::AWS::Response>:
|
23
|
+
# * body<~Hash>:
|
24
|
+
# * 'requestId'<~String> - Id of request
|
25
|
+
# * 'return'<~Boolean> - success?
|
26
|
+
def authorize_security_group_ingress(options = {})
|
27
|
+
request({
|
28
|
+
'Action' => 'AuthorizeSecurityGroupIngress'
|
29
|
+
}.merge!(options), Fog::Parsers::AWS::EC2::Basic.new)
|
30
|
+
end
|
31
|
+
|
28
32
|
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
else
|
29
37
|
|
38
|
+
module Fog
|
39
|
+
module AWS
|
40
|
+
class EC2
|
41
|
+
|
42
|
+
# TODO: handle the GroupName/Source/Source case
|
43
|
+
def authorize_security_group_ingress(options = {})
|
44
|
+
response = Fog::Response.new
|
45
|
+
group = Fog::AWS::EC2.data[:security_groups][options['GroupName']]
|
46
|
+
|
47
|
+
group['ipPermissions'] ||= []
|
48
|
+
group['ipPermissions'] << {
|
49
|
+
'groups' => [],
|
50
|
+
'fromPort' => options['FromPort'],
|
51
|
+
'ipRanges' => [{ 'cidrIp' => options['CidrIp'] }],
|
52
|
+
'ipProtocol' => options['IpProtocol'],
|
53
|
+
'toPort' => options['ToPort']
|
54
|
+
}
|
55
|
+
|
56
|
+
response.status = 200
|
57
|
+
response.body = {
|
58
|
+
'requestId' => Fog::AWS::Mock.request_id,
|
59
|
+
'return' => true
|
60
|
+
}
|
61
|
+
response
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
30
65
|
end
|
31
66
|
end
|
67
|
+
|
32
68
|
end
|
@@ -37,10 +37,10 @@ else
|
|
37
37
|
response = Fog::Response.new
|
38
38
|
unless Fog::AWS::EC2.data[:security_groups][name]
|
39
39
|
data = {
|
40
|
-
'
|
41
|
-
'
|
40
|
+
'groupDescription' => description,
|
41
|
+
'groupName' => name,
|
42
42
|
'ipPermissions' => [],
|
43
|
-
'
|
43
|
+
'ownerId' => Fog::AWS::Mock.owner_id
|
44
44
|
}
|
45
45
|
Fog::AWS::EC2.data[:security_groups][name] = data
|
46
46
|
response.body = {
|
@@ -1,41 +1,71 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
1
|
+
unless Fog.mocking?
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module AWS
|
5
|
+
class EC2
|
6
|
+
|
7
|
+
# Describe all or specified images.
|
8
|
+
#
|
9
|
+
# ==== Params
|
10
|
+
# * options<~Hash> - Optional params
|
11
|
+
# * 'ExecutableBy'<~String> - Only return images that the executable_by
|
12
|
+
# user has explicit permission to launch
|
13
|
+
# * 'ImageId'<~Array> - Ids of images to describe
|
14
|
+
# * 'Owner'<~String> - Only return images belonging to owner.
|
15
|
+
#
|
16
|
+
# ==== Returns
|
17
|
+
# * response<~Fog::AWS::Response>:
|
18
|
+
# * body<~Hash>:
|
19
|
+
# * 'requestId'<~String> - Id of request
|
20
|
+
# * 'imagesSet'<~Array>:
|
21
|
+
# * 'architecture'<~String> - Architecture of the image
|
22
|
+
# * 'imageId'<~String> - Id of the image
|
23
|
+
# * 'imageLocation'<~String> - Location of the image
|
24
|
+
# * 'imageOwnerId'<~String> - Id of the owner of the image
|
25
|
+
# * 'imageState'<~String> - State of the image
|
26
|
+
# * 'imageType'<~String> - Type of the image
|
27
|
+
# * 'isPublic'<~Boolean> - Whether or not the image is public
|
28
|
+
# * 'kernelId'<~String> - Kernel id associated with image, if any
|
29
|
+
# * 'platform'<~String> - Operating platform of the image
|
30
|
+
# * 'productCodes'<~Array> - Product codes for the image
|
31
|
+
# * 'ramdiskId'<~String> - Ramdisk id associated with image, if any
|
32
|
+
def describe_images(options = {})
|
33
|
+
if image_id = options.delete('ImageId')
|
34
|
+
options.merge!(indexed_params('ImageId', image_id))
|
35
|
+
end
|
36
|
+
request({
|
37
|
+
'Action' => 'DescribeImages'
|
38
|
+
}.merge!(options), Fog::Parsers::AWS::EC2::DescribeImages.new)
|
33
39
|
end
|
34
|
-
|
35
|
-
'Action' => 'DescribeImages'
|
36
|
-
}.merge!(options), Fog::Parsers::AWS::EC2::DescribeImages.new)
|
40
|
+
|
37
41
|
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
else
|
46
|
+
|
47
|
+
module Fog
|
48
|
+
module AWS
|
49
|
+
class EC2
|
38
50
|
|
51
|
+
def describe_images(options = {})
|
52
|
+
response = Fog::Response.new
|
53
|
+
images = []
|
54
|
+
|
55
|
+
(rand(101 + 100)).times do
|
56
|
+
images << Fog::AWS::Mock.image
|
57
|
+
end
|
58
|
+
|
59
|
+
response.status = 200
|
60
|
+
response.body = {
|
61
|
+
'requestId' => Fog::AWS::Mock.request_id,
|
62
|
+
'imagesSet' => images
|
63
|
+
}
|
64
|
+
response
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
39
68
|
end
|
40
69
|
end
|
70
|
+
|
41
71
|
end
|