PageRenderTime 89ms CodeModel.GetById 11ms app.highlight 61ms RepoModel.GetById 3ms app.codeStats 1ms

/boto-2.5.2/boto/rds/__init__.py

#
Python | 1019 lines | 737 code | 20 blank | 262 comment | 40 complexity | db968f3407b7177dacf6e4eae95f4959 MD5 | raw file
   1# Copyright (c) 2009 Mitch Garnaat http://garnaat.org/
   2#
   3# Permission is hereby granted, free of charge, to any person obtaining a
   4# copy of this software and associated documentation files (the
   5# "Software"), to deal in the Software without restriction, including
   6# without limitation the rights to use, copy, modify, merge, publish, dis-
   7# tribute, sublicense, and/or sell copies of the Software, and to permit
   8# persons to whom the Software is furnished to do so, subject to the fol-
   9# lowing conditions:
  10#
  11# The above copyright notice and this permission notice shall be included
  12# in all copies or substantial portions of the Software.
  13#
  14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  16# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  17# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20# IN THE SOFTWARE.
  21#
  22
  23import boto.utils
  24import urllib
  25from boto.connection import AWSQueryConnection
  26from boto.rds.dbinstance import DBInstance
  27from boto.rds.dbsecuritygroup import DBSecurityGroup
  28from boto.rds.parametergroup import ParameterGroup
  29from boto.rds.dbsnapshot import DBSnapshot
  30from boto.rds.event import Event
  31from boto.rds.regioninfo import RDSRegionInfo
  32
  33
  34def regions():
  35    """
  36    Get all available regions for the RDS service.
  37
  38    :rtype: list
  39    :return: A list of :class:`boto.rds.regioninfo.RDSRegionInfo`
  40    """
  41    return [RDSRegionInfo(name='us-east-1',
  42                          endpoint='rds.us-east-1.amazonaws.com'),
  43            RDSRegionInfo(name='eu-west-1',
  44                          endpoint='rds.eu-west-1.amazonaws.com'),
  45            RDSRegionInfo(name='us-west-1',
  46                          endpoint='rds.us-west-1.amazonaws.com'),
  47            RDSRegionInfo(name='us-west-2',
  48                          endpoint='rds.us-west-2.amazonaws.com'),
  49            RDSRegionInfo(name='sa-east-1',
  50                          endpoint='rds.sa-east-1.amazonaws.com'),
  51            RDSRegionInfo(name='ap-northeast-1',
  52                          endpoint='rds.ap-northeast-1.amazonaws.com'),
  53            RDSRegionInfo(name='ap-southeast-1',
  54                          endpoint='rds.ap-southeast-1.amazonaws.com')
  55            ]
  56
  57
  58def connect_to_region(region_name, **kw_params):
  59    """
  60    Given a valid region name, return a
  61    :class:`boto.ec2.connection.EC2Connection`.
  62    Any additional parameters after the region_name are passed on to
  63    the connect method of the region object.
  64
  65    :type: str
  66    :param region_name: The name of the region to connect to.
  67
  68    :rtype: :class:`boto.ec2.connection.EC2Connection` or ``None``
  69    :return: A connection to the given region, or None if an invalid region
  70             name is given
  71    """
  72    for region in regions():
  73        if region.name == region_name:
  74            return region.connect(**kw_params)
  75    return None
  76
  77#boto.set_stream_logger('rds')
  78
  79
  80class RDSConnection(AWSQueryConnection):
  81
  82    DefaultRegionName = 'us-east-1'
  83    DefaultRegionEndpoint = 'rds.us-east-1.amazonaws.com'
  84    APIVersion = '2011-04-01'
  85
  86    def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
  87                 is_secure=True, port=None, proxy=None, proxy_port=None,
  88                 proxy_user=None, proxy_pass=None, debug=0,
  89                 https_connection_factory=None, region=None, path='/',
  90                 security_token=None):
  91        if not region:
  92            region = RDSRegionInfo(self, self.DefaultRegionName,
  93                                   self.DefaultRegionEndpoint)
  94        self.region = region
  95        AWSQueryConnection.__init__(self, aws_access_key_id,
  96                                    aws_secret_access_key,
  97                                    is_secure, port, proxy, proxy_port,
  98                                    proxy_user, proxy_pass,
  99                                    self.region.endpoint, debug,
 100                                    https_connection_factory, path,
 101                                    security_token)
 102
 103    def _required_auth_capability(self):
 104        return ['rds']
 105
 106    # DB Instance methods
 107
 108    def get_all_dbinstances(self, instance_id=None, max_records=None,
 109                            marker=None):
 110        """
 111        Retrieve all the DBInstances in your account.
 112
 113        :type instance_id: str
 114        :param instance_id: DB Instance identifier.  If supplied, only
 115                            information this instance will be returned.
 116                            Otherwise, info about all DB Instances will
 117                            be returned.
 118
 119        :type max_records: int
 120        :param max_records: The maximum number of records to be returned.
 121                            If more results are available, a MoreToken will
 122                            be returned in the response that can be used to
 123                            retrieve additional records.  Default is 100.
 124
 125        :type marker: str
 126        :param marker: The marker provided by a previous request.
 127
 128        :rtype: list
 129        :return: A list of :class:`boto.rds.dbinstance.DBInstance`
 130        """
 131        params = {}
 132        if instance_id:
 133            params['DBInstanceIdentifier'] = instance_id
 134        if max_records:
 135            params['MaxRecords'] = max_records
 136        if marker:
 137            params['Marker'] = marker
 138        return self.get_list('DescribeDBInstances', params,
 139                             [('DBInstance', DBInstance)])
 140
 141    def create_dbinstance(self, id, allocated_storage, instance_class,
 142                          master_username, master_password, port=3306,
 143                          engine='MySQL5.1', db_name=None, param_group=None,
 144                          security_groups=None, availability_zone=None,
 145                          preferred_maintenance_window=None,
 146                          backup_retention_period=None,
 147                          preferred_backup_window=None,
 148                          multi_az=False,
 149                          engine_version=None,
 150                          auto_minor_version_upgrade=True):
 151        """
 152        Create a new DBInstance.
 153
 154        :type id: str
 155        :param id: Unique identifier for the new instance.
 156                   Must contain 1-63 alphanumeric characters.
 157                   First character must be a letter.
 158                   May not end with a hyphen or contain two consecutive hyphens
 159
 160        :type allocated_storage: int
 161        :param allocated_storage: Initially allocated storage size, in GBs.
 162                                  Valid values are [5-1024]
 163
 164        :type instance_class: str
 165        :param instance_class: The compute and memory capacity of
 166                               the DBInstance. Valid values are:
 167
 168                               * db.m1.small
 169                               * db.m1.large
 170                               * db.m1.xlarge
 171                               * db.m2.xlarge
 172                               * db.m2.2xlarge
 173                               * db.m2.4xlarge
 174
 175        :type engine: str
 176        :param engine: Name of database engine. Must be MySQL5.1 for now.
 177
 178        :type master_username: str
 179        :param master_username: Name of master user for the DBInstance.
 180                                Must be 1-15 alphanumeric characters, first
 181                                must be a letter.
 182
 183        :type master_password: str
 184        :param master_password: Password of master user for the DBInstance.
 185                                Must be 4-16 alphanumeric characters.
 186
 187        :type port: int
 188        :param port: Port number on which database accepts connections.
 189                     Valid values [1115-65535].  Defaults to 3306.
 190
 191        :type db_name: str
 192        :param db_name: Name of a database to create when the DBInstance
 193                        is created.  Default is to create no databases.
 194
 195        :type param_group: str
 196        :param param_group: Name of DBParameterGroup to associate with
 197                            this DBInstance.  If no groups are specified
 198                            no parameter groups will be used.
 199
 200        :type security_groups: list of str or list of DBSecurityGroup objects
 201        :param security_groups: List of names of DBSecurityGroup to
 202            authorize on this DBInstance.
 203
 204        :type availability_zone: str
 205        :param availability_zone: Name of the availability zone to place
 206                                  DBInstance into.
 207
 208        :type preferred_maintenance_window: str
 209        :param preferred_maintenance_window: The weekly time range (in UTC)
 210                                             during which maintenance can occur.
 211                                             Default is Sun:05:00-Sun:09:00
 212
 213        :type backup_retention_period: int
 214        :param backup_retention_period: The number of days for which automated
 215                                        backups are retained.  Setting this to
 216                                        zero disables automated backups.
 217
 218        :type preferred_backup_window: str
 219        :param preferred_backup_window: The daily time range during which
 220                                        automated backups are created (if
 221                                        enabled).  Must be in h24:mi-hh24:mi
 222                                        format (UTC).
 223
 224        :type multi_az: bool
 225        :param multi_az: If True, specifies the DB Instance will be
 226                         deployed in multiple availability zones.
 227
 228        :type engine_version: str
 229        :param engine_version: Version number of the database engine to use.
 230
 231        :type auto_minor_version_upgrade: bool
 232        :param auto_minor_version_upgrade: Indicates that minor engine
 233                                           upgrades will be applied
 234                                           automatically to the Read Replica
 235                                           during the maintenance window.
 236                                           Default is True.
 237
 238        :rtype: :class:`boto.rds.dbinstance.DBInstance`
 239        :return: The new db instance.
 240        """
 241        params = {'DBInstanceIdentifier': id,
 242                  'AllocatedStorage': allocated_storage,
 243                  'DBInstanceClass': instance_class,
 244                  'Engine': engine,
 245                  'MasterUsername': master_username,
 246                  'MasterUserPassword': master_password,
 247                  'Port': port,
 248                  'MultiAZ': str(multi_az).lower(),
 249                  'AutoMinorVersionUpgrade':
 250                      str(auto_minor_version_upgrade).lower()}
 251        if db_name:
 252            params['DBName'] = db_name
 253        if param_group:
 254            params['DBParameterGroupName'] = param_group
 255        if security_groups:
 256            l = []
 257            for group in security_groups:
 258                if isinstance(group, DBSecurityGroup):
 259                    l.append(group.name)
 260                else:
 261                    l.append(group)
 262            self.build_list_params(params, l, 'DBSecurityGroups.member')
 263        if availability_zone:
 264            params['AvailabilityZone'] = availability_zone
 265        if preferred_maintenance_window:
 266            params['PreferredMaintenanceWindow'] = preferred_maintenance_window
 267        if backup_retention_period is not None:
 268            params['BackupRetentionPeriod'] = backup_retention_period
 269        if preferred_backup_window:
 270            params['PreferredBackupWindow'] = preferred_backup_window
 271        if engine_version:
 272            params['EngineVersion'] = engine_version
 273
 274        return self.get_object('CreateDBInstance', params, DBInstance)
 275
 276    def create_dbinstance_read_replica(self, id, source_id,
 277                                       instance_class=None,
 278                                       port=3306,
 279                                       availability_zone=None,
 280                                       auto_minor_version_upgrade=None):
 281        """
 282        Create a new DBInstance Read Replica.
 283
 284        :type id: str
 285        :param id: Unique identifier for the new instance.
 286                   Must contain 1-63 alphanumeric characters.
 287                   First character must be a letter.
 288                   May not end with a hyphen or contain two consecutive hyphens
 289
 290        :type source_id: str
 291        :param source_id: Unique identifier for the DB Instance for which this
 292                          DB Instance will act as a Read Replica.
 293
 294        :type instance_class: str
 295        :param instance_class: The compute and memory capacity of the
 296                               DBInstance.  Default is to inherit from
 297                               the source DB Instance.
 298
 299                               Valid values are:
 300
 301                               * db.m1.small
 302                               * db.m1.large
 303                               * db.m1.xlarge
 304                               * db.m2.xlarge
 305                               * db.m2.2xlarge
 306                               * db.m2.4xlarge
 307
 308        :type port: int
 309        :param port: Port number on which database accepts connections.
 310                     Default is to inherit from source DB Instance.
 311                     Valid values [1115-65535].  Defaults to 3306.
 312
 313        :type availability_zone: str
 314        :param availability_zone: Name of the availability zone to place
 315                                  DBInstance into.
 316
 317        :type auto_minor_version_upgrade: bool
 318        :param auto_minor_version_upgrade: Indicates that minor engine
 319                                           upgrades will be applied
 320                                           automatically to the Read Replica
 321                                           during the maintenance window.
 322                                           Default is to inherit this value
 323                                           from the source DB Instance.
 324
 325        :rtype: :class:`boto.rds.dbinstance.DBInstance`
 326        :return: The new db instance.
 327        """
 328        params = {'DBInstanceIdentifier': id,
 329                  'SourceDBInstanceIdentifier': source_id}
 330        if instance_class:
 331            params['DBInstanceClass'] = instance_class
 332        if port:
 333            params['Port'] = port
 334        if availability_zone:
 335            params['AvailabilityZone'] = availability_zone
 336        if auto_minor_version_upgrade is not None:
 337            if auto_minor_version_upgrade is True:
 338                params['AutoMinorVersionUpgrade'] = 'true'
 339            else:
 340                params['AutoMinorVersionUpgrade'] = 'false'
 341
 342        return self.get_object('CreateDBInstanceReadReplica',
 343                               params, DBInstance)
 344
 345    def modify_dbinstance(self, id, param_group=None, security_groups=None,
 346                          preferred_maintenance_window=None,
 347                          master_password=None, allocated_storage=None,
 348                          instance_class=None,
 349                          backup_retention_period=None,
 350                          preferred_backup_window=None,
 351                          multi_az=False,
 352                          apply_immediately=False):
 353        """
 354        Modify an existing DBInstance.
 355
 356        :type id: str
 357        :param id: Unique identifier for the new instance.
 358
 359        :type security_groups: list of str or list of DBSecurityGroup objects
 360        :param security_groups: List of names of DBSecurityGroup to authorize on
 361                                this DBInstance.
 362
 363        :type preferred_maintenance_window: str
 364        :param preferred_maintenance_window: The weekly time range (in UTC)
 365                                             during which maintenance can
 366                                             occur.
 367                                             Default is Sun:05:00-Sun:09:00
 368
 369        :type master_password: str
 370        :param master_password: Password of master user for the DBInstance.
 371                                Must be 4-15 alphanumeric characters.
 372
 373        :type allocated_storage: int
 374        :param allocated_storage: The new allocated storage size, in GBs.
 375                                  Valid values are [5-1024]
 376
 377        :type instance_class: str
 378        :param instance_class: The compute and memory capacity of the
 379                               DBInstance.  Changes will be applied at
 380                               next maintenance window unless
 381                               apply_immediately is True.
 382
 383                               Valid values are:
 384
 385                               * db.m1.small
 386                               * db.m1.large
 387                               * db.m1.xlarge
 388                               * db.m2.xlarge
 389                               * db.m2.2xlarge
 390                               * db.m2.4xlarge
 391
 392        :type apply_immediately: bool
 393        :param apply_immediately: If true, the modifications will be applied
 394                                  as soon as possible rather than waiting for
 395                                  the next preferred maintenance window.
 396
 397        :type backup_retention_period: int
 398        :param backup_retention_period: The number of days for which automated
 399                                        backups are retained.  Setting this to
 400                                        zero disables automated backups.
 401
 402        :type preferred_backup_window: str
 403        :param preferred_backup_window: The daily time range during which
 404                                        automated backups are created (if
 405                                        enabled).  Must be in h24:mi-hh24:mi
 406                                        format (UTC).
 407
 408        :type multi_az: bool
 409        :param multi_az: If True, specifies the DB Instance will be
 410                         deployed in multiple availability zones.
 411
 412        :rtype: :class:`boto.rds.dbinstance.DBInstance`
 413        :return: The modified db instance.
 414        """
 415        params = {'DBInstanceIdentifier': id}
 416        if param_group:
 417            params['DBParameterGroupName'] = param_group
 418        if security_groups:
 419            l = []
 420            for group in security_groups:
 421                if isinstance(group, DBSecurityGroup):
 422                    l.append(group.name)
 423                else:
 424                    l.append(group)
 425            self.build_list_params(params, l, 'DBSecurityGroups.member')
 426        if preferred_maintenance_window:
 427            params['PreferredMaintenanceWindow'] = preferred_maintenance_window
 428        if master_password:
 429            params['MasterUserPassword'] = master_password
 430        if allocated_storage:
 431            params['AllocatedStorage'] = allocated_storage
 432        if instance_class:
 433            params['DBInstanceClass'] = instance_class
 434        if backup_retention_period is not None:
 435            params['BackupRetentionPeriod'] = backup_retention_period
 436        if preferred_backup_window:
 437            params['PreferredBackupWindow'] = preferred_backup_window
 438        if multi_az:
 439            params['MultiAZ'] = 'true'
 440        if apply_immediately:
 441            params['ApplyImmediately'] = 'true'
 442
 443        return self.get_object('ModifyDBInstance', params, DBInstance)
 444
 445    def delete_dbinstance(self, id, skip_final_snapshot=False,
 446                          final_snapshot_id=''):
 447        """
 448        Delete an existing DBInstance.
 449
 450        :type id: str
 451        :param id: Unique identifier for the new instance.
 452
 453        :type skip_final_snapshot: bool
 454        :param skip_final_snapshot: This parameter determines whether a final
 455                                    db snapshot is created before the instance
 456                                    is deleted.  If True, no snapshot
 457                                    is created.  If False, a snapshot
 458                                    is created before deleting the instance.
 459
 460        :type final_snapshot_id: str
 461        :param final_snapshot_id: If a final snapshot is requested, this
 462                                  is the identifier used for that snapshot.
 463
 464        :rtype: :class:`boto.rds.dbinstance.DBInstance`
 465        :return: The deleted db instance.
 466        """
 467        params = {'DBInstanceIdentifier': id}
 468        if skip_final_snapshot:
 469            params['SkipFinalSnapshot'] = 'true'
 470        else:
 471            params['SkipFinalSnapshot'] = 'false'
 472            params['FinalDBSnapshotIdentifier'] = final_snapshot_id
 473        return self.get_object('DeleteDBInstance', params, DBInstance)
 474
 475    def reboot_dbinstance(self, id):
 476        """
 477        Reboot DBInstance.
 478
 479        :type id: str
 480        :param id: Unique identifier of the instance.
 481
 482        :rtype: :class:`boto.rds.dbinstance.DBInstance`
 483        :return: The rebooting db instance.
 484        """
 485        params = {'DBInstanceIdentifier': id}
 486        return self.get_object('RebootDBInstance', params, DBInstance)
 487
 488    # DBParameterGroup methods
 489
 490    def get_all_dbparameter_groups(self, groupname=None, max_records=None,
 491                                  marker=None):
 492        """
 493        Get all parameter groups associated with your account in a region.
 494
 495        :type groupname: str
 496        :param groupname: The name of the DBParameter group to retrieve.
 497                          If not provided, all DBParameter groups will be returned.
 498
 499        :type max_records: int
 500        :param max_records: The maximum number of records to be returned.
 501                            If more results are available, a MoreToken will
 502                            be returned in the response that can be used to
 503                            retrieve additional records.  Default is 100.
 504
 505        :type marker: str
 506        :param marker: The marker provided by a previous request.
 507
 508        :rtype: list
 509        :return: A list of :class:`boto.ec2.parametergroup.ParameterGroup`
 510        """
 511        params = {}
 512        if groupname:
 513            params['DBParameterGroupName'] = groupname
 514        if max_records:
 515            params['MaxRecords'] = max_records
 516        if marker:
 517            params['Marker'] = marker
 518        return self.get_list('DescribeDBParameterGroups', params,
 519                             [('DBParameterGroup', ParameterGroup)])
 520
 521    def get_all_dbparameters(self, groupname, source=None,
 522                             max_records=None, marker=None):
 523        """
 524        Get all parameters associated with a ParameterGroup
 525
 526        :type groupname: str
 527        :param groupname: The name of the DBParameter group to retrieve.
 528
 529        :type source: str
 530        :param source: Specifies which parameters to return.
 531                       If not specified, all parameters will be returned.
 532                       Valid values are: user|system|engine-default
 533
 534        :type max_records: int
 535        :param max_records: The maximum number of records to be returned.
 536                            If more results are available, a MoreToken will
 537                            be returned in the response that can be used to
 538                            retrieve additional records.  Default is 100.
 539
 540        :type marker: str
 541        :param marker: The marker provided by a previous request.
 542
 543        :rtype: :class:`boto.ec2.parametergroup.ParameterGroup`
 544        :return: The ParameterGroup
 545        """
 546        params = {'DBParameterGroupName': groupname}
 547        if source:
 548            params['Source'] = source
 549        if max_records:
 550            params['MaxRecords'] = max_records
 551        if marker:
 552            params['Marker'] = marker
 553        pg = self.get_object('DescribeDBParameters', params, ParameterGroup)
 554        pg.name = groupname
 555        return pg
 556
 557    def create_parameter_group(self, name, engine='MySQL5.1', description=''):
 558        """
 559        Create a new dbparameter group for your account.
 560
 561        :type name: string
 562        :param name: The name of the new dbparameter group
 563
 564        :type engine: str
 565        :param engine: Name of database engine.
 566
 567        :type description: string
 568        :param description: The description of the new security group
 569
 570        :rtype: :class:`boto.rds.dbsecuritygroup.DBSecurityGroup`
 571        :return: The newly created DBSecurityGroup
 572        """
 573        params = {'DBParameterGroupName': name,
 574                  'DBParameterGroupFamily': engine,
 575                  'Description': description}
 576        return self.get_object('CreateDBParameterGroup', params, ParameterGroup)
 577
 578    def modify_parameter_group(self, name, parameters=None):
 579        """
 580        Modify a parameter group for your account.
 581
 582        :type name: string
 583        :param name: The name of the new parameter group
 584
 585        :type parameters: list of :class:`boto.rds.parametergroup.Parameter`
 586        :param parameters: The new parameters
 587
 588        :rtype: :class:`boto.rds.parametergroup.ParameterGroup`
 589        :return: The newly created ParameterGroup
 590        """
 591        params = {'DBParameterGroupName': name}
 592        for i in range(0, len(parameters)):
 593            parameter = parameters[i]
 594            parameter.merge(params, i+1)
 595        return self.get_list('ModifyDBParameterGroup', params,
 596                             ParameterGroup, verb='POST')
 597
 598    def reset_parameter_group(self, name, reset_all_params=False,
 599                              parameters=None):
 600        """
 601        Resets some or all of the parameters of a ParameterGroup to the
 602        default value
 603
 604        :type key_name: string
 605        :param key_name: The name of the ParameterGroup to reset
 606
 607        :type parameters: list of :class:`boto.rds.parametergroup.Parameter`
 608        :param parameters: The parameters to reset.  If not supplied,
 609                           all parameters will be reset.
 610        """
 611        params = {'DBParameterGroupName': name}
 612        if reset_all_params:
 613            params['ResetAllParameters'] = 'true'
 614        else:
 615            params['ResetAllParameters'] = 'false'
 616            for i in range(0, len(parameters)):
 617                parameter = parameters[i]
 618                parameter.merge(params, i+1)
 619        return self.get_status('ResetDBParameterGroup', params)
 620
 621    def delete_parameter_group(self, name):
 622        """
 623        Delete a DBSecurityGroup from your account.
 624
 625        :type key_name: string
 626        :param key_name: The name of the DBSecurityGroup to delete
 627        """
 628        params = {'DBParameterGroupName': name}
 629        return self.get_status('DeleteDBParameterGroup', params)
 630
 631    # DBSecurityGroup methods
 632
 633    def get_all_dbsecurity_groups(self, groupname=None, max_records=None,
 634                                  marker=None):
 635        """
 636        Get all security groups associated with your account in a region.
 637
 638        :type groupnames: list
 639        :param groupnames: A list of the names of security groups to retrieve.
 640                           If not provided, all security groups will
 641                           be returned.
 642
 643        :type max_records: int
 644        :param max_records: The maximum number of records to be returned.
 645                            If more results are available, a MoreToken will
 646                            be returned in the response that can be used to
 647                            retrieve additional records.  Default is 100.
 648
 649        :type marker: str
 650        :param marker: The marker provided by a previous request.
 651
 652        :rtype: list
 653        :return: A list of :class:`boto.rds.dbsecuritygroup.DBSecurityGroup`
 654        """
 655        params = {}
 656        if groupname:
 657            params['DBSecurityGroupName'] = groupname
 658        if max_records:
 659            params['MaxRecords'] = max_records
 660        if marker:
 661            params['Marker'] = marker
 662        return self.get_list('DescribeDBSecurityGroups', params,
 663                             [('DBSecurityGroup', DBSecurityGroup)])
 664
 665    def create_dbsecurity_group(self, name, description=None):
 666        """
 667        Create a new security group for your account.
 668        This will create the security group within the region you
 669        are currently connected to.
 670
 671        :type name: string
 672        :param name: The name of the new security group
 673
 674        :type description: string
 675        :param description: The description of the new security group
 676
 677        :rtype: :class:`boto.rds.dbsecuritygroup.DBSecurityGroup`
 678        :return: The newly created DBSecurityGroup
 679        """
 680        params = {'DBSecurityGroupName': name}
 681        if description:
 682            params['DBSecurityGroupDescription'] = description
 683        group = self.get_object('CreateDBSecurityGroup', params,
 684                                DBSecurityGroup)
 685        group.name = name
 686        group.description = description
 687        return group
 688
 689    def delete_dbsecurity_group(self, name):
 690        """
 691        Delete a DBSecurityGroup from your account.
 692
 693        :type key_name: string
 694        :param key_name: The name of the DBSecurityGroup to delete
 695        """
 696        params = {'DBSecurityGroupName': name}
 697        return self.get_status('DeleteDBSecurityGroup', params)
 698
 699    def authorize_dbsecurity_group(self, group_name, cidr_ip=None,
 700                                   ec2_security_group_name=None,
 701                                   ec2_security_group_owner_id=None):
 702        """
 703        Add a new rule to an existing security group.
 704        You need to pass in either src_security_group_name and
 705        src_security_group_owner_id OR a CIDR block but not both.
 706
 707        :type group_name: string
 708        :param group_name: The name of the security group you are adding
 709                           the rule to.
 710
 711        :type ec2_security_group_name: string
 712        :param ec2_security_group_name: The name of the EC2 security group
 713                                        you are granting access to.
 714
 715        :type ec2_security_group_owner_id: string
 716        :param ec2_security_group_owner_id: The ID of the owner of the EC2
 717                                            security group you are granting
 718                                            access to.
 719
 720        :type cidr_ip: string
 721        :param cidr_ip: The CIDR block you are providing access to.
 722                        See http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
 723
 724        :rtype: bool
 725        :return: True if successful.
 726        """
 727        params = {'DBSecurityGroupName': group_name}
 728        if ec2_security_group_name:
 729            params['EC2SecurityGroupName'] = ec2_security_group_name
 730        if ec2_security_group_owner_id:
 731            params['EC2SecurityGroupOwnerId'] = ec2_security_group_owner_id
 732        if cidr_ip:
 733            params['CIDRIP'] = urllib.quote(cidr_ip)
 734        return self.get_object('AuthorizeDBSecurityGroupIngress', params,
 735                               DBSecurityGroup)
 736
 737    def revoke_dbsecurity_group(self, group_name, ec2_security_group_name=None,
 738                                ec2_security_group_owner_id=None, cidr_ip=None):
 739        """
 740        Remove an existing rule from an existing security group.
 741        You need to pass in either ec2_security_group_name and
 742        ec2_security_group_owner_id OR a CIDR block.
 743
 744        :type group_name: string
 745        :param group_name: The name of the security group you are removing
 746                           the rule from.
 747
 748        :type ec2_security_group_name: string
 749        :param ec2_security_group_name: The name of the EC2 security group
 750                                        from which you are removing access.
 751
 752        :type ec2_security_group_owner_id: string
 753        :param ec2_security_group_owner_id: The ID of the owner of the EC2
 754                                            security from which you are
 755                                            removing access.
 756
 757        :type cidr_ip: string
 758        :param cidr_ip: The CIDR block from which you are removing access.
 759                        See http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
 760
 761        :rtype: bool
 762        :return: True if successful.
 763        """
 764        params = {'DBSecurityGroupName': group_name}
 765        if ec2_security_group_name:
 766            params['EC2SecurityGroupName'] = ec2_security_group_name
 767        if ec2_security_group_owner_id:
 768            params['EC2SecurityGroupOwnerId'] = ec2_security_group_owner_id
 769        if cidr_ip:
 770            params['CIDRIP'] = cidr_ip
 771        return self.get_object('RevokeDBSecurityGroupIngress', params,
 772                               DBSecurityGroup)
 773
 774    # For backwards compatibility.  This method was improperly named
 775    # in previous versions.  I have renamed it to match the others.
 776    revoke_security_group = revoke_dbsecurity_group
 777
 778    # DBSnapshot methods
 779
 780    def get_all_dbsnapshots(self, snapshot_id=None, instance_id=None,
 781                            max_records=None, marker=None):
 782        """
 783        Get information about DB Snapshots.
 784
 785        :type snapshot_id: str
 786        :param snapshot_id: The unique identifier of an RDS snapshot.
 787                            If not provided, all RDS snapshots will be returned.
 788
 789        :type instance_id: str
 790        :param instance_id: The identifier of a DBInstance.  If provided,
 791                            only the DBSnapshots related to that instance will
 792                            be returned.
 793                            If not provided, all RDS snapshots will be returned.
 794
 795        :type max_records: int
 796        :param max_records: The maximum number of records to be returned.
 797                            If more results are available, a MoreToken will
 798                            be returned in the response that can be used to
 799                            retrieve additional records.  Default is 100.
 800
 801        :type marker: str
 802        :param marker: The marker provided by a previous request.
 803
 804        :rtype: list
 805        :return: A list of :class:`boto.rds.dbsnapshot.DBSnapshot`
 806        """
 807        params = {}
 808        if snapshot_id:
 809            params['DBSnapshotIdentifier'] = snapshot_id
 810        if instance_id:
 811            params['DBInstanceIdentifier'] = instance_id
 812        if max_records:
 813            params['MaxRecords'] = max_records
 814        if marker:
 815            params['Marker'] = marker
 816        return self.get_list('DescribeDBSnapshots', params,
 817                             [('DBSnapshot', DBSnapshot)])
 818
 819    def create_dbsnapshot(self, snapshot_id, dbinstance_id):
 820        """
 821        Create a new DB snapshot.
 822
 823        :type snapshot_id: string
 824        :param snapshot_id: The identifier for the DBSnapshot
 825
 826        :type dbinstance_id: string
 827        :param dbinstance_id: The source identifier for the RDS instance from
 828                              which the snapshot is created.
 829
 830        :rtype: :class:`boto.rds.dbsnapshot.DBSnapshot`
 831        :return: The newly created DBSnapshot
 832        """
 833        params = {'DBSnapshotIdentifier': snapshot_id,
 834                  'DBInstanceIdentifier': dbinstance_id}
 835        return self.get_object('CreateDBSnapshot', params, DBSnapshot)
 836
 837    def delete_dbsnapshot(self, identifier):
 838        """
 839        Delete a DBSnapshot
 840
 841        :type identifier: string
 842        :param identifier: The identifier of the DBSnapshot to delete
 843        """
 844        params = {'DBSnapshotIdentifier': identifier}
 845        return self.get_object('DeleteDBSnapshot', params, DBSnapshot)
 846
 847    def restore_dbinstance_from_dbsnapshot(self, identifier, instance_id,
 848                                           instance_class, port=None,
 849                                           availability_zone=None,
 850                                           multi_az=None,
 851                                           auto_minor_version_upgrade=None):
 852        """
 853        Create a new DBInstance from a DB snapshot.
 854    
 855        :type identifier: string
 856        :param identifier: The identifier for the DBSnapshot
 857    
 858        :type instance_id: string
 859        :param instance_id: The source identifier for the RDS instance from
 860                              which the snapshot is created.
 861    
 862        :type instance_class: str
 863        :param instance_class: The compute and memory capacity of the
 864                               DBInstance.  Valid values are:
 865                               db.m1.small | db.m1.large | db.m1.xlarge |
 866                               db.m2.2xlarge | db.m2.4xlarge
 867    
 868        :type port: int
 869        :param port: Port number on which database accepts connections.
 870                     Valid values [1115-65535].  Defaults to 3306.
 871    
 872        :type availability_zone: str
 873        :param availability_zone: Name of the availability zone to place
 874                                  DBInstance into.
 875
 876        :type multi_az: bool
 877        :param multi_az: If True, specifies the DB Instance will be
 878                         deployed in multiple availability zones.
 879                         Default is the API default.
 880
 881        :type auto_minor_version_upgrade: bool
 882        :param auto_minor_version_upgrade: Indicates that minor engine
 883                                           upgrades will be applied
 884                                           automatically to the Read Replica
 885                                           during the maintenance window.
 886                                           Default is the API default.
 887    
 888        :rtype: :class:`boto.rds.dbinstance.DBInstance`
 889        :return: The newly created DBInstance
 890        """
 891        params = {'DBSnapshotIdentifier': identifier,
 892                  'DBInstanceIdentifier': instance_id,
 893                  'DBInstanceClass': instance_class}
 894        if port:
 895            params['Port'] = port
 896        if availability_zone:
 897            params['AvailabilityZone'] = availability_zone
 898        if multi_az is not None:
 899            params['MultiAZ'] = str(multi_az).lower()
 900        if auto_minor_version_upgrade is not None:
 901            params['AutoMinorVersionUpgrade'] = str(auto_minor_version_upgrade).lower()
 902        return self.get_object('RestoreDBInstanceFromDBSnapshot',
 903                               params, DBInstance)
 904
 905    def restore_dbinstance_from_point_in_time(self, source_instance_id,
 906                                              target_instance_id,
 907                                              use_latest=False,
 908                                              restore_time=None,
 909                                              dbinstance_class=None,
 910                                              port=None,
 911                                              availability_zone=None):
 912
 913        """
 914        Create a new DBInstance from a point in time.
 915
 916        :type source_instance_id: string
 917        :param source_instance_id: The identifier for the source DBInstance.
 918
 919        :type target_instance_id: string
 920        :param target_instance_id: The identifier of the new DBInstance.
 921
 922        :type use_latest: bool
 923        :param use_latest: If True, the latest snapshot availabile will
 924                           be used.
 925
 926        :type restore_time: datetime
 927        :param restore_time: The date and time to restore from.  Only
 928                             used if use_latest is False.
 929
 930        :type instance_class: str
 931        :param instance_class: The compute and memory capacity of the
 932                               DBInstance.  Valid values are:
 933                               db.m1.small | db.m1.large | db.m1.xlarge |
 934                               db.m2.2xlarge | db.m2.4xlarge
 935
 936        :type port: int
 937        :param port: Port number on which database accepts connections.
 938                     Valid values [1115-65535].  Defaults to 3306.
 939
 940        :type availability_zone: str
 941        :param availability_zone: Name of the availability zone to place
 942                                  DBInstance into.
 943
 944        :rtype: :class:`boto.rds.dbinstance.DBInstance`
 945        :return: The newly created DBInstance
 946        """
 947        params = {'SourceDBInstanceIdentifier': source_instance_id,
 948                  'TargetDBInstanceIdentifier': target_instance_id}
 949        if use_latest:
 950            params['UseLatestRestorableTime'] = 'true'
 951        elif restore_time:
 952            params['RestoreTime'] = restore_time.isoformat()
 953        if dbinstance_class:
 954            params['DBInstanceClass'] = dbinstance_class
 955        if port:
 956            params['Port'] = port
 957        if availability_zone:
 958            params['AvailabilityZone'] = availability_zone
 959        return self.get_object('RestoreDBInstanceToPointInTime',
 960                               params, DBInstance)
 961
 962    # Events
 963
 964    def get_all_events(self, source_identifier=None, source_type=None,
 965                       start_time=None, end_time=None,
 966                       max_records=None, marker=None):
 967        """
 968        Get information about events related to your DBInstances,
 969        DBSecurityGroups and DBParameterGroups.
 970
 971        :type source_identifier: str
 972        :param source_identifier: If supplied, the events returned will be
 973                                  limited to those that apply to the identified
 974                                  source.  The value of this parameter depends
 975                                  on the value of source_type.  If neither
 976                                  parameter is specified, all events in the time
 977                                  span will be returned.
 978
 979        :type source_type: str
 980        :param source_type: Specifies how the source_identifier should
 981                            be interpreted.  Valid values are:
 982                            b-instance | db-security-group |
 983                            db-parameter-group | db-snapshot
 984
 985        :type start_time: datetime
 986        :param start_time: The beginning of the time interval for events.
 987                           If not supplied, all available events will
 988                           be returned.
 989
 990        :type end_time: datetime
 991        :param end_time: The ending of the time interval for events.
 992                         If not supplied, all available events will
 993                         be returned.
 994
 995        :type max_records: int
 996        :param max_records: The maximum number of records to be returned.
 997                            If more results are available, a MoreToken will
 998                            be returned in the response that can be used to
 999                            retrieve additional records.  Default is 100.
1000
1001        :type marker: str
1002        :param marker: The marker provided by a previous request.
1003
1004        :rtype: list
1005        :return: A list of class:`boto.rds.event.Event`
1006        """
1007        params = {}
1008        if source_identifier and source_type:
1009            params['SourceIdentifier'] = source_identifier
1010            params['SourceType'] = source_type
1011        if start_time:
1012            params['StartTime'] = start_time.isoformat()
1013        if end_time:
1014            params['EndTime'] = end_time.isoformat()
1015        if max_records:
1016            params['MaxRecords'] = max_records
1017        if marker:
1018            params['Marker'] = marker
1019        return self.get_list('DescribeEvents', params, [('Event', Event)])