fog-aws 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +4 -0
  4. data/README.md +1 -1
  5. data/gemfiles/Gemfile-edge +5 -0
  6. data/lib/fog/aws/models/compute/security_group.rb +4 -4
  7. data/lib/fog/aws/models/rds/cluster.rb +93 -0
  8. data/lib/fog/aws/models/rds/cluster_snapshots.rb +48 -0
  9. data/lib/fog/aws/models/rds/clusters.rb +23 -0
  10. data/lib/fog/aws/models/rds/parameters.rb +15 -0
  11. data/lib/fog/aws/models/rds/server.rb +29 -11
  12. data/lib/fog/aws/models/rds/servers.rb +4 -0
  13. data/lib/fog/aws/models/rds/snapshot.rb +36 -17
  14. data/lib/fog/aws/parsers/rds/create_db_cluster.rb +32 -0
  15. data/lib/fog/aws/parsers/rds/create_db_cluster_snapshot.rb +33 -0
  16. data/lib/fog/aws/parsers/rds/db_cluster_parser.rb +71 -0
  17. data/lib/fog/aws/parsers/rds/db_cluster_snapshot_parser.rb +32 -0
  18. data/lib/fog/aws/parsers/rds/db_parameter_parser.rb +30 -0
  19. data/lib/fog/aws/parsers/rds/db_parser.rb +2 -1
  20. data/lib/fog/aws/parsers/rds/delete_db_cluster.rb +32 -0
  21. data/lib/fog/aws/parsers/rds/delete_db_cluster_snapshot.rb +32 -0
  22. data/lib/fog/aws/parsers/rds/describe_db_cluster_snapshots.rb +34 -0
  23. data/lib/fog/aws/parsers/rds/describe_db_clusters.rb +34 -0
  24. data/lib/fog/aws/parsers/rds/describe_engine_default_parameters.rb +34 -0
  25. data/lib/fog/aws/parsers/rds/restore_db_instance_from_db_snapshot.rb +2 -2
  26. data/lib/fog/aws/parsers/rds/snapshot_parser.rb +6 -13
  27. data/lib/fog/aws/rds.rb +25 -0
  28. data/lib/fog/aws/requests/compute/describe_availability_zones.rb +5 -2
  29. data/lib/fog/aws/requests/rds/create_db_cluster.rb +98 -0
  30. data/lib/fog/aws/requests/rds/create_db_cluster_snapshot.rb +68 -0
  31. data/lib/fog/aws/requests/rds/create_db_instance.rb +42 -4
  32. data/lib/fog/aws/requests/rds/create_db_snapshot.rb +1 -1
  33. data/lib/fog/aws/requests/rds/delete_db_cluster.rb +55 -0
  34. data/lib/fog/aws/requests/rds/delete_db_cluster_snapshot.rb +43 -0
  35. data/lib/fog/aws/requests/rds/delete_db_instance.rb +9 -0
  36. data/lib/fog/aws/requests/rds/delete_db_snapshot.rb +2 -1
  37. data/lib/fog/aws/requests/rds/describe_db_cluster_snapshots.rb +66 -0
  38. data/lib/fog/aws/requests/rds/describe_db_clusters.rb +54 -0
  39. data/lib/fog/aws/requests/rds/describe_db_instances.rb +4 -0
  40. data/lib/fog/aws/requests/rds/describe_db_parameters.rb +15 -1
  41. data/lib/fog/aws/requests/rds/describe_engine_default_parameters.rb +40 -0
  42. data/lib/fog/aws/requests/rds/modify_db_instance.rb +52 -49
  43. data/lib/fog/aws/requests/rds/modify_db_parameter_group.rb +28 -1
  44. data/lib/fog/aws/requests/rds/restore_db_instance_from_db_snapshot.rb +63 -2
  45. data/lib/fog/aws/version.rb +1 -1
  46. data/tests/models/rds/cluster_tests.rb +54 -0
  47. data/tests/models/rds/clusters_tests.rb +5 -0
  48. data/tests/models/rds/helper.rb +13 -0
  49. data/tests/models/rds/server_tests.rb +3 -3
  50. data/tests/models/rds/servers_tests.rb +18 -0
  51. data/tests/requests/compute/instance_tests.rb +2 -3
  52. data/tests/requests/rds/cluster_snapshot_tests.rb +43 -0
  53. data/tests/requests/rds/cluster_tests.rb +37 -0
  54. data/tests/requests/rds/helper.rb +84 -0
  55. data/tests/requests/rds/instance_tests.rb +16 -4
  56. data/tests/requests/rds/parameter_group_tests.rb +1 -1
  57. data/tests/requests/rds/parameter_request_tests.rb +0 -2
  58. metadata +27 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fe29ce48c8320ccf8c25c90b13c56ceb6ea94c3
4
- data.tar.gz: dde71551b86d3333f8e85cbae203fd85cef1cb8b
3
+ metadata.gz: e77bea854342136841867ba57ed6e1675c276946
4
+ data.tar.gz: 2df27806c77f8443b44cf76358575e98d34b3320
5
5
  SHA512:
6
- metadata.gz: ddd00c675fb5dee5a7eeccbb255e380342b4a819278071d9c7ed1b746f6b2d03125ef5b0844bdb111d007d238812d10f9807cb925874f7685026369faf47f588
7
- data.tar.gz: d31c7bbd8cb8b18d2a0ffdfc54a09c8f7bb6adb678c8d571aba151624e8912f6190bd3f16475dab04e3a1901ccb3d302b68ec832a84f73a9fdbacd70e7431593
6
+ metadata.gz: 57c26f03d63dfef478f8df9360d6e3e4111c73e4e2ebc0c4a9936e2a19c08719c6bf509c472434b9668a9abe85ce2a17b665bcec136541a2f896ec508e1327cd
7
+ data.tar.gz: 1968a9af031b2e8ffa1ea65678d9f12bad0032f72b4fa76f4580381e1e0a86c2e6e72f870c8c7e44178b1b7404b2a981628a96c299e1cdf2fb2a9e1e2eec6825
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.a
14
14
  mkmf.log
15
15
  tests/.fog
16
+ gemfiles/Gemfile-edge.lock
@@ -23,6 +23,10 @@ matrix:
23
23
  gemfile: Gemfile
24
24
  - rvm: 2.2.0
25
25
  gemfile: gemfiles/Gemfile-edge
26
+ - rvm: 2.3.0
27
+ gemfile: gemfiles/Gemfile-edge
28
+ - rvm: 2.3.0
29
+ gemfile: Gemfile
26
30
  - rvm: jruby-18mode
27
31
  gemfile: gemfiles/Gemfile-ruby-1.8.7
28
32
  - rvm: jruby-19mode
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Build Status](https://travis-ci.org/fog/fog-aws.svg?branch=master)](https://travis-ci.org/fog/fog-aws)
5
5
  [![Dependency Status](https://gemnasium.com/fog/fog-aws.svg)](https://gemnasium.com/fog/fog-aws)
6
6
  [![Test Coverage](https://codeclimate.com/github/fog/fog-aws/badges/coverage.svg)](https://codeclimate.com/github/fog/fog-aws)
7
- [![Code Climate](https://codeclimate.com/github/fog/fog-aws.png)](https://codeclimate.com/github/fog/fog-aws)
7
+ [![Code Climate](https://codeclimate.com/github/fog/fog-aws.svg)](https://codeclimate.com/github/fog/fog-aws)
8
8
 
9
9
 
10
10
  ## Installation
@@ -4,6 +4,11 @@ source "https://rubygems.org"
4
4
  gem "fog-core", :github => "fog/fog-core"
5
5
  gem "fog-json", :github => "fog/fog-json"
6
6
 
7
+ group :test, :default do
8
+ gem 'pry-nav'
9
+ gem 'mime-types', '~> 2.6', '>= 2.6.2'
10
+ end
11
+
7
12
  gem "codeclimate-test-reporter", group: :test, require: nil
8
13
 
9
14
  gemspec :path => "../"
@@ -83,8 +83,8 @@ module Fog
83
83
  requires_one :name, :group_id
84
84
 
85
85
  ip_permission = {
86
- 'FromPort' => range.min,
87
- 'ToPort' => range.max,
86
+ 'FromPort' => range.begin,
87
+ 'ToPort' => range.end,
88
88
  'IpProtocol' => options[:ip_protocol] || 'tcp'
89
89
  }
90
90
 
@@ -197,8 +197,8 @@ module Fog
197
197
  requires_one :name, :group_id
198
198
 
199
199
  ip_permission = {
200
- 'FromPort' => range.min,
201
- 'ToPort' => range.max,
200
+ 'FromPort' => range.begin,
201
+ 'ToPort' => range.end,
202
202
  'IpProtocol' => options[:ip_protocol] || 'tcp'
203
203
  }
204
204
 
@@ -0,0 +1,93 @@
1
+ module Fog
2
+ module AWS
3
+ class RDS
4
+ class Cluster < Fog::Model
5
+ identity :id, :aliases => 'DBClusterIdentifier'
6
+
7
+ attribute :allocated_storage, :aliases => 'AllocatedStorage', :type => :integer
8
+ attribute :backup_retention_period, :aliases => 'BackupRetentionPeriod', :type => :integer
9
+ attribute :db_cluster_members, :aliases => 'DBClusterMembers', :type => :array
10
+ attribute :db_cluster_parameter_group, :aliases => 'DBClusterParameterGroup'
11
+ attribute :db_subnet_group, :aliases => 'DBSubnetGroup'
12
+ attribute :endpoint, :aliases => 'Endpoint'
13
+ attribute :engine, :aliases => 'Engine'
14
+ attribute :engine_version, :aliases => 'EngineVersion'
15
+ attribute :password, :aliases => 'MasterUserPassword'
16
+ attribute :master_username, :aliases => 'MasterUsername'
17
+ attribute :port, :aliases => 'Port', :type => :integer
18
+ attribute :preferred_backup_window, :aliases => 'PreferredBackupWindow'
19
+ attribute :preferred_maintenance_window, :aliases => 'PreferredMaintenanceWindow'
20
+ attribute :state, :aliases => 'Status'
21
+ attribute :vpc_security_groups, :aliases => 'VpcSecurityGroups'
22
+
23
+ attr_accessor :storage_encrypted #not in the response
24
+
25
+ def ready?
26
+ state == "available"
27
+ end
28
+
29
+ def snapshots
30
+ requires :id
31
+ service.cluster_snapshots(:cluster => self)
32
+ end
33
+
34
+ def servers(set=db_cluster_members)
35
+ set.map do |member|
36
+ service.servers.get(member['DBInstanceIdentifier'])
37
+ end
38
+ end
39
+
40
+ def master
41
+ db_cluster_members.detect { |member| member["master"] }
42
+ end
43
+
44
+ def replicas
45
+ servers(db_cluster_members.select { |member| !member["master"] })
46
+ end
47
+
48
+ def has_replica?(replica_name)
49
+ replicas.detect { |replica| replica.id == replica_name }
50
+ end
51
+
52
+ def destroy(snapshot_identifier=nil)
53
+ requires :id
54
+ service.delete_db_cluster(id, snapshot_identifier, snapshot_identifier.nil?)
55
+ true
56
+ end
57
+
58
+ def save
59
+ requires :id
60
+ requires :engine
61
+ requires :master_username
62
+ requires :password
63
+
64
+ data = service.create_db_cluster(id, attributes_to_params)
65
+ merge_attributes(data.body['CreateDBClusterResult']['DBCluster'])
66
+ true
67
+ end
68
+
69
+ def attributes_to_params
70
+ options = {
71
+ 'AllocatedStorage' => allocated_storage,
72
+ 'BackupRetentionPeriod' => backup_retention_period,
73
+ 'DBClusterIdentifier' => identity,
74
+ 'DBClusterParameterGroup' => db_cluster_parameter_group,
75
+ 'DBSubnetGroup' => db_subnet_group,
76
+ 'Endpoint' => endpoint,
77
+ 'Engine' => engine,
78
+ 'EngineVersion' => engine_version,
79
+ 'MasterUserPassword' => password,
80
+ 'MasterUsername' => master_username,
81
+ 'PreferredBackupWindow' => preferred_backup_window,
82
+ 'PreferredMaintenanceWindow' => preferred_maintenance_window,
83
+ 'Status' => state,
84
+ 'StorageEncrypted' => storage_encrypted,
85
+ 'VpcSecurityGroups' => vpc_security_groups,
86
+ }
87
+
88
+ options.delete_if { |key,value| value.nil? }
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,48 @@
1
+ require 'fog/aws/models/rds/snapshot'
2
+
3
+ module Fog
4
+ module AWS
5
+ class RDS
6
+ class ClusterSnapshots < Fog::Collection
7
+ attribute :cluster
8
+ attribute :filters
9
+ model Fog::AWS::RDS::Snapshot
10
+
11
+ def initialize(attributes)
12
+ self.filters ||= {}
13
+ if attributes[:cluster]
14
+ filters[:identifier] = attributes[:cluster].id
15
+ end
16
+
17
+ if attributes[:type]
18
+ filters[:type] = attributes[:type]
19
+ end
20
+ super
21
+ end
22
+
23
+ def all(filters_arg = filters)
24
+ filters.merge!(filters_arg)
25
+
26
+ page = service.describe_db_cluster_snapshots(filters).body['DescribeDBClusterSnapshotsResult']
27
+ filters[:marker] = page['Marker']
28
+ load(page['DBClusterSnapshots'])
29
+ end
30
+
31
+ def get(identity)
32
+ data = service.describe_db_cluster_snapshots(:snapshot_id => identity).body['DescribeDBClusterSnapshotsResult']['DBClusterSnapshots'].first
33
+ new(data) # data is an attribute hash
34
+ rescue Fog::AWS::RDS::NotFound
35
+ nil
36
+ end
37
+
38
+ def create(params={})
39
+ if cluster
40
+ super(params.merge(:cluster_id => cluster.id))
41
+ else
42
+ super(params)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,23 @@
1
+ require 'fog/aws/models/rds/cluster'
2
+
3
+ module Fog
4
+ module AWS
5
+ class RDS
6
+ class Clusters < Fog::Collection
7
+ model Fog::AWS::RDS::Cluster
8
+
9
+ def all
10
+ data = service.describe_db_clusters.body['DescribeDBClustersResult']['DBClusters']
11
+ load(data)
12
+ end
13
+
14
+ def get(identity)
15
+ data = service.describe_db_clusters(identity).body['DescribeDBClustersResult']['DBClusters'].first
16
+ new(data)
17
+ rescue Fog::AWS::RDS::NotFound
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -29,6 +29,21 @@ module Fog
29
29
  end
30
30
  load(result) # data is an array of attribute hashes
31
31
  end
32
+
33
+ def defaults(family)
34
+ page1 = service.describe_engine_default_parameters(family).body['DescribeEngineDefaultParametersResult']
35
+
36
+ marker = page1['Marker']
37
+ parameters = page1['Parameters']
38
+
39
+ until marker.nil?
40
+ body = service.describe_engine_default_parameters(family, 'Marker' => marker).body['DescribeEngineDefaultParametersResult']
41
+ marker = body['Marker']
42
+ parameters += body['Parameters']
43
+ end
44
+
45
+ load(parameters)
46
+ end
32
47
  end
33
48
  end
34
49
  end
@@ -10,6 +10,7 @@ module Fog
10
10
  attribute :backup_retention_period, :aliases => 'BackupRetentionPeriod', :type => :integer
11
11
  attribute :ca_certificate_id, :aliases => 'CACertificateIdentifier'
12
12
  attribute :character_set_name, :aliases => 'CharacterSetName'
13
+ attribute :cluster_id, :aliases => 'DBClusterIdentifier'
13
14
  attribute :created_at, :aliases => 'InstanceCreateTime', :type => :time
14
15
  attribute :db_name, :aliases => 'DBName'
15
16
  attribute :db_parameter_groups, :aliases => 'DBParameterGroups'
@@ -38,7 +39,12 @@ module Fog
38
39
  attribute :tde_credential_arn, :aliases => 'TdeCredentialArn'
39
40
  attribute :vpc_security_groups, :aliases => 'VpcSecurityGroups', :type => :array
40
41
 
41
- attr_accessor :password, :parameter_group_name, :security_group_names, :port
42
+ attr_accessor :password, :parameter_group_name, :security_group_names, :port, :source_snapshot_id
43
+
44
+ def cluster
45
+ return nil unless cluster_id
46
+ service.clusters.get(cluster_id)
47
+ end
42
48
 
43
49
  def create_read_replica(replica_id, options={})
44
50
  options[:security_group_names] ||= options['DBSecurityGroups']
@@ -104,16 +110,27 @@ module Fog
104
110
  end
105
111
 
106
112
  def save
107
- requires :engine
108
- requires :allocated_storage
109
- requires :master_username
110
- requires :password
111
-
112
- self.flavor_id ||= 'db.m1.small'
113
-
114
- data = service.create_db_instance(id, attributes_to_params)
115
- merge_attributes(data.body['CreateDBInstanceResult']['DBInstance'])
116
- true
113
+ if source_snapshot_id
114
+ requires :id
115
+ data = service.restore_db_instance_from_db_snapshot(source_snapshot_id, id, attributes_to_params)
116
+ merge_attributes(data.body['RestoreDBInstanceFromDBSnapshotResult']['DBInstance'])
117
+ else
118
+ requires :engine
119
+
120
+ if engine == 'aurora'
121
+ requires :cluster_id
122
+ self.flavor_id ||= 'db.r3.large'
123
+ else
124
+ requires :master_username
125
+ requires :password
126
+ requires :allocated_storage
127
+ self.flavor_id ||= 'db.m1.small'
128
+ end
129
+
130
+ data = service.create_db_instance(id, attributes_to_params)
131
+ merge_attributes(data.body['CreateDBInstanceResult']['DBInstance'])
132
+ true
133
+ end
117
134
  end
118
135
 
119
136
  # Converts attributes to a parameter hash suitable for requests
@@ -123,6 +140,7 @@ module Fog
123
140
  'AutoMinorVersionUpgrade' => auto_minor_version_upgrade,
124
141
  'AvailabilityZone' => availability_zone,
125
142
  'BackupRetentionPeriod' => backup_retention_period,
143
+ 'DBClusterIdentifier' => cluster_id,
126
144
  'DBInstanceClass' => flavor_id,
127
145
  'DBInstanceIdentifier' => id,
128
146
  'DBName' => db_name,
@@ -17,6 +17,10 @@ module Fog
17
17
  rescue Fog::AWS::RDS::NotFound
18
18
  nil
19
19
  end
20
+
21
+ def restore(options)
22
+ create(options)
23
+ end
20
24
  end
21
25
  end
22
26
  end
@@ -2,20 +2,25 @@ module Fog
2
2
  module AWS
3
3
  class RDS
4
4
  class Snapshot < Fog::Model
5
- identity :id, :aliases => ['DBSnapshotIdentifier', :name]
6
- attribute :instance_id, :aliases => 'DBInstanceIdentifier'
7
- attribute :created_at, :aliases => 'SnapshotCreateTime', :type => :time
8
- attribute :instance_created_at, :aliases => 'InstanceCreateTime', :type => :time
9
- attribute :engine, :aliases => 'Engine'
10
- attribute :engine_version, :aliases => 'EngineVersion'
11
- attribute :master_username, :aliases => 'MasterUsername'
12
- attribute :state, :aliases => 'Status'
13
- attribute :port, :aliases => 'Port', :type => :integer
14
- attribute :allocated_storage, :aliases => 'AllocatedStorage', :type => :integer
15
- attribute :iops, :aliases => 'Iops', :type => :integer
16
- attribute :availability_zone, :aliases => 'AvailabilityZone'
17
- attribute :type, :aliases => 'SnapshotType'
18
- attribute :publicly_accessible, :aliases => 'PubliclyAccessible'
5
+ identity :id, :aliases => ['DBSnapshotIdentifier', 'DBClusterSnapshotIdentifier', :name]
6
+
7
+ attribute :allocated_storage, :aliases => 'AllocatedStorage', :type => :integer
8
+ attribute :availability_zone, :aliases => 'AvailabilityZone'
9
+ attribute :cluster_created_at, :aliases => 'ClusterCreateTime', :type => :time
10
+ attribute :cluster_id, :aliases => 'DBClusterIdentifier'
11
+ attribute :created_at, :aliases => 'SnapshotCreateTime', :type => :time
12
+ attribute :engine, :aliases => 'Engine'
13
+ attribute :engine_version, :aliases => 'EngineVersion'
14
+ attribute :instance_created_at, :aliases => 'InstanceCreateTime', :type => :time
15
+ attribute :instance_id, :aliases => 'DBInstanceIdentifier'
16
+ attribute :iops, :aliases => 'Iops', :type => :integer
17
+ attribute :license_model, :aliases => 'LicenseModel'
18
+ attribute :master_username, :aliases => 'MasterUsername'
19
+ attribute :port, :aliases => 'Port', :type => :integer
20
+ attribute :publicly_accessible, :aliases => 'PubliclyAccessible'
21
+ attribute :state, :aliases => 'Status'
22
+ attribute :storage_type, :aliases => 'StorageType'
23
+ attribute :type, :aliases => 'SnapshotType'
19
24
 
20
25
  def ready?
21
26
  state == 'available'
@@ -23,16 +28,25 @@ module Fog
23
28
 
24
29
  def destroy
25
30
  requires :id
31
+ requires_one :instance_id, :cluster_id
26
32
 
27
- service.delete_db_snapshot(id)
33
+ if instance_id
34
+ service.delete_db_snapshot(id)
35
+ else
36
+ service.delete_db_cluster_snapshot(id)
37
+ end
28
38
  true
29
39
  end
30
40
 
31
41
  def save
32
- requires :instance_id
42
+ requires_one :instance_id, :cluster_id
33
43
  requires :id
34
44
 
35
- data = service.create_db_snapshot(instance_id, id).body['CreateDBSnapshotResult']['DBSnapshot']
45
+ data = if instance_id
46
+ service.create_db_snapshot(instance_id, id).body['CreateDBSnapshotResult']['DBSnapshot']
47
+ elsif cluster_id
48
+ service.create_db_cluster_snapshot(cluster_id, id).body['CreateDBClusterSnapshotResult']['DBClusterSnapshot']
49
+ end
36
50
  merge_attributes(data)
37
51
  true
38
52
  end
@@ -41,6 +55,11 @@ module Fog
41
55
  requires :instance_id
42
56
  service.servers.get(instance_id)
43
57
  end
58
+
59
+ def cluster
60
+ requires :cluster_id
61
+ service.clusters.get(cluster_id)
62
+ end
44
63
  end
45
64
  end
46
65
  end
@@ -0,0 +1,32 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module RDS
5
+ require 'fog/aws/parsers/rds/db_cluster_parser'
6
+
7
+ class CreateDBCluster < Fog::Parsers::AWS::RDS::DbClusterParser
8
+ def reset
9
+ @response = { 'CreateDBClusterResult' => {}, 'ResponseMetadata' => {} }
10
+ super
11
+ end
12
+
13
+ def start_element(name, attrs = [])
14
+ super
15
+ end
16
+
17
+ def end_element(name)
18
+ case name
19
+ when 'DBCluster'
20
+ @response['CreateDBClusterResult']['DBCluster'] = @db_cluster
21
+ @db_cluster = fresh_cluster
22
+ when 'RequestId'
23
+ @response['ResponseMetadata'][name] = value
24
+ else
25
+ super
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end