当前位置: 首页>>代码示例>>Python>>正文


Python client.delete_container函数代码示例

本文整理汇总了Python中swiftclient.client.delete_container函数的典型用法代码示例。如果您正苦于以下问题:Python delete_container函数的具体用法?Python delete_container怎么用?Python delete_container使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了delete_container函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_one_node_fails

 def test_one_node_fails(self):
     # Create container1
     # Kill container1 servers excepting two of the primaries
     # Delete container1
     # Restart other container1 primary server
     # Create container1/object1 (allowed because at least server thinks the
     #   container exists)
     # Get to a final state
     # Assert all container1 servers indicate container1 is alive and
     #   well with object1
     # Assert account level also indicates container1 is alive and
     #   well with object1
     container1 = 'container-%s' % uuid4()
     cpart, cnodes = self.container_ring.get_nodes(self.account, container1)
     client.put_container(self.url, self.token, container1)
     kill_nonprimary_server(cnodes, self.port2server, self.pids)
     kill_server(cnodes[0]['port'], self.port2server, self.pids)
     client.delete_container(self.url, self.token, container1)
     start_server(cnodes[0]['port'], self.port2server, self.pids)
     client.put_object(self.url, self.token, container1, 'object1', '123')
     get_to_final_state()
     for cnode in cnodes:
         self.assertEquals(
             [o['name'] for o in direct_client.direct_get_container(
                 cnode, cpart, self.account, container1)[1]],
             ['object1'])
     headers, containers = client.get_account(self.url, self.token)
     self.assertEquals(headers['x-account-container-count'], '1')
     self.assertEquals(headers['x-account-object-count'], '1')
     self.assertEquals(headers['x-account-bytes-used'], '3')
开发者ID:Dieterbe,项目名称:swift,代码行数:30,代码来源:test_container_failures.py

示例2: delete_container

def delete_container(request, container, force=True):
    """
    Deletes a container. If force is True, it will deletes all objects first.
    """

    storage_url = get_endpoint(request, 'adminURL')
    auth_token = get_token_id(request)
    http_conn = client.http_connection(storage_url,
                                       insecure=settings.SWIFT_INSECURE)

    if force:
        try:
            _, objects = client.get_container(storage_url,
                                           auth_token,
                                           container,
                                           http_conn=http_conn)

        except client.ClientException as err:
            log.exception('{}{}'.format(ugettext('Exception:').encode('UTF-8'), err))
            return False

        for obj in objects:
            delete_object(request=request,
                          container=container,
                          objectname=obj['name'])

    try:
        client.delete_container(storage_url, auth_token,
                                container, http_conn=http_conn)
        actionlog.log(request.user.username, "delete", container)
    except client.ClientException as err:
        log.exception('{}{}'.format(ugettext('Exception:').encode('UTF-8'), err))
        return False

    return True
开发者ID:globocom,项目名称:vault,代码行数:35,代码来源:views.py

示例3: delete_data

 def delete_data(self, context, container_name):
     url = self._get_endpoint_url(context)
     token = context.auth_token
     try:
         headers, info = swift_client.get_container(
             url, token, container_name
         )
         for obj in info:
             try:
                 swift_client.delete_object(
                     url, token, container_name, obj['name']
                 )
             except swift_exceptions.ClientException as e:
                 LOG.error(e)
                 if e.http_status != 404:
                     raise
         swift_client.delete_container(url, token, container_name)
     except swift_exceptions.ClientException as e:
         LOG.error(e)
         if e.http_status == 404:
             raise exception.ContainerNotExists(
                 container_name=container_name
             )
         else:
             raise exception.ContainerDeletionError(
                 container_name=container_name
             )
开发者ID:accelazh,项目名称:magnetodb,代码行数:27,代码来源:api.py

示例4: delete_container

    def delete_container(self, name):
        if not self.http_conn:
            self.connect()

        swift.delete_container(url=self.swift_url, token=self.token, http_conn=self.http_conn, container=name)
        if self.debug:
            print("Container {0} deleted".format(name))
开发者ID:jesusaurus,项目名称:openstack-tests,代码行数:7,代码来源:swiftTest.py

示例5: delete

 def delete(self):
     name = self.path.strip('/')
     try:
         client.delete_container(
             self.storage_url,
             self.auth_token,
             name,
             http_conn=self.http_connection)
     except client.ClientException:
         raise dav_error.DAVError(dav_error.HTTP_INTERNAL_ERROR)
开发者ID:cschwede,项目名称:swiftdav,代码行数:10,代码来源:swiftdav.py

示例6: moveRecursive

    def moveRecursive(self, newname):
        """ Move/rename a container.

        This is only working for empty containers and objects with a size of 0.
        Required by some clients because they create a folder "New folder" first.

        For all other requests this will simply return HTTP_FORBIDDEN. """
        oldname = self.path.lstrip('/')
        newname = newname.lstrip('/')

        if '/' not in oldname:
            try:
                # Container deletion will fail if not empty
                client.delete_container(self.storage_url,
                                        self.auth_token,
                                        oldname)
                client.put_container(self.storage_url,
                                     self.auth_token,
                                     newname)
            except client.ClientException:
                raise dav_error.DAVError(dav_error.HTTP_FORBIDDEN)

        else:
            old_container, _, old_object = oldname.partition('/')
            new_container, _, new_object = newname.partition('/')
            if old_container != new_container:
                raise dav_error.DAVError(dav_error.HTTP_FORBIDDEN)

            # If it is a pseudofolder, check that it is empty
            _, objects = client.get_container(
                self.storage_url,
                self.auth_token,
                container=self.container,
                delimiter='/',
                prefix=sanitize(old_object).rstrip('/') + '/',
                http_conn=self.http_connection)
            if len(objects) != 1:  # first object is the pseudofolder entry
                raise dav_error.DAVError(dav_error.HTTP_FORBIDDEN)

            # also check if the object is empty
            if objects[0].get('bytes') != 0:
                raise dav_error.DAVError(dav_error.HTTP_FORBIDDEN)

            # Do a COPY to preserve existing metadata and content-type
            client.put_object(self.storage_url,
								  self.auth_token,
								  self.container,
								  sanitize(new_object),
                                  headers = {'X-Copy-From': '/' + oldname + '/'},
								  http_conn=self.http_connection)
            client.delete_object(self.storage_url,
                                 self.auth_token,
                                 self.container,
                                 old_object + '/',
                                 http_conn=self.http_connection)
开发者ID:cschwede,项目名称:swiftdav,代码行数:55,代码来源:swiftdav.py

示例7: copyMoveSingle

    def copyMoveSingle(self, destPath, isMove):
        src = '/'.join(self.path.split('/')[2:])
        dst = '/'.join(destPath.split('/')[2:])

        src_cont = self.path.split('/')[1]
        dst_cont = destPath.split('/')[1]

        # Make sure target container exists
        try:
            client.put_container(self.storage_url,
                                 self.auth_token,
                                 dst_cont,
                                 http_conn=self.http_connection)
        except:
            pass

        _, objects = client.get_container(self.storage_url,
                                          self.auth_token,
                                          container=src_cont,
                                          delimiter='/',
                                          prefix=src,
                                          http_conn=self.http_connection)

        for obj in objects:
            objname = obj.get('name', obj.get('subdir'))
            headers = {'X-Copy-From': '%s/%s' % (self.container, objname)}
            newname = objname.replace(src, dst)
            if newname[-1] == '/':
                newname = newname.rstrip('/') + '/'
            try:
                client.put_object(self.storage_url,
                                  self.auth_token,
                                  dst_cont,
                                  newname,
                                  headers=headers,
                                  http_conn=self.http_connection)
                if isMove:
                    client.delete_object(self.storage_url,
                                         self.auth_token,
                                         src_cont,
                                         objname,
                                         http_conn=self.http_connection)
            except client.ClientException:
                pass

        # will only succeed if container is empty
        if isMove:
            try:
                client.delete_container(self.storage_url,
                                        self.auth_token,
                                        self.container,
                                        http_conn=self.http_connection)
            except client.ClientException:
                pass
开发者ID:mikalv,项目名称:swiftdav,代码行数:54,代码来源:swiftdav.py

示例8: delete_account_cont

 def delete_account_cont(self, account_url, token):
     cnx = sclient.http_connection(account_url)
     al = sclient.get_account(None, token,
                              http_conn=cnx,
                              full_listing=True)
     for container in [c['name'] for c in al[1]]:
         ci = sclient.get_container(None, token,
                                    container, http_conn=cnx,
                                    full_listing=True)
         on = [od['name'] for od in ci[1]]
         for obj in on:
             sclient.delete_object('', token, container,
                                   obj, http_conn=cnx)
         sclient.delete_container('', token, container, http_conn=cnx)
开发者ID:RegBinder,项目名称:swiftsync,代码行数:14,代码来源:test_syncer.py

示例9: run_test

 def run_test(num_locks, catch_503):
     container = 'container-%s' % uuid4()
     client.put_container(self.url, self.token, container)
     db_files = self._get_container_db_files(container)
     db_conns = []
     for i in range(num_locks):
         db_conn = sqlite3.connect(db_files[i])
         db_conn.execute('begin exclusive transaction')
         db_conns.append(db_conn)
     if catch_503:
         try:
             client.delete_container(self.url, self.token, container)
         except client.ClientException, e:
             self.assertEquals(e.http_status, 503)
开发者ID:HodongHwang,项目名称:swift,代码行数:14,代码来源:test_container_failures.py

示例10: delete_container

def delete_container(request, container):
    """ Deletes a container """

    storage_url = request.session.get("storage_url", "")
    auth_token = request.session.get("auth_token", "")

    try:
        _m, objects = client.get_container(storage_url, auth_token, container)
        for obj in objects:
            client.delete_object(storage_url, auth_token, container, obj["name"])
        client.delete_container(storage_url, auth_token, container)
        messages.add_message(request, messages.INFO, _("Container deleted."))
    except client.ClientException:
        messages.add_message(request, messages.ERROR, _("Access denied."))

    return redirect(containerview)
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:16,代码来源:containers.py

示例11: test_first_two_nodes_fail

    def test_first_two_nodes_fail(self):
        container = 'container-%s' % uuid4()
        client.put_container(self.url, self.token, container)
        self.assert_(container in [c['name'] for c in
                     client.get_account(self.url, self.token)[1]])

        object1 = 'object1'
        client.put_object(self.url, self.token, container, object1, 'test')
        self.assert_(container in [c['name'] for c in
                     client.get_account(self.url, self.token)[1]])
        self.assert_(object1 in [o['name'] for o in
                     client.get_container(self.url, self.token, container)[1]])

        cpart, cnodes = self.container_ring.get_nodes(self.account, container)
        for x in xrange(2):
            kill(self.pids[self.port2server[cnodes[x]['port']]], SIGTERM)

        client.delete_object(self.url, self.token, container, object1)
        self.assert_(container in [c['name'] for c in
                     client.get_account(self.url, self.token)[1]])
        self.assert_(object1 not in [o['name'] for o in
                     client.get_container(self.url, self.token, container)[1]])

        for x in xrange(2):
            self.pids[self.port2server[cnodes[x]['port']]] = \
                Popen(['swift-container-server',
                       '/etc/swift/container-server/%d.conf' %
                        ((cnodes[x]['port'] - 6001) / 10)]).pid
        sleep(2)
        self.assert_(container in [c['name'] for c in
                     client.get_account(self.url, self.token)[1]])
        # This okay because the first node hasn't got the update that the
        # object was deleted yet.
        self.assert_(object1 in [o['name'] for o in
                     direct_client.direct_get_container(cnodes[0], cpart,
                     self.account, container)[1]])

        # This fails because all three nodes have to indicate deletion before
        # we tell the user it worked. Since the first node 409s (it hasn't got
        # the update that the object was deleted yet), the whole must 503
        # (until every is synced up, then the delete would work).
        exc = None
        try:
            client.delete_container(self.url, self.token, container)
        except client.ClientException, err:
            exc = err
开发者ID:HodongHwang,项目名称:swift,代码行数:46,代码来源:test_container_failures.py

示例12: run_test

 def run_test(num_locks, catch_503):
     container = "container-%s" % uuid4()
     client.put_container(self.url, self.token, container)
     db_files = self._get_container_db_files(container)
     db_conns = []
     for i in range(num_locks):
         db_conn = connect(db_files[i])
         db_conn.execute("begin exclusive transaction")
         db_conns.append(db_conn)
     if catch_503:
         try:
             client.delete_container(self.url, self.token, container)
         except client.ClientException as err:
             self.assertEquals(err.http_status, 503)
         else:
             self.fail("Expected ClientException but didn't get it")
     else:
         client.delete_container(self.url, self.token, container)
开发者ID:kun--hust,项目名称:sdscloud,代码行数:18,代码来源:test_container_failures.py

示例13: delete_container

def delete_container(request, container):
    """ Deletes a container """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    try:
        _m, objects = client.get_container(storage_url, auth_token, container)
        for obj in objects:
            client.delete_object(storage_url, auth_token,
                                 container, obj['name'])
        client.delete_container(storage_url, auth_token, container)
        messages.add_message(request, messages.INFO, _("Container deleted."))
    except client.ClientException:
        traceback.print_exc()
        messages.add_message(request, messages.ERROR, _("Access denied."))

    return redirect(containerview)
开发者ID:unibg-seclab,项目名称:django-swiftbrowser,代码行数:18,代码来源:views.py

示例14: del_container

def del_container(container):
    headers, objs = container_info(container)
    if len(objs) != 0:
        for i in objs:
            del_object(container,i['name'])
    return client.delete_container(url = storageURL,
                                   token = authtoken,
                                   container = container
                                  )
开发者ID:daokhactuan48,项目名称:Admin-Dashboard,代码行数:9,代码来源:swift_test.py

示例15: delete_container

    def delete_container(self, container_name):
        """

        :param container_name:
        :return:
        """
        ret = sc.delete_container(self.storage_location, self.ks.auth_token, container_name)
        if ret is None:
            print('Container: %s has been deleted.' % container_name)
开发者ID:subecho,项目名称:Iridium,代码行数:9,代码来源:swift.py


注:本文中的swiftclient.client.delete_container函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。