Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add db_instance collection and instance funcitonality

  • Loading branch information...
commit d02495c16a19e6a895f9e5b38767760744a93b95 1 parent 5a2f11e
Neville Kadwa authored trevorrowe committed
58  lib/aws/api_config/RDS-2012-07-31.yml
@@ -70,6 +70,10 @@
70 70
                 :rename: :db_instances
71 71
                 :list: true
72 72
                 :children:
  73
+                  InstanceCreateTime:
  74
+                    :type: :time
  75
+                  LatestRestorableTime:
  76
+                    :type: :time
73 77
                   DBSubnetGroup:
74 78
                     :children:
75 79
                       Subnets:
@@ -107,6 +111,10 @@
107 111
         :children:
108 112
           DBInstance:
109 113
             :children:
  114
+              InstanceCreateTime:
  115
+                :type: :time
  116
+              LatestRestorableTime:
  117
+                :type: :time
110 118
               DBSubnetGroup:
111 119
                 :children:
112 120
                   Subnets:
@@ -250,6 +258,10 @@
250 258
         :children:
251 259
           DBInstance:
252 260
             :children:
  261
+              InstanceCreateTime:
  262
+                :type: :time
  263
+              LatestRestorableTime:
  264
+                :type: :time
253 265
               DBSubnetGroup:
254 266
                 :children:
255 267
                   Subnets:
@@ -315,6 +327,10 @@
315 327
         :children:
316 328
           DBInstance:
317 329
             :children:
  330
+              InstanceCreateTime:
  331
+                :type: :time
  332
+              LatestRestorableTime:
  333
+                :type: :time
318 334
               DBSubnetGroup:
319 335
                 :children:
320 336
                   Subnets:
@@ -350,6 +366,10 @@
350 366
         :children:
351 367
           DBInstance:
352 368
             :children:
  369
+              InstanceCreateTime:
  370
+                :type: :time
  371
+              LatestRestorableTime:
  372
+                :type: :time
353 373
               DBSubnetGroup:
354 374
                 :children:
355 375
                   Subnets:
@@ -466,6 +486,10 @@
466 486
         :children:
467 487
           DBInstance:
468 488
             :children:
  489
+              InstanceCreateTime:
  490
+                :type: :time
  491
+              LatestRestorableTime:
  492
+                :type: :time
469 493
               DBSubnetGroup:
470 494
                 :children:
471 495
                   Subnets:
@@ -527,4 +551,36 @@
527 551
           Value:
528 552
           - :string
529 553
           - :required
530  
-  :outputs: {}
  554
+  :outputs: {}
  555
+- :name: DescribeReservedDBInstances
  556
+  :method: :describe_reserved_db_instances
  557
+  :inputs:
  558
+    DBInstanceClass:
  559
+    - :string
  560
+    Duration:
  561
+    - :string
  562
+    Marker:
  563
+    - :string
  564
+    MaxRecords:
  565
+    - :integer
  566
+    MultiAZ:
  567
+    - :string
  568
+    OfferingType:
  569
+    - :string
  570
+    ProductDescription:
  571
+    - :string
  572
+    ReservedDBInstanceId:
  573
+    - :string
  574
+    ReservedDBInstancesOfferingId:
  575
+    - :string
  576
+  :outputs:
  577
+    :children:
  578
+      DescribeReservedDBInstancesResult:
  579
+        :ignore: true
  580
+        :children:
  581
+          ReservedDBInstances:
  582
+            :ignore: true
  583
+            :children:
  584
+              ReservedDBInstance:
  585
+                :rename: :reserved_db_instances
  586
+                :list: true
9  lib/aws/rds.rb
@@ -22,8 +22,8 @@ class RDS
22 22
     AWS.register_autoloads(self) do
23 23
       autoload :Client, 'client'
24 24
       autoload :Errors, 'errors'
25  
-      #autoload :InstanceGroup, 'instance_group'
26  
-      #autoload :InstanceGroupCollection, 'instance_group_collection'
  25
+      autoload :DBInstance, 'db_instance'
  26
+      autoload :DBInstanceCollection, 'db_instance_collection'
27 27
       #autoload :JobFlow, 'job_flow'
28 28
       #autoload :JobFlowCollection, 'job_flow_collection'
29 29
       autoload :Request, 'request'
@@ -31,5 +31,10 @@ class RDS
31 31
 
32 32
     include Core::ServiceInterface
33 33
 
  34
+    def db_instances
  35
+      DBInstanceCollection.new(:config => config)
  36
+    end
  37
+    alias_method :instances, :db_instances
  38
+
34 39
   end
35 40
 end
77  lib/aws/rds/db_instance.rb
... ...
@@ -0,0 +1,77 @@
  1
+module AWS
  2
+  class RDS
  3
+    class DBInstance < Core::Resource
  4
+
  5
+      # @param [String] job_flow_id
  6
+      # @param [Hash] options
  7
+      # @private
  8
+      def initialize db_instance_id, options = {}
  9
+        @db_instance_identifier = db_instance_id
  10
+        super
  11
+      end
  12
+
  13
+      attr_reader :db_instance_identifier
  14
+
  15
+      alias_method :id, :db_instance_identifier
  16
+
  17
+      attribute :allocated_storage, :static => true
  18
+      alias_method :size, :allocated_storage
  19
+
  20
+      attribute :availability_zone, :static => true
  21
+      attribute :backup_retention_period, :static => true
  22
+      attribute :character_set_name, :static => true
  23
+      attribute :db_instance_class, :static => true
  24
+      attribute :db_name, :static => true
  25
+      attribute :engine, :static => true
  26
+      attribute :engine_version, :static => true
  27
+      attribute :master_username, :static => true
  28
+      attribute :multi_az, :static => true
  29
+      attribute :preferred_backup_window, :static => true
  30
+      attribute :preferred_maintenance_window, :static => true
  31
+      attribute :read_replica_db_instance_identifiers, :static => true
  32
+      attribute :read_replica_source_db_instance_identifier, :static => true
  33
+
  34
+      attribute :db_instance_status
  35
+      alias_method :status, :db_instance_status
  36
+
  37
+      attribute :endpoint_address,
  38
+                :from => [:endpoint, :address], :static => true
  39
+      attribute :endpoint_port,
  40
+                :from => [:endpoint, :port], :static => true
  41
+
  42
+      attribute :creation_date_time,
  43
+                :from => [:instance_create_time],
  44
+                :static => true,
  45
+                :alias => :created_at
  46
+
  47
+      attribute :latest_restorable_time
  48
+
  49
+      populates_from(:describe_db_instances) do |resp|
  50
+        resp.data[:db_instances].find{|j| j[:db_instance_identifier] == db_instance_identifier }
  51
+      end
  52
+
  53
+      def reboot options={}
  54
+        options[:db_instance_identifier] = db_instance_identifier
  55
+        client.reboot_db_instance(options)
  56
+        nil
  57
+      end
  58
+
  59
+      def delete options={}
  60
+        options[:db_instance_identifier] = db_instance_identifier
  61
+        client.delete_db_instance(options)
  62
+        nil
  63
+      end
  64
+
  65
+      protected
  66
+
  67
+      def resource_identifiers
  68
+        [[:db_instance_identifier, id]]
  69
+      end
  70
+
  71
+      def get_resource attr = nil
  72
+        client.describe_db_instances(:db_instance_identifier => db_instance_identifier)
  73
+      end
  74
+
  75
+    end
  76
+  end
  77
+end
53  lib/aws/rds/db_instance_collection.rb
... ...
@@ -0,0 +1,53 @@
  1
+require 'date'
  2
+require 'time'
  3
+
  4
+module AWS
  5
+  class RDS
  6
+    class DBInstanceCollection
  7
+
  8
+      include Core::Collection::WithLimitAndNextToken
  9
+
  10
+      # @private
  11
+      def initialize options = {}
  12
+        @filters = options[:filters] || {}
  13
+        super
  14
+      end
  15
+
  16
+      # @param [String] db_instance_id
  17
+      # @return [DBInstance] Returns a {DBInstance} with the given ID.
  18
+      def [] db_instance_id
  19
+        DBInstance.new(db_instance_id, :config => config)
  20
+      end
  21
+
  22
+      def create options = {}
  23
+        response = client.create_db_instance(options)
  24
+
  25
+        self[response.data[:db_instance][:db_instance_identifier]]
  26
+      end
  27
+
  28
+      protected
  29
+
  30
+      def _each_item marker, max_items, options = {}, &block
  31
+
  32
+        options[:marker] = marker if marker
  33
+        options[:max_items] = max_items if max_items
  34
+
  35
+        response = client.describe_db_instances(@filters.merge(options))
  36
+        response.data[:db_instances].each do |details|
  37
+
  38
+          db_instance = DBInstance.new_from(
  39
+              :describe_db_instances,
  40
+              details,
  41
+              details[:db_instance_identifier],
  42
+              :config => config)
  43
+
  44
+          yield(db_instance)
  45
+
  46
+        end
  47
+
  48
+        response.data[:marker]
  49
+      end
  50
+
  51
+    end
  52
+  end
  53
+end

0 notes on commit d02495c

Please sign in to comment.
Something went wrong with that request. Please try again.