o
    ȷes                     @   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__ H/var/www/ideatree/venv/lib/python3.10/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	|| _ d S |dkr|| _d S |dkr|| _d S |dkr$|| _d S |dkr-|| _d S |dkr6|| _d S |dkrLzt|| _W d S    || _Y d S |dkrU|| _d S |d	krb|	 d
k| _
d S t| || d S )N
snapshotIdvolumeIdr   	startTimeownerId
ownerAlias
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   sL   | j j| jg|d}t|dkr| |d  | jS |r#t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   get_all_snapshotsr	   lenr)   
ValueErrorr   )r   validater+   rsr   r   r   update]   s   zSnapshot.updatec                 C   s   | j j| j|dS Nr*   )r   delete_snapshotr	   r   r+   r   r   r   deleteo   s   zSnapshot.deletec                 C   s   | j j| j| j|d}|jS r2   )r   get_snapshot_attributer	   AttrNameattrs)r   r+   r8   r   r   r   get_permissionsr   s   zSnapshot.get_permissionsc                 C      | j j| j| jd|||dS )Naddr*   r   modify_snapshot_attributer	   r7   r   user_idsgroupsr+   r   r   r   sharez      
zSnapshot.sharec                 C   r:   )Nremover*   r<   r>   r   r   r   unshare   rB   zSnapshot.unsharec                 C   s   | j j| j| j|dS r2   )r   reset_snapshot_attributer	   r7   r4   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sizevolume_typeiopsr+   r   r   r   rH      s   
zSnapshot.create_volumer   )FF)F)NNF)NNNF)__name__
__module____qualname____doc__r7   r   r   r'   r)   r1   r5   r9   rA   rD   rF   rH   __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_idr8   )r   parentr   r   r   r      s   
zSnapshotAttribute.__init__c                 C   s   d S r   r   )r   r%   r8   r   r   r   r   startElement   s   zSnapshotAttribute.startElementc                 C   s   |dkr	d| _ d S |dkr$d| jv r| jd | d S |g| jd< d S |dkr?d| jv r7| jd | d S |g| jd< d S |dkrH|| _d S t| || d S )Nr   create_volume_permissiongroupr@   userIdr?   r   )r%   r8   appendrS   r#   r$   r   r   r   r'      s   



zSnapshotAttribute.endElementr   )rM   rN   rO   r   rU   r'   r   r   r   r   rR      s    
rR   N)rP   boto.ec2.ec2objectr   boto.ec2.zoner   r   objectrR   r   r   r   r   <module>   s    