• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python client.delete_object函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: delete_object

def delete_object(dest_cnx,
                  dest_token,
                  container_name,
                  object_name):
    parsed = dest_cnx[0]
    url = '%s://%s/%s' % (parsed.scheme, parsed.netloc, parsed.path)
    swiftclient.delete_object(url=url,
                              token=dest_token,
                              container=container_name,
                              http_conn=dest_cnx,
                              name=object_name)
开发者ID:Greyhatno,项目名称:swiftsync,代码行数:11,代码来源:objects.py


示例17: delete_pseudofolder

def delete_pseudofolder(request, container, pseudofolder):
    """ Deletes an empty object, used as a pseudofolder """

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

    objects = client.get_container(storage_url, auth_token,
                                   container, prefix=pseudofolder,
                                   http_conn=http_conn)[1]

    count_deletes = 0
    for obj in objects:
        try:
            client.delete_object(storage_url, token=auth_token,
                                 container=container, name=obj['name'],
                                 http_conn=http_conn)
            count_deletes += 1
        except client.ClientException as err:
            log.exception('{}{}'.format(_('Exception:').encode('UTF-8'), err))

    # Empty pseudofolder
    if count_deletes == 1 and count_deletes == len(objects):
        messages.add_message(request, messages.SUCCESS,
                _('Pseudofolder deleted.'))

    # Non empty pseudofolder
    elif count_deletes > 1 and count_deletes == len(objects):
        messages.add_message(request, messages.SUCCESS,
                _('Pseudofolder and {0} objects deleted.').format(count_deletes - 1))
    elif count_deletes > 0 and count_deletes < len(objects):
        messages.add_message(request, messages.SUCCESS,
                _('It was not possible to delete all objects.'))
    else:
        messages.add_message(request, messages.ERROR,
                _('Fail to delete pseudofolder.'))

    if pseudofolder[-1] == '/':  # deleting a pseudofolder, move one level up
        pseudofolder = pseudofolder[:-1]

    prefix = '/'.join(pseudofolder.split('/')[:-1])

    if prefix:
        prefix += '/'

    actionlog.log(request.user.username, "delete", pseudofolder)

    if prefix:
        return redirect(objectview, container=container, prefix=prefix)
    else:
        return redirect(objectview, container=container)
开发者ID:globocom,项目名称:vault,代码行数:52,代码来源:views.py


示例18: deleteall

def deleteall(request):
    try:
        storage_url, auth_token = _get_auth_data(request.session)
        auth_data_dict = request.data
        for filename in auth_data_dict:
            try:
                client.delete_object(storage_url, auth_token, 'Image', filename)
            except Exception as e:
                print(filename.encode('utf-8') + '\n')
    except Exception as e:
        print e
        raise e
    return 'SUCCESS'
开发者ID:InBetween,项目名称:AssetManager,代码行数:13,代码来源:views.py


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


示例20: undeploy

def undeploy(r, storlet, account, headers):
    response = dict()
    try:
        c.delete_object(settings.SWIFT_URL+settings.SWIFT_API_VERSION+"/"+"AUTH_"+str(account),headers["X-Auth-Token"],
            'storlet', storlet["name"], None, None, None, None, response)
        print 'response, ', response
    except:
        return JSONResponse(response.get("reason"), status=response.get('status'))
    status = response.get('status')
    if 200 <= status < 300:
        r.delete("AUTH_"+str(account)+":"+str(storlet["name"]))
        r.lrem("AUTH_"+str(account), str(storlet["name"]), 1)
        return JSONResponse('The object has been deleted', status=status)
    return JSONResponse(response.get("reason"), status=status)
开发者ID:iostackproject,项目名称:Crystal-Controller,代码行数:14,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python client.get_account函数代码示例发布时间:2022-05-27
下一篇:
Python client.delete_container函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap