Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
0
    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'))
Пример #10
0
 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)
Пример #11
0
    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'))
Пример #12
0
    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'))
Пример #13
0
 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)
Пример #14
0
    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}
Пример #15
0
    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)
Пример #16
0
    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)
Пример #17
0
    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'))
Пример #18
0
    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}
Пример #19
0
    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)
Пример #20
0
    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")
Пример #21
0
    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)
Пример #22
0
    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"
Пример #23
0
    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)
Пример #24
0
    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")
Пример #25
0
    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"
Пример #26
0
 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
Пример #27
0
    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)
Пример #28
0
 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
Пример #29
0
 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
Пример #30
0
 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
Пример #31
0
    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
Пример #32
0
    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
Пример #33
0
 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)
Пример #34
0
 def create_security_group(self, xml_bytes):
     root = XML(xml_bytes)
     return root.findtext("groupId")
Пример #35
0
 def _parse_truth_return(self, xml_bytes):
     root = XML(xml_bytes)
     return root.findtext("return") == "true"
Пример #36
0
def parse_error_message(data):
    element = XML(data).find('Error')
    _type = element.findtext('Type').strip()
    message = element.findtext('Message').strip()
    return _type, message
Пример #37
0
            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")
Пример #38
0
def parse_get_queue_url(data):
    element = XML(data).find('GetQueueUrlResult')
    return element.findtext('QueueUrl').strip()
Пример #39
0
 def create_security_group(self, xml_bytes):
     root = XML(xml_bytes)
     return root.findtext("groupId")
Пример #40
0
 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)
Пример #41
0
def parse_create_queue(data):
    element = XML(data).find('CreateQueueResult')
    url = element.findtext('QueueUrl').strip()
    return url
Пример #42
0
 def from_xml(cls, xml_bytes):
     """
     Create an instance from a C{RequestPaymentConfiguration} XML document.
     """
     root = XML(xml_bytes)
     return cls(root.findtext("Payer"))
Пример #43
0
 def from_xml(cls, xml_bytes):
     """
     Create an instance from a C{RequestPaymentConfiguration} XML document.
     """
     root = XML(xml_bytes)
     return cls(root.findtext("Payer"))
Пример #44
0
 def _parse_allocate_address(self, xml_bytes):
     address_data = XML(xml_bytes)
     return address_data.findtext("publicIp")
Пример #45
0
 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)
Пример #46
0
 def _parse_allocate_address(self, xml_bytes):
     address_data = XML(xml_bytes)
     return address_data.findtext("publicIp")
Пример #47
0
def parse_create_queue(data):
    element = XML(data).find('CreateQueueResult')
    url = element.findtext('QueueUrl').strip()
    return url
Пример #48
0
 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)
Пример #49
0
 def _parse_truth_return(self, xml_bytes):
     root = XML(xml_bytes)
     return root.findtext("return") == "true"
Пример #50
0
 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}
Пример #51
0
def parse_error_message(data):
    element = XML(data).find('Error')
    _type = element.findtext('Type').strip()
    message = element.findtext('Message').strip()
    return _type, message
Пример #52
0
def parse_get_queue_url(data):
    element = XML(data).find('GetQueueUrlResult')
    return element.findtext('QueueUrl').strip()
Пример #53
0
 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}