U
    W+d/                    @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZmZ dd Zdd ZG dd deZdS )    N)AWSQueryConnection)
DBInstance)DBSecurityGroup)OptionGroupOptionGroupOption)ParameterGroup)
DBSnapshot)Event)RDSRegionInfo)DBSubnetGroup)VPCSecurityGroupMembership)get_regions)connect)LogFileLogFileObjectc                   C   s   t dttdS )z
    Get all available regions for the RDS service.

    :rtype: list
    :return: A list of :class:`boto.rds.regioninfo.RDSRegionInfo`
    rdsZ
region_clsZconnection_cls)r   r
   RDSConnection r   r   5/tmp/pip-unpacked-wheel-dlxw5sjy/boto/rds/__init__.pyregions'   s
    r   c                 K   s   t d| fttd|S )a  
    Given a valid region name, return a
    :class:`boto.rds.RDSConnection`.
    Any additional parameters after the region_name are passed on to
    the connect method of the region object.

    :type: str
    :param region_name: The name of the region to connect to.

    :rtype: :class:`boto.rds.RDSConnection` or ``None``
    :return: A connection to the given region, or None if an invalid region
             name is given
    r   r   )r   r
   r   )Zregion_nameZ	kw_paramsr   r   r   connect_to_region5   s
    
r   c                       s  e Zd ZdZdZdZdW fdd		Zd
d ZdXddZdYddZ	dZddZ
d[ddZd\ddZd]ddZdd Zd^ddZd_d d!Zd`d"d#Zdad$d%Zdbd&d'Zd(d) Zdcd*d+Zddd,d-Zd.d/ Zded0d1Zdfd2d3ZeZdgd4d5Zdhd6d7Zdid8d9Zd:d; Zd<d= Zd>d? Z djd@dAZ!dkdBdCZ"dldDdEZ#dFdG Z$dHdI Z%dmdJdKZ&dndLdMZ'dodNdOZ(dPdQ Z)dpdSdTZ*dqdUdVZ+  Z,S )rr   z	us-east-1zrds.amazonaws.comz
2013-05-15NTr   /c                    sP   |st | | j| j}|| _tt| j||||||||| jj|	|
||||d d S )N)validate_certsprofile_name)r
   DefaultRegionNameDefaultRegionEndpointregionsuperr   __init__Zendpoint)selfZaws_access_key_idZaws_secret_access_keyZ	is_secureportproxyZ
proxy_portZ
proxy_userZ
proxy_passdebugZhttps_connection_factoryr   pathZsecurity_tokenr   r   	__class__r   r   r   O   s*          zRDSConnection.__init__c                 C   s   dgS )Nzhmac-v4r   )r    r   r   r   _required_auth_capabilityc   s    z'RDSConnection._required_auth_capabilityc                 C   s<   i }|r||d< |r||d< |r(||d< |  d|dtfgS )aa  
        Retrieve all the DBInstances in your account.

        :type instance_id: str
        :param instance_id: DB Instance identifier.  If supplied, only
                            information this instance will be returned.
                            Otherwise, info about all DB Instances will
                            be returned.

        :type max_records: int
        :param max_records: The maximum number of records to be returned.
                            If more results are available, a MoreToken will
                            be returned in the response that can be used to
                            retrieve additional records.  Default is 100.

        :type marker: str
        :param marker: The marker provided by a previous request.

        :rtype: list
        :return: A list of :class:`boto.rds.dbinstance.DBInstance`
        DBInstanceIdentifier
MaxRecordsMarkerZDescribeDBInstancesr   )get_listr   )r    instance_idmax_recordsmarkerparamsr   r   r   get_all_dbinstancesh   s    z!RDSConnection.get_all_dbinstances  MySQL5.1Fc                 C   s  ||rt | nd||||||t|	tr0|	jn|	||||||||rPt | nd||||d}|
rg }|
D ]&}t|tr||j ql|| ql| ||d |rg }|D ]&}t|tr||j	 q|| q| ||d t
| D ]\}}|dkr||= q| d|tS )a#%  
        Create a new DBInstance.

        :type id: str
        :param id: Unique identifier for the new instance.
                   Must contain 1-63 alphanumeric characters.
                   First character must be a letter.
                   May not end with a hyphen or contain two consecutive hyphens

        :type allocated_storage: int
        :param allocated_storage: Initially allocated storage size, in GBs.
                                  Valid values are depending on the engine value.

                                  * MySQL = 5--3072
                                  * oracle-se1 = 10--3072
                                  * oracle-se = 10--3072
                                  * oracle-ee = 10--3072
                                  * sqlserver-ee = 200--1024
                                  * sqlserver-se = 200--1024
                                  * sqlserver-ex = 30--1024
                                  * sqlserver-web = 30--1024
                                  * postgres = 5--3072

        :type instance_class: str
        :param instance_class: The compute and memory capacity of
                               the DBInstance. Valid values are:

                               * db.t1.micro
                               * db.m1.small
                               * db.m1.medium
                               * db.m1.large
                               * db.m1.xlarge
                               * db.m2.xlarge
                               * db.m2.2xlarge
                               * db.m2.4xlarge

        :type engine: str
        :param engine: Name of database engine. Defaults to MySQL but can be;

                       * MySQL
                       * oracle-se1
                       * oracle-se
                       * oracle-ee
                       * sqlserver-ee
                       * sqlserver-se
                       * sqlserver-ex
                       * sqlserver-web
                       * postgres

        :type master_username: str
        :param master_username: Name of master user for the DBInstance.

                                * MySQL must be;
                                  - 1--16 alphanumeric characters
                                  - first character must be a letter
                                  - cannot be a reserved MySQL word

                                * Oracle must be:
                                  - 1--30 alphanumeric characters
                                  - first character must be a letter
                                  - cannot be a reserved Oracle word

                                * SQL Server must be:
                                  - 1--128 alphanumeric characters
                                  - first character must be a letter
                                  - cannot be a reserver SQL Server word

        :type master_password: str
        :param master_password: Password of master user for the DBInstance.

                                * MySQL must be 8--41 alphanumeric characters

                                * Oracle must be 8--30 alphanumeric characters

                                * SQL Server must be 8--128 alphanumeric characters.

        :type port: int
        :param port: Port number on which database accepts connections.
                     Valid values [1115-65535].

                     * MySQL defaults to 3306

                     * Oracle defaults to 1521

                     * SQL Server defaults to 1433 and _cannot_ be 1434, 3389,
                       47001, 49152, and 49152 through 49156.

                     * PostgreSQL defaults to 5432

        :type db_name: str
        :param db_name: * MySQL:
                          Name of a database to create when the DBInstance
                          is created. Default is to create no databases.

                          Must contain 1--64 alphanumeric characters and cannot
                          be a reserved MySQL word.

                        * Oracle:
                          The Oracle System ID (SID) of the created DB instances.
                          Default is ORCL. Cannot be longer than 8 characters.

                        * SQL Server:
                          Not applicable and must be None.

                        * PostgreSQL:
                          Name of a database to create when the DBInstance
                          is created. Default is to create no databases.

                          Must contain 1--63 alphanumeric characters. Must
                          begin with a letter or an underscore. Subsequent
                          characters can be letters, underscores, or digits (0-9)
                          and cannot be a reserved PostgreSQL word.

        :type param_group: str or ParameterGroup object
        :param param_group: Name of DBParameterGroup or ParameterGroup instance
                            to associate with this DBInstance.  If no groups are
                            specified no parameter groups will be used.

        :type security_groups: list of str or list of DBSecurityGroup objects
        :param security_groups: List of names of DBSecurityGroup to
            authorize on this DBInstance.

        :type availability_zone: str
        :param availability_zone: Name of the availability zone to place
                                  DBInstance into.

        :type preferred_maintenance_window: str
        :param preferred_maintenance_window: The weekly time range (in UTC)
                                             during which maintenance can occur.
                                             Default is Sun:05:00-Sun:09:00

        :type backup_retention_period: int
        :param backup_retention_period: The number of days for which automated
                                        backups are retained.  Setting this to
                                        zero disables automated backups.

        :type preferred_backup_window: str
        :param preferred_backup_window: The daily time range during which
                                        automated backups are created (if
                                        enabled).  Must be in h24:mi-hh24:mi
                                        format (UTC).

        :type multi_az: bool
        :param multi_az: If True, specifies the DB Instance will be
                         deployed in multiple availability zones.

                         For Microsoft SQL Server, must be set to false. You cannot set
                         the AvailabilityZone parameter if the MultiAZ parameter is
                         set to true.

        :type engine_version: str
        :param engine_version: The version number of the database engine to use.

                               * MySQL format example: 5.1.42

                               * Oracle format example: 11.2.0.2.v2

                               * SQL Server format example: 10.50.2789.0.v1

                               * PostgreSQL format example: 9.3

        :type auto_minor_version_upgrade: bool
        :param auto_minor_version_upgrade: Indicates that minor engine
                                           upgrades will be applied
                                           automatically to the Read Replica
                                           during the maintenance window.
                                           Default is True.
        :type character_set_name: str
        :param character_set_name: For supported engines, indicates that the DB Instance
                                   should be associated with the specified CharacterSet.

        :type db_subnet_group_name: str
        :param db_subnet_group_name: A DB Subnet Group to associate with this DB Instance.
                                     If there is no DB Subnet Group, then it is a non-VPC DB
                                     instance.

        :type license_model: str
        :param license_model: License model information for this DB Instance.

                              Valid values are;
                              - license-included
                              - bring-your-own-license
                              - general-public-license

                              All license types are not supported on all engines.

        :type option_group_name: str
        :param option_group_name: Indicates that the DB Instance should be associated
                                  with the specified option group.

        :type iops: int
        :param iops:  The amount of IOPS (input/output operations per second) to Provisioned
                      for the DB Instance. Can be modified at a later date.

                      Must scale linearly. For every 1000 IOPS provision, you must allocated
                      100 GB of storage space. This scales up to 1 TB / 10 000 IOPS for MySQL
                      and Oracle. MSSQL is limited to 700 GB / 7 000 IOPS.

                      If you specify a value, it must be at least 1000 IOPS and you must
                      allocate 100 GB of storage.

        :type vpc_security_groups: list of str or a VPCSecurityGroupMembership object
        :param vpc_security_groups: List of VPC security group ids or a list of
            VPCSecurityGroupMembership objects this DBInstance should be a member of

        :rtype: :class:`boto.rds.dbinstance.DBInstance`
        :return: The new db instance.
        N)AllocatedStorageAutoMinorVersionUpgradeAvailabilityZoneBackupRetentionPeriodZCharacterSetNameDBInstanceClassr(   ZDBNameDBParameterGroupNameDBSubnetGroupNameZEngineZEngineVersionIopsZLicenseModelZMasterUsernameMasterUserPasswordMultiAZOptionGroupNamePortPreferredBackupWindowPreferredMaintenanceWindowDBSecurityGroups.memberVpcSecurityGroupIds.memberZCreateDBInstance)strlower
isinstancer   namer   appendbuild_list_paramsr   	vpc_grouplistitems
get_objectr   )r    idallocated_storageinstance_classZmaster_usernamemaster_passwordr!   engineZdb_nameparam_groupsecurity_groupsavailability_zonepreferred_maintenance_windowbackup_retention_periodpreferred_backup_windowmulti_azZengine_versionauto_minor_version_upgradeZcharacter_set_namedb_subnet_group_nameZlicense_modelZoption_group_nameiopsvpc_security_groupsr/   lgroupvpc_grpkvr   r   r   create_dbinstance   sX      

 zRDSConnection.create_dbinstancec                 C   s^   ||d}|r||d< |r"||d< |r.||d< |dk	rP|dkrHd|d< nd	|d< |  d
|tS )a  
        Create a new DBInstance Read Replica.

        :type id: str
        :param id: Unique identifier for the new instance.
                   Must contain 1-63 alphanumeric characters.
                   First character must be a letter.
                   May not end with a hyphen or contain two consecutive hyphens

        :type source_id: str
        :param source_id: Unique identifier for the DB Instance for which this
                          DB Instance will act as a Read Replica.

        :type instance_class: str
        :param instance_class: The compute and memory capacity of the
                               DBInstance.  Default is to inherit from
                               the source DB Instance.

                               Valid values are:

                               * db.m1.small
                               * db.m1.large
                               * db.m1.xlarge
                               * db.m2.xlarge
                               * db.m2.2xlarge
                               * db.m2.4xlarge

        :type port: int
        :param port: Port number on which database accepts connections.
                     Default is to inherit from source DB Instance.
                     Valid values [1115-65535].  Defaults to 3306.

        :type availability_zone: str
        :param availability_zone: Name of the availability zone to place
                                  DBInstance into.

        :type auto_minor_version_upgrade: bool
        :param auto_minor_version_upgrade: Indicates that minor engine
                                           upgrades will be applied
                                           automatically to the Read Replica
                                           during the maintenance window.
                                           Default is to inherit this value
                                           from the source DB Instance.

        :rtype: :class:`boto.rds.dbinstance.DBInstance`
        :return: The new db instance.
        )r(   SourceDBInstanceIdentifierr7   r>   r5   NTtruer4   falseZCreateDBInstanceReadReplicarL   r   )r    rM   Z	source_idrO   r!   rT   rY   r/   r   r   r   create_dbinstance_read_replica  s"    4
 z,RDSConnection.create_dbinstance_read_replicac                 C   s2   d|i}|dk	r||d< |r$||d< |  d|tS )a  
        Promote a Read Replica to a standalone DB Instance.

        :type id: str
        :param id: Unique identifier for the new instance.
                   Must contain 1-63 alphanumeric characters.
                   First character must be a letter.
                   May not end with a hyphen or contain two consecutive hyphens

        :type backup_retention_period: int
        :param backup_retention_period: The number of days for which automated
                                        backups are retained.  Setting this to
                                        zero disables automated backups.

        :type preferred_backup_window: str
        :param preferred_backup_window: The daily time range during which
                                        automated backups are created (if
                                        enabled).  Must be in h24:mi-hh24:mi
                                        format (UTC).

        :rtype: :class:`boto.rds.dbinstance.DBInstance`
        :return: The new db instance.
        r(   Nr6   r?   ZPromoteReadReplicarf   )r    rM   rV   rW   r/   r   r   r   promote_read_replica  s    z"RDSConnection.promote_read_replicac                 C   s:  d|i}|r$t |tr|jn||d< |rfg }|D ]&}t |trL||j q0|| q0| ||d |rg }|D ]&}t |tr||j qr|| qr| ||d |r||d< |r||d< |r||d< |r||d< |d	k	r||d
< |	r|	|d< |
rd|d< |rd|d< |r||d< |r,||d< | d|t	S )a  
        Modify an existing DBInstance.

        :type id: str
        :param id: Unique identifier for the new instance.

        :type param_group: str or ParameterGroup object
        :param param_group: Name of DBParameterGroup or ParameterGroup instance
                            to associate with this DBInstance.  If no groups are
                            specified no parameter groups will be used.

        :type security_groups: list of str or list of DBSecurityGroup objects
        :param security_groups: List of names of DBSecurityGroup to authorize on
                                this DBInstance.

        :type preferred_maintenance_window: str
        :param preferred_maintenance_window: The weekly time range (in UTC)
                                             during which maintenance can
                                             occur.
                                             Default is Sun:05:00-Sun:09:00

        :type master_password: str
        :param master_password: Password of master user for the DBInstance.
                                Must be 4-15 alphanumeric characters.

        :type allocated_storage: int
        :param allocated_storage: The new allocated storage size, in GBs.
                                  Valid values are [5-1024]

        :type instance_class: str
        :param instance_class: The compute and memory capacity of the
                               DBInstance.  Changes will be applied at
                               next maintenance window unless
                               apply_immediately is True.

                               Valid values are:

                               * db.m1.small
                               * db.m1.large
                               * db.m1.xlarge
                               * db.m2.xlarge
                               * db.m2.2xlarge
                               * db.m2.4xlarge

        :type apply_immediately: bool
        :param apply_immediately: If true, the modifications will be applied
                                  as soon as possible rather than waiting for
                                  the next preferred maintenance window.

        :type backup_retention_period: int
        :param backup_retention_period: The number of days for which automated
                                        backups are retained.  Setting this to
                                        zero disables automated backups.

        :type preferred_backup_window: str
        :param preferred_backup_window: The daily time range during which
                                        automated backups are created (if
                                        enabled).  Must be in h24:mi-hh24:mi
                                        format (UTC).

        :type multi_az: bool
        :param multi_az: If True, specifies the DB Instance will be
                         deployed in multiple availability zones.

        :type iops: int
        :param iops:  The amount of IOPS (input/output operations per second) to Provisioned
                      for the DB Instance. Can be modified at a later date.

                      Must scale linearly. For every 1000 IOPS provision, you must allocated
                      100 GB of storage space. This scales up to 1 TB / 10 000 IOPS for MySQL
                      and Oracle. MSSQL is limited to 700 GB / 7 000 IOPS.

                      If you specify a value, it must be at least 1000 IOPS and you must
                      allocate 100 GB of storage.

        :type vpc_security_groups: list of str or a VPCSecurityGroupMembership object
        :param vpc_security_groups: List of VPC security group ids or a
            VPCSecurityGroupMembership object this DBInstance should be a member of

        :type new_instance_id: str
        :param new_instance_id: New name to rename the DBInstance to.

        :rtype: :class:`boto.rds.dbinstance.DBInstance`
        :return: The modified db instance.
        r(   r8   rA   rB   r@   r;   r3   r7   Nr6   r?   rd   r<   ZApplyImmediatelyr:   ZNewDBInstanceIdentifierZModifyDBInstance)
rE   r   rF   r   rG   rH   r   rI   rL   r   )r    rM   rR   rS   rU   rP   rN   rO   rV   rW   rX   Zapply_immediatelyr[   r\   Znew_instance_idr/   r]   r^   r_   r   r   r   modify_dbinstance3  sR    a

zRDSConnection.modify_dbinstance c                 C   s4   d|i}|rd|d< nd|d< ||d< |  d|tS )a?  
        Delete an existing DBInstance.

        :type id: str
        :param id: Unique identifier for the new instance.

        :type skip_final_snapshot: bool
        :param skip_final_snapshot: This parameter determines whether a final
                                    db snapshot is created before the instance
                                    is deleted.  If True, no snapshot
                                    is created.  If False, a snapshot
                                    is created before deleting the instance.

        :type final_snapshot_id: str
        :param final_snapshot_id: If a final snapshot is requested, this
                                  is the identifier used for that snapshot.

        :rtype: :class:`boto.rds.dbinstance.DBInstance`
        :return: The deleted db instance.
        r(   rd   ZSkipFinalSnapshotre   ZFinalDBSnapshotIdentifierZDeleteDBInstancerf   )r    rM   Zskip_final_snapshotZfinal_snapshot_idr/   r   r   r   delete_dbinstance  s    
zRDSConnection.delete_dbinstancec                 C   s   d|i}|  d|tS )z
        Reboot DBInstance.

        :type id: str
        :param id: Unique identifier of the instance.

        :rtype: :class:`boto.rds.dbinstance.DBInstance`
        :return: The rebooting db instance.
        r(   ZRebootDBInstancerf   )r    rM   r/   r   r   r   reboot_dbinstance  s    
zRDSConnection.reboot_dbinstancec                 C   s<   i }|r||d< |r||d< |r(||d< |  d|dtfgS )a  
        Get all parameter groups associated with your account in a region.

        :type groupname: str
        :param groupname: The name of the DBParameter group to retrieve.
                          If not provided, all DBParameter groups will be returned.

        :type max_records: int
        :param max_records: The maximum number of records to be returned.
                            If more results are available, a MoreToken will
                            be returned in the response that can be used to
                            retrieve additional records.  Default is 100.

        :type marker: str
        :param marker: The marker provided by a previous request.

        :rtype: list
        :return: A list of :class:`boto.ec2.parametergroup.ParameterGroup`
        r8   r)   r*   ZDescribeDBParameterGroupsZDBParameterGroup)r+   r   r    	groupnamer-   r.   r/   r   r   r   get_all_dbparameter_groups  s    z(RDSConnection.get_all_dbparameter_groupsc                 C   sD   d|i}|r||d< |r ||d< |r,||d< |  d|t}||_|S )a  
        Get all parameters associated with a ParameterGroup

        :type groupname: str
        :param groupname: The name of the DBParameter group to retrieve.

        :type source: str
        :param source: Specifies which parameters to return.
                       If not specified, all parameters will be returned.
                       Valid values are: user|system|engine-default

        :type max_records: int
        :param max_records: The maximum number of records to be returned.
                            If more results are available, a MoreToken will
                            be returned in the response that can be used to
                            retrieve additional records.  Default is 100.

        :type marker: str
        :param marker: The marker provided by a previous request.

        :rtype: :class:`boto.ec2.parametergroup.ParameterGroup`
        :return: The ParameterGroup
        r8   ZSourcer)   r*   ZDescribeDBParameters)rL   r   rF   )r    rn   sourcer-   r.   r/   Zpgr   r   r   get_all_dbparameters  s    z"RDSConnection.get_all_dbparametersc                 C   s   |||d}|  d|tS )a  
        Create a new dbparameter group for your account.

        :type name: string
        :param name: The name of the new dbparameter group

        :type engine: str
        :param engine: Name of database engine.

        :type description: string
        :param description: The description of the new dbparameter group

        :rtype: :class:`boto.rds.parametergroup.ParameterGroup`
        :return: The newly created ParameterGroup
        )r8   ZDBParameterGroupFamilyDescriptionZCreateDBParameterGroup)rL   r   )r    rF   rQ   descriptionr/   r   r   r   create_parameter_group0  s
    z$RDSConnection.create_parameter_groupc                 C   sF   d|i}t dt|D ]}|| }|||d  q| jd|tddS )a~  
        Modify a ParameterGroup for your account.

        :type name: string
        :param name: The name of the new ParameterGroup

        :type parameters: list of :class:`boto.rds.parametergroup.Parameter`
        :param parameters: The new parameters

        :rtype: :class:`boto.rds.parametergroup.ParameterGroup`
        :return: The newly created ParameterGroup
        r8   r      ZModifyDBParameterGroupPOST)Zverb)rangelenmerger+   r   )r    rF   
parametersr/   i	parameterr   r   r   modify_parameter_groupE  s     z$RDSConnection.modify_parameter_groupc                 C   sV   d|i}|rd|d< n4d|d< t dt|D ]}|| }|||d  q,| d|S )a  
        Resets some or all of the parameters of a ParameterGroup to the
        default value

        :type key_name: string
        :param key_name: The name of the ParameterGroup to reset

        :type parameters: list of :class:`boto.rds.parametergroup.Parameter`
        :param parameters: The parameters to reset.  If not supplied,
                           all parameters will be reset.
        r8   rd   ZResetAllParametersre   r   ru   ZResetDBParameterGroup)rw   rx   ry   
get_status)r    rF   Zreset_all_paramsrz   r/   r{   r|   r   r   r   reset_parameter_groupY  s    
z#RDSConnection.reset_parameter_groupc                 C   s   d|i}|  d|S )z
        Delete a ParameterGroup from your account.

        :type key_name: string
        :param key_name: The name of the ParameterGroup to delete
        r8   ZDeleteDBParameterGroupr~   r    rF   r/   r   r   r   delete_parameter_groupp  s    z$RDSConnection.delete_parameter_groupc                 C   s<   i }|r||d< |r||d< |r(||d< |  d|dtfgS )a;  
        Get all security groups associated with your account in a region.

        :type groupnames: list
        :param groupnames: A list of the names of security groups to retrieve.
                           If not provided, all security groups will
                           be returned.

        :type max_records: int
        :param max_records: The maximum number of records to be returned.
                            If more results are available, a MoreToken will
                            be returned in the response that can be used to
                            retrieve additional records.  Default is 100.

        :type marker: str
        :param marker: The marker provided by a previous request.

        :rtype: list
        :return: A list of :class:`boto.rds.dbsecuritygroup.DBSecurityGroup`
        DBSecurityGroupNamer)   r*   ZDescribeDBSecurityGroupsr   )r+   r   rm   r   r   r   get_all_dbsecurity_groups|  s    z'RDSConnection.get_all_dbsecurity_groupsc                 C   s2   d|i}|r||d< |  d|t}||_||_|S )a  
        Create a new security group for your account.
        This will create the security group within the region you
        are currently connected to.

        :type name: string
        :param name: The name of the new security group

        :type description: string
        :param description: The description of the new security group

        :rtype: :class:`boto.rds.dbsecuritygroup.DBSecurityGroup`
        :return: The newly created DBSecurityGroup
        r   ZDBSecurityGroupDescriptionZCreateDBSecurityGroup)rL   r   rF   rs   )r    rF   rs   r/   r^   r   r   r   create_dbsecurity_group  s    z%RDSConnection.create_dbsecurity_groupc                 C   s   d|i}|  d|S )z
        Delete a DBSecurityGroup from your account.

        :type key_name: string
        :param key_name: The name of the DBSecurityGroup to delete
        r   ZDeleteDBSecurityGroupr   r   r   r   r   delete_dbsecurity_group  s    z%RDSConnection.delete_dbsecurity_groupc                 C   s@   d|i}|r||d< |r ||d< |r2t ||d< | d|tS )a  
        Add a new rule to an existing security group.
        You need to pass in either src_security_group_name and
        src_security_group_owner_id OR a CIDR block but not both.

        :type group_name: string
        :param group_name: The name of the security group you are adding
                           the rule to.

        :type ec2_security_group_name: string
        :param ec2_security_group_name: The name of the EC2 security group
                                        you are granting access to.

        :type ec2_security_group_owner_id: string
        :param ec2_security_group_owner_id: The ID of the owner of the EC2
                                            security group you are granting
                                            access to.

        :type cidr_ip: string
        :param cidr_ip: The CIDR block you are providing access to.
                        See http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing

        :rtype: bool
        :return: True if successful.
        r   EC2SecurityGroupNameEC2SecurityGroupOwnerIdCIDRIPZAuthorizeDBSecurityGroupIngress)urllibquoterL   r   )r    
group_namecidr_ipec2_security_group_nameec2_security_group_owner_idr/   r   r   r   authorize_dbsecurity_group  s    z(RDSConnection.authorize_dbsecurity_groupc                 C   s:   d|i}|r||d< |r ||d< |r,||d< |  d|tS )a  
        Remove an existing rule from an existing security group.
        You need to pass in either ec2_security_group_name and
        ec2_security_group_owner_id OR a CIDR block.

        :type group_name: string
        :param group_name: The name of the security group you are removing
                           the rule from.

        :type ec2_security_group_name: string
        :param ec2_security_group_name: The name of the EC2 security group
                                        from which you are removing access.

        :type ec2_security_group_owner_id: string
        :param ec2_security_group_owner_id: The ID of the owner of the EC2
                                            security from which you are
                                            removing access.

        :type cidr_ip: string
        :param cidr_ip: The CIDR block from which you are removing access.
                        See http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing

        :rtype: bool
        :return: True if successful.
        r   r   r   r   ZRevokeDBSecurityGroupIngress)rL   r   )r    r   r   r   r   r/   r   r   r   revoke_dbsecurity_group  s    z%RDSConnection.revoke_dbsecurity_groupc                 C   sH   i }|r||d< |r||d< |r(||d< |r4||d< |  d|dtfgS )a!  
        Get information about DB Snapshots.

        :type snapshot_id: str
        :param snapshot_id: The unique identifier of an RDS snapshot.
                            If not provided, all RDS snapshots will be returned.

        :type instance_id: str
        :param instance_id: The identifier of a DBInstance.  If provided,
                            only the DBSnapshots related to that instance will
                            be returned.
                            If not provided, all RDS snapshots will be returned.

        :type max_records: int
        :param max_records: The maximum number of records to be returned.
                            If more results are available, a MoreToken will
                            be returned in the response that can be used to
                            retrieve additional records.  Default is 100.

        :type marker: str
        :param marker: The marker provided by a previous request.

        :rtype: list
        :return: A list of :class:`boto.rds.dbsnapshot.DBSnapshot`
        DBSnapshotIdentifierr(   r)   r*   ZDescribeDBSnapshotsr   )r+   r   )r    snapshot_idr,   r-   r.   r/   r   r   r   get_all_dbsnapshots  s    z!RDSConnection.get_all_dbsnapshotsc                 C   sX   d|i}|r||d< |r ||d< |r,||d< |r8||d< |rD||d< |  d|dtfgS )	a  
        Get all log files

        :type instance_id: str
        :param instance_id: The identifier of a DBInstance.

        :type max_records: int
        :param max_records: Number of log file names to return.

        :type marker: str
        :param marker: The marker provided by a previous request.

        :file_size: int
        :param file_size: Filter results to files large than this size in bytes.

        :filename_contains: str
        :param filename_contains: Filter results to files with filename containing this string

        :file_last_written: int
        :param file_last_written: Filter results to files written after this time (POSIX timestamp)

        :rtype: list
        :return: A list of :class:`boto.rds.logfile.LogFile`
        r(   ZFileSizeZFilenameContainsZFileLastWrittenr*   r)   ZDescribeDBLogFilesZDescribeDBLogFilesDetails)r+   r   )r    dbinstance_idr-   r.   	file_sizeZfilename_containsZfile_last_writtenr/   r   r   r   get_all_logs6  s    zRDSConnection.get_all_logsc                 C   sP   ||d}|r||d< |r"||d< |r.||d< |  d|t}|rL||_||_|S )aN  
        Download a log file from RDS

        :type instance_id: str
        :param instance_id: The identifier of a DBInstance.

        :type log_file_name: str
        :param log_file_name: The name of the log file to retrieve

        :type marker: str
        :param marker: A marker returned from a previous call to this method, or 0 to indicate the start of file. If
                       no marker is specified, this will fetch log lines from the end of file instead.

        :type number_of_lines: int
        :param marker: The maximium number of lines to be returned.
        )r(   ZLogFileNamer*   ZNumberOfLinesr)   ZDownloadDBLogFilePortion)rL   r   Zlog_filenamer   )r    r   Zlog_file_namer.   Znumber_of_linesr-   r/   logfiler   r   r   get_log_filec  s    zRDSConnection.get_log_filec                 C   s   ||d}|  d|tS )a  
        Create a new DB snapshot.

        :type snapshot_id: string
        :param snapshot_id: The identifier for the DBSnapshot

        :type dbinstance_id: string
        :param dbinstance_id: The source identifier for the RDS instance from
                              which the snapshot is created.

        :rtype: :class:`boto.rds.dbsnapshot.DBSnapshot`
        :return: The newly created DBSnapshot
        )r   r(   ZCreateDBSnapshotrL   r   )r    r   r   r/   r   r   r   create_dbsnapshot  s    zRDSConnection.create_dbsnapshotc                 C   s   ||d}|  d|tS )a  
        Copies the specified DBSnapshot.

        :type source_snapshot_id: string
        :param source_snapshot_id: The identifier for the source DB snapshot.

        :type target_snapshot_id: string
        :param target_snapshot_id: The identifier for the copied snapshot.

        :rtype: :class:`boto.rds.dbsnapshot.DBSnapshot`
        :return: The newly created DBSnapshot.
        )ZSourceDBSnapshotIdentifierZTargetDBSnapshotIdentifierZCopyDBSnapshotr   )r    Zsource_snapshot_idZtarget_snapshot_idr/   r   r   r   copy_dbsnapshot  s    zRDSConnection.copy_dbsnapshotc                 C   s   d|i}|  d|tS )z
        Delete a DBSnapshot

        :type identifier: string
        :param identifier: The identifier of the DBSnapshot to delete
        r   ZDeleteDBSnapshotr   )r    
identifierr/   r   r   r   delete_dbsnapshot  s    zRDSConnection.delete_dbsnapshotc	           
      C   sr   |||d}	|r||	d< |r$||	d< |dk	r<t | |	d< |dk	rTt | |	d< |dk	rd||	d< | d|	tS )	a  
        Create a new DBInstance from a DB snapshot.

        :type identifier: string
        :param identifier: The identifier for the DBSnapshot

        :type instance_id: string
        :param instance_id: The source identifier for the RDS instance from
                              which the snapshot is created.

        :type instance_class: str
        :param instance_class: The compute and memory capacity of the
                               DBInstance.  Valid values are:
                               db.m1.small | db.m1.large | db.m1.xlarge |
                               db.m2.2xlarge | db.m2.4xlarge

        :type port: int
        :param port: Port number on which database accepts connections.
                     Valid values [1115-65535].  Defaults to 3306.

        :type availability_zone: str
        :param availability_zone: Name of the availability zone to place
                                  DBInstance into.

        :type multi_az: bool
        :param multi_az: If True, specifies the DB Instance will be
                         deployed in multiple availability zones.
                         Default is the API default.

        :type auto_minor_version_upgrade: bool
        :param auto_minor_version_upgrade: Indicates that minor engine
                                           upgrades will be applied
                                           automatically to the Read Replica
                                           during the maintenance window.
                                           Default is the API default.

        :type db_subnet_group_name: str
        :param db_subnet_group_name: A DB Subnet Group to associate with this DB Instance.
                                     If there is no DB Subnet Group, then it is a non-VPC DB
                                     instance.

        :rtype: :class:`boto.rds.dbinstance.DBInstance`
        :return: The newly created DBInstance
        )r   r(   r7   r>   r5   Nr<   r4   r9   ZRestoreDBInstanceFromDBSnapshot)rC   rD   rL   r   )
r    r   r,   rO   r!   rT   rX   rY   rZ   r/   r   r   r   "restore_dbinstance_from_dbsnapshot  s$    2 z0RDSConnection.restore_dbinstance_from_dbsnapshotc	           
      C   sj   ||d}	|rd|	d< n|r(|  |	d< |r4||	d< |r@||	d< |rL||	d< |dk	r\||	d	< | d
|	tS )aF  
        Create a new DBInstance from a point in time.

        :type source_instance_id: string
        :param source_instance_id: The identifier for the source DBInstance.

        :type target_instance_id: string
        :param target_instance_id: The identifier of the new DBInstance.

        :type use_latest: bool
        :param use_latest: If True, the latest snapshot availabile will
                           be used.

        :type restore_time: datetime
        :param restore_time: The date and time to restore from.  Only
                             used if use_latest is False.

        :type instance_class: str
        :param instance_class: The compute and memory capacity of the
                               DBInstance.  Valid values are:
                               db.m1.small | db.m1.large | db.m1.xlarge |
                               db.m2.2xlarge | db.m2.4xlarge

        :type port: int
        :param port: Port number on which database accepts connections.
                     Valid values [1115-65535].  Defaults to 3306.

        :type availability_zone: str
        :param availability_zone: Name of the availability zone to place
                                  DBInstance into.

        :type db_subnet_group_name: str
        :param db_subnet_group_name: A DB Subnet Group to associate with this DB Instance.
                                     If there is no DB Subnet Group, then it is a non-VPC DB
                                     instance.

        :rtype: :class:`boto.rds.dbinstance.DBInstance`
        :return: The newly created DBInstance
        )rc   ZTargetDBInstanceIdentifierrd   ZUseLatestRestorableTimeZRestoreTimer7   r>   r5   Nr9   ZRestoreDBInstanceToPointInTime)	isoformatrL   r   )
r    Zsource_instance_idZtarget_instance_idZ
use_latestZrestore_timeZdbinstance_classr!   rT   rZ   r/   r   r   r   %restore_dbinstance_from_point_in_time  s&    0
 z3RDSConnection.restore_dbinstance_from_point_in_timec                 C   sh   i }|r|r||d< ||d< |r,|  |d< |r<|  |d< |rH||d< |rT||d< | d|dtfgS )	a$  
        Get information about events related to your DBInstances,
        DBSecurityGroups and DBParameterGroups.

        :type source_identifier: str
        :param source_identifier: If supplied, the events returned will be
                                  limited to those that apply to the identified
                                  source.  The value of this parameter depends
                                  on the value of source_type.  If neither
                                  parameter is specified, all events in the time
                                  span will be returned.

        :type source_type: str
        :param source_type: Specifies how the source_identifier should
                            be interpreted.  Valid values are:
                            b-instance | db-security-group |
                            db-parameter-group | db-snapshot

        :type start_time: datetime
        :param start_time: The beginning of the time interval for events.
                           If not supplied, all available events will
                           be returned.

        :type end_time: datetime
        :param end_time: The ending of the time interval for events.
                         If not supplied, all available events will
                         be returned.

        :type max_records: int
        :param max_records: The maximum number of records to be returned.
                            If more results are available, a MoreToken will
                            be returned in the response that can be used to
                            retrieve additional records.  Default is 100.

        :type marker: str
        :param marker: The marker provided by a previous request.

        :rtype: list
        :return: A list of class:`boto.rds.event.Event`
        ZSourceIdentifierZ
SourceTypeZ	StartTimeZEndTimer)   r*   ZDescribeEventsr	   )r   r+   r	   )r    Zsource_identifierZsource_type
start_timeZend_timer-   r.   r/   r   r   r   get_all_events=  s    +zRDSConnection.get_all_eventsc                 C   s&   ||d}|  ||d | d|tS )a  
        Create a new Database Subnet Group.

        :type name: string
        :param name: The identifier for the db_subnet_group

        :type desc: string
        :param desc: A description of the db_subnet_group

        :type subnet_ids: list
        :param subnets: A list of the subnet identifiers to include in the
                        db_subnet_group

        :rtype: :class:`boto.rds.dbsubnetgroup.DBSubnetGroup
        :return: the created db_subnet_group
        )r9   DBSubnetGroupDescriptionSubnetIds.memberZCreateDBSubnetGrouprH   rL   r   )r    rF   desc
subnet_idsr/   r   r   r   create_db_subnet_groupv  s
    z$RDSConnection.create_db_subnet_groupc                 C   s   d|i}|  d|tS )z
        Delete a Database Subnet Group.

        :type name: string
        :param name: The identifier of the db_subnet_group to delete

        :rtype: :class:`boto.rds.dbsubnetgroup.DBSubnetGroup`
        :return: The deleted db_subnet_group.
        r9   ZDeleteDBSubnetGroup)rL   r   r   r   r   r   delete_db_subnet_group  s    z$RDSConnection.delete_db_subnet_groupc                 C   sJ   t  }|dk	r||d< |dk	r&||d< |dk	r6||d< | d|dtfgS )a5  
        Retrieve all the DBSubnetGroups in your account.

        :type name: str
        :param name: DBSubnetGroup name If supplied, only information about
                     this DBSubnetGroup will be returned. Otherwise, info
                     about all DBSubnetGroups will be returned.

        :type max_records: int
        :param max_records: The maximum number of records to be returned.
                            If more results are available, a Token will be
                            returned in the response that can be used to
                            retrieve additional records.  Default is 100.

        :type marker: str
        :param marker: The marker provided by a previous request.

        :rtype: list
        :return: A list of :class:`boto.rds.dbsubnetgroup.DBSubnetGroup`
        Nr9   r)   r*   ZDescribeDBSubnetGroupsr   )dictr+   r   )r    rF   r-   r.   r/   r   r   r   get_all_db_subnet_groups  s    z&RDSConnection.get_all_db_subnet_groupsc                 C   s<   d|i}|dk	r||d< |dk	r.|  ||d | d|tS )a  
        Modify a parameter group for your account.

        :type name: string
        :param name: The name of the new parameter group

        :type parameters: list of :class:`boto.rds.parametergroup.Parameter`
        :param parameters: The new parameters

        :rtype: :class:`boto.rds.parametergroup.ParameterGroup`
        :return: The newly created ParameterGroup
        r9   Nr   r   ZModifyDBSubnetGroupr   )r    rF   rs   r   r/   r   r   r   modify_db_subnet_group  s    z$RDSConnection.modify_db_subnet_groupc                 C   s8   ||||d}|  d|t}||_||_||_||_|S )ai  
        Create a new option group for your account.
        This will create the option group within the region you
        are currently connected to.

        :type name: string
        :param name: The name of the new option group

        :type engine_name: string
        :param engine_name: Specifies the name of the engine that this option
                            group should be associated with.

        :type major_engine_version: string
        :param major_engine_version: Specifies the major version of the engine
                                     that this option group should be
                                     associated with.

        :type description: string
        :param description: The description of the new option group

        :rtype: :class:`boto.rds.optiongroup.OptionGroup`
        :return: The newly created OptionGroup
        )r=   
EngineNameMajorEngineVersionZOptionGroupDescriptionZCreateOptionGroup)rL   r   rF   engine_namemajor_engine_versionrs   )r    rF   r   r   rs   r/   r^   r   r   r   create_option_group  s    z!RDSConnection.create_option_groupc                 C   s   d|i}|  d|S )z
        Delete an OptionGroup from your account.

        :type key_name: string
        :param key_name: The name of the OptionGroup to delete
        r=   ZDeleteOptionGroupr   r   r   r   r   delete_option_group  s    z!RDSConnection.delete_option_groupd   c                 C   sZ   i }|r||d< n|r*|r*||d< ||d< |r:t ||d< |rF||d< | d|dtfgS )a  
        Describes the available option groups.

        :type name: str
        :param name: The name of the option group to describe. Cannot be
                     supplied together with engine_name or major_engine_version.

        :type engine_name: str
        :param engine_name: Filters the list of option groups to only include
                            groups associated with a specific database engine.

        :type major_engine_version: datetime
        :param major_engine_version: Filters the list of option groups to only
                                     include groups associated with a specific
                                     database engine version. If specified, then
                                     engine_name must also be specified.

        :type max_records: int
        :param max_records: The maximum number of records to be returned.
                            If more results are available, a MoreToken will
                            be returned in the response that can be used to
                            retrieve additional records.  Default is 100.

        :type marker: str
        :param marker: The marker provided by a previous request.

        :rtype: list
        :return: A list of class:`boto.rds.optiongroup.OptionGroup`
        r=   r   r   r)   r*   ZDescribeOptionGroupsr   )intr+   r   )r    rF   r   r   r-   r.   r/   r   r   r   describe_option_groups  s     
z$RDSConnection.describe_option_groupsc                 C   sL   i }|r|r||d< ||d< |r,t ||d< |r8||d< | d|dtfgS )a`  
        Describes the available option group options.

        :type engine_name: str
        :param engine_name: Filters the list of option groups to only include
                            groups associated with a specific database engine.

        :type major_engine_version: datetime
        :param major_engine_version: Filters the list of option groups to only
                                     include groups associated with a specific
                                     database engine version. If specified, then
                                     engine_name must also be specified.

        :type max_records: int
        :param max_records: The maximum number of records to be returned.
                            If more results are available, a MoreToken will
                            be returned in the response that can be used to
                            retrieve additional records.  Default is 100.

        :type marker: str
        :param marker: The marker provided by a previous request.

        :rtype: list
        :return: A list of class:`boto.rds.optiongroup.Option`
        r   r   r)   r*   ZDescribeOptionGroupOptionsZOptionGroupOptions)r   r+   r   )r    r   r   r-   r.   r/   r   r   r   describe_option_group_options0  s    z+RDSConnection.describe_option_group_options)NNTNNNNNr   NNr   NTN)NNN)r1   r2   NNNNNNNFNTNNNNNN)Nr1   NN)NN)NNNNNNNNFFNNN)Frj   )NNN)NNN)r2   rj   )N)FN)NNN)N)NNN)NNN)NNNN)NNNNN)NNN)NNNNN)FNNNNN)NNNNNN)NNN)NN)N)NNNr   N)NNr   N)-__name__
__module____qualname__r   r   Z
APIVersionr   r'   r0   rb   rg   rh   ri   rk   rl   ro   rq   rt   r}   r   r   r   r   r   r   r   Zrevoke_security_groupr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   r%   r   r   I   s                          
'                  
  D    
G  
#             
   
  
    
$

  
  
 

   
&    
'    
'
-
(     
D      
C       
9

 
&
     
.     r   )r   Zboto.connectionr   Zboto.rds.dbinstancer   Zboto.rds.dbsecuritygroupr   Zboto.rds.optiongroupr   r   Zboto.rds.parametergroupr   Zboto.rds.dbsnapshotr   Zboto.rds.eventr	   Zboto.rds.regioninfor
   Zboto.rds.dbsubnetgroupr   Z#boto.rds.vpcsecuritygroupmembershipr   Zboto.regioninfor   r   Zboto.rds.logfiler   r   r   r   r   r   r   r   r   <module>   s    