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
@@ -70,6 +70,8 @@ else
70
70
  if Time.now - instance['launchTime'] > 2
71
71
  instance['instanceState'] = { :code => 16, :name => 'running' }
72
72
  end
73
+ when 'rebooting'
74
+ instance['instanceState'] = { :code => 16, :name => 'running' }
73
75
  when 'shutting-down'
74
76
  if Time.now - Fog::AWS::EC2.data[:deleted_at][instance['instanceId']] > 2
75
77
  instance['instanceState'] = { :code => 16, :name => 'terminating' }
@@ -1,26 +1,57 @@
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)
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ module AWS
5
+ class EC2
6
+
7
+ # Retrieve console output for specified instance
8
+ #
9
+ # ==== Parameters
10
+ # * instance_id<~String> - Id of instance to get console output from
11
+ #
12
+ # ==== Returns
13
+ # # * response<~Fog::AWS::Response>:
14
+ # * body<~Hash>:
15
+ # * 'instanceId'<~String> - Id of instance
16
+ # * 'output'<~String> - Console output
17
+ # * 'requestId'<~String> - Id of request
18
+ # * 'timestamp'<~Time> - Timestamp of last update to output
19
+ def get_console_output(instance_id)
20
+ request({
21
+ 'Action' => 'GetConsoleOutput',
22
+ 'InstanceId' => instance_id
23
+ }, Fog::Parsers::AWS::EC2::GetConsoleOutput.new)
24
+ end
25
+
22
26
  end
27
+ end
28
+ end
23
29
 
30
+ else
31
+
32
+ module Fog
33
+ module AWS
34
+ class EC2
35
+
36
+ def get_console_output(instance_id)
37
+ response = Fog::Response.new
38
+ if instance = Fog::AWS::EC2.data[:instances][instance_id]
39
+ response.status = 200
40
+ response.body = {
41
+ 'instanceId' => instance_id,
42
+ 'output' => Fog::AWS::Mock.console_output,
43
+ 'requestId' => Fog::AWS::Mock.request_id,
44
+ 'timestamp' => Time.now
45
+ }
46
+ else
47
+ response.status = 400
48
+ raise(Fog::Errors.status_error(200, 400, response))
49
+ end
50
+ response
51
+ end
52
+
53
+ end
24
54
  end
25
55
  end
56
+
26
57
  end
@@ -1,24 +1,57 @@
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)
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ module AWS
5
+ class EC2
6
+
7
+ # Reboot specified instances
8
+ #
9
+ # ==== Parameters
10
+ # * instance_id<~Array> - Ids of instances to reboot
11
+ #
12
+ # ==== Returns
13
+ # # * response<~Fog::AWS::Response>:
14
+ # * body<~Hash>:
15
+ # * 'requestId'<~String> - Id of request
16
+ # * 'return'<~Boolean> - success?
17
+ def reboot_instances(instance_id = [])
18
+ params = indexed_params('InstanceId', instance_id)
19
+ request({
20
+ 'Action' => 'RebootInstances'
21
+ }.merge!(params), Fog::Parsers::AWS::EC2::Basic.new)
22
+ end
23
+
20
24
  end
25
+ end
26
+ end
21
27
 
28
+ else
29
+
30
+ module Fog
31
+ module AWS
32
+ class EC2
33
+
34
+ def reboot_instances(instance_id = [])
35
+ response = Fog::Response.new
36
+ instance_id = [*instance_id]
37
+ if (Fog::AWS::EC2.data[:instances].keys & instance_id).length == instance_id.length
38
+ for instance_id in instance_id
39
+ Fog::AWS::EC2.data[:instances][instance_id]['status'] = 'rebooting'
40
+ end
41
+ response.status = 200
42
+ response.body = {
43
+ 'requestId' => Fog::AWS::Mock.request_id,
44
+ 'return' => true
45
+ }
46
+ else
47
+ response.status = 400
48
+ raise(Fog::Errors.status_error(200, 400, response))
49
+ end
50
+ response
51
+ end
52
+
53
+ end
22
54
  end
23
55
  end
56
+
24
57
  end
@@ -1,32 +1,68 @@
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)
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ module AWS
5
+ class EC2
6
+
7
+ # Remove permissions from 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 revoke_security_group_ingress(options = {})
27
+ request({
28
+ 'Action' => 'RevokeSecurityGroupIngress'
29
+ }.merge!(options), Fog::Parsers::AWS::EC2::Basic.new)
30
+ end
31
+
28
32
  end
33
+ end
34
+ end
35
+
36
+ else
37
+
38
+ module Fog
39
+ module AWS
40
+ class EC2
29
41
 
42
+ # TODO: handle the GroupName/Source/Source case
43
+ def revoke_security_group_ingress(options = {})
44
+ response = Fog::Response.new
45
+ group = Fog::AWS::EC2.data[:security_groups][options['GroupName']]
46
+
47
+ ingress = group['ipPermissions'].select {|permission|
48
+ permission['fromPort'] == options['FromPort'] &&
49
+ permission['ipProtocol'] == options['IpProtocol'] &&
50
+ permission['toPort'] == options['ToPort'] &&
51
+ permission['ipRanges'].first['cidrIp'] == options['CidrIp']
52
+ }.first
53
+
54
+ group['ipPermissions'].delete(ingress)
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
@@ -21,7 +21,7 @@ unless Fog.mocking?
21
21
  # * 'Placement.AvailabilityZone'<~String> - Placement constraint for instances
22
22
  # * 'DeviceName'<~String> - ?
23
23
  # * 'Encoding'<~String> - ?
24
- # * 'GroupId'<~String> - Name of security group for instances
24
+ # * 'groupId'<~String> - Name of security group for instances
25
25
  # * 'InstanceType'<~String> - Type of instance to boot. Valid options
26
26
  # in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge']
27
27
  # default is 'm1.small'
@@ -39,17 +39,19 @@ else
39
39
  class EC2
40
40
 
41
41
  def terminate_instances(instance_id)
42
- instance_id = [*instance_id]
43
42
  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]
43
+ instance_id = [*instance_id]
44
+ if (Fog::AWS::EC2.data[:instances].keys & instance_id).length == instance_id.length
45
+ for instance_id in instance_id
46
+ response.body = {
47
+ 'requestId' => Fog::AWS::Mock.request_id,
48
+ 'instancesSet' => []
49
+ }
50
+ instance = Fog::AWS::EC2.data[:instances][instance_id]
50
51
  Fog::AWS::EC2.data[:deleted_at][instance_id] = Time.now
51
52
  instance['status'] = 'deleting'
52
53
  response.status = 200
54
+ # TODO: the codes are mostly educated guessing, not certainty
53
55
  code = case instance['state']
54
56
  when 'pending'
55
57
  0
@@ -59,16 +61,18 @@ else
59
61
  32
60
62
  when 'terminated'
61
63
  64
64
+ when 'rebooting'
65
+ 128
62
66
  end
63
67
  response.body['instancesSet'] << {
64
68
  'instanceId' => instance_id,
65
69
  'previousState' => { 'name' => instance['state'], 'code' => code },
66
70
  'shutdownState' => { 'name' => 'shutting-down', 'code' => 32}
67
71
  }
68
- else
69
- response.status = 400
70
- raise(Fog::Errors.status_error(200, 400, response))
71
72
  end
73
+ else
74
+ response.status = 400
75
+ raise(Fog::Errors.status_error(200, 400, response))
72
76
  end
73
77
  response
74
78
  end
data/lib/fog/aws/s3.rb CHANGED
@@ -12,40 +12,36 @@ module Fog
12
12
  end
13
13
 
14
14
  def self.reload
15
- current_directory = File.dirname(__FILE__)
16
- load "#{current_directory}/../collection.rb"
17
- load "#{current_directory}/../connection.rb"
18
- load "#{current_directory}/../model.rb"
19
- load "#{current_directory}/../parser.rb"
20
- load "#{current_directory}/../response.rb"
21
-
22
- models_directory = "#{current_directory}/models/s3"
23
- load "#{models_directory}/bucket.rb"
24
- load "#{models_directory}/buckets.rb"
25
- load "#{models_directory}/object.rb"
26
- load "#{models_directory}/objects.rb"
27
- load "#{models_directory}/owner.rb"
28
-
29
- parsers_directory = "#{current_directory}/parsers/s3"
30
- load "#{parsers_directory}/copy_object.rb"
31
- load "#{parsers_directory}/get_bucket.rb"
32
- load "#{parsers_directory}/get_bucket_location.rb"
33
- load "#{parsers_directory}/get_request_payment.rb"
34
- load "#{parsers_directory}/get_service.rb"
35
-
36
- requests_directory = "#{current_directory}/requests/s3"
37
- load "#{requests_directory}/copy_object.rb"
38
- load "#{requests_directory}/delete_bucket.rb"
39
- load "#{requests_directory}/delete_object.rb"
40
- load "#{requests_directory}/get_bucket.rb"
41
- load "#{requests_directory}/get_bucket_location.rb"
42
- load "#{requests_directory}/get_object.rb"
43
- load "#{requests_directory}/get_request_payment.rb"
44
- load "#{requests_directory}/get_service.rb"
45
- load "#{requests_directory}/head_object.rb"
46
- load "#{requests_directory}/put_bucket.rb"
47
- load "#{requests_directory}/put_object.rb"
48
- load "#{requests_directory}/put_request_payment.rb"
15
+ load "fog/collection.rb"
16
+ load "fog/connection.rb"
17
+ load "fog/model.rb"
18
+ load "fog/parser.rb"
19
+ load "fog/response.rb"
20
+
21
+ load "fog/aws/models/s3/bucket.rb"
22
+ load "fog/aws/models/s3/buckets.rb"
23
+ load "fog/aws/models/s3/object.rb"
24
+ load "fog/aws/models/s3/objects.rb"
25
+ load "fog/aws/models/s3/owner.rb"
26
+
27
+ load "fog/aws/parsers/s3/copy_object.rb"
28
+ load "fog/aws/parsers/s3/get_bucket.rb"
29
+ load "fog/aws/parsers/s3/get_bucket_location.rb"
30
+ load "fog/aws/parsers/s3/get_request_payment.rb"
31
+ load "fog/aws/parsers/s3/get_service.rb"
32
+
33
+ load "fog/aws/requests/s3/copy_object.rb"
34
+ load "fog/aws/requests/s3/delete_bucket.rb"
35
+ load "fog/aws/requests/s3/delete_object.rb"
36
+ load "fog/aws/requests/s3/get_bucket.rb"
37
+ load "fog/aws/requests/s3/get_bucket_location.rb"
38
+ load "fog/aws/requests/s3/get_object.rb"
39
+ load "fog/aws/requests/s3/get_request_payment.rb"
40
+ load "fog/aws/requests/s3/get_service.rb"
41
+ load "fog/aws/requests/s3/head_object.rb"
42
+ load "fog/aws/requests/s3/put_bucket.rb"
43
+ load "fog/aws/requests/s3/put_object.rb"
44
+ load "fog/aws/requests/s3/put_request_payment.rb"
49
45
 
50
46
  if Fog.mocking?
51
47
  reset_data
@@ -134,7 +130,7 @@ DATA
134
130
  if ['acl', 'location', 'logging', 'requestPayment', 'torrent'].include?(params[:query])
135
131
  canonical_resource << "?#{params[:query]}"
136
132
  end
137
- string_to_sign << "#{canonical_resource}"
133
+ string_to_sign << "#{canonical_resource}".downcase
138
134
 
139
135
  hmac = @hmac.update(string_to_sign)
140
136
  signature = Base64.encode64(hmac.digest).chomp!
@@ -12,28 +12,25 @@ module Fog
12
12
  end
13
13
 
14
14
  def self.reload
15
- current_directory = File.dirname(__FILE__)
16
- load "#{current_directory}/../connection.rb"
17
- load "#{current_directory}/../parser.rb"
18
- load "#{current_directory}/../response.rb"
19
-
20
- parsers_directory = "#{current_directory}/parsers/simpledb"
21
- load "#{parsers_directory}/basic.rb"
22
- load "#{parsers_directory}/domain_metadata.rb"
23
- load "#{parsers_directory}/get_attributes.rb"
24
- load "#{parsers_directory}/list_domains.rb"
25
- load "#{parsers_directory}/select.rb"
26
-
27
- requests_directory = "#{current_directory}/requests/simpledb"
28
- load "#{requests_directory}/batch_put_attributes.rb"
29
- load "#{requests_directory}/create_domain.rb"
30
- load "#{requests_directory}/delete_attributes.rb"
31
- load "#{requests_directory}/delete_domain.rb"
32
- load "#{requests_directory}/domain_metadata.rb"
33
- load "#{requests_directory}/get_attributes.rb"
34
- load "#{requests_directory}/list_domains.rb"
35
- load "#{requests_directory}/put_attributes.rb"
36
- load "#{requests_directory}/select.rb"
15
+ load "fog/connection.rb"
16
+ load "fog/parser.rb"
17
+ load "fog/response.rb"
18
+
19
+ load "fog/aws/parsers/simpledb/basic.rb"
20
+ load "fog/aws/parsers/simpledb/domain_metadata.rb"
21
+ load "fog/aws/parsers/simpledb/get_attributes.rb"
22
+ load "fog/aws/parsers/simpledb/list_domains.rb"
23
+ load "fog/aws/parsers/simpledb/select.rb"
24
+
25
+ load "fog/aws/requests/simpledb/batch_put_attributes.rb"
26
+ load "fog/aws/requests/simpledb/create_domain.rb"
27
+ load "fog/aws/requests/simpledb/delete_attributes.rb"
28
+ load "fog/aws/requests/simpledb/delete_domain.rb"
29
+ load "fog/aws/requests/simpledb/domain_metadata.rb"
30
+ load "fog/aws/requests/simpledb/get_attributes.rb"
31
+ load "fog/aws/requests/simpledb/list_domains.rb"
32
+ load "fog/aws/requests/simpledb/put_attributes.rb"
33
+ load "fog/aws/requests/simpledb/select.rb"
37
34
 
38
35
  if Fog.mocking?
39
36
  reset_data