U
    W+ds                     @   s@   d Z ddlmZ ddlmZ G dd deZG dd deZdS )	z0
Represents an EC2 Elastic Block Store Snapshot
    )TaggedEC2Object)Zonec                       s   e Zd ZdZdZd fdd	Zdd Zdd	 Zd
d ZdddZ	dddZ
dddZdddZd ddZd!ddZd"ddZ  ZS )#Snapshota  
    Represents an EBS snapshot.
    :ivar id: The unique ID of the snapshot.
    :ivar volume_id: The ID of the volume this snapshot was created
    from.
    :ivar status: The status of the snapshot.
    :ivar progress: The percent complete of the snapshot.
    :ivar start_time: The timestamp of when the snapshot was created.
    :ivar owner_id: The id of the account that owns the snapshot.
    :ivar owner_alias: The alias of the account that owns the snapshot.
    :ivar volume_size: The size (in GB) of the volume the snapshot was created from.
    :ivar description: The description of the snapshot.
    :ivar encrypted: True if this snapshot is encrypted
    createVolumePermissionNc                    sP   t t| | d | _d | _d | _d | _d | _d | _d | _	d | _
d | _d | _d S N)superr   __init__id	volume_idstatusprogress
start_timeowner_idowner_aliasvolume_sizedescription	encrypted)self
connection	__class__ 5/tmp/pip-unpacked-wheel-dlxw5sjy/boto/ec2/snapshot.pyr   0   s    zSnapshot.__init__c                 C   s
   d| j  S )NzSnapshot:%s)r	   )r   r   r   r   __repr__=   s    zSnapshot.__repr__c                 C   s   |dkr|| _ n|dkr || _n|dkr0|| _n|dkr@|| _n|dkrP|| _np|dkr`|| _n`|dkrzt|| _W q   || _Y qX n4|dkr|| _n$|d	kr|	 d
k| _
nt| || d S )N
snapshotIdZvolumeIdr   Z	startTimeZownerIdZ
ownerAliasZ
volumeSizer   r   true)r	   r
   r   r   r   r   intr   r   lowerr   setattrr   namevaluer   r   r   r   
endElement@   s,    zSnapshot.endElementc                 C   s   |j | _ |j| _d S r   )r   r   )r   updatedr   r   r   _updateY   s    zSnapshot._updateFc                 C   sH   | j j| jg|d}t|dkr0| |d  n|rBtd| j | jS )a  
        Update the data associated with this snapshot by querying EC2.

        :type validate: bool
        :param validate: By default, if EC2 returns no data about the
                         snapshot the update method returns quietly.  If
                         the validate param is True, however, it will
                         raise a ValueError exception if no data is
                         returned from EC2.
        dry_runr   z%s is not a valid Snapshot ID)r   Zget_all_snapshotsr	   lenr$   
ValueErrorr   )r   validater&   rsr   r   r   update]   s    zSnapshot.updatec                 C   s   | j j| j|dS Nr%   )r   Zdelete_snapshotr	   r   r&   r   r   r   deleteo   s    zSnapshot.deletec                 C   s   | j j| j| j|d}|jS r,   )r   Zget_snapshot_attributer	   AttrNameattrs)r   r&   r0   r   r   r   get_permissionsr   s    zSnapshot.get_permissionsc                 C   s   | j j| j| jd|||dS )Naddr%   r   Zmodify_snapshot_attributer	   r/   r   user_idsgroupsr&   r   r   r   sharez   s    
zSnapshot.sharec                 C   s   | j j| j| jd|||dS )Nremover%   r3   r4   r   r   r   unshare   s    
zSnapshot.unsharec                 C   s   | j j| j| j|dS r,   )r   Zreset_snapshot_attributer	   r/   r-   r   r   r   reset_permissions   s
    zSnapshot.reset_permissionsc              	   C   s.   t |tr|j}| jj||| j||| j|dS )aq  
        Create a new EBS Volume from this Snapshot

        :type zone: string or :class:`boto.ec2.zone.Zone`
        :param zone: The availability zone in which the Volume will be created.

        :type size: int
        :param size: The size of the new volume, in GiB. (optional). Defaults to
            the size of the snapshot.

        :type volume_type: string
        :param volume_type: The type of the volume. (optional).  Valid
            values are: standard | io1 | gp2.

        :type iops: int
        :param iops: The provisioned IOPs you want to associate with
            this volume. (optional)
        r%   )
isinstancer   r    r   create_volumer	   r   )r   zonesizeZvolume_typeZiopsr&   r   r   r   r<      s    
zSnapshot.create_volume)N)FF)F)F)NNF)NNF)F)NNNF)__name__
__module____qualname____doc__r/   r   r   r"   r$   r+   r.   r1   r7   r9   r:   r<   __classcell__r   r   r   r   r      s   





  r   c                   @   s&   e Zd ZdddZdd Zdd ZdS )	SnapshotAttributeNc                 C   s   d | _ i | _d S r   )snapshot_idr0   )r   parentr   r   r   r      s    zSnapshotAttribute.__init__c                 C   s   d S r   r   )r   r    r0   r   r   r   r   startElement   s    zSnapshotAttribute.startElementc                 C   s   |dkrd| _ n|dkrBd| jkr4| jd | q|g| jd< nN|dkrtd| jkrf| jd | q|g| jd< n|dkr|| _nt| || d S )Nr   Zcreate_volume_permissiongroupr6   ZuserIdr5   r   )r    r0   appendrE   r   r   r   r   r   r"      s    

zSnapshotAttribute.endElement)N)r?   r@   rA   r   rG   r"   r   r   r   r   rD      s   
rD   N)rB   Zboto.ec2.ec2objectr   Zboto.ec2.zoner   r   objectrD   r   r   r   r   <module>   s
    