fog 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/.document +5 -0
  2. data/.gitignore +6 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +7 -0
  5. data/Rakefile +98 -0
  6. data/VERSION +1 -0
  7. data/benchs/fog_vs.rb +135 -0
  8. data/benchs/headers_split_vs_match.rb +18 -0
  9. data/benchs/params.rb +43 -0
  10. data/benchs/parse_vs_push.rb +60 -0
  11. data/benchs/stripping.rb +26 -0
  12. data/lib/fog.rb +21 -0
  13. data/lib/fog/aws.rb +145 -0
  14. data/lib/fog/aws/ec2.rb +173 -0
  15. data/lib/fog/aws/models/ec2/address.rb +31 -0
  16. data/lib/fog/aws/models/ec2/addresses.rb +36 -0
  17. data/lib/fog/aws/models/ec2/key_pair.rb +35 -0
  18. data/lib/fog/aws/models/ec2/key_pairs.rb +36 -0
  19. data/lib/fog/aws/models/ec2/volume.rb +47 -0
  20. data/lib/fog/aws/models/ec2/volumes.rb +36 -0
  21. data/lib/fog/aws/models/s3/bucket.rb +77 -0
  22. data/lib/fog/aws/models/s3/buckets.rb +83 -0
  23. data/lib/fog/aws/models/s3/object.rb +76 -0
  24. data/lib/fog/aws/models/s3/objects.rb +97 -0
  25. data/lib/fog/aws/models/s3/owner.rb +18 -0
  26. data/lib/fog/aws/parsers/ec2/allocate_address.rb +19 -0
  27. data/lib/fog/aws/parsers/ec2/attach_volume.rb +22 -0
  28. data/lib/fog/aws/parsers/ec2/basic.rb +25 -0
  29. data/lib/fog/aws/parsers/ec2/create_key_pair.rb +20 -0
  30. data/lib/fog/aws/parsers/ec2/create_snapshot.rb +22 -0
  31. data/lib/fog/aws/parsers/ec2/create_volume.rb +24 -0
  32. data/lib/fog/aws/parsers/ec2/describe_addresses.rb +30 -0
  33. data/lib/fog/aws/parsers/ec2/describe_availability_zones.rb +30 -0
  34. data/lib/fog/aws/parsers/ec2/describe_images.rb +49 -0
  35. data/lib/fog/aws/parsers/ec2/describe_instances.rb +73 -0
  36. data/lib/fog/aws/parsers/ec2/describe_key_pairs.rb +30 -0
  37. data/lib/fog/aws/parsers/ec2/describe_regions.rb +30 -0
  38. data/lib/fog/aws/parsers/ec2/describe_security_groups.rb +75 -0
  39. data/lib/fog/aws/parsers/ec2/describe_snapshots.rb +30 -0
  40. data/lib/fog/aws/parsers/ec2/describe_volumes.rb +57 -0
  41. data/lib/fog/aws/parsers/ec2/detach_volume.rb +22 -0
  42. data/lib/fog/aws/parsers/ec2/get_console_output.rb +28 -0
  43. data/lib/fog/aws/parsers/ec2/run_instances.rb +65 -0
  44. data/lib/fog/aws/parsers/ec2/terminate_instances.rb +55 -0
  45. data/lib/fog/aws/parsers/s3/copy_object.rb +22 -0
  46. data/lib/fog/aws/parsers/s3/get_bucket.rb +46 -0
  47. data/lib/fog/aws/parsers/s3/get_bucket_location.rb +20 -0
  48. data/lib/fog/aws/parsers/s3/get_request_payment.rb +20 -0
  49. data/lib/fog/aws/parsers/s3/get_service.rb +32 -0
  50. data/lib/fog/aws/parsers/simpledb/basic.rb +31 -0
  51. data/lib/fog/aws/parsers/simpledb/domain_metadata.rb +30 -0
  52. data/lib/fog/aws/parsers/simpledb/get_attributes.rb +34 -0
  53. data/lib/fog/aws/parsers/simpledb/list_domains.rb +28 -0
  54. data/lib/fog/aws/parsers/simpledb/select.rb +39 -0
  55. data/lib/fog/aws/requests/ec2/allocate_address.rb +50 -0
  56. data/lib/fog/aws/requests/ec2/associate_address.rb +59 -0
  57. data/lib/fog/aws/requests/ec2/attach_volume.rb +71 -0
  58. data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +32 -0
  59. data/lib/fog/aws/requests/ec2/create_key_pair.rb +60 -0
  60. data/lib/fog/aws/requests/ec2/create_security_group.rb +61 -0
  61. data/lib/fog/aws/requests/ec2/create_snapshot.rb +65 -0
  62. data/lib/fog/aws/requests/ec2/create_volume.rb +66 -0
  63. data/lib/fog/aws/requests/ec2/delete_key_pair.rb +49 -0
  64. data/lib/fog/aws/requests/ec2/delete_security_group.rb +52 -0
  65. data/lib/fog/aws/requests/ec2/delete_snapshot.rb +53 -0
  66. data/lib/fog/aws/requests/ec2/delete_volume.rb +55 -0
  67. data/lib/fog/aws/requests/ec2/describe_addresses.rb +61 -0
  68. data/lib/fog/aws/requests/ec2/describe_availability_zones.rb +64 -0
  69. data/lib/fog/aws/requests/ec2/describe_images.rb +41 -0
  70. data/lib/fog/aws/requests/ec2/describe_instances.rb +114 -0
  71. data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +63 -0
  72. data/lib/fog/aws/requests/ec2/describe_regions.rb +61 -0
  73. data/lib/fog/aws/requests/ec2/describe_security_groups.rb +71 -0
  74. data/lib/fog/aws/requests/ec2/describe_snapshots.rb +78 -0
  75. data/lib/fog/aws/requests/ec2/describe_volumes.rb +85 -0
  76. data/lib/fog/aws/requests/ec2/detach_volume.rb +62 -0
  77. data/lib/fog/aws/requests/ec2/disassociate_address.rb +55 -0
  78. data/lib/fog/aws/requests/ec2/get_console_output.rb +26 -0
  79. data/lib/fog/aws/requests/ec2/reboot_instances.rb +24 -0
  80. data/lib/fog/aws/requests/ec2/release_address.rb +50 -0
  81. data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +32 -0
  82. data/lib/fog/aws/requests/ec2/run_instances.rb +134 -0
  83. data/lib/fog/aws/requests/ec2/terminate_instances.rb +80 -0
  84. data/lib/fog/aws/requests/s3/copy_object.rb +79 -0
  85. data/lib/fog/aws/requests/s3/delete_bucket.rb +53 -0
  86. data/lib/fog/aws/requests/s3/delete_object.rb +52 -0
  87. data/lib/fog/aws/requests/s3/get_bucket.rb +100 -0
  88. data/lib/fog/aws/requests/s3/get_bucket_location.rb +53 -0
  89. data/lib/fog/aws/requests/s3/get_object.rb +82 -0
  90. data/lib/fog/aws/requests/s3/get_request_payment.rb +53 -0
  91. data/lib/fog/aws/requests/s3/get_service.rb +58 -0
  92. data/lib/fog/aws/requests/s3/head_object.rb +61 -0
  93. data/lib/fog/aws/requests/s3/put_bucket.rb +69 -0
  94. data/lib/fog/aws/requests/s3/put_object.rb +76 -0
  95. data/lib/fog/aws/requests/s3/put_request_payment.rb +56 -0
  96. data/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +31 -0
  97. data/lib/fog/aws/requests/simpledb/create_domain.rb +25 -0
  98. data/lib/fog/aws/requests/simpledb/delete_attributes.rb +34 -0
  99. data/lib/fog/aws/requests/simpledb/delete_domain.rb +25 -0
  100. data/lib/fog/aws/requests/simpledb/domain_metadata.rb +30 -0
  101. data/lib/fog/aws/requests/simpledb/get_attributes.rb +35 -0
  102. data/lib/fog/aws/requests/simpledb/list_domains.rb +30 -0
  103. data/lib/fog/aws/requests/simpledb/put_attributes.rb +29 -0
  104. data/lib/fog/aws/requests/simpledb/select.rb +29 -0
  105. data/lib/fog/aws/s3.rb +157 -0
  106. data/lib/fog/aws/simpledb.rb +157 -0
  107. data/lib/fog/collection.rb +77 -0
  108. data/lib/fog/connection.rb +130 -0
  109. data/lib/fog/errors.rb +145 -0
  110. data/lib/fog/model.rb +72 -0
  111. data/lib/fog/parser.rb +30 -0
  112. data/lib/fog/response.rb +12 -0
  113. data/spec/aws/models/s3/bucket_spec.rb +130 -0
  114. data/spec/aws/models/s3/buckets_spec.rb +79 -0
  115. data/spec/aws/models/s3/object_spec.rb +121 -0
  116. data/spec/aws/models/s3/objects_spec.rb +112 -0
  117. data/spec/aws/models/s3/owner_spec.rb +18 -0
  118. data/spec/aws/requests/ec2/allocate_address_spec.rb +18 -0
  119. data/spec/aws/requests/ec2/associate_address_spec.rb +42 -0
  120. data/spec/aws/requests/ec2/attach_volume_spec.rb +53 -0
  121. data/spec/aws/requests/ec2/authorize_security_group_ingress_spec.rb +26 -0
  122. data/spec/aws/requests/ec2/create_key_pair_spec.rb +36 -0
  123. data/spec/aws/requests/ec2/create_security_group_spec.rb +34 -0
  124. data/spec/aws/requests/ec2/create_snapshot_spec.rb +37 -0
  125. data/spec/aws/requests/ec2/create_volume_spec.rb +23 -0
  126. data/spec/aws/requests/ec2/delete_key_pair_spec.rb +21 -0
  127. data/spec/aws/requests/ec2/delete_security_group_spec.rb +26 -0
  128. data/spec/aws/requests/ec2/delete_snapshot_spec.rb +35 -0
  129. data/spec/aws/requests/ec2/delete_volume_spec.rb +26 -0
  130. data/spec/aws/requests/ec2/describe_addresses_spec.rb +38 -0
  131. data/spec/aws/requests/ec2/describe_availability_zones_spec.rb +23 -0
  132. data/spec/aws/requests/ec2/describe_images_spec.rb +39 -0
  133. data/spec/aws/requests/ec2/describe_instances_spec.rb +86 -0
  134. data/spec/aws/requests/ec2/describe_key_pairs_spec.rb +42 -0
  135. data/spec/aws/requests/ec2/describe_regions_spec.rb +21 -0
  136. data/spec/aws/requests/ec2/describe_security_groups_spec.rb +51 -0
  137. data/spec/aws/requests/ec2/describe_snapshots_spec.rb +54 -0
  138. data/spec/aws/requests/ec2/describe_volumes_spec.rb +50 -0
  139. data/spec/aws/requests/ec2/detach_volume_spec.rb +43 -0
  140. data/spec/aws/requests/ec2/disassociate_address_spec.rb +35 -0
  141. data/spec/aws/requests/ec2/get_console_output_spec.rb +23 -0
  142. data/spec/aws/requests/ec2/reboot_instances_spec.rb +21 -0
  143. data/spec/aws/requests/ec2/release_address_spec.rb +26 -0
  144. data/spec/aws/requests/ec2/revoke_security_group_ingress_spec.rb +32 -0
  145. data/spec/aws/requests/ec2/run_instances_spec.rb +41 -0
  146. data/spec/aws/requests/ec2/terminate_instances_spec.rb +35 -0
  147. data/spec/aws/requests/s3/copy_object_spec.rb +62 -0
  148. data/spec/aws/requests/s3/delete_bucket_spec.rb +36 -0
  149. data/spec/aws/requests/s3/delete_object_spec.rb +37 -0
  150. data/spec/aws/requests/s3/get_bucket_location_spec.rb +30 -0
  151. data/spec/aws/requests/s3/get_bucket_spec.rb +110 -0
  152. data/spec/aws/requests/s3/get_object_spec.rb +45 -0
  153. data/spec/aws/requests/s3/get_request_payment_spec.rb +30 -0
  154. data/spec/aws/requests/s3/get_service_spec.rb +33 -0
  155. data/spec/aws/requests/s3/head_object_spec.rb +28 -0
  156. data/spec/aws/requests/s3/put_bucket_spec.rb +19 -0
  157. data/spec/aws/requests/s3/put_object_spec.rb +38 -0
  158. data/spec/aws/requests/s3/put_request_payment_spec.rb +29 -0
  159. data/spec/aws/requests/simpledb/batch_put_attributes_spec.rb +22 -0
  160. data/spec/aws/requests/simpledb/create_domain_spec.rb +21 -0
  161. data/spec/aws/requests/simpledb/delete_attributes_spec.rb +22 -0
  162. data/spec/aws/requests/simpledb/delete_domain_spec.rb +21 -0
  163. data/spec/aws/requests/simpledb/domain_metadata_spec.rb +43 -0
  164. data/spec/aws/requests/simpledb/get_attributes_spec.rb +31 -0
  165. data/spec/aws/requests/simpledb/list_domains_spec.rb +30 -0
  166. data/spec/aws/requests/simpledb/put_attributes_spec.rb +22 -0
  167. data/spec/aws/requests/simpledb/select_spec.rb +9 -0
  168. data/spec/lorem.txt +1 -0
  169. data/spec/spec.opts +1 -0
  170. data/spec/spec_helper.rb +66 -0
  171. metadata +309 -0
@@ -0,0 +1,114 @@
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ module AWS
5
+ class EC2
6
+
7
+ # Describe all or specified instances
8
+ #
9
+ # ==== Parameters
10
+ # * instance_id<~Array> - List of instance ids to describe, defaults to all
11
+ #
12
+ # ==== Returns
13
+ # * response<~Fog::AWS::Response>:
14
+ # * body<~Hash>:
15
+ # * 'requestId'<~String> - Id of request
16
+ # * 'reservationSet'<~Array>:
17
+ # * 'groupSet'<~Array> - Group names for reservation
18
+ # * 'ownerId'<~String> - AWS Access Key ID of reservation owner
19
+ # * 'reservationId'<~String> - Id of the reservation
20
+ # * 'instancesSet'<~Array>:
21
+ # * instance<~Hash>:
22
+ # * 'amiLaunchIndex'<~Integer> - reference to instance in launch group
23
+ # * 'dnsName'<~String> - public dns name, blank until instance is running
24
+ # * 'imageId'<~String> - image id of ami used to launch instance
25
+ # * 'instanceId'<~String> - id of the instance
26
+ # * 'instanceState'<~Hash>:
27
+ # * 'code'<~Integer> - current status code
28
+ # * 'name'<~String> - current status name
29
+ # * 'instanceType'<~String> - type of instance
30
+ # * 'kernelId'<~String> - Id of kernel used to launch instance
31
+ # * 'keyName'<~String> - name of key used launch instances or blank
32
+ # * 'launchTime'<~Time> - time instance was launched
33
+ # * 'monitoring'<~Hash>:
34
+ # * 'state'<~Boolean - state of monitoring
35
+ # * 'placement'<~Hash>:
36
+ # * 'availabilityZone'<~String> - Availability zone of the instance
37
+ # * 'productCodes'<~Array> - Product codes for the instance
38
+ # * 'privateDnsName'<~String> - private dns name, blank until instance is running
39
+ # * 'ramdiskId'<~String> - Id of ramdisk used to launch instance
40
+ # * 'reason'<~String> - reason for most recent state transition, or blank
41
+ def describe_instances(instance_id = [])
42
+ params = indexed_params('InstanceId', instance_id)
43
+ request({
44
+ 'Action' => 'DescribeInstances'
45
+ }.merge!(params), Fog::Parsers::AWS::EC2::DescribeInstances.new)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+
52
+ else
53
+
54
+ module Fog
55
+ module AWS
56
+ class EC2
57
+
58
+ def describe_instances(instance_id = {})
59
+ response = Fog::Response.new
60
+ instance_id = [*instance_id]
61
+ if instance_id != []
62
+ instance_set = Fog::AWS::EC2.data[:instances].reject {|key,value| !instance_id.include?(key)}.values
63
+ else
64
+ instance_set = Fog::AWS::EC2.data[:instances].values
65
+ end
66
+
67
+ instance_set.each do |instance|
68
+ case instance['instanceState']
69
+ when 'pending'
70
+ if Time.now - instance['launchTime'] > 2
71
+ instance['instanceState'] = { :code => 16, :name => 'running' }
72
+ end
73
+ when 'shutting-down'
74
+ if Time.now - Fog::AWS::EC2.data[:deleted_at][instance['instanceId']] > 2
75
+ instance['instanceState'] = { :code => 16, :name => 'terminating' }
76
+ end
77
+ when 'terminating'
78
+ if Time.now - Fog::AWS::EC2.data[:deleted_at][instance['instanceId']] > 4
79
+ Fog::AWS::EC2.data[:deleted_at].delete(instance['instanceId'])
80
+ Fog::AWS::EC2.data[:instances].delete(instance['instanceId'])
81
+ end
82
+ end
83
+ end
84
+
85
+ if instance_id.length == 0 || instance_id.length == instance_set.length
86
+ response.status = 200
87
+
88
+ reservation_set = {}
89
+ instance_set.each do |instance|
90
+ reservation_set[instance['reservationId']] ||= {
91
+ 'groupSet' => instance['groupSet'],
92
+ 'instancesSet' => [],
93
+ 'ownerId' => instance['ownerId'],
94
+ 'reservationId' => instance['reservationId']
95
+ }
96
+ reservation_set[instance['reservationId']]['instancesSet'] << instance.reject{|key,value| !['amiLaunchIndex', 'dnsName', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'placement', 'privateDnsName', 'productCodes', 'ramdiskId', 'reason'].include?(key)}
97
+ end
98
+
99
+ response.body = {
100
+ 'requestId' => Fog::AWS::Mock.request_id,
101
+ 'reservationSet' => reservation_set.values
102
+ }
103
+ else
104
+ response.status = 400
105
+ raise(Fog::Errors.status_error(200, 400, response))
106
+ end
107
+ response
108
+ end
109
+
110
+ end
111
+ end
112
+ end
113
+
114
+ end
@@ -0,0 +1,63 @@
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ module AWS
5
+ class EC2
6
+
7
+ # Describe all or specified key pairs
8
+ #
9
+ # ==== Parameters
10
+ # * key_name<~Array>:: List of key names to describe, defaults to all
11
+ #
12
+ # ==== Returns
13
+ # * response<~Fog::AWS::Response>:
14
+ # * body<~Hash>:
15
+ # * 'requestId'<~String> - Id of request
16
+ # * 'keySet'<~Array>:
17
+ # * 'keyName'<~String> - Name of key
18
+ # * 'keyFingerprint'<~String> - Fingerprint of key
19
+ def describe_key_pairs(key_name = [])
20
+ params = indexed_params('KeyName', key_name)
21
+ request({
22
+ 'Action' => 'DescribeKeyPairs'
23
+ }.merge!(params), Fog::Parsers::AWS::EC2::DescribeKeyPairs.new)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+
30
+ else
31
+
32
+ module Fog
33
+ module AWS
34
+ class EC2
35
+
36
+ def describe_key_pairs(key_name = [])
37
+ response = Fog::Response.new
38
+ key_name = [*key_name]
39
+ if key_name != []
40
+ key_set = Fog::AWS::EC2.data[:key_pairs].reject {|key, value| !key_name.include?(key)}.values
41
+ else
42
+ key_set = Fog::AWS::EC2.data[:key_pairs].values
43
+ end
44
+ if key_name.length == 0 || key_name.length == key_set.length
45
+ response.status = 200
46
+ response.body = {
47
+ 'requestId' => Fog::AWS::Mock.request_id,
48
+ 'keySet' => key_set.map do |key|
49
+ key.reject {|key,value| !['keyFingerprint', 'keyName'].include?(key)}
50
+ end
51
+ }
52
+ else
53
+ response.status = 400
54
+ raise(Fog::Errors.status_error(200, 400, response))
55
+ end
56
+ response
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,61 @@
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ module AWS
5
+ class EC2
6
+
7
+ # Describe all or specified regions
8
+ #
9
+ # ==== Params
10
+ # * region_name<~String> - List of regions to describe, defaults to all
11
+ #
12
+ # ==== Returns
13
+ # * response<~Fog::AWS::Response>:
14
+ # * body<~Hash>:
15
+ # * 'requestId'<~String> - Id of request
16
+ # * 'regionInfo'<~Array>:
17
+ # * 'regionName'<~String> - Name of region
18
+ # * 'regionEndpoint'<~String> - Service endpoint for region
19
+ def describe_regions(region_name = [])
20
+ params = indexed_params('RegionName', region_name)
21
+ request({
22
+ 'Action' => 'DescribeRegions'
23
+ }.merge!(params), Fog::Parsers::AWS::EC2::DescribeRegions.new)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+
30
+ else
31
+
32
+ module Fog
33
+ module AWS
34
+ class EC2
35
+
36
+ def describe_regions(region_name = [])
37
+ response = Fog::Response.new
38
+ region_name = [*region_name]
39
+ regions = {
40
+ 'eu-west-1' => {"regionName"=>"eu-west-1", "regionEndpoint"=>"eu-west-1.ec2.amazonaws.com"},
41
+ 'us-east-1' => {"regionName"=>"us-east-1", "regionEndpoint"=>"us-east-1.ec2.amazonaws.com"}
42
+ }
43
+ if region_name != []
44
+ region_info = regions.reject {|key, value| !region_name.include?(key)}.values
45
+ else
46
+ region_info = regions.values
47
+ end
48
+
49
+ response.status = 200
50
+ response.body = {
51
+ 'requestId' => Fog::AWS::Mock.request_id,
52
+ 'regionInfo' => region_info
53
+ }
54
+ response
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,71 @@
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ module AWS
5
+ class EC2
6
+
7
+ # Describe all or specified security groups
8
+ #
9
+ # ==== Parameters
10
+ # * group_name<~Array> - List of groups to describe, defaults to all
11
+ #
12
+ # === Returns
13
+ # * response<~Fog::AWS::Response>:
14
+ # * body<~Hash>:
15
+ # * 'requestId'<~String> - Id of request
16
+ # * 'securityGroupInfo'<~Array>:
17
+ # * 'groupDescription'<~String> - Description of security group
18
+ # * 'groupName'<~String> - Name of security group
19
+ # * 'ipPermissions'<~Array>:
20
+ # * 'fromPort'<~Integer> - Start of port range (or -1 for ICMP wildcard)
21
+ # * 'groups'<~Array>:
22
+ # * 'groupName'<~String> - Name of security group
23
+ # * 'userId'<~String> - AWS User Id of account
24
+ # * 'ipProtocol'<~String> - Ip protocol, must be in ['tcp', 'udp', 'icmp']
25
+ # * 'ipRanges'<~Array>:
26
+ # * 'cidrIp'<~String> - CIDR range
27
+ # * 'toPort'<~Integer> - End of port range (or -1 for ICMP wildcard)
28
+ # * 'ownerId'<~String> - AWS Access Key Id of the owner of the security group
29
+ def describe_security_groups(group_name = [])
30
+ params = indexed_params('GroupName', group_name)
31
+ request({
32
+ 'Action' => 'DescribeSecurityGroups',
33
+ }.merge!(params), Fog::Parsers::AWS::EC2::DescribeSecurityGroups.new)
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+
40
+ else
41
+
42
+ module Fog
43
+ module AWS
44
+ class EC2
45
+
46
+ def describe_security_groups(group_name = [])
47
+ response = Fog::Response.new
48
+ group_name = [*group_name]
49
+ if group_name != []
50
+ security_group_info = Fog::AWS::EC2.data[:security_groups].reject {|key, value| !group_name.include?(key)}.values
51
+ else
52
+ security_group_info = Fog::AWS::EC2.data[:security_groups].values
53
+ end
54
+ if group_name.length == 0 || group_name.length == security_group_info.length
55
+ response.status = 200
56
+ response.body = {
57
+ 'requestId' => Fog::AWS::Mock.request_id,
58
+ 'securityGroupInfo' => security_group_info
59
+ }
60
+ else
61
+ response.status = 400
62
+ raise(Fog::Errors.status_error(200, 400, response))
63
+ end
64
+ response
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,78 @@
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ module AWS
5
+ class EC2
6
+
7
+ # Describe all or specified snapshots
8
+ #
9
+ # ==== Parameters
10
+ # * snapshot_id<~Array> - List of snapshots to describe, defaults to all
11
+ #
12
+ # ==== Returns
13
+ # * response<~Fog::AWS::Response>:
14
+ # * body<~Hash>:
15
+ # * 'requestId'<~String> - Id of request
16
+ # * 'snapshotSet'<~Array>:
17
+ # * 'progress'<~String>: The percentage progress of the snapshot
18
+ # * 'snapshotId'<~String>: Id of the snapshot
19
+ # * 'startTime'<~Time>: Timestamp of when snapshot was initiated
20
+ # * 'status'<~String>: Snapshot state, in ['pending', 'completed']
21
+ # * 'volumeId'<~String>: Id of volume that snapshot contains
22
+ def describe_snapshots(snapshot_id = [])
23
+ params = indexed_params('SnapshotId', snapshot_id)
24
+ request({
25
+ 'Action' => 'DescribeSnapshots'
26
+ }.merge!(params), Fog::Parsers::AWS::EC2::DescribeSnapshots.new)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+
33
+ else
34
+
35
+ module Fog
36
+ module AWS
37
+ class EC2
38
+
39
+ def describe_snapshots(snapshot_id = [])
40
+ response = Fog::Response.new
41
+ snapshot_id = [*snapshot_id]
42
+ if snapshot_id != []
43
+ snapshot_set = Fog::AWS::EC2.data[:snapshots].reject {|key,value| !snapshot_id.include?(key)}.values
44
+ else
45
+ snapshot_set = Fog::AWS::EC2.data[:snapshots].values
46
+ end
47
+
48
+ snapshot_set.each do |snapshot|
49
+ case snapshot['status']
50
+ when 'creating'
51
+ if Time.now - volume['createTime'] > 2
52
+ snapshot['progress'] = '100%'
53
+ snapshot['status'] = 'completed'
54
+ else
55
+ snapshot['progress'] = '50%'
56
+ snapshot['status'] = 'in progress'
57
+ end
58
+ end
59
+ end
60
+
61
+ if snapshot_id.length == 0 || snapshot_id.length == snapshot_set.length
62
+ response.status = 200
63
+ response.body = {
64
+ 'requestId' => Fog::AWS::Mock.request_id,
65
+ 'snapshotSet' => snapshot_set
66
+ }
67
+ else
68
+ response.status = 400
69
+ raise(Fog::Errors.status_error(200, 400, response))
70
+ end
71
+ response
72
+ end
73
+
74
+ end
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,85 @@
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ module AWS
5
+ class EC2
6
+
7
+ # Describe all or specified volumes.
8
+ #
9
+ # ==== Parameters
10
+ # * volume_id<~Array> - List of volumes to describe, defaults to all
11
+ #
12
+ # ==== Returns
13
+ # * response<~Fog::AWS::Response>:
14
+ # * body<~Hash>:
15
+ # * 'volumeSet'<~Array>:
16
+ # * 'availabilityZone'<~String> - Availability zone for volume
17
+ # * 'createTime'<~Time> - Timestamp for creation
18
+ # * 'size'<~Integer> - Size in GiBs for volume
19
+ # * 'snapshotId'<~String> - Snapshot volume was created from, if any
20
+ # * 'status'<~String> - State of volume
21
+ # * 'volumeId'<~String> - Reference to volume
22
+ # * 'attachmentSet'<~Array>:
23
+ # * 'attachmentTime'<~Time> - Timestamp for attachment
24
+ # * 'device'<~String> - How value is exposed to instance
25
+ # * 'instanceId'<~String> - Reference to attached instance
26
+ # * 'status'<~String> - Attachment state
27
+ # * 'volumeId'<~String> - Reference to volume
28
+ def describe_volumes(volume_id = [])
29
+ params = indexed_params('VolumeId', volume_id)
30
+ request({
31
+ 'Action' => 'DescribeVolumes'
32
+ }.merge!(params), Fog::Parsers::AWS::EC2::DescribeVolumes.new)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+
39
+ else
40
+
41
+ module Fog
42
+ module AWS
43
+ class EC2
44
+
45
+ def describe_volumes(volume_id = [])
46
+ response = Fog::Response.new
47
+ volume_id = [*volume_id]
48
+ if volume_id != []
49
+ volume_set = Fog::AWS::EC2.data[:volumes].reject {|key,value| !volume_id.include?(key)}.values
50
+ else
51
+ volume_set = Fog::AWS::EC2.data[:volumes].values
52
+ end
53
+
54
+ volume_set.each do |volume|
55
+ case volume['status']
56
+ when 'creating'
57
+ if Time.now - volume['createTime'] > 2
58
+ volume['status'] = 'available'
59
+ end
60
+ when 'deleting'
61
+ if Time.now - Fog::AWS::EC2.data[:deleted_at][volume['volumeId']] > 2
62
+ Fog::AWS::EC2.data[:deleted_at].delete(volume['volumeId'])
63
+ Fog::AWS::EC2.data[:volumes].delete(volume['volumeId'])
64
+ end
65
+ end
66
+ end
67
+
68
+ if volume_id.length == 0 || volume_id.length == volume_set.length
69
+ response.status = 200
70
+ response.body = {
71
+ 'requestId' => Fog::AWS::Mock.request_id,
72
+ 'volumeSet' => volume_set
73
+ }
74
+ else
75
+ response.status = 400
76
+ raise(Fog::Errors.status_error(200, 400, response))
77
+ end
78
+ response
79
+ end
80
+
81
+ end
82
+ end
83
+ end
84
+
85
+ end