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


Python client.delete_object函数代码示例

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


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

示例1: delete_object

    def delete_object(self, container, prefix, name):
        try:
            object_name = prefix + name
    	    client.delete_object(self.storage_url, self.token, container, object_name)
	    return True
        except:
            return False
开发者ID:flyz1360,项目名称:ThuCloudDisk,代码行数:7,代码来源:swift.py

示例2: delmByID

def delmByID(request, me_id, uname, id):
    """
    :param request:
    :param me_id: the parent_secl_id of Tmeta database,we can return the page after we delete the id of meta.
    :param uname: the user's name
    :param id: the meta object_id
    :return: return to the page of before we execute delete.
    """
    name_token = '_'.join([uname, 'token'])
    name_url = '_'.join([uname, 'url'])
    try:
        auth_token = cache.get(name_token).split(':')[-1]
        storage_url = cache.get(name_url)
    except Exception as e:
        return HttpResponse("<h1>You have no token!</h1></ br><p>Please Press 获取token Button!</p>")
    bb = Tmeta.objects.get(object_id=id)
    container = 'ytf'
    objectname = bb.path
    print "DELETE============"
    print storage_url
    print objectname.split('/')[-1]
    try:
        client.delete_object(storage_url, auth_token, container, objectname.split('/')[-1])
        #values=(path, name, secfiled, seclevel, stype, token, str(url)+'/%s' % path)
        #print values
        #content = popen("curl -X DELETE -D- -H 'object_name:%s' -H 'parent_secl_id:%s' -H 'obj_seclevel:%s' -H 'Content-Type:%s' -H '%s' %s" % values).readlines()
        bb.delete()
        print "DELETE SUCESS"
        messages.add_message(request, messages.INFO, _("Object deleted."))
    except client.ClientException as e:
        print "DELETE fail",e
        messages.add_message(request, messages.ERROR, _("Access denied."))
        return HttpResponse(e)
    return HttpResponseRedirect("/meta/id=%s/name=%s" % (me_id, uname))
开发者ID:hbhdytf,项目名称:mac-web,代码行数:34,代码来源:views.py

示例3: delete_given_object

def delete_given_object(request, container, objectname):
    '''Delete the given object. '''

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

    client.delete_object(storage_url, auth_token, container, objectname)
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:7,代码来源:utils.py

示例4: dependency_undeploy

def dependency_undeploy(request, id, account):
    try:
        r = get_redis_connection()
    except:
        return JSONResponse('Problems to connect with the DB', status=500)
    dependency = r.hgetall("dependency:"+str(id))

    if not dependency:
        return JSONResponse('Dependency does not exists', status=404)
    if not r.exists("AUTH_"+str(account)+":dependency:"+str(dependency["name"])):
        return JSONResponse('Dependency '+str(dependency["name"])+' has not been deployed already', status=404)

    if request.method == 'PUT':
        headers = is_valid_request(request)
        if not headers:
            return JSONResponse('You must be authenticated. You can authenticate yourself  with the header X-Auth-Token ', status=401)
        response = dict()
        try:
            c.delete_object(settings.SWIFT_URL+settings.SWIFT_API_VERSION+"/"+"AUTH_"+str(account),headers["X-Auth-Token"],
                'dependency', dependency["name"], None, None, None, None, response)
        except:
            return JSONResponse(response.get("reason"), status=response.get('status'))
        status = response.get('status')
        if 200 <= status < 300:
            r.delete("AUTH_"+str(account)+":dependency:"+str(dependency["name"]))
            r.lrem("AUTH_"+str(account)+":dependencies", str(dependency["name"]), 1)
            return JSONResponse('The dependency has been deleted', status=status)
        return JSONResponse(response.get("reason"), status=status)
    return JSONResponse('Method '+str(request.method)+' not allowed.', status=405)
开发者ID:iostackproject,项目名称:Crystal-Controller,代码行数:29,代码来源:views.py

示例5: 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]

        if self.is_subdir(src):
            client.put_object(self.storage_url,
                              self.auth_token,
                              dst_cont,
                              dst.rstrip('/') + '/',
                              content_type='application/directory',
                              http_conn=self.http_connection)
            return

        headers = {'X-Copy-From': self.path}
        try:
            client.put_object(self.storage_url,
                              self.auth_token,
                              dst_cont,
                              dst,
                              headers=headers,
                              http_conn=self.http_connection)

            if isMove:
                client.delete_object(self.storage_url,
                                     self.auth_token,
                                     src_cont,
                                     src,
                                     http_conn=self.http_connection)
        except client.ClientException:
            pass
开发者ID:morucci,项目名称:swiftdav,代码行数:32,代码来源:swiftdav.py

示例6: 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

示例7: test_delete_propogate

    def test_delete_propogate(self):
        # create EC container
        headers = {'X-Storage-Policy': self.policy.name}
        client.put_container(self.url, self.token, self.container_name,
                             headers=headers)

        # get our node lists
        opart, onodes = self.object_ring.get_nodes(
            self.account, self.container_name, self.object_name)
        hnodes = self.object_ring.get_more_nodes(opart)
        p_dev2 = self.device_dir('object', onodes[1])

        # PUT object
        contents = Body()
        client.put_object(self.url, self.token, self.container_name,
                          self.object_name, contents=contents)

        # now lets shut one down
        self.kill_drive(p_dev2)

        # delete on the ones that are left
        client.delete_object(self.url, self.token,
                             self.container_name,
                             self.object_name)

        # spot check a node
        try:
            self.direct_get(onodes[0], opart)
        except direct_client.DirectClientException as err:
            self.assertEqual(err.http_status, 404)
        else:
            self.fail('Node data on %r was not fully destoryed!' %
                      (onodes[0],))

        # enable the first node again
        self.revive_drive(p_dev2)

        # propogate the delete...
        # fire up reconstructor on handoff nodes only
        for hnode in hnodes:
            hnode_id = (hnode['port'] - 6000) / 10
            self.reconstructor.once(number=hnode_id)

        # check the first node to make sure its gone
        try:
            self.direct_get(onodes[1], opart)
        except direct_client.DirectClientException as err:
            self.assertEqual(err.http_status, 404)
        else:
            self.fail('Node data on %r was not fully destoryed!' %
                      (onodes[0]))

        # make sure proxy get can't find it
        try:
            self.proxy_get()
        except Exception as err:
            self.assertEqual(err.http_status, 404)
        else:
            self.fail('Node data on %r was not fully destoryed!' %
                      (onodes[0]))
开发者ID:2015-ucsc-hp,项目名称:swift,代码行数:60,代码来源:test_reconstructor_revert.py

示例8: _test_sync

    def _test_sync(self, object_post_as_copy):
        source_container, dest_container = self._setup_synced_containers()

        # upload to source
        object_name = 'object-%s' % uuid.uuid4()
        put_headers = {'X-Object-Meta-Test': 'put_value'}
        client.put_object(self.url, self.token, source_container, object_name,
                          'test-body', headers=put_headers)

        # cycle container-sync
        Manager(['container-sync']).once()

        resp_headers, body = client.get_object(self.url, self.token,
                                               dest_container, object_name)
        self.assertEqual(body, 'test-body')
        self.assertIn('x-object-meta-test', resp_headers)
        self.assertEqual('put_value', resp_headers['x-object-meta-test'])

        # update metadata with a POST, using an internal client so we can
        # vary the object_post_as_copy setting - first use post-as-copy
        post_headers = {'Content-Type': 'image/jpeg',
                        'X-Object-Meta-Test': 'post_value'}
        int_client = self.make_internal_client(
            object_post_as_copy=object_post_as_copy)
        int_client.set_object_metadata(self.account, source_container,
                                       object_name, post_headers)
        # sanity checks...
        resp_headers = client.head_object(
            self.url, self.token, source_container, object_name)
        self.assertIn('x-object-meta-test', resp_headers)
        self.assertEqual('post_value', resp_headers['x-object-meta-test'])
        self.assertEqual('image/jpeg', resp_headers['content-type'])

        # cycle container-sync
        Manager(['container-sync']).once()

        # verify that metadata changes were sync'd
        resp_headers, body = client.get_object(self.url, self.token,
                                               dest_container, object_name)
        self.assertEqual(body, 'test-body')
        self.assertIn('x-object-meta-test', resp_headers)
        self.assertEqual('post_value', resp_headers['x-object-meta-test'])
        self.assertEqual('image/jpeg', resp_headers['content-type'])

        # delete the object
        client.delete_object(
            self.url, self.token, source_container, object_name)
        with self.assertRaises(ClientException) as cm:
            client.get_object(
                self.url, self.token, source_container, object_name)
        self.assertEqual(404, cm.exception.http_status)  # sanity check

        # cycle container-sync
        Manager(['container-sync']).once()

        # verify delete has been sync'd
        with self.assertRaises(ClientException) as cm:
            client.get_object(
                self.url, self.token, dest_container, object_name)
        self.assertEqual(404, cm.exception.http_status)  # sanity check
开发者ID:Ahiknsr,项目名称:swift,代码行数:60,代码来源:test_container_sync.py

示例9: delete

    def delete(self, credentials):
        if credentials is None:
            raise BadRequest('Swift backend requires credentials in x-auth-token headers')

        log.debug('Deleting Swift object %s' % self.context.value)
        protocol, schema, host, path = parse_uri(self.context.value)
        uri = "%s:%s%s" % (schema, host, path)
        client.delete_object(uri, credentials, path)
开发者ID:stoxy,项目名称:stoxy,代码行数:8,代码来源:swift.py

示例10: delete

 def delete(self):
     try:
             client.delete_object(self.storage_url,
                                  self.auth_token,
                                  self.container,
                                  self.objectname,
                                  http_conn=self.http_connection)
     except client.ClientException:
         pass
开发者ID:cschwede,项目名称:swiftdav,代码行数:9,代码来源:swiftdav.py

示例11: delete_given_object

def delete_given_object(request, container, objectname):
    """Delete the given object. """

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

    client.delete_object(
        storage_url, auth_token, container, objectname,
        headers={"X-Forwarded-For": request.META.get('REMOTE_ADDR')})
开发者ID:bkawula,项目名称:django-swiftbrowser,代码行数:9,代码来源:__init__.py

示例12: cache_delete

 def cache_delete(self, context, plan_name, key):
     swift_client = self.get_object_client(context)
     try:
         swift_client.delete_object(
             constants.TRIPLEO_CACHE_CONTAINER,
             self._cache_key(plan_name, key)
         )
     except swiftexceptions.ClientException:
         # cache or container does not exist. Ignore
         pass
开发者ID:infraredgirl,项目名称:tripleo-common,代码行数:10,代码来源:base.py

示例13: delete_object

 def delete_object(self):
     """
     issue delete for test object
     """
     try:
         client.delete_object(self.url, self.token, self.container_name,
                              self.object_name)
     except ClientException as err:
         if err.http_status != HTTP_NOT_FOUND:
             raise
开发者ID:2015-ucsc-hp,项目名称:swift,代码行数:10,代码来源:brain.py

示例14: 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

示例15: 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


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