U
    W+d                     @   sD   d Z ddlmZ G dd deZG dd deZG dd deZd	S )
z
Represents an DBSecurityGroup
    )SecurityGroupc                   @   sN   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdddZ	dddZ
dS )DBSecurityGroupa  
    Represents an RDS database security group

    Properties reference available from the AWS documentation at
    http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DeleteDBSecurityGroup.html

    :ivar Status: The current status of the security group. Possible values are
        [ active, ? ]. Reference documentation lacks specifics of possibilities
    :ivar connection: :py:class:`boto.rds.RDSConnection` associated with the current object
    :ivar description: The description of the security group
    :ivar ec2_groups: List of :py:class:`EC2 Security Group
        <boto.ec2.securitygroup.SecurityGroup>` objects that this security
        group PERMITS
    :ivar ip_ranges: List of :py:class:`boto.rds.dbsecuritygroup.IPRange`
        objects (containing CIDR addresses) that this security group PERMITS
    :ivar name: Name of the security group
    :ivar owner_id: ID of the owner of the security group. Can be 'None'
    Nc                 C   s(   || _ || _|| _|| _g | _g | _d S N)
connectionowner_idnamedescription
ec2_groups	ip_ranges)selfr   r   r   r    r   </tmp/pip-unpacked-wheel-dlxw5sjy/boto/rds/dbsecuritygroup.py__init__.   s    zDBSecurityGroup.__init__c                 C   s
   d| j  S )NzDBSecurityGroup:%sr   r   r   r   r   __repr__7   s    zDBSecurityGroup.__repr__c                 C   sH   |dkr t | }| j| |S |dkr@t| }| j| |S d S d S )NIPRangeEC2SecurityGroup)r   r
   appendr   r	   )r   r   attrsr   ZcidrZec2_grpr   r   r   startElement:   s    zDBSecurityGroup.startElementc                 C   sJ   |dkr|| _ n6|dkr || _n&|dkr0|| _n|dkr:nt| || d S )NZOwnerIdZDBSecurityGroupNameZDBSecurityGroupDescriptionZIPRanges)r   r   r   setattrr   r   valuer   r   r   r   
endElementF   s    zDBSecurityGroup.endElementc                 C   s   | j | jS r   )r   Zdelete_dbsecurity_groupr   r   r   r   r   deleteR   s    zDBSecurityGroup.deletec                 C   s4   t |tr|j}|j}nd}d}| j| j|||S )a  
        Add a new rule to this DBSecurity group.
        You need to pass in either a CIDR block to authorize or
        and EC2 SecurityGroup.

        :type cidr_ip: string
        :param cidr_ip: A valid CIDR IP range to authorize

        :type ec2_group: :class:`boto.ec2.securitygroup.SecurityGroup`
        :param ec2_group: An EC2 security group to authorize

        :rtype: bool
        :return: True if successful.
        N)
isinstancer   r   r   r   Zauthorize_dbsecurity_groupr   cidr_ipZ	ec2_groupZ
group_nameZgroup_owner_idr   r   r   	authorizeU   s    

zDBSecurityGroup.authorizec                 C   s<   t |tr*|j}|j}| jj| j||dS | jj| j|dS )a  
        Revoke access to a CIDR range or EC2 SecurityGroup.
        You need to pass in either a CIDR block or
        an EC2 SecurityGroup from which to revoke access.

        :type cidr_ip: string
        :param cidr_ip: A valid CIDR IP range to revoke

        :type ec2_group: :class:`boto.ec2.securitygroup.SecurityGroup`
        :param ec2_group: An EC2 security group to revoke

        :rtype: bool
        :return: True if successful.
        )Zec2_security_group_nameZec2_security_group_owner_idr   )r   r   r   r   r   Zrevoke_dbsecurity_groupr   r   r   r   revokeo   s    
 zDBSecurityGroup.revoke)NNNN)NN)NN)__name__
__module____qualname____doc__r   r   r   r   r   r   r!   r   r   r   r   r      s       
	
r   c                   @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )r   zj
    Describes a CIDR address range for use in a DBSecurityGroup

    :ivar cidr_ip: IP Address range
    Nc                 C   s   || _ d | _d | _d S r   )parentr   statusr   r&   r   r   r   r      s    zIPRange.__init__c                 C   s
   d| j  S )Nz
IPRange:%sr    r   r   r   r   r      s    zIPRange.__repr__c                 C   s   d S r   r   r   r   r   r   r   r   r   r      s    zIPRange.startElementc                 C   s0   |dkr|| _ n|dkr || _nt| || d S )NZCIDRIPZStatus)r   r'   r   r   r   r   r   r      s
    zIPRange.endElement)Nr"   r#   r$   r%   r   r   r   r   r   r   r   r   r      s
   
r   c                   @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )r   zF
    Describes an EC2 security group for use in a DBSecurityGroup
    Nc                 C   s   || _ d | _d | _d S r   )r&   r   r   r(   r   r   r   r      s    zEC2SecurityGroup.__init__c                 C   s
   d| j  S )NzEC2SecurityGroup:%sr   r   r   r   r   r      s    zEC2SecurityGroup.__repr__c                 C   s   d S r   r   r)   r   r   r   r      s    zEC2SecurityGroup.startElementc                 C   s0   |dkr|| _ n|dkr || _nt| || d S )NZEC2SecurityGroupNameZEC2SecurityGroupOwnerId)r   r   r   r   r   r   r   r      s
    zEC2SecurityGroup.endElement)Nr*   r   r   r   r   r      s
   
r   N)r%   Zboto.ec2.securitygroupr   objectr   r   r   r   r   r   r   <module>   s   o