コード例 #1
0
    def create_container(self, container_name):
        if self.ex_location_name:
            root = Element('CreateBucketConfiguration')
            child = SubElement(root, 'LocationConstraint')
            child.text = self.ex_location_name

            data = tostring(root)
        else:
            data = ''

        response = self.connection.request('/%s' % (container_name),
                                           data=data,
                                           method='PUT')

        if response.status == httplib.OK:
            container = Container(name=container_name, extra=None, driver=self)
            return container
        elif response.status == httplib.CONFLICT:
            raise InvalidContainerNameError(
                value='Container with this name already exists. The name must '
                'be unique among all the containers in the system',
                container_name=container_name,
                driver=self)
        elif response.status == httplib.BAD_REQUEST:
            raise ContainerError(
                value='Bad request when creating container: %s' %
                response.body,
                container_name=container_name,
                driver=self)

        raise LibcloudError('Unexpected status code: %s' % (response.status),
                            driver=self)
コード例 #2
0
ファイル: oss.py プロジェクト: wandera/libcloud
    def create_container(self, container_name, ex_location=None):
        """
        @inherits :class:`StorageDriver.create_container`

        :keyword ex_location: The desired location where to create container
        :type keyword: ``str``
        """
        extra = None
        if ex_location:
            root = Element("CreateBucketConfiguration")
            child = SubElement(root, "LocationConstraint")
            child.text = ex_location

            data = tostring(root)
            extra = {"location": ex_location}
        else:
            data = ""

        container = Container(name=container_name, extra=extra, driver=self)
        response = self.connection.request("/",
                                           data=data,
                                           method="PUT",
                                           container=container)

        if response.status == httplib.OK:
            return container
        elif response.status == httplib.CONFLICT:
            raise InvalidContainerNameError(
                value="Container with this name already exists. The name must "
                "be unique among all the containers in the system",
                container_name=container_name,
                driver=self,
            )
        elif response.status == httplib.BAD_REQUEST:
            raise ContainerError(
                value="Bad request when creating container: %s" %
                response.body,
                container_name=container_name,
                driver=self,
            )

        raise LibcloudError("Unexpected status code: %s" % (response.status),
                            driver=self)
コード例 #3
0
    def create_container(self, container_name):
        if self.ex_location_name:
            root = Element("CreateBucketConfiguration")
            child = SubElement(root, "LocationConstraint")
            child.text = self.ex_location_name

            data = tostring(root)
        else:
            data = ""

        response = self.connection.request(
            "/%s" % (container_name), data=data, method="PUT"
        )

        if response.status == httplib.OK:
            container = Container(name=container_name, extra=None, driver=self)
            return container
        elif response.status == httplib.CONFLICT:
            if "BucketAlreadyOwnedByYou" in response.body:
                raise ContainerAlreadyExistsError(
                    value="Container with this name already exists. The name "
                    "be unique among all the containers in the system.",
                    container_name=container_name,
                    driver=self,
                )

            raise InvalidContainerNameError(
                value="Container with this name already exists. The name must "
                "be unique among all the containers in the system.",
                container_name=container_name,
                driver=self,
            )
        elif response.status == httplib.BAD_REQUEST:
            raise ContainerError(
                value="Bad request when creating container: %s" % response.body,
                container_name=container_name,
                driver=self,
            )

        raise LibcloudError(
            "Unexpected status code: %s" % (response.status), driver=self
        )