Esempio n. 1
0
 def copy_task(conn, container, name, part_name, part_base_name):
     # open a new connection
     conn = ProxyConnection(None,
                            preauthurl=conn.url,
                            preauthtoken=conn.token)
     headers = {'x-copy-from': quote("/%s/%s" % (container, name))}
     logging.debug("copying first part %r/%r, %r" %
                   (container, part_name, headers))
     try:
         conn.put_object(container,
                         part_name,
                         headers=headers,
                         contents=None)
     except ClientException as ex:
         logging.error("Failed to copy %s: %s" % (name, ex.http_reason))
         sys.exit(1)
     # setup the manifest
     headers = {
         'x-object-manifest':
         quote("%s/%s" % (container, part_base_name))
     }
     logging.debug("creating manifest %r/%r, %r" %
                   (container, name, headers))
     try:
         conn.put_object(container,
                         name,
                         headers=headers,
                         contents=None)
     except ClientException as ex:
         logging.error("Failed to store the manifest %s: %s" %
                       (name, ex.http_reason))
         sys.exit(1)
     logging.debug("copy task done")
     conn.close()
Esempio n. 2
0
    def rename(self, src, dst):
        """
        Rename a file/directory from src to dst.

        Raises OSError on error.
        """
        src = self.abspath(src)
        dst = self.abspath(dst)
        logging.debug("rename %r -> %r" % (src, dst))
        self._listdir_cache.flush()
        # Check not renaming to itself
        if src == dst:
            logging.debug("Renaming %r to itself - doing nothing" % src)
            return
        # If dst is an existing directory, copy src inside it
        if self.isdir(dst):
            if dst:
                dst += "/"
            dst += posixpath.basename(src)
        # Check constraints for renaming a directory
        if self.isdir(src):
            if self.listdir(src):
                raise IOSError(ENOTEMPTY, "Can't rename non-empty directory: %s" % src)
            if self.isfile(dst):
                raise IOSError(ENOTDIR, "Can't rename directory to file")
        # Check not renaming to itself
        if src == dst:
            logging.debug("Renaming %r to itself - doing nothing" % src)
            return
        # Parse the paths now
        src_container_name, src_path = parse_fspath(src)
        dst_container_name, dst_path = parse_fspath(dst)
        logging.debug("`.. %r/%r -> %r/%r" % (src_container_name, src_path, dst_container_name, dst_path))
        # Check if we are renaming containers
        if not src_path and not dst_path and src_container_name and dst_container_name:
            return self._rename_container(src_container_name, dst_container_name)
        # ...otherwise can't deal with root stuff
        if not src_container_name or not src_path or not dst_container_name or not dst_path:
            raise IOSError(EACCES, "Can't rename to / from root")
        # Check destination directory exists
        if not self.isdir(posixpath.split(dst)[0]):
            raise IOSError(ENOENT, "Can't copy %r to %r, destination directory doesn't exist" % (src, dst))

        # check dst container
        self._container_exists(dst_container_name)

        # Do the rename of the file/dir
        meta = self.conn.head_object(src_container_name, src_path)
        if 'x-object-manifest' in meta:
            # a manifest file
            headers = { 'x-object-manifest': quote(meta['x-object-manifest']) }
        else:
            # regular file
            headers = { 'x-copy-from': quote("/%s/%s" % (src_container_name, src_path)) }
        self.conn.put_object(dst_container_name, dst_path, headers=headers, contents=None)
        # Delete src
        self.conn.delete_object(src_container_name, src_path)
        self._listdir_cache.flush(posixpath.dirname(src))
        self._listdir_cache.flush(posixpath.dirname(dst))
 def test_quote(self):
     value = b'bytes\xff'
     self.assertEqual('bytes%FF', c.quote(value))
     value = 'native string'
     self.assertEqual('native%20string', c.quote(value))
     value = u'unicode string'
     self.assertEqual('unicode%20string', c.quote(value))
     value = u'unicode:\xe9\u20ac'
     self.assertEqual('unicode%3A%C3%A9%E2%82%AC', c.quote(value))
 def test_quote(self):
     value = b"bytes\xff"
     self.assertEqual("bytes%FF", c.quote(value))
     value = "native string"
     self.assertEqual("native%20string", c.quote(value))
     value = u"unicode string"
     self.assertEqual("unicode%20string", c.quote(value))
     value = u"unicode:\xe9\u20ac"
     self.assertEqual("unicode%3A%C3%A9%E2%82%AC", c.quote(value))
Esempio n. 5
0
 def test_quote(self):
     value = b'bytes\xff'
     self.assertEqual('bytes%FF', c.quote(value))
     value = 'native string'
     self.assertEqual('native%20string', c.quote(value))
     value = u'unicode string'
     self.assertEqual('unicode%20string', c.quote(value))
     value = u'unicode:\xe9\u20ac'
     self.assertEqual('unicode%3A%C3%A9%E2%82%AC', c.quote(value))
Esempio n. 6
0
    def _prepare_connection(self):
        compute_nodes = self.compute_nodes.split(',')
        compute_node = random.sample(compute_nodes, 1)

        self.logger.info('Forwarding request to a compute node: ' +
                         compute_node[0])
        url = os.path.join('http://', compute_node[0], self.api_version,
                           self.account)

        parsed, conn = http_connection(url)
        path = '%s/%s/%s' % (parsed.path, quote(self.container), quote(
            self.obj))

        return conn, path
Esempio n. 7
0
 def copy_task(conn, container, name, part_name, part_base_name):
     # open a new connection
     url, token = conn.get_auth()
     conn = ProxyConnection(None,
                            preauthurl=url,
                            preauthtoken=token,
                            insecure=conn.insecure)
     headers = {'x-copy-from': quote("/%s/%s" % (container, name))}
     if self.storage_policy is not None:
         headers.update(
             {'x-storage-policy': quote(self.storage_policy)})
     logging.debug("copying first part %r/%r, %r" %
                   (container, part_name, headers))
     try:
         conn.put_object(container,
                         part_name,
                         headers=headers,
                         contents=None)
     except ClientException as ex:
         logging.error("Failed to copy %s: %s" % (name, ex.http_reason))
         sys.exit(1)
     # setup the manifest
     headers = {
         'x-object-manifest':
         quote("%s/%s" % (container, part_base_name))
     }
     if self.storage_policy is not None:
         headers.update(
             {'x-storage-policy': quote(self.storage_policy)})
     logging.debug("creating manifest %r/%r, %r" %
                   (container, name, headers))
     try:
         conn.put_object(container,
                         name,
                         headers=headers,
                         contents=None)
     except ClientException as ex:
         logging.error("Failed to store the manifest %s: %s" %
                       (name, ex.http_reason))
         sys.exit(1)
     logging.debug("copy task done")
     conn.close()
Esempio n. 8
0
 def copy_task(conn, container, name, part_name, part_base_name):
     # open a new connection
     conn = ProxyConnection(None, preauthurl=conn.url, preauthtoken=conn.token)
     headers = { 'x-copy-from': quote("/%s/%s" % (container, name)) }
     logging.debug("copying first part %r/%r, %r" % (container, part_name, headers))
     try:
         conn.put_object(container, part_name, headers=headers, contents=None)
     except ClientException as ex:
         logging.error("Failed to copy %s: %s" % (name, ex.http_reason))
         sys.exit(1)
     # setup the manifest
     headers = { 'x-object-manifest': quote("%s/%s" % (container, part_base_name)) }
     logging.debug("creating manifest %r/%r, %r" % (container, name, headers))
     try:
         conn.put_object(container, name, headers=headers, contents=None)
     except ClientException as ex:
         logging.error("Failed to store the manifest %s: %s" % (name, ex.http_reason))
         sys.exit(1)
     logging.debug("copy task done")
     conn.close()
Esempio n. 9
0
 def test_quote(self):
     value = 'standard string'
     self.assertEquals('standard%20string', c.quote(value))
     value = u'\u0075nicode string'
     self.assertEquals('unicode%20string', c.quote(value))
 def test_quote(self):
     value = 'standard string'
     self.assertEquals('standard%20string', c.quote(value))
     value = u'\u0075nicode string'
     self.assertEquals('unicode%20string', c.quote(value))
Esempio n. 11
0
    def rename(self, src, dst):
        """
        Rename a file/directory from src to dst.

        Raises OSError on error.
        """
        src = self.abspath(src)
        dst = self.abspath(dst)
        logging.debug("rename %r -> %r" % (src, dst))
        self._listdir_cache.flush()
        # Check not renaming to itself
        if src == dst:
            logging.debug("Renaming %r to itself - doing nothing" % src)
            return
        # If dst is an existing directory, copy src inside it
        if self.isdir(dst):
            if dst:
                dst += "/"
            dst += posixpath.basename(src)
        # Check constraints for renaming a directory
        if self.isdir(src):
            if self.listdir(src):
                raise IOSError(ENOTEMPTY,
                               "Can't rename non-empty directory: %s" % src)
            if self.isfile(dst):
                raise IOSError(ENOTDIR, "Can't rename directory to file")
        # Check not renaming to itself
        if src == dst:
            logging.debug("Renaming %r to itself - doing nothing" % src)
            return
        # Parse the paths now
        src_container_name, src_path = parse_fspath(src)
        dst_container_name, dst_path = parse_fspath(dst)
        logging.debug(
            "`.. %r/%r -> %r/%r" %
            (src_container_name, src_path, dst_container_name, dst_path))
        # Check if we are renaming containers
        if not src_path and not dst_path and src_container_name and dst_container_name:
            return self._rename_container(src_container_name,
                                          dst_container_name)
        # ...otherwise can't deal with root stuff
        if not src_container_name or not src_path or not dst_container_name or not dst_path:
            raise IOSError(EACCES, "Can't rename to / from root")
        # Check destination directory exists
        if not self.isdir(posixpath.split(dst)[0]):
            raise IOSError(
                ENOENT,
                "Can't copy %r to %r, destination directory doesn't exist" %
                (src, dst))

        # check dst container
        self._container_exists(dst_container_name)

        # Do the rename of the file/dir
        meta = self.conn.head_object(src_container_name, src_path)
        if 'x-object-manifest' in meta:
            # a manifest file
            headers = {'x-object-manifest': quote(meta['x-object-manifest'])}
        else:
            # regular file
            headers = {
                'x-copy-from': quote("/%s/%s" % (src_container_name, src_path))
            }
        self.conn.put_object(dst_container_name,
                             dst_path,
                             headers=headers,
                             contents=None)
        # Delete src
        self.conn.delete_object(src_container_name, src_path)
        self._listdir_cache.flush(posixpath.dirname(src))
        self._listdir_cache.flush(posixpath.dirname(dst))
 def test_quote(self):
     value = "standard string"
     self.assertEquals("standard%20string", c.quote(value))
     value = u"\u0075nicode string"
     self.assertEquals("unicode%20string", c.quote(value))