o ckF[(@s\dZddlmZddlmZddlmZGdddeZGdddeZ Gd d d eZ d S) z0 Represents an EC2 Elastic Block Storage Volume ) ResultSet)Tag)TaggedEC2ObjectcseZdZdZdfdd ZddZfddZd d Zd d ZdddZ d ddZ d ddZ dddZ d!ddZ ddZddZd"ddZZS)#Volumea Represents an EBS volume. :ivar id: The unique ID of the volume. :ivar create_time: The timestamp of when the volume was created. :ivar status: The status of the volume. :ivar size: The size (in GB) of the volume. :ivar snapshot_id: The ID of the snapshot this volume was created from, if applicable. :ivar attach_data: An AttachmentSet object. :ivar zone: The availability zone this volume is in. :ivar type: The type of volume (standard or consistent-iops) :ivar iops: If this volume is of type consistent-iops, this is the number of IOPS provisioned (10-300). :ivar encrypted: True if this volume is encrypted. NcsPtt||d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ dSN) superr__init__id create_timestatussize snapshot_id attach_datazonetypeiops encrypted)self connection __class__1/usr/lib/python3/dist-packages/boto/ec2/volume.pyr2s zVolume.__init__cC d|jS)Nz Volume:%sr rrrr__repr__? zVolume.__repr__csXtt||||}|dur|S|dkrt|_|jS|dkr*tdtfg|_|jSdS)N attachmentSettagSetitem)rr startElement AttachmentSetrrrtags)rnameattrsrretvalrrrr!BszVolume.startElementcCs|dkr ||_dS|dkr||_dS|dkr!|dkr||_dSdS|dkr,t||_dS|dkr5||_dS|dkr>||_dS|dkrG||_dS|d krRt||_dS|d kr_| d k|_ dSt |||dS) NvolumeId createTimer r snapshotIdavailabilityZone volumeTyperrtrue) r r r intr r rrrlowerrsetattrrr$valuerrrr endElementOs*      zVolume.endElementcCs|j|jdSr)__dict__update)rupdatedrrr_updatefszVolume._updateFcs^jjjg|d}fdd|D}t|dkr#|djS|r,tdjjS)a Update the data associated with this volume by querying EC2. :type validate: bool :param validate: By default, if EC2 returns no data about the volume 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_runcsg|] }|jjkr|qSrr).0xrrr ysz!Volume.update..rz%s is not a valid Volume ID)rget_all_volumesr lenr7 ValueErrorr )rvalidater9 unfiltered_rsrsrrrr5is  z Volume.updatecCs|jj|j|dS)zc Delete this EBS volume. :rtype: bool :return: True if successful r8)r delete_volumer )rr9rrrdeletesz Volume.deletecCs|jj|j|||dS)a Attach this EBS volume to an EC2 instance. :type instance_id: str :param instance_id: The ID of the EC2 instance to which it will be attached. :type device: str :param device: The device on the instance through which the volume will be exposed (e.g. /dev/sdh) :rtype: bool :return: True if successful r8)r attach_volumer )r instance_iddevicer9rrrattachs z Volume.attachcCs<d}|jr |jj}d}|jr|jj}|jj|j||||dS)a Detach this EBS volume from an EC2 instance. :type force: bool :param force: Forces detachment if the previous detachment attempt did not occur cleanly. This option can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance will not have an opportunity to flush file system caches nor file system meta data. If you use this option, you must perform file system check and repair procedures. :rtype: bool :return: True if successful Nr8)rrFrGr detach_volumer )rforcer9rFrGrrrdetachsz Volume.detachcCs|jj|j||dS)a Create a snapshot of this EBS Volume. :type description: str :param description: A description of the snapshot. Limited to 256 characters. :rtype: :class:`boto.ec2.snapshot.Snapshot` :return: The created Snapshot object r8)rcreate_snapshotr )r descriptionr9rrrrLs  zVolume.create_snapshotcCs|jS)zW Returns the state of the volume. Same value as the status attribute. )r rrrr volume_stateszVolume.volume_statecCsd}|jr |jj}|S)z+ Get the attachment state. N)rr )rstaterrrattachment_stateszVolume.attachment_statecCs:|jj|||d}g}|D] }|j|jkr||q |S)a Get all snapshots related to this volume. Note that this requires that all available snapshots for the account be retrieved from EC2 first and then the list is filtered client-side to contain only those for this volume. :type owner: str :param owner: If present, only the snapshots owned by the specified user will be returned. Valid values are: * self * amazon * AWS Account ID :type restorable_by: str :param restorable_by: If present, only the snapshots that are restorable by the specified account id will be returned. :rtype: list of L{boto.ec2.snapshot.Snapshot} :return: The requested Snapshot objects )owner restorable_byr9)rget_all_snapshots volume_idr append)rrQrRr9rBminesnaprrr snapshotss  zVolume.snapshotsr)FF)F)NF)NNF)__name__ __module__ __qualname____doc__rrr!r3r7r5rDrHrKrLrNrPrX __classcell__rrrrr s       rc@s0eZdZdZddZddZddZdd Zd S) r"a Represents an EBS attachmentset. :ivar id: The unique ID of the volume. :ivar instance_id: The unique ID of the attached instance :ivar status: The status of the attachment :ivar attach_time: Attached since :ivar device: The device the instance has mapped cCs"d|_d|_d|_d|_d|_dSr)r rFr attach_timerGrrrrr s  zAttachmentSet.__init__cCr)NzAttachmentSet:%srrrrrrrzAttachmentSet.__repr__cCsdSrrrr$r%rrrrr!szAttachmentSet.startElementcCsj|dkr ||_dS|dkr||_dS|dkr||_dS|dkr$||_dS|dkr-||_dSt|||dS)Nr' instanceIdr attachTimerG)r rFr r^rGr0r1rrrr3s     zAttachmentSet.endElementN)rYrZr[r\rrr!r3rrrrr"s   r"c@s&eZdZdddZddZddZdS) VolumeAttributeNcCsd|_d|_i|_dSr)r _key_namer%)rparentrrrr(s zVolumeAttribute.__init__cCs|dkr||_dS)N autoEnableIO)rcr_rrrr!-szVolumeAttribute.startElementcCsV|dkr|dkrd|j|j<dSd|j|j<dS|dkr#||_dSt|||dS)Nr2r-TFr')r/r%rcr r0r1rrrr32s  zVolumeAttribute.endElementr)rYrZr[rr!r3rrrrrb's  rbN) r\boto.resultsetr boto.ec2.tagrboto.ec2.ec2objectrrobjectr"rbrrrrs   b&