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.
Files changed (54) hide show
  1. data/README.rdoc +79 -2
  2. data/VERSION +1 -1
  3. data/fog.gemspec +28 -6
  4. data/lib/fog.rb +10 -7
  5. data/lib/fog/aws.rb +35 -9
  6. data/lib/fog/aws/ec2.rb +82 -69
  7. data/lib/fog/aws/models/ec2/address.rb +23 -1
  8. data/lib/fog/aws/models/ec2/addresses.rb +26 -2
  9. data/lib/fog/aws/models/ec2/instance.rb +135 -0
  10. data/lib/fog/aws/models/ec2/instances.rb +56 -0
  11. data/lib/fog/aws/models/ec2/key_pair.rb +17 -2
  12. data/lib/fog/aws/models/ec2/key_pairs.rb +29 -3
  13. data/lib/fog/aws/models/ec2/security_group.rb +41 -0
  14. data/lib/fog/aws/models/ec2/security_groups.rb +62 -0
  15. data/lib/fog/aws/models/ec2/snapshot.rb +12 -12
  16. data/lib/fog/aws/models/ec2/snapshots.rb +43 -21
  17. data/lib/fog/aws/models/ec2/volume.rb +21 -10
  18. data/lib/fog/aws/models/ec2/volumes.rb +30 -4
  19. data/lib/fog/aws/models/s3/buckets.rb +5 -8
  20. data/lib/fog/aws/models/s3/objects.rb +4 -7
  21. data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +63 -27
  22. data/lib/fog/aws/requests/ec2/create_security_group.rb +3 -3
  23. data/lib/fog/aws/requests/ec2/describe_images.rb +65 -35
  24. data/lib/fog/aws/requests/ec2/describe_instances.rb +2 -0
  25. data/lib/fog/aws/requests/ec2/get_console_output.rb +52 -21
  26. data/lib/fog/aws/requests/ec2/reboot_instances.rb +52 -19
  27. data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +63 -27
  28. data/lib/fog/aws/requests/ec2/run_instances.rb +1 -1
  29. data/lib/fog/aws/requests/ec2/terminate_instances.rb +14 -10
  30. data/lib/fog/aws/s3.rb +31 -35
  31. data/lib/fog/aws/simpledb.rb +19 -22
  32. data/lib/fog/collection.rb +3 -3
  33. data/lib/fog/connection.rb +2 -2
  34. data/lib/fog/errors.rb +1 -1
  35. data/lib/fog/model.rb +3 -3
  36. data/spec/aws/models/ec2/address_spec.rb +84 -0
  37. data/spec/aws/models/ec2/addresses_spec.rb +70 -0
  38. data/spec/aws/models/ec2/key_pair_spec.rb +84 -0
  39. data/spec/aws/models/ec2/key_pairs_spec.rb +71 -0
  40. data/spec/aws/models/ec2/security_group_spec.rb +84 -0
  41. data/spec/aws/models/ec2/security_groups_spec.rb +71 -0
  42. data/spec/aws/models/ec2/snapshot_spec.rb +93 -0
  43. data/spec/aws/models/ec2/snapshots_spec.rb +74 -0
  44. data/spec/aws/models/ec2/volume_spec.rb +84 -0
  45. data/spec/aws/models/ec2/volumes_spec.rb +70 -0
  46. data/spec/aws/models/s3/bucket_spec.rb +0 -1
  47. data/spec/aws/models/s3/buckets_spec.rb +2 -11
  48. data/spec/aws/requests/ec2/describe_security_groups_spec.rb +1 -1
  49. data/spec/aws/requests/ec2/get_console_output_spec.rb +9 -0
  50. data/spec/aws/requests/ec2/reboot_instances_spec.rb +11 -2
  51. data/spec/aws/requests/ec2/run_instances_spec.rb +1 -1
  52. data/spec/spec_helper.rb +1 -1
  53. metadata +26 -4
  54. 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(:connection => self)
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(:connection => connection)
14
- data['snapshotSet'].each do |volume|
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
- volume = new(attributes)
24
- volume.save
25
- volume
40
+ snapshot = new(attributes)
41
+ snapshot.save
42
+ snapshot
26
43
  end
27
44
 
28
- def new(attributes = {})
29
- Fog::AWS::S3::Snapshot.new({
30
- :connection => connection,
31
- :volume => @volume,
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 volume
37
- @volume
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
- private
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 :device, 'createTime'
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 delete
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
- update_attributes(new_attributes)
37
+ merge_attributes(new_attributes)
32
38
  true
33
39
  end
34
40
 
35
41
  def snapshots
36
- @snapshots ||= begin
37
- Fog::AWS::S3::Snapshots.new(
38
- :connection => connection,
39
- :volume => self
40
- )
41
- end
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(:connection => connection)
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(attributes.merge!(:connection => connection))
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
- :is_truncated => 'IsTruncated',
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
- objects_data = {}
41
+ options = {}
45
42
  for key, value in data
46
- if ['IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
47
- objects_data[key] = value
43
+ if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
44
+ options[key] = value
48
45
  end
49
46
  end
50
- bucket.objects.merge_attributes(objects_data)
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 :is_truncated, 'IsTruncated'
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, attributes).objects
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
- module Fog
2
- module AWS
3
- class EC2
4
-
5
- # Add permissions to 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 authorize_security_group_ingress(options = {})
25
- request({
26
- 'Action' => 'AuthorizeSecurityGroupIngress'
27
- }.merge!(options), Fog::Parsers::AWS::EC2::Basic.new)
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
- 'GroupDescription' => description,
41
- 'GroupName' => name,
40
+ 'groupDescription' => description,
41
+ 'groupName' => name,
42
42
  'ipPermissions' => [],
43
- 'OwnerId' => Fog::AWS::Mock.owner_id
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
- module Fog
2
- module AWS
3
- class EC2
4
-
5
- # Describe all or specified images.
6
- #
7
- # ==== Params
8
- # * options<~Hash> - Optional params
9
- # * 'ExecutableBy'<~String> - Only return images that the executable_by
10
- # user has explicit permission to launch
11
- # * 'ImageId'<~Array> - Ids of images to describe
12
- # * 'Owner'<~String> - Only return images belonging to owner.
13
- #
14
- # ==== Returns
15
- # * response<~Fog::AWS::Response>:
16
- # * body<~Hash>:
17
- # * 'requestId'<~String> - Id of request
18
- # * 'imagesSet'<~Array>:
19
- # * 'architecture'<~String> - Architecture of the image
20
- # * 'imageId'<~String> - Id of the image
21
- # * 'imageLocation'<~String> - Location of the image
22
- # * 'imageOwnerId'<~String> - Id of the owner of the image
23
- # * 'imageState'<~String> - State of the image
24
- # * 'imageType'<~String> - Type of the image
25
- # * 'isPublic'<~Boolean> - Whether or not the image is public
26
- # * 'kernelId'<~String> - Kernel id associated with image, if any
27
- # * 'platform'<~String> - Operating platform of the image
28
- # * 'productCodes'<~Array> - Product codes for the image
29
- # * 'ramdiskId'<~String> - Ramdisk id associated with image, if any
30
- def describe_images(options = {})
31
- if image_id = options.delete('ImageId')
32
- options.merge!(indexed_params('ImageId', image_id))
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
- request({
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