def describe_volumes(self, xml_bytes): """Parse the XML returned by the C{DescribeVolumes} function. @param xml_bytes: XML bytes with a C{DescribeVolumesResponse} root element. @return: A list of L{Volume} instances. TODO: attachementSetItemResponseType#deleteOnTermination """ root = XML(xml_bytes) result = [] for volume_data in root.find("volumeSet"): volume_id = volume_data.findtext("volumeId") size = int(volume_data.findtext("size")) snapshot_id = volume_data.findtext("snapshotId") availability_zone = volume_data.findtext("availabilityZone") status = volume_data.findtext("status") create_time = volume_data.findtext("createTime") create_time = datetime.strptime( create_time[:19], "%Y-%m-%dT%H:%M:%S") volume = model.Volume( volume_id, size, status, create_time, availability_zone, snapshot_id) result.append(volume) for attachment_data in volume_data.find("attachmentSet"): instance_id = attachment_data.findtext("instanceId") device = attachment_data.findtext("device") status = attachment_data.findtext("status") attach_time = attachment_data.findtext("attachTime") attach_time = datetime.strptime( attach_time[:19], "%Y-%m-%dT%H:%M:%S") attachment = model.Attachment( instance_id, device, status, attach_time) volume.attachments.append(attachment) return result
def _parse_describe_volumes(self, xml_bytes): root = XML(xml_bytes) result = [] for volume_data in root.find("volumeSet"): volume_id = volume_data.findtext("volumeId") size = int(volume_data.findtext("size")) status = volume_data.findtext("status") availability_zone = volume_data.findtext("availabilityZone") snapshot_id = volume_data.findtext("snapshotId") create_time = volume_data.findtext("createTime") create_time = datetime.strptime(create_time[:19], "%Y-%m-%dT%H:%M:%S") volume = model.Volume(volume_id, size, status, create_time, availability_zone, snapshot_id) result.append(volume) for attachment_data in volume_data.find("attachmentSet"): instance_id = attachment_data.findtext("instanceId") status = attachment_data.findtext("status") device = attachment_data.findtext("device") attach_time = attachment_data.findtext("attachTime") attach_time = datetime.strptime(attach_time[:19], "%Y-%m-%dT%H:%M:%S") attachment = model.Attachment(instance_id, device, status, attach_time) volume.attachments.append(attachment) return result
def _parse_create_volume(self, xml_bytes): root = XML(xml_bytes) volume_id = root.findtext("volumeId") size = int(root.findtext("size")) status = root.findtext("status") create_time = root.findtext("createTime") availability_zone = root.findtext("availabilityZone") snapshot_id = root.findtext("snapshotId") create_time = datetime.strptime(create_time[:19], "%Y-%m-%dT%H:%M:%S") volume = model.Volume(volume_id, size, status, create_time, availability_zone, snapshot_id) return volume
def create_volume(self, xml_bytes): """Parse the XML returned by the C{CreateVolume} function. @param xml_bytes: XML bytes with a C{CreateVolumeResponse} root element. @return: The L{Volume} instance created. """ root = XML(xml_bytes) volume_id = root.findtext("volumeId") size = int(root.findtext("size")) status = root.findtext("status") create_time = root.findtext("createTime") availability_zone = root.findtext("availabilityZone") snapshot_id = root.findtext("snapshotId") create_time = datetime.strptime(create_time[:19], "%Y-%m-%dT%H:%M:%S") volume = model.Volume(volume_id, size, status, create_time, availability_zone, snapshot_id) return volume