fog-aws 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/lib/fog/aws/compute.rb +6 -0
  4. data/lib/fog/aws/models/compute/flavors.rb +60 -0
  5. data/lib/fog/aws/models/compute/volume.rb +41 -22
  6. data/lib/fog/aws/models/compute/vpc.rb +34 -0
  7. data/lib/fog/aws/models/rds/security_group.rb +4 -2
  8. data/lib/fog/aws/models/storage/file.rb +1 -1
  9. data/lib/fog/aws/parsers/compute/describe_volumes_modifications.rb +30 -0
  10. data/lib/fog/aws/parsers/compute/describe_vpc_classic_link.rb +3 -1
  11. data/lib/fog/aws/parsers/compute/describe_vpc_classic_link_dns_support.rb +26 -0
  12. data/lib/fog/aws/parsers/compute/modify_volume.rb +26 -0
  13. data/lib/fog/aws/rds.rb +1 -1
  14. data/lib/fog/aws/requests/compute/attach_classic_link_vpc.rb +3 -3
  15. data/lib/fog/aws/requests/compute/create_vpc.rb +10 -9
  16. data/lib/fog/aws/requests/compute/describe_volumes_modifications.rb +93 -0
  17. data/lib/fog/aws/requests/compute/describe_vpc_classic_link.rb +2 -1
  18. data/lib/fog/aws/requests/compute/describe_vpc_classic_link_dns_support.rb +53 -0
  19. data/lib/fog/aws/requests/compute/detach_classic_link_vpc.rb +1 -3
  20. data/lib/fog/aws/requests/compute/disable_vpc_classic_link_dns_support.rb +45 -0
  21. data/lib/fog/aws/requests/compute/enable_vpc_classic_link_dns_support.rb +45 -0
  22. data/lib/fog/aws/requests/compute/modify_volume.rb +88 -0
  23. data/lib/fog/aws/requests/rds/authorize_db_security_group_ingress.rb +10 -5
  24. data/lib/fog/aws/requests/rds/create_db_subnet_group.rb +3 -4
  25. data/lib/fog/aws/requests/rds/delete_db_subnet_group.rb +2 -0
  26. data/lib/fog/aws/requests/rds/revoke_db_security_group_ingress.rb +9 -4
  27. data/lib/fog/aws/version.rb +1 -1
  28. data/tests/models/compute/volume_tests.rb +16 -1
  29. data/tests/models/compute/vpc_tests.rb +23 -1
  30. data/tests/models/rds/security_group_tests.rb +30 -6
  31. data/tests/requests/compute/volume_tests.rb +42 -2
  32. data/tests/requests/compute/vpc_tests.rb +41 -5
  33. metadata +10 -2
@@ -0,0 +1,93 @@
1
+ module Fog
2
+ module Compute
3
+ class AWS
4
+ class Real
5
+ require 'fog/aws/parsers/compute/describe_volumes_modifications'
6
+
7
+ # Reports the current modification status of EBS volumes.
8
+ #
9
+ # ==== Parameters
10
+ # * filters<~Hash> - List of filters to limit results with
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>
15
+ # * 'volumeModificationSet'<~Array>:
16
+ # * 'targetIops'<~Integer> - Target IOPS rate of the volume being modified.
17
+ # * 'originalIops'<~Integer> - Original IOPS rate of the volume being modified.
18
+ # * 'modificationState'<~String> - Current state of modification. Modification state is null for unmodified volumes.
19
+ # * 'targetSize'<~Integer> - Target size of the volume being modified.
20
+ # * 'targetVolumeType'<~String> - Target EBS volume type of the volume being modified.
21
+ # * 'volumeId'<~String> - ID of the volume being modified.
22
+ # * 'progress'<~Integer> - Modification progress from 0 to 100%.
23
+ # * 'startTime'<~Time> - Modification start time
24
+ # * 'endTime'<~Time> - Modification end time
25
+ # * 'originalSize'<~Integer> - Original size of the volume being modified.
26
+ # * 'originalVolumeType'<~String> - Original EBS volume type of the volume being modified.
27
+
28
+ def describe_volumes_modifications(filters = {})
29
+ params = {}
30
+ if volume_id = filters.delete('volume-id')
31
+ params.merge!(Fog::AWS.indexed_param('VolumeId.%d', [*volume_id]))
32
+ end
33
+ params.merge!(Fog::AWS.indexed_filters(filters))
34
+ request({
35
+ 'Action' => 'DescribeVolumesModifications',
36
+ :idempotent => true,
37
+ :parser => Fog::Parsers::Compute::AWS::DescribeVolumesModifications.new
38
+ }.merge(params))
39
+ end
40
+ end
41
+
42
+ class Mock
43
+ def describe_volumes_modifications(filters = {})
44
+ response = Excon::Response.new
45
+
46
+ modification_set = self.data[:volume_modifications].values
47
+
48
+ aliases = {
49
+ 'volume-id' => 'volumeId',
50
+ 'modification-state' => 'modificationState',
51
+ 'target-size' => 'targetSize',
52
+ 'target-iops' => 'targetIops',
53
+ 'target-volume-type' => 'targetVolumeType',
54
+ 'original-size' => 'originalSize',
55
+ 'original-iops' => 'originalIops',
56
+ 'original-volume-type' => 'originalVolumeType',
57
+ 'start-time' => 'startTime'
58
+ }
59
+
60
+ attribute_aliases = {
61
+ 'targetSize' => 'size',
62
+ 'targetVolumeType' => 'volumeType',
63
+ 'targetIops' => 'iops'
64
+ }
65
+
66
+ for filter_key, filter_value in filters
67
+ aliased_key = aliases[filter_key]
68
+ modification_set = modification_set.reject { |m| ![*filter_value].include?(m[aliased_key]) }
69
+ end
70
+
71
+ modification_set.each do |modification|
72
+ case modification['modificationState']
73
+ when 'modifying'
74
+ volume = self.data[:volumes][modification['volumeId']]
75
+ modification['modificationState'] = 'optimizing'
76
+ %w(targetSize targetIops targetVolumeType).each do |attribute|
77
+ aliased_attribute = attribute_aliases[attribute]
78
+ volume[aliased_attribute] = modification[attribute] if modification[attribute]
79
+ end
80
+ self.data[:volumes][modification['volumeId']] = volume
81
+ when 'optimizing'
82
+ modification['modificationState'] = 'completed'
83
+ modification['endTime'] = Time.now
84
+ end
85
+ end
86
+
87
+ response.body = {'requestId' => Fog::AWS::Mock.request_id, 'volumeModificationSet' => modification_set}
88
+ response
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -45,7 +45,7 @@ module Fog
45
45
  vpcs = apply_tag_filters(vpcs, options[:filters], 'vpcId') if options[:filters]
46
46
 
47
47
  response.status = 200
48
- vpc_data = vpcs.collect do |vpc|
48
+ vpc_data = vpcs.collect do |vpc|
49
49
  {
50
50
  'vpcId' => vpc['vpcId'],
51
51
  'classicLinkEnabled' => vpc['classicLinkEnabled'],
@@ -56,6 +56,7 @@ module Fog
56
56
  'requestId' => Fog::AWS::Mock.request_id,
57
57
  'vpcSet' => vpc_data
58
58
  }
59
+ response
59
60
  end
60
61
  end
61
62
  end
@@ -0,0 +1,53 @@
1
+ module Fog
2
+ module Compute
3
+ class AWS
4
+ class Real
5
+ require 'fog/aws/parsers/compute/describe_vpc_classic_link_dns_support'
6
+
7
+ # escribes the ClassicLink DNS support status of one or more VPCs
8
+ #
9
+ # ==== Parameters
10
+ # * options<~Hash>
11
+ # * vpc_ids<~Array> - An array of vpc ids to restrict results to
12
+ # * 'MaxResults' - Maximum number of items to return
13
+ # * 'NextToken' - The token for the next set of items to return
14
+ #
15
+ # ==== Returns
16
+ # * response<~Excon::Response>:
17
+ # * body<~Hash>:
18
+ # * 'requestId'<~String> - Id of the request
19
+ # * 'vpcs'<~Array> - Information about the ClassicLink DNS support status of the VPCs
20
+ # * 'vpcId'<~String>
21
+ # * 'classicLinkDnsSupported'<~Boolean>
22
+ #
23
+ # http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcClassicLinkDnsSupport.html
24
+
25
+ def describe_vpc_classic_link_dns_support(options={})
26
+ params = {}
27
+ params.merge!(Fog::AWS.indexed_param('VpcIds', options[:vpc_ids])) if options[:vpc_ids]
28
+ request({
29
+ 'Action' => 'DescribeVpcClassicLinkDnsSupport',
30
+ 'MaxResults' => options['MaxResults'],
31
+ 'NextToken' => options['NextToken'],
32
+ :parser => Fog::Parsers::Compute::AWS::DescribeVpcClassicLinkDnsSupport.new
33
+ }.merge(params))
34
+ end
35
+ end
36
+
37
+ class Mock
38
+ def describe_vpc_classic_link_dns_support(options={})
39
+ response = Excon::Response.new
40
+
41
+ vpcs = self.data[:vpcs]
42
+
43
+ if options[:vpc_ids]
44
+ vpcs = vpcs.select { |v| options[:vpc_ids].include?(v['vpcId']) }
45
+ end
46
+
47
+ response.body = {'vpcs' => vpcs.map { |v| {"vpcId" => v['vpcId'], "classicLinkDnsSupported" => v['classicLinkDnsSupport']} } }
48
+ response
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -26,7 +26,6 @@ module Fog
26
26
  'DryRun' => dry_run,
27
27
  :parser => Fog::Parsers::Compute::AWS::Basic.new
28
28
  )
29
-
30
29
  end
31
30
  end
32
31
 
@@ -47,12 +46,11 @@ module Fog
47
46
  instance['classicLinkVpcId'] = nil
48
47
  end
49
48
  response
50
- elsif !instance
49
+ elsif !instance
51
50
  raise Fog::Compute::AWS::NotFound.new("The instance ID '#{instance_id}' does not exist.")
52
51
  elsif !vpc
53
52
  raise Fog::Compute::AWS::NotFound.new("The VPC '#{vpc_id}' does not exist.")
54
53
  end
55
-
56
54
  end
57
55
  end
58
56
  end
@@ -0,0 +1,45 @@
1
+ module Fog
2
+ module Compute
3
+ class AWS
4
+ class Real
5
+ require 'fog/aws/parsers/compute/basic'
6
+
7
+ # Disables DNS hostname resolution for ClassicLink
8
+ #
9
+ # ==== Parameters
10
+ # * vpc_id<~String> - The ID of the ClassicLink-enabled VPC.
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'requestId'<~String> - Id of the request
16
+ # * 'return'<~Boolean> - Whether the request succeeded
17
+ #
18
+ # http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DisableVpcClassicLinkDnsSupport.html
19
+
20
+ def disable_vpc_classic_link_dns_support(vpc_id)
21
+ request(
22
+ 'Action' => 'DisableVpcClassicLinkDnsSupport',
23
+ 'VpcId' => vpc_id,
24
+ :parser => Fog::Parsers::Compute::AWS::Basic.new
25
+ )
26
+ end
27
+ end
28
+
29
+ class Mock
30
+ def disable_vpc_classic_link_dns_support(vpc_id)
31
+ response = Excon::Response.new
32
+ unless vpc = self.data[:vpcs].find { |v| v['vpcId'] == vpc_id }
33
+ raise Fog::Compute::AWS::NotFound.new("The VPC '#{vpc_id}' does not exist")
34
+ end
35
+ vpc['classicLinkDnsSupport'] = false
36
+ response.body = {
37
+ 'requestId' => Fog::AWS::Mock.request_id,
38
+ 'return' => true
39
+ }
40
+ response
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ module Fog
2
+ module Compute
3
+ class AWS
4
+ class Real
5
+ require 'fog/aws/parsers/compute/basic'
6
+
7
+ # Enables a VPC to support DNS hostname resolution for ClassicLink
8
+ #
9
+ # ==== Parameters
10
+ # * vpc_id<~String> - The ID of the ClassicLink-enabled VPC.
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'requestId'<~String> - Id of the request
16
+ # * 'return'<~Boolean> - Whether the request succeeded
17
+ #
18
+ # http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EnableVpcClassicLinkDnsSupport.html
19
+
20
+ def enable_vpc_classic_link_dns_support(vpc_id)
21
+ request(
22
+ 'Action' => 'EnableVpcClassicLinkDnsSupport',
23
+ 'VpcId' => vpc_id,
24
+ :parser => Fog::Parsers::Compute::AWS::Basic.new
25
+ )
26
+ end
27
+ end
28
+
29
+ class Mock
30
+ def enable_vpc_classic_link_dns_support(vpc_id)
31
+ response = Excon::Response.new
32
+ unless vpc = self.data[:vpcs].find { |v| v['vpcId'] == vpc_id }
33
+ raise Fog::Compute::AWS::NotFound.new("The VPC '#{vpc_id}' does not exist")
34
+ end
35
+ vpc['classicLinkDnsSupport'] = true
36
+ response.body = {
37
+ 'requestId' => Fog::AWS::Mock.request_id,
38
+ 'return' => true
39
+ }
40
+ response
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,88 @@
1
+ module Fog
2
+ module Compute
3
+ class AWS
4
+ class Real
5
+ require 'fog/aws/parsers/compute/modify_volume'
6
+
7
+ # Modifies a volume
8
+ #
9
+ # ==== Parameters
10
+ # * volume_id<~String> - The ID of the volume
11
+ # * options<~Hash>:
12
+ # * 'VolumeType'<~String> - Type of volume
13
+ # * 'Size'<~Integer> - Size in GiBs fo the volume
14
+ # * 'Iops'<~Integer> - Number of IOPS the volume supports
15
+ #
16
+ # ==== Response
17
+ # * response<~Excon::Response>:
18
+ # * body<~Hash>:
19
+ # * 'targetIops'<~Integer> - Target IOPS rate of the volume being modified.
20
+ # * 'originalIops'<~Integer> - Original IOPS rate of the volume being modified.
21
+ # * 'modificationState'<~String> - Current state of modification. Modification state is null for unmodified volumes.
22
+ # * 'targetSize'<~Integer> - Target size of the volume being modified.
23
+ # * 'targetVolumeType'<~String> - Target EBS volume type of the volume being modified.
24
+ # * 'volumeId'<~String> - ID of the volume being modified.
25
+ # * 'progress'<~Integer> - Modification progress from 0 to 100%.
26
+ # * 'startTime'<~Time> - Modification start time
27
+ # * 'endTime'<~Time> - Modification end time
28
+ # * 'originalSize'<~Integer> - Original size of the volume being modified.
29
+ # * 'originalVolumeType'<~String> - Original EBS volume type of the volume being modified.
30
+
31
+ def modify_volume(volume_id, options={})
32
+ request({
33
+ 'Action' => "ModifyVolume",
34
+ 'VolumeId' => volume_id,
35
+ :parser => Fog::Parsers::Compute::AWS::ModifyVolume.new
36
+ }.merge(options))
37
+ end
38
+ end
39
+
40
+ class Mock
41
+ def modify_volume(volume_id, options={})
42
+ response = Excon::Response.new
43
+ volume = self.data[:volumes][volume_id]
44
+
45
+ if volume["volumeType"] == 'standard' && options['VolumeType']
46
+ raise Fog::Compute::AWS::Error.new("InvalidParameterValue => Volume type EBS Magnetic is not supported.")
47
+ end
48
+
49
+ volume_modification = {
50
+ 'modificationState' => 'modifying',
51
+ 'progress' => 0,
52
+ 'startTime' => Time.now,
53
+ 'volumeId' => volume_id
54
+ }
55
+
56
+ if options['Size']
57
+ volume_modification.merge!(
58
+ 'originalSize' => volume['size'],
59
+ 'targetSize' => options['Size']
60
+ )
61
+ end
62
+
63
+ if options['Iops']
64
+ volume_modification.merge!(
65
+ 'originalIops' => volume['iops'],
66
+ 'targetIops' => options['Iops']
67
+ )
68
+ end
69
+
70
+ if options['VolumeType']
71
+ if options["VolumeType"] == 'standard'
72
+ raise Fog::Compute::AWS::Error.new("InvalidParameterValue => Volume type EBS Magnetic is not supported.")
73
+ end
74
+ volume_modification.merge!(
75
+ 'originalVolumeType' => volume['volumeType'],
76
+ 'targetVolumeType' => options['VolumeType']
77
+ )
78
+ end
79
+
80
+ self.data[:volume_modifications][volume_id] = volume_modification
81
+
82
+ response.body = {'volumeModification' => volume_modification, 'requestId' => Fog::AWS::Mock.request_id}
83
+ response
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -15,8 +15,8 @@ module Fog
15
15
  # * response<~Excon::Response>:
16
16
  # * body<~Hash>:
17
17
  def authorize_db_security_group_ingress(name, opts={})
18
- unless opts.key?('CIDRIP') || (opts.key?('EC2SecurityGroupName') && opts.key?('EC2SecurityGroupOwnerId'))
19
- raise ArgumentError, 'Must specify CIDRIP, or both EC2SecurityGroupName and EC2SecurityGroupOwnerId'
18
+ unless opts.key?('CIDRIP') || ((opts.key?('EC2SecurityGroupName') || opts.key?('EC2SecurityGroupId')) && opts.key?('EC2SecurityGroupOwnerId'))
19
+ raise ArgumentError, 'Must specify CIDRIP, or one of EC2SecurityGroupName or EC2SecurityGroupId, and EC2SecurityGroupOwnerId'
20
20
  end
21
21
 
22
22
  request({
@@ -29,8 +29,13 @@ module Fog
29
29
 
30
30
  class Mock
31
31
  def authorize_db_security_group_ingress(name, opts = {})
32
- unless opts.key?('CIDRIP') || (opts.key?('EC2SecurityGroupName') && opts.key?('EC2SecurityGroupOwnerId'))
33
- raise ArgumentError, 'Must specify CIDRIP, or both EC2SecurityGroupName and EC2SecurityGroupOwnerId'
32
+ unless opts.key?('CIDRIP') || ((opts.key?('EC2SecurityGroupName') || opts.key?('EC2SecurityGroupId')) && opts.key?('EC2SecurityGroupOwnerId'))
33
+ raise ArgumentError, 'Must specify CIDRIP, or one of EC2SecurityGroupName or EC2SecurityGroupId, and EC2SecurityGroupOwnerId'
34
+ end
35
+
36
+ if ec2_security_group_id = opts.delete("EC2SecurityGroupId")
37
+ ec2_security_group = (Fog::Compute::AWS::Mock.data[self.region][self.aws_access_key_id][:security_groups] || {}).values.detect { |sg| sg['groupId'] == ec2_security_group_id }
38
+ opts['EC2SecurityGroupName'] = ec2_security_group['groupName']
34
39
  end
35
40
 
36
41
  response = Excon::Response.new
@@ -42,7 +47,7 @@ module Fog
42
47
  end
43
48
  sec_group['IPRanges'] << opts.merge({"Status" => 'authorizing'})
44
49
  else
45
- if sec_group['EC2SecurityGroups'].find{|h| h['EC2SecurityGroupName'] == opts['EC2SecurityGroupName']}
50
+ if sec_group['EC2SecurityGroups'].find{|h| h['EC2SecurityGroupName'] == opts['EC2SecurityGroupName'] || h['EC2SecurityGroupId'] == opts['EC2SecurityGroupId']}
46
51
  raise Fog::AWS::RDS::AuthorizationAlreadyExists.new("AuthorizationAlreadyExists => #{opts['EC2SecurityGroupName']} is alreay defined")
47
52
  end
48
53
  sec_group['EC2SecurityGroups'] << opts.merge({"Status" => 'authorizing'})
@@ -31,15 +31,14 @@ module Fog
31
31
  end
32
32
 
33
33
  # collection = Fog::Compute::AWS.new(:aws_access_key_id => 'mock key', :aws_secret_access_key => 'mock secret')
34
- collection = Fog::Compute[:aws]
35
- collection.region = @region
34
+ compute_data = Fog::Compute::AWS::Mock.data[self.region][self.aws_access_key_id]
36
35
 
37
36
  subnets = subnet_ids.map do |snid|
38
- subnet = collection.subnets.get(snid)
37
+ subnet = compute_data[:subnets].detect { |s| s['subnetId'] == snid }
39
38
  raise Fog::AWS::RDS::NotFound.new("InvalidSubnet => The subnet '#{snid}' was not found") if subnet.nil?
40
39
  subnet
41
40
  end
42
- vpc_id = subnets.first.vpc_id
41
+ vpc_id = subnets.first['vpcId']
43
42
 
44
43
  data = {
45
44
  'DBSubnetGroupName' => name,
@@ -26,6 +26,8 @@ module Fog
26
26
  raise Fog::AWS::RDS::NotFound.new("DBSubnetGroupNotFound => The subnet group '#{name}' doesn't exists")
27
27
  end
28
28
 
29
+ self.data[:subnet_groups].delete(name)
30
+
29
31
  response.body = {
30
32
  'ResponseMetadata'=>{ 'RequestId'=> Fog::AWS::Mock.request_id },
31
33
  'return' => true,
@@ -15,8 +15,8 @@ module Fog
15
15
  # * response<~Excon::Response>:
16
16
  # * body<~Hash>:
17
17
  def revoke_db_security_group_ingress(name, opts={})
18
- unless opts.key?('CIDRIP') || (opts.key?('EC2SecurityGroupName') && opts.key?('EC2SecurityGroupOwnerId'))
19
- raise ArgumentError, 'Must specify CIDRIP, or both EC2SecurityGroupName and EC2SecurityGroupOwnerId'
18
+ unless opts.key?('CIDRIP') || ((opts.key?('EC2SecurityGroupName') || opts.key?('EC2SecurityGroupId')) && opts.key?('EC2SecurityGroupOwnerId'))
19
+ raise ArgumentError, 'Must specify CIDRIP, or one of EC2SecurityGroupName or EC2SecurityGroupId, and EC2SecurityGroupOwnerId'
20
20
  end
21
21
 
22
22
  request({
@@ -29,8 +29,13 @@ module Fog
29
29
 
30
30
  class Mock
31
31
  def revoke_db_security_group_ingress(name, opts = {})
32
- unless opts.key?('CIDRIP') || (opts.key?('EC2SecurityGroupName') && opts.key?('EC2SecurityGroupOwnerId'))
33
- raise ArgumentError, 'Must specify CIDRIP, or both EC2SecurityGroupName and EC2SecurityGroupOwnerId'
32
+ unless opts.key?('CIDRIP') || ((opts.key?('EC2SecurityGroupName') || opts.key?('EC2SecurityGroupId')) && opts.key?('EC2SecurityGroupOwnerId'))
33
+ raise ArgumentError, 'Must specify CIDRIP, or one of EC2SecurityGroupName or EC2SecurityGroupId, and EC2SecurityGroupOwnerId'
34
+ end
35
+
36
+ if ec2_security_group_id = opts.delete("EC2SecurityGroupId")
37
+ ec2_security_group = (Fog::Compute::AWS::Mock.data[self.region][self.aws_access_key_id][:security_groups] || {}).values.detect { |sg| sg['groupId'] == ec2_security_group_id }
38
+ opts['EC2SecurityGroupName'] = ec2_security_group['groupName']
34
39
  end
35
40
 
36
41
  response = Excon::Response.new