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 InvalidContainerNameError(value='Container name contains ' + 'invalid characters.', container_name=container_name, driver=self) raise LibcloudError('Unexpected status code: %s' % (response.status), driver=self)
def create_container(self, container_name): """ @inherits: :class:`StorageDriver.create_container` """ params = {"restype": "container"} container_path = "/%s" % (container_name) response = self.connection.request(container_path, params=params, method="PUT") if response.status == httplib.CREATED: return self._response_to_container(container_name, response) elif response.status == httplib.CONFLICT: raise ContainerAlreadyExistsError( 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 InvalidContainerNameError( value="Container name contains " + "invalid characters.", container_name=container_name, driver=self, ) raise LibcloudError("Unexpected status code: %s" % (response.status), driver=self)
def create_container(self, container_name): """ @inherits: :class:`StorageDriver.create_container` """ params = {'restype': 'container'} container_path = '/%s' % (container_name) response = self.connection.request(container_path, params=params, method='PUT') if response.status == httplib.CREATED: return self._response_to_container(container_name, response) elif response.status == httplib.CONFLICT: raise ContainerAlreadyExistsError( 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 InvalidContainerNameError(value='Container name contains ' + 'invalid characters.', container_name=container_name, driver=self) raise LibcloudError('Unexpected status code: %s' % (response.status), driver=self)
def _encode_container_name(self, name): """ Encode container name so it can be used as part of the HTTP request. """ if name.startswith('/'): name = name[1:] name = urlquote(name) if name.find('/') != -1: raise InvalidContainerNameError(value='Container name cannot' ' contain slashes', container_name=name, driver=self) if len(name) > 256: raise InvalidContainerNameError( value='Container name cannot be longer than 256 bytes', container_name=name, driver=self) return name
def _check_container_name(self, container_name): """ Check if the container name is valid :param container_name: Container name :type container_name: ``str`` """ if '/' in container_name or '\\' in container_name: raise InvalidContainerNameError(value=None, driver=self, container_name=container_name)
def _clean_container_name(self, name): """ Clean container name. """ if name.startswith('/'): name = name[1:] name = urllib.quote(name) if name.find('/') != -1: raise InvalidContainerNameError(value='Container name cannot' ' contain slashes', container_name=name, driver=self) if len(name) > 256: raise InvalidContainerNameError(value='Container name cannot be' ' longer than 256 bytes', container_name=name, driver=self) return name
def _check_container_name(self, container_name): """ Check if the container name is valid @param container_name: Container name @type container_name: C{str} """ if ' ' in container_name: raise InvalidContainerNameError(value=None, driver=self, container_name=container_name)
def create_container(self, container_name): """ Create a new container with path 'container_name' """ #Containers do not end in slash if container_name.endswith('/'): container_name = container_name[:-1] self._check_container_name(container_name) try: new_collection = self.connection.session.collections.create( container_name) return self._to_container(new_collection) except: #CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME 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)
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)
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 )