def _parse_versioning_config(self, xml_bytes): """Parse a C{VersioningConfiguration} XML document.""" root = XML(xml_bytes) mfa_delete = root.findtext("MfaDelete") status = root.findtext("Status") return VersioningConfiguration(mfa_delete=mfa_delete, status=status)
def _parse_get_bucket(self, response): status, xml_bytes = response root = XML(xml_bytes) name = root.findtext("Name") prefix = root.findtext("Prefix") marker = root.findtext("Marker") max_keys = root.findtext("MaxKeys") is_truncated = root.findtext("IsTruncated") contents = [] for content_data in root.findall("Contents"): key = content_data.findtext("Key") date_text = content_data.findtext("LastModified") modification_date = parseTime(date_text) etag = content_data.findtext("ETag") size = content_data.findtext("Size") storage_class = content_data.findtext("StorageClass") owner_id = content_data.findtext("Owner/ID") owner_display_name = content_data.findtext("Owner/DisplayName") owner = ItemOwner(owner_id, owner_display_name) content_item = BucketItem(key, modification_date, etag, size, storage_class, owner) contents.append(content_item) common_prefixes = [] for prefix_data in root.findall("CommonPrefixes"): common_prefixes.append(prefix_data.text) return BucketListing(name, prefix, marker, max_keys, is_truncated, contents, common_prefixes)
def _parse_get_bucket(self, xml_bytes): root = XML(xml_bytes) name = root.findtext("Name") prefix = root.findtext("Prefix") marker = root.findtext("Marker") max_keys = root.findtext("MaxKeys") is_truncated = root.findtext("IsTruncated") contents = [] for content_data in root.findall("Contents"): key = content_data.findtext("Key") date_text = content_data.findtext("LastModified") modification_date = parseTime(date_text) etag = content_data.findtext("ETag") size = content_data.findtext("Size") storage_class = content_data.findtext("StorageClass") owner_id = content_data.findtext("Owner/ID") owner_display_name = content_data.findtext("Owner/DisplayName") owner = ItemOwner(owner_id, owner_display_name) content_item = BucketItem(key, modification_date, etag, size, storage_class, owner) contents.append(content_item) common_prefixes = [] for prefix_data in root.findall("CommonPrefixes"): common_prefixes.append(prefix_data.text) return BucketListing(name, prefix, marker, max_keys, is_truncated, contents, common_prefixes)
def _parse_website_config(self, xml_bytes): """Parse a C{WebsiteConfiguration} XML document.""" root = XML(xml_bytes) index_suffix = root.findtext("IndexDocument/Suffix") error_key = root.findtext("ErrorDocument/Key") return WebsiteConfiguration(index_suffix, error_key)
def _parse_website_config(self, response): """Parse a C{WebsiteConfiguration} XML document.""" status, xml_bytes = response root = XML(xml_bytes) index_suffix = root.findtext("IndexDocument/Suffix") error_key = root.findtext("ErrorDocument/Key") return WebsiteConfiguration(index_suffix, error_key)
def _parse_versioning_config(self, response): """Parse a C{VersioningConfiguration} XML document.""" status, xml_bytes = response root = XML(xml_bytes) mfa_delete = root.findtext("MfaDelete") status = root.findtext("Status") return VersioningConfiguration(mfa_delete=mfa_delete, status=status)
def import_keypair(self, xml_bytes, key_material): """Extract the key name and the fingerprint from the result. TODO: there is no corresponding method in the 2009-11-30 version of the ec2 wsdl. Delete this? """ keypair_data = XML(xml_bytes) key_name = keypair_data.findtext("keyName") key_fingerprint = keypair_data.findtext("keyFingerprint") return model.Keypair(key_name, key_fingerprint, key_material)
def from_xml(cls, xml_bytes): """ Create an instance of this class from XML bytes. @param xml_bytes: C{str} bytes of XML to parse @return: an instance of L{MultipartCompletionResponse} """ root = XML(xml_bytes) return cls(root.findtext('Location'), root.findtext('Bucket'), root.findtext('Key'), root.findtext('ETag'))
def _parse_create_snapshot(self, xml_bytes): root = XML(xml_bytes) snapshot_id = root.findtext("snapshotId") volume_id = root.findtext("volumeId") status = root.findtext("status") start_time = root.findtext("startTime") start_time = datetime.strptime(start_time[:19], "%Y-%m-%dT%H:%M:%S") progress = root.findtext("progress")[:-1] progress = float(progress or "0") / 100.0 return model.Snapshot(snapshot_id, volume_id, status, start_time, progress)
def from_xml(cls, xml_bytes): """ Create an instance of this from XML bytes. @param xml_bytes: C{str} bytes of XML to parse @return: an instance of L{MultipartInitiationResponse} """ root = XML(xml_bytes) return cls(root.findtext('Bucket'), root.findtext('Key'), root.findtext('UploadId'))
def _parse_create_snapshot(self, xml_bytes): root = XML(xml_bytes) snapshot_id = root.findtext("snapshotId") volume_id = root.findtext("volumeId") status = root.findtext("status") start_time = root.findtext("startTime") start_time = datetime.strptime(start_time[:19], "%Y-%m-%dT%H:%M:%S") progress = root.findtext("progress")[:-1] progress = float(progress or "0") / 100. return model.Snapshot(snapshot_id, volume_id, status, start_time, progress)
def attach_volume(self, xml_bytes): """Parse the XML returned by the C{AttachVolume} function. @param xml_bytes: XML bytes with a C{AttachVolumeResponse} root element. @return: a C{dict} with status and attach_time keys. """ root = XML(xml_bytes) status = root.findtext("status") attach_time = root.findtext("attachTime") attach_time = datetime.strptime(attach_time[:19], "%Y-%m-%dT%H:%M:%S") return {"status": status, "attach_time": attach_time}
def create_keypair(self, xml_bytes): """Parse the XML returned by the C{CreateKeyPair} function. @param xml_bytes: XML bytes with a C{CreateKeyPairResponse} root element. @return: The L{Keypair} instance created. """ keypair_data = XML(xml_bytes) key_name = keypair_data.findtext("keyName") key_fingerprint = keypair_data.findtext("keyFingerprint") key_material = keypair_data.findtext("keyMaterial") return model.Keypair(key_name, key_fingerprint, key_material)
def attach_volume(self, xml_bytes): """Parse the XML returned by the C{AttachVolume} function. @param xml_bytes: XML bytes with a C{AttachVolumeResponse} root element. @return: a C{dict} with status and attach_time keys. """ root = XML(xml_bytes) status = root.findtext("status") attach_time = root.findtext("attachTime") attach_time = datetime.strptime( attach_time[:19], "%Y-%m-%dT%H:%M:%S") return {"status": status, "attach_time": attach_time}
def _parse_notification_config(self, xml_bytes): """Parse a C{NotificationConfiguration} XML document.""" root = XML(xml_bytes) topic = root.findtext("TopicConfiguration/Topic") event = root.findtext("TopicConfiguration/Event") return NotificationConfiguration(topic, event)
def allocate_address(self, xml_bytes): """Parse the XML returned by the C{AllocateAddress} function. @param xml_bytes: XML bytes with a C{AllocateAddress} root element. @return: The public ip address as a string. """ address_data = XML(xml_bytes) return address_data.findtext("publicIp")
def create_snapshot(self, xml_bytes): """Parse the XML returned by the C{CreateSnapshot} function. @param xml_bytes: XML bytes with a C{CreateSnapshotResponse} root element. @return: The L{Snapshot} instance created. """ root = XML(xml_bytes) snapshot_id = root.findtext("snapshotId") volume_id = root.findtext("volumeId") status = root.findtext("status") start_time = root.findtext("startTime") start_time = datetime.strptime(start_time[:19], "%Y-%m-%dT%H:%M:%S") progress = root.findtext("progress")[:-1] progress = float(progress or "0") / 100. return model.Snapshot(snapshot_id, volume_id, status, start_time, progress)
def truth_return(self, xml_bytes): """Parse the XML for a truth value. @param xml_bytes: XML bytes. @return: True if the node contains "return" otherwise False. """ root = XML(xml_bytes) return root.findtext("return") == "true"
def _parse_notification_config(self, response): """Parse a C{NotificationConfiguration} XML document.""" status, xml_bytes = response root = XML(xml_bytes) topic = root.findtext("TopicConfiguration/Topic") event = root.findtext("TopicConfiguration/Event") return NotificationConfiguration(topic, event)
def _parse_run_instances(self, xml_bytes): """ Parse the reservations XML payload that is returned from an AWS RunInstances API call. """ root = XML(xml_bytes) # Get the security group information. groups = [] for group_data in root.find("groupSet"): group_id = group_data.findtext("groupId") groups.append(group_id) # Create a reservation object with the parsed data. reservation = model.Reservation( reservation_id=root.findtext("reservationId"), owner_id=root.findtext("ownerId"), groups=groups ) # Get the list of instances. instances = self._parse_instances_set(root, reservation) return instances
def create_snapshot(self, xml_bytes): """Parse the XML returned by the C{CreateSnapshot} function. @param xml_bytes: XML bytes with a C{CreateSnapshotResponse} root element. @return: The L{Snapshot} instance created. """ root = XML(xml_bytes) snapshot_id = root.findtext("snapshotId") volume_id = root.findtext("volumeId") status = root.findtext("status") start_time = root.findtext("startTime") start_time = datetime.strptime( start_time[:19], "%Y-%m-%dT%H:%M:%S") progress = root.findtext("progress")[:-1] progress = float(progress or "0") / 100. return model.Snapshot( snapshot_id, volume_id, status, start_time, progress)
def _parse_run_instances(self, xml_bytes): """ Parse the reservations XML payload that is returned from an AWS RunInstances API call. """ root = XML(xml_bytes) # Get the security group information. groups = [] for group_data in root.find("groupSet"): group_id = group_data.findtext("groupId") groups.append(group_id) # Create a reservation object with the parsed data. reservation = model.Reservation( reservation_id=root.findtext("reservationId"), owner_id=root.findtext("ownerId"), groups=groups) # Get the list of instances. instances = self._parse_instances_set(root, reservation) return instances
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
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")) snapshot_id = root.findtext("snapshotId") availability_zone = root.findtext("availabilityZone") status = root.findtext("status") create_time = root.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) return volume
def import_keypair(self, xml_bytes, key_material): """Extract the key name and the fingerprint from the result.""" keypair_data = XML(xml_bytes) key_name = keypair_data.findtext("keyName") key_fingerprint = keypair_data.findtext("keyFingerprint") return model.Keypair(key_name, key_fingerprint, key_material)
def create_security_group(self, xml_bytes): root = XML(xml_bytes) return root.findtext("groupId")
def _parse_truth_return(self, xml_bytes): root = XML(xml_bytes) return root.findtext("return") == "true"
def parse_error_message(data): element = XML(data).find('Error') _type = element.findtext('Type').strip() message = element.findtext('Message').strip() return _type, message
args.append(("max-keys", "%d" % (max_keys,))) if args: object_name = "?" + urlencode(args) else: object_name = None details = self._details( method=b"GET", url_context=self._url_context(bucket=bucket, object_name=object_name), ) d = self._submit(self._query_factory(details)) d.addCallback(self._parse_get_bucket) return d def _parse_get_bucket(self, (response, xml_bytes)): root = XML(xml_bytes) name = root.findtext("Name") prefix = root.findtext("Prefix") marker = root.findtext("Marker") max_keys = root.findtext("MaxKeys") is_truncated = root.findtext("IsTruncated") contents = [] for content_data in root.findall("Contents"): key = content_data.findtext("Key") date_text = content_data.findtext("LastModified") modification_date = parseTime(date_text) etag = content_data.findtext("ETag") size = content_data.findtext("Size") storage_class = content_data.findtext("StorageClass") owner_id = content_data.findtext("Owner/ID") owner_display_name = content_data.findtext("Owner/DisplayName")
def parse_get_queue_url(data): element = XML(data).find('GetQueueUrlResult') return element.findtext('QueueUrl').strip()
def _parse_create_keypair(self, xml_bytes): keypair_data = XML(xml_bytes) key_name = keypair_data.findtext("keyName") key_fingerprint = keypair_data.findtext("keyFingerprint") key_material = keypair_data.findtext("keyMaterial") return model.Keypair(key_name, key_fingerprint, key_material)
def parse_create_queue(data): element = XML(data).find('CreateQueueResult') url = element.findtext('QueueUrl').strip() return url
def from_xml(cls, xml_bytes): """ Create an instance from a C{RequestPaymentConfiguration} XML document. """ root = XML(xml_bytes) return cls(root.findtext("Payer"))
def _parse_allocate_address(self, xml_bytes): address_data = XML(xml_bytes) return address_data.findtext("publicIp")
def _parse_attach_volume(self, xml_bytes): root = XML(xml_bytes) status = root.findtext("status") attach_time = root.findtext("attachTime") attach_time = datetime.strptime(attach_time[:19], "%Y-%m-%dT%H:%M:%S") return {"status": status, "attach_time": attach_time}