B
    ?F[s                 @   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__ 0lib/python3.7/site-packages/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ry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 )N)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   Zvalidater"   Zrsr   r   r   update]   s    zSnapshot.updatec             C   s   | j j| j|dS )N)r"   )r   Zdelete_snapshotr   )r   r"   r   r   r   deleteo   s    zSnapshot.deletec             C   s   | j j| j| j|d}|jS )N)r"   )r   Zget_snapshot_attributer   AttrNameattrs)r   r"   r(   r   r   r   get_permissionsr   s
    zSnapshot.get_permissionsc             C   s   | j j| j| jd|||dS )Nadd)r"   )r   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remove)r"   )r   r+   r   r'   )r   r,   r-   r"   r   r   r   unshare   s    
zSnapshot.unsharec             C   s   | j j| j| j|dS )N)r"   )r   Zreset_snapshot_attributer   r'   )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   ZzonesizeZvolume_typeZiopsr"   r   r   r   r3      s    
zSnapshot.create_volume)N)FF)F)F)NNF)NNF)F)NNNF)__name__
__module____qualname____doc__r'   r   r   r   r!   r%   r&   r)   r.   r0   r1   r3   __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 )N)snapshot_idr(   )r   parentr   r   r   r      s    zSnapshotAttribute.__init__c             C   s   d S )Nr   )r   r   r(   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groupr-   ZuserIdr,   r   )r   r(   appendr;   r   )r   r   r   r   r   r   r   r      s    

zSnapshotAttribute.endElement)N)r5   r6   r7   r   r=   r   r   r   r   r   r:      s   
r:   N)r8   Zboto.ec2.ec2objectr   Zboto.ec2.zoner   r   objectr:   r   r   r   r   <module>   s
    