fog-aws 1.4.1 → 2.0.0

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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -8
  3. data/CHANGELOG.md +40 -2
  4. data/CONTRIBUTING.md +6 -6
  5. data/CONTRIBUTORS.md +104 -1
  6. data/LICENSE.md +1 -1
  7. data/fog-aws.gemspec +4 -2
  8. data/lib/fog/aws.rb +1 -0
  9. data/lib/fog/aws/compute.rb +86 -2
  10. data/lib/fog/aws/credential_fetcher.rb +4 -2
  11. data/lib/fog/aws/mock.rb +8 -0
  12. data/lib/fog/aws/models/compute/flavors.rb +40 -0
  13. data/lib/fog/aws/models/compute/subnet.rb +1 -0
  14. data/lib/fog/aws/models/compute/vpc.rb +11 -2
  15. data/lib/fog/aws/models/iam/access_keys.rb +0 -2
  16. data/lib/fog/aws/models/rds/instance_option.rb +6 -0
  17. data/lib/fog/aws/parsers/compute/create_subnet.rb +2 -0
  18. data/lib/fog/aws/parsers/compute/describe_subnets.rb +1 -1
  19. data/lib/fog/aws/parsers/compute/describe_vpcs.rb +71 -37
  20. data/lib/fog/aws/parsers/iam/list_access_keys.rb +1 -1
  21. data/lib/fog/aws/parsers/rds/describe_orderable_db_instance_options.rb +4 -3
  22. data/lib/fog/aws/requests/auto_scaling/detach_instances.rb +3 -4
  23. data/lib/fog/aws/requests/compute/authorize_security_group_egress.rb +8 -6
  24. data/lib/fog/aws/requests/compute/authorize_security_group_ingress.rb +25 -21
  25. data/lib/fog/aws/requests/compute/copy_snapshot.rb +22 -9
  26. data/lib/fog/aws/requests/compute/create_network_interface.rb +2 -2
  27. data/lib/fog/aws/requests/compute/create_route_table.rb +1 -1
  28. data/lib/fog/aws/requests/compute/create_security_group.rb +24 -19
  29. data/lib/fog/aws/requests/compute/create_subnet.rb +14 -10
  30. data/lib/fog/aws/requests/compute/create_vpc.rb +38 -10
  31. data/lib/fog/aws/requests/compute/delete_security_group.rb +9 -9
  32. data/lib/fog/aws/requests/compute/describe_network_interface_attribute.rb +16 -14
  33. data/lib/fog/aws/requests/compute/describe_security_groups.rb +30 -6
  34. data/lib/fog/aws/requests/compute/describe_subnets.rb +12 -11
  35. data/lib/fog/aws/requests/compute/modify_network_interface_attribute.rb +3 -3
  36. data/lib/fog/aws/requests/compute/revoke_security_group_egress.rb +19 -25
  37. data/lib/fog/aws/requests/compute/revoke_security_group_ingress.rb +18 -25
  38. data/lib/fog/aws/requests/compute/run_instances.rb +1 -1
  39. data/lib/fog/aws/requests/efs/create_mount_target.rb +8 -4
  40. data/lib/fog/aws/requests/elb/create_load_balancer.rb +6 -37
  41. data/lib/fog/aws/requests/kinesis/put_record.rb +1 -2
  42. data/lib/fog/aws/requests/kinesis/put_records.rb +1 -2
  43. data/lib/fog/aws/requests/lambda/invoke.rb +1 -1
  44. data/lib/fog/aws/requests/rds/describe_orderable_db_instance_options.rb +12 -6
  45. data/lib/fog/aws/requests/storage/put_object.rb +0 -1
  46. data/lib/fog/aws/service_mapper.rb +129 -0
  47. data/lib/fog/aws/version.rb +1 -1
  48. data/tests/helpers/collection_helper.rb +0 -6
  49. data/tests/models/efs/mount_target_tests.rb +3 -1
  50. data/tests/models/elasticache/subnet_groups_tests.rb +0 -1
  51. data/tests/models/storage/file_tests.rb +0 -4
  52. data/tests/models/storage/url_tests.rb +1 -20
  53. data/tests/models/storage/versions_tests.rb +0 -5
  54. data/tests/requests/compute/network_interface_tests.rb +2 -13
  55. data/tests/requests/compute/subnet_tests.rb +3 -1
  56. data/tests/requests/compute/vpc_tests.rb +8 -6
  57. data/tests/requests/dns/dns_tests.rb +0 -4
  58. data/tests/requests/efs/file_system_tests.rb +1 -1
  59. data/tests/requests/iam/managed_policy_tests.rb +0 -1
  60. data/tests/requests/iam/versioned_managed_policy_tests.rb +3 -12
  61. data/tests/requests/lambda/helper.rb +2 -2
  62. data/tests/requests/rds/helper.rb +7 -2
  63. data/tests/requests/rds/instance_option_tests.rb +7 -1
  64. data/tests/requests/storage/object_tests.rb +2 -11
  65. metadata +9 -10
  66. data/gemfiles/Gemfile-ruby-1.8.7 +0 -6
  67. data/gemfiles/Gemfile-ruby-1.9 +0 -7
@@ -10,6 +10,7 @@ module Fog
10
10
  attribute :availability_zone, :aliases => 'availabilityZone'
11
11
  attribute :tag_set, :aliases => 'tagSet'
12
12
  attribute :map_public_ip_on_launch, :aliases => 'mapPublicIpOnLaunch'
13
+ attribute :default_for_az, :aliases => 'defaultForAz'
13
14
 
14
15
  def ready?
15
16
  requires :state
@@ -10,8 +10,17 @@ module Fog
10
10
  attribute :tags, :aliases => 'tagSet'
11
11
  attribute :tenancy, :aliases => 'instanceTenancy'
12
12
  attribute :is_default, :aliases => 'isDefault'
13
- attribute :ipv_6_cidr_block_association_set, :aliases => 'ipv6CidrBlockAssociationSet'
14
- attribute :amazon_provided_ipv_6_cidr_block, :aliases => 'amazonProvidedIpv6CidrBlock'
13
+
14
+ attribute :cidr_block_association_set, :aliases => 'cidrBlockAssociationSet'
15
+
16
+ attribute :ipv6_cidr_block_association_set, :aliases => 'ipv6CidrBlockAssociationSet'
17
+ attribute :amazon_provided_ipv6_cidr_block, :aliases => 'amazonProvidedIpv6CidrBlock'
18
+
19
+ # Backward compatibility. Please use ipv6_cidr_block_association_set
20
+ alias_method :ipv_6_cidr_block_association_set, :ipv6_cidr_block_association_set
21
+ alias_method :ipv_6_cidr_block_association_set=, :ipv6_cidr_block_association_set=
22
+ alias_method :amazon_provided_ipv_6_cidr_block, :amazon_provided_ipv6_cidr_block
23
+ alias_method :amazon_provided_ipv_6_cidr_block=, :amazon_provided_ipv6_cidr_block=
15
24
 
16
25
  def subnets
17
26
  service.subnets(:filters => {'vpcId' => self.identity}).all
@@ -13,8 +13,6 @@ module Fog
13
13
 
14
14
  def all
15
15
  data = service.list_access_keys('UserName'=> @username).body['AccessKeys']
16
- # AWS response doesn't contain the UserName, this injects it
17
- data.each {|access_key| access_key['UserName'] = @username }
18
16
  load(data)
19
17
  end
20
18
 
@@ -10,6 +10,12 @@ module Fog
10
10
  attribute :availability_zones, :aliases => 'AvailabilityZones', :type => :array
11
11
  attribute :db_instance_class, :aliases => 'DBInstanceClass'
12
12
  attribute :vpc, :aliases => 'Vpc', :type => :boolean
13
+ attribute :supports_iops, :aliases => 'SupportsIops', :type => :boolean
14
+ attribute :supports_enhanced_monitoring, :aliases => 'SupportsEnhancedMonitoring', :type => :boolean
15
+ attribute :supports_iam_database_authentication, :aliases => 'SupportsIAMDatabaseAuthentication', :type => :boolean
16
+ attribute :supports_performance_insights, :aliases => 'SupportsPerformanceInsights', :type => :boolean
17
+ attribute :supports_storage_encryption, :aliases => 'SupportsStorageEncryption', :type => :boolean
18
+ attribute :storage_type, :aliases => 'StorageType'
13
19
  end
14
20
  end
15
21
  end
@@ -32,6 +32,8 @@ module Fog
32
32
  case name
33
33
  when 'subnetId', 'state', 'vpcId', 'cidrBlock', 'availableIpAddressCount', 'availabilityZone'
34
34
  @subnet[name] = value
35
+ when 'mapPublicIpOnLaunch', 'defaultForAz'
36
+ @subnet[name] = value == 'true' ? true : false
35
37
  when 'subnet'
36
38
  @response['subnet'] = @subnet
37
39
  when 'requestId'
@@ -32,7 +32,7 @@ module Fog
32
32
  case name
33
33
  when 'subnetId', 'state', 'vpcId', 'cidrBlock', 'availableIpAddressCount', 'availabilityZone'
34
34
  @subnet[name] = value
35
- when 'mapPublicIpOnLaunch'
35
+ when 'mapPublicIpOnLaunch', 'defaultForAz'
36
36
  @subnet[name] = value == 'true' ? true : false
37
37
  when 'item'
38
38
  @response['subnetSet'] << @subnet
@@ -4,55 +4,89 @@ module Fog
4
4
  module AWS
5
5
  class DescribeVpcs < Fog::Parsers::Base
6
6
  def reset
7
- @vpc = { 'tagSet' => {}, 'ipv6CidrBlockAssociationSet' => {} }
8
7
  @response = { 'vpcSet' => [] }
9
- @tag = {}
8
+ @context = []
10
9
  end
11
10
 
12
11
  def start_element(name, attrs = [])
13
12
  super
14
- case name
15
- when 'tagSet'
16
- @in_tag_set = true
17
- when 'ipv6CidrBlockAssociationSet'
18
- @in_ipv6_set = true
13
+ @context.push(name)
14
+
15
+ case @context[1 .. -1].join('.')
16
+ when 'vpcSet.item'
17
+ @current_vpc = { 'tagSet' => {}, 'cidrBlockAssociationSet' => [], 'ipv6CidrBlockAssociationSet' => [] }
18
+
19
+ when 'vpcSet.item.tagSet.item'
20
+ @current_tag_key = @current_tag_value = nil
21
+
22
+ when 'vpcSet.item.cidrBlockAssociationSet.item'
23
+ @current_cidr_block = {}
24
+
25
+ when 'vpcSet.item.ipv6CidrBlockAssociationSet.item'
26
+ @current_ipv6_block = {}
19
27
  end
20
28
  end
21
29
 
22
30
  def end_element(name)
23
- if @in_tag_set
24
- case name
25
- when 'item'
26
- @vpc['tagSet'][@tag['key']] = @tag['value']
27
- @tag = {}
28
- when 'key', 'value'
29
- @tag[name] = value
30
- when 'tagSet'
31
- @in_tag_set = false
32
- end
33
- elsif @in_ipv6_set
34
- case name
35
- when 'ipv6CidrBlock', 'associationId'
36
- @vpc['ipv6CidrBlockAssociationSet'][name] = value
37
- when 'ipv6CidrBlockState'
38
- @vpc['ipv6CidrBlockAssociationSet'][name] = {'State' => value.squish}
39
- when 'ipv6CidrBlockAssociationSet'
40
- @vpc['amazonProvidedIpv6CidrBlock'] = !value.blank?
41
- @in_ipv6_set = false
42
- end
43
- else
44
- case name
45
- when 'vpcId', 'state', 'cidrBlock', 'dhcpOptionsId', 'instanceTenancy'
46
- @vpc[name] = value
47
- when 'isDefault'
48
- @vpc['isDefault'] = value == 'true'
49
- when 'item'
50
- @response['vpcSet'] << @vpc
51
- @vpc = { 'tagSet' => {}, 'ipv6CidrBlockAssociationSet' => {} }
31
+ case @context[1 .. -1].join('.')
32
+ # tagSet
33
+
34
+ when 'vpcSet.item.tagSet.item'
35
+ @current_vpc['tagSet'][@current_tag_key] = @current_tag_value
36
+ @current_tag_key = @current_tag_value = nil
37
+
38
+ when 'vpcSet.item.tagSet.item.key'
39
+ @current_tag_key = value
40
+
41
+ when 'vpcSet.item.tagSet.item.value'
42
+ @current_tag_value = value
43
+
44
+ # cidrBlockAssociationSet
45
+
46
+ when 'vpcSet.item.cidrBlockAssociationSet.item.cidrBlock',
47
+ 'vpcSet.item.cidrBlockAssociationSet.item.associationId'
48
+ @current_cidr_block[name] = value
49
+
50
+ when 'vpcSet.item.cidrBlockAssociationSet.item.cidrBlockState'
51
+ @current_cidr_block['state'] = value.strip
52
+
53
+ when 'vpcSet.item.cidrBlockAssociationSet.item'
54
+ @current_vpc['cidrBlockAssociationSet'] << @current_cidr_block
55
+
56
+ # ipv6CidrBlockAssociationSet
57
+
58
+ when 'vpcSet.item.ipv6CidrBlockAssociationSet.item.ipv6CidrBlock',
59
+ 'vpcSet.item.ipv6CidrBlockAssociationSet.item.associationId'
60
+ @current_ipv6_block[name] = value
61
+
62
+ when 'vpcSet.item.ipv6CidrBlockAssociationSet.item.ipv6CidrBlockState'
63
+ @current_ipv6_block['state'] = value.strip
64
+
65
+ when 'vpcSet.item.ipv6CidrBlockAssociationSet.item'
66
+ @current_vpc['ipv6CidrBlockAssociationSet'] << @current_ipv6_block
67
+
68
+ # vpc
69
+
70
+ when 'vpcSet.item.vpcId',
71
+ 'vpcSet.item.state',
72
+ 'vpcSet.item.cidrBlock',
73
+ 'vpcSet.item.dhcpOptionsId',
74
+ 'vpcSet.item.instanceTenancy'
75
+ @current_vpc[name] = value
76
+
77
+ when 'vpcSet.item.isDefault'
78
+ @current_vpc['isDefault'] = value == 'true'
79
+
80
+ when 'vpcSet.item'
81
+ @response['vpcSet'] << @current_vpc
82
+
83
+ # root
84
+
52
85
  when 'requestId'
53
86
  @response[name] = value
54
- end
55
87
  end
88
+
89
+ @context.pop
56
90
  end
57
91
  end
58
92
  end
@@ -10,7 +10,7 @@ module Fog
10
10
 
11
11
  def end_element(name)
12
12
  case name
13
- when 'AccessKeyId', 'Status', 'Username'
13
+ when 'AccessKeyId', 'Status', 'UserName'
14
14
  @access_key[name] = value
15
15
  when 'member'
16
16
  @response['AccessKeys'] << @access_key
@@ -19,12 +19,13 @@ module Fog
19
19
 
20
20
  def end_element(name)
21
21
  case name
22
- when 'MultiAZCapable', 'ReadReplicaCapable', 'Vpc' then @db_instance_option[name] = to_boolean(value)
23
- when 'Engine', 'LicenseModel', 'EngineVersion', 'DBInstanceClass' then @db_instance_option[name] = value
22
+ when 'MultiAZCapable', 'ReadReplicaCapable', 'Vpc', 'SupportsIops',
23
+ 'SupportsEnhancedMonitoring', 'SupportsIAMDatabaseAuthentication',
24
+ 'SupportsPerformanceInsights', 'SupportsStorageEncryption' then @db_instance_option[name] = to_boolean(value)
25
+ when 'Engine', 'LicenseModel', 'EngineVersion', 'DBInstanceClass', 'StorageType' then @db_instance_option[name] = value
24
26
  when 'AvailabilityZones' then @db_instance_option[name] = @availability_zones
25
27
  when 'AvailabilityZone' then @availability_zones << @availability_zone unless @availability_zone.empty?
26
28
  when 'Name' then @availability_zone[name] = value
27
- when 'ProvisionedIopsCapable' then @availability_zone[name] = to_boolean(value)
28
29
  when 'OrderableDBInstanceOption'
29
30
  @db_instance_options << @db_instance_option
30
31
  @db_instance_option = {}
@@ -13,9 +13,7 @@ module Fog
13
13
  #
14
14
  # * AutoScalingGroupName<~String> - The name of the Auto Scaling group``
15
15
  # * 'InstanceIds'<~Array> - The list of Auto Scaling instances to detach.
16
- #
17
- # * options<~Hash>:
18
- # 'shouldDecrementDesiredCapacity'<~Boolean> - decrement the asg capacity or not (it will boot another if an instance id detached)
16
+ # * ShouldDecrementDesiredCapacity<~Boolean> - decrement the asg capacity or not (it will boot another if an instance id detached)
19
17
  #
20
18
  # ==== See Also
21
19
  #
@@ -23,6 +21,7 @@ module Fog
23
21
 
24
22
  ExpectedOptions[:asg_name] = %w[AutoScalingGroupName]
25
23
  ExpectedOptions[:instance_ids] = %w[InstanceIds]
24
+ ExpectedOptions[:should_decrement_desired_capacity] = %w[ShouldDecrementDesiredCapacity]
26
25
 
27
26
  def detach_instances(auto_scaling_group_name, options = {})
28
27
 
@@ -46,7 +45,7 @@ module Fog
46
45
 
47
46
  class Mock
48
47
  def detach_instances(auto_scaling_group_name, options = {})
49
- unexpected_options = options.keys - ExpectedOptions[:asg_name] - ExpectedOptions[:instance_ids]
48
+ unexpected_options = options.keys - ExpectedOptions[:asg_name] - ExpectedOptions[:instance_ids] - ExpectedOptions[:should_decrement_desired_capacity]
50
49
 
51
50
  unless unexpected_options.empty?
52
51
  raise Fog::AWS::AutoScaling::ValidationError.new("Options #{unexpected_options.join(',')} should not be included in request")
@@ -57,14 +57,16 @@ module Fog
57
57
  class Mock
58
58
  def authorize_security_group_egress(group_name, options = {})
59
59
  options = Fog::AWS.parse_security_group_options(group_name, options)
60
- if options.key?('GroupName')
61
- group_name = options['GroupName']
62
- else
63
- group_name = self.data[:security_groups].reject { |k,v| v['groupId'] != options['GroupId'] } .keys.first
64
- end
60
+
61
+ group = if options.key?('GroupName')
62
+ self.data[:security_groups].values.find { |v| v['groupName'] == options['GroupName'] }
63
+ else
64
+ self.data[:security_groups][options.fetch('GroupId')]
65
+ end
65
66
 
66
67
  response = Excon::Response.new
67
- group = self.data[:security_groups][group_name] || raise(Fog::Compute::AWS::NotFound.new("The security group '#{group_name}' does not exist"))
68
+ group ||
69
+ raise(Fog::Compute::AWS::NotFound.new("The security group '#{group_name}' does not exist"))
68
70
 
69
71
  verify_permission_options(options, group['vpcId'] != nil)
70
72
 
@@ -80,14 +80,16 @@ module Fog
80
80
  class Mock
81
81
  def authorize_security_group_ingress(group_name, options = {})
82
82
  options = Fog::AWS.parse_security_group_options(group_name, options)
83
- if options.key?('GroupName')
84
- group_name = options['GroupName']
85
- else
86
- group_name = self.data[:security_groups].reject { |k,v| v['groupId'] != options['GroupId'] } .keys.first
87
- end
83
+
84
+ group = if options.key?('GroupName')
85
+ self.data[:security_groups].values.find { |v| v['groupName'] == options['GroupName'] }
86
+ else
87
+ self.data[:security_groups][options.fetch('GroupId')]
88
+ end
88
89
 
89
90
  response = Excon::Response.new
90
- group = self.data[:security_groups][group_name] || raise(Fog::Compute::AWS::NotFound.new("The security group '#{group_name}' does not exist"))
91
+ group ||
92
+ raise(Fog::Compute::AWS::NotFound.new("The security group '#{group_name}' does not exist"))
91
93
 
92
94
  verify_permission_options(options, group['vpcId'] != nil)
93
95
 
@@ -150,14 +152,15 @@ module Fog
150
152
  else
151
153
  options['SourceSecurityGroupName']
152
154
  end
153
- source_group_id=self.data[:security_groups][group_name]['groupId']
155
+ source_group_id, _ = self.data[:security_groups].find { |_,v| v['groupName'] == group_name }
156
+
154
157
  ['tcp', 'udp'].each do |protocol|
155
158
  normalized_permissions << {
156
159
  'ipProtocol' => protocol,
157
160
  'fromPort' => 1,
158
161
  'toPort' => 65535,
159
162
  'groups' => [{
160
- 'groupName' => options['SourceSecurityGroupName'],
163
+ 'groupName' => group_name,
161
164
  'userId' => options['SourceSecurityGroupOwnerId'] || self.data[:owner_id],
162
165
  'groupId' => source_group_id
163
166
  }],
@@ -169,7 +172,7 @@ module Fog
169
172
  'fromPort' => -1,
170
173
  'toPort' => -1,
171
174
  'groups' => [{
172
- 'groupName' => options['SourceSecurityGroupName'],
175
+ 'groupName' => group_name,
173
176
  'userId' => options['SourceSecurityGroupOwnerId'] || self.data[:owner_id],
174
177
  'groupId' => source_group_id
175
178
  }],
@@ -188,18 +191,19 @@ module Fog
188
191
 
189
192
  groups = (permission['Groups'] || []).map do |authorized_group|
190
193
  security_group = if group_name = authorized_group['GroupName']
191
- self.data[:security_groups][group_name]
194
+ self.data[:security_groups].values.find { |sg| sg['groupName'] == group_name }
192
195
  elsif group_id = authorized_group['GroupId']
193
- self.data[:security_groups].values.find { |sg| sg['groupId'] == group_id }
194
- end ||
195
- raise(Fog::Compute::AWS::NotFound.new("The security group '#{group_name || group_id}' does not exist"))
196
-
197
- {
198
- 'groupName' => authorized_group['GroupName'] || security_group["groupName"],
199
- 'userId' => authorized_group['UserId'] || self.data[:owner_id],
200
- 'groupId' => authorized_group["GroupId"] || security_group['groupId']
201
- }
202
- end
196
+ self.data[:security_groups][group_id]
197
+ end
198
+ security_group ||
199
+ raise(Fog::Compute::AWS::NotFound.new("The security group '#{group_name || group_id}' does not exist"))
200
+
201
+ {
202
+ 'groupName' => authorized_group['GroupName'] || security_group['groupName'],
203
+ 'userId' => authorized_group['UserId'] || self.data[:owner_id],
204
+ 'groupId' => authorized_group["GroupId"] || security_group['groupId']
205
+ }
206
+ end
203
207
 
204
208
 
205
209
  if ['tcp', 'udp', 'icmp'].include?(permission['IpProtocol'])
@@ -208,7 +212,7 @@ module Fog
208
212
  'fromPort' => Integer(permission['FromPort']),
209
213
  'toPort' => Integer(permission['ToPort']),
210
214
  'groups' => groups,
211
- 'ipRanges' => (permission['IpRanges'] || []).map {|r| { 'cidrIp' => r['CidrIp'] } }
215
+ 'ipRanges' => (permission['IpRanges'] || []).map {|r| { 'cidrIp' => r['CidrIp'] } }
212
216
  }
213
217
  else
214
218
  normalized_permissions << {
@@ -9,6 +9,11 @@ module Fog
9
9
  # ==== Parameters
10
10
  # * source_snapshot_id<~String> - Id of snapshot
11
11
  # * source_region<~String> - Region to move it from
12
+ # * options<~Hash>:
13
+ # * 'Description'<~String> - A description for the EBS snapshot
14
+ # * 'Encrypted'<~Boolean> - Specifies whether the destination snapshot should be encrypted
15
+ # * 'KmsKeyId'<~String> - The full ARN of the AWS Key Management Service (AWS KMS) CMK
16
+ # to use when creating the snapshot copy.
12
17
  #
13
18
  # ==== Returns
14
19
  # * response<~Excon::Response>:
@@ -17,14 +22,22 @@ module Fog
17
22
  # * 'snapshotId'<~String> - id of snapshot
18
23
  #
19
24
  # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CopySnapshot.html]
20
- def copy_snapshot(source_snapshot_id, source_region, description = nil)
21
- request(
22
- 'Action' => 'CopySnapshot',
23
- 'SourceSnapshotId'=> source_snapshot_id,
24
- 'SourceRegion' => source_region,
25
- 'Description' => description,
26
- :parser => Fog::Parsers::Compute::AWS::CopySnapshot.new
27
- )
25
+ def copy_snapshot(source_snapshot_id, source_region, options = {})
26
+ # For backward compatibility. In previous versions third param was a description
27
+ if options.is_a?(String)
28
+ Fog::Logger.warning("copy_snapshot with description as a string in third param is deprecated, use hash instead: copy_snapshot('source-id', 'source-region', { 'Description' => 'some description' })")
29
+ options = { 'Description' => options }
30
+ end
31
+ params = {
32
+ 'Action' => 'CopySnapshot',
33
+ 'SourceSnapshotId' => source_snapshot_id,
34
+ 'SourceRegion' => source_region,
35
+ 'Description' => options['Description'],
36
+ :parser => Fog::Parsers::Compute::AWS::CopySnapshot.new
37
+ }
38
+ params['Encrypted'] = true if options['Encrypted']
39
+ params['KmsKeyId'] = options['KmsKeyId'] if options['Encrypted'] && options['KmsKeyId']
40
+ request(params)
28
41
  end
29
42
  end
30
43
 
@@ -35,7 +48,7 @@ module Fog
35
48
  # Fog::AWS[:compute].copy_snapshot("snap-1db0a957", 'us-east-1')
36
49
  #
37
50
 
38
- def copy_snapshot(source_snapshot_id, source_region, description = nil)
51
+ def copy_snapshot(source_snapshot_id, source_region, options = {})
39
52
  response = Excon::Response.new
40
53
  response.status = 200
41
54
  snapshot_id = Fog::AWS::Mock.snapshot_id
@@ -73,11 +73,11 @@ module Fog
73
73
  groups = {}
74
74
  if options['GroupSet']
75
75
  options['GroupSet'].each do |group_id|
76
- group_obj = self.data[:security_groups].select { |k,v| v['groupId'] == group_id }.first
76
+ group_obj = self.data[:security_groups][group_id]
77
77
  if group_obj.nil?
78
78
  raise Fog::Compute::AWS::Error.new("Unknown security group '#{group_id}' specified")
79
79
  end
80
- groups[group_id] = group_obj
80
+ groups[group_id] = group_obj['groupName']
81
81
  end
82
82
  end
83
83
 
@@ -39,7 +39,7 @@ module Fog
39
39
  unless vpc.nil?
40
40
  response.status = 200
41
41
  route_table = {
42
- 'routeTableId' => "rtb-#{Fog::Mock.random_hex(8)}",
42
+ 'routeTableId' => Fog::AWS::Mock.route_table_id,
43
43
  'vpcId' => vpc["vpcId"],
44
44
  'routeSet' => [{
45
45
  "destinationCidrBlock" => vpc["cidrBlock"],
@@ -33,26 +33,31 @@ module Fog
33
33
  class Mock
34
34
  def create_security_group(name, description, vpc_id=nil)
35
35
  response = Excon::Response.new
36
- unless self.data[:security_groups][name]
37
- data = {
38
- 'groupDescription' => description,
39
- 'groupName' => name,
40
- 'groupId' => Fog::AWS::Mock.security_group_id,
41
- 'ipPermissionsEgress' => [],
42
- 'ipPermissions' => [],
43
- 'ownerId' => self.data[:owner_id],
44
- 'vpcId' => vpc_id
45
- }
46
- self.data[:security_groups][name] = data
47
- response.body = {
48
- 'requestId' => Fog::AWS::Mock.request_id,
49
- 'groupId' => data['groupId'],
50
- 'return' => true
51
- }
52
- response
53
- else
54
- raise Fog::Compute::AWS::Error.new("InvalidGroup.Duplicate => The security group '#{name}' already exists")
36
+
37
+ vpc_id ||= Fog::AWS::Mock.default_vpc_for(region)
38
+ group_id = Fog::AWS::Mock.security_group_id
39
+
40
+ if self.data[:security_groups].find { |_,v| v['groupName'] == name }
41
+ raise Fog::Compute::AWS::Error,
42
+ "InvalidGroup.Duplicate => The security group '#{name}' already exists"
55
43
  end
44
+
45
+ self.data[:security_groups][group_id] = {
46
+ 'groupDescription' => description,
47
+ 'groupName' => name,
48
+ 'groupId' => group_id,
49
+ 'ipPermissionsEgress' => [],
50
+ 'ipPermissions' => [],
51
+ 'ownerId' => self.data[:owner_id],
52
+ 'vpcId' => vpc_id
53
+ }
54
+
55
+ response.body = {
56
+ 'requestId' => Fog::AWS::Mock.request_id,
57
+ 'groupId' => group_id,
58
+ 'return' => true
59
+ }
60
+ response
56
61
  end
57
62
  end
58
63
  end