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

Python client.put_object函数代码示例

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

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



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

示例1: test_main

 def test_main(self):
     container = 'container-%s' % uuid4()
     client.put_container(self.url, self.token, container)
     apart, anodes = self.account_ring.get_nodes(self.account)
     anode = anodes[0]
     cpart, cnodes = self.container_ring.get_nodes(self.account, container)
     cnode = cnodes[0]
     kill(self.pids[self.port2server[cnode['port']]], SIGTERM)
     obj = 'object-%s' % uuid4()
     client.put_object(self.url, self.token, container, obj, '')
     self.pids[self.port2server[cnode['port']]] = \
         Popen(['swift-container-server',
                '/etc/swift/container-server/%d.conf' %
                 ((cnode['port'] - 6001) / 10)]).pid
     sleep(2)
     self.assert_(not direct_client.direct_get_container(cnode, cpart,
                         self.account, container)[1])
     ps = []
     for n in xrange(1, 5):
         ps.append(Popen(['swift-object-updater',
                          '/etc/swift/object-server/%d.conf' % n, 'once']))
     for p in ps:
         p.wait()
     objs = [o['name'] for o in direct_client.direct_get_container(cnode,
                                 cpart, self.account, container)[1]]
     self.assert_(obj in objs)
开发者ID:HodongHwang,项目名称:swift,代码行数:26,代码来源:test_object_async_update.py


示例2: uploadNote

    def uploadNote(self, note, title):
        if len(title) == 0:
            title = self._generateObjectTitle(note.getTitle())
        metaManager = MetaManager(self._storage_url, self._token, title)
        currentCreateDate = metaManager.getCreateDate()
        content = note.getContent().encode('ascii', 'ignore')
        put_object(
            self._storage_url,
            self._token,
            Configuration.container_name,
            title,
            content)
        lastModifiedDate = MetaManager.dateNow()
        # currentCreateDate may be None because note may be new
        # this comment is just a companion for the one above, he felt lonely
        if currentCreateDate is None:
            currentCreateDate = lastModifiedDate

        metaManager.setCreateDate(currentCreateDate)
        metaManager.setLastModifiedDate(lastModifiedDate)
        # we only need to keep the previous tags, NONE IS CORRECT DO NOT CHANGE
        metaManager.setTags(None)
        metaManager.commitMeta()
        print title
        return title
开发者ID:icclab,项目名称:powdernote,代码行数:25,代码来源:SwiftManager.py


示例3: put_file_as_storlet_input_object

def put_file_as_storlet_input_object(url, token, local_path, local_file):
    resp = dict()
    f = open("%s/%s" % (local_path, local_file), "r")
    c.put_object(url, token, "myobjects", local_file, f, content_type="application/octet-stream", response_dict=resp)
    f.close()
    status = resp.get("status")
    assert status == 200 or status == 201
开发者ID:ajiang38740,项目名称:swift-storlets,代码行数:7,代码来源:storlets_test_utils.py


示例4: test_main

    def test_main(self):
        # Create container
        container = 'container-%s' % uuid4()
        client.put_container(self.url, self.token, container)

        # Kill container servers excepting two of the primaries
        cpart, cnodes = self.container_ring.get_nodes(self.account, container)
        cnode = cnodes[0]
        kill_nonprimary_server(cnodes, self.ipport2server, self.pids)
        kill_server((cnode['ip'], cnode['port']),
                    self.ipport2server, self.pids)

        # Create container/obj
        obj = 'object-%s' % uuid4()
        client.put_object(self.url, self.token, container, obj, '')

        # Restart other primary server
        start_server((cnode['ip'], cnode['port']),
                     self.ipport2server, self.pids)

        # Assert it does not know about container/obj
        self.assert_(not direct_client.direct_get_container(
            cnode, cpart, self.account, container)[1])

        # Run the object-updaters
        Manager(['object-updater']).once()

        # Assert the other primary server now knows about container/obj
        objs = [o['name'] for o in direct_client.direct_get_container(
            cnode, cpart, self.account, container)[1]]
        self.assert_(obj in objs)
开发者ID:bigdig,项目名称:swift,代码行数:31,代码来源:test_object_async_update.py


示例5: create_pseudofolder

def create_pseudofolder(request, container, prefix=None):
    """ Creates a pseudofolder (empty object of type application/directory) """
    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    form = PseudoFolderForm(request.POST)
    if form.is_valid():
        foldername = request.POST.get('foldername', None)
        if prefix:
            foldername = prefix + '/' + foldername
        foldername = os.path.normpath(foldername)
        foldername = foldername.strip('/')
        foldername += '/'

        content_type = 'application/directory'
        obj = None

        try:
            client.put_object(storage_url, auth_token,
                              container, foldername, obj,
                              content_type=content_type)
            messages.add_message(request, messages.INFO,
                                 _("Pseudofolder created."))
        except client.ClientException:
            traceback.print_exc()
            messages.add_message(request, messages.ERROR, _("Access denied."))

        if prefix:
            return redirect(objectview, container=container, prefix=prefix)
        return redirect(objectview, container=container)

    return render_to_response('create_pseudofolder.html', {
                              'container': container,
                              'prefix': prefix,
                              }, context_instance=RequestContext(request))
开发者ID:unibg-seclab,项目名称:django-swiftbrowser,代码行数:35,代码来源:views.py


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


示例7: test_sync_lazy_dkey

    def test_sync_lazy_dkey(self):
        # Create synced containers, but with no key at dest
        source_container, dest_container =\
            self._setup_synced_containers('secret', None)

        # upload to source
        object_name = 'object-%s' % uuid.uuid4()
        client.put_object(self.url, self.token, source_container, object_name,
                          'test-body')

        # cycle container-sync, nothing should happen
        Manager(['container-sync']).once()
        with self.assertRaises(ClientException) as err:
            _junk, body = client.get_object(self.url, self.token,
                                            dest_container, object_name)
        self.assertEqual(err.exception.http_status, HTTP_NOT_FOUND)

        # amend dest key
        dest_headers = {'X-Container-Sync-Key': 'secret'}
        client.put_container(self.url, self.token, dest_container,
                             headers=dest_headers)
        # cycle container-sync, should replicate
        Manager(['container-sync']).once()
        _junk, body = client.get_object(self.url, self.token,
                                        dest_container, object_name)
        self.assertEqual(body, 'test-body')
开发者ID:Ahiknsr,项目名称:swift,代码行数:26,代码来源:test_container_sync.py


示例8: createEmptyResource

 def createEmptyResource(self, name):
     client.put_object(self.storage_url,
                       self.auth_token,
                       self.container,
                       sanitize(name),
                       http_conn=self.http_connection)
     return ObjectResource(self.container, name, self.environ, self.objects)
开发者ID:cschwede,项目名称:swiftdav,代码行数:7,代码来源:swiftdav.py


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


示例10: test_main

 def test_main(self):
     # Create container
     # Kill container servers excepting two of the primaries
     # Create container/obj
     # Restart other primary server
     # Assert it does not know about container/obj
     # Run the object-updaters
     # Assert the other primary server now knows about container/obj
     container = 'container-%s' % uuid4()
     client.put_container(self.url, self.token, container)
     cpart, cnodes = self.container_ring.get_nodes(self.account, container)
     cnode = cnodes[0]
     kill_nonprimary_server(cnodes, self.port2server, self.pids)
     kill_server(cnode['port'], self.port2server, self.pids)
     obj = 'object-%s' % uuid4()
     client.put_object(self.url, self.token, container, obj, '')
     start_server(cnode['port'], self.port2server, self.pids)
     self.assert_(not direct_client.direct_get_container(
         cnode, cpart, self.account, container)[1])
     processes = []
     for node in xrange(1, 5):
         processes.append(Popen(['swift-object-updater',
                                 '/etc/swift/object-server/%d.conf' % node,
                                 'once']))
     for process in processes:
         process.wait()
     objs = [o['name'] for o in direct_client.direct_get_container(
         cnode, cpart, self.account, container)[1]]
     self.assert_(obj in objs)
开发者ID:ChicoTeam,项目名称:swift,代码行数:29,代码来源:test_object_async_update.py


示例11: testTestStorlet

def testTestStorlet(url, token):
    print "Deploying test storlet"
    put_storlet_object(url, 
                       token, 
                       TEST_STORLET_NAME,
                       "%s/TestStorlet/bin/" % PATH_TO_STORLETS,
                       '', 
                       'com.ibm.storlet.test.test1')

    print "uploading object to execute test upon"
    c.put_object(url,
                 token,
                 'myobjects',
                 'test_object',
                 'some content')
    print "Invoking test storlet to print"
    invokeTestStorlet(url, token, "print", False)
    print "Invoking test storlet to crash"
    invokeTestStorlet(url, token, "crash")
    print "Invoking test storlet to hold"
    invokeTestStorlet(url, token, "hold")
    print "Invoking test storlet to print"
    invokeTestStorlet(url, token, "print", False)
    print "Invoking test storlet in parallel to print"
    invokeTestStorletinParallel(url, token)
开发者ID:ymoatti,项目名称:swift-storlets,代码行数:25,代码来源:sys_test.py


示例12: handleCopy

    def handleCopy(self, destPath, depthInfinity):
        dst = '/'.join(destPath.split('/')[2:])

        try:
            client.head_object(self.storage_url,
                               self.auth_token,
                               self.container,
                               dst,
                               http_conn=self.http_connection)
        except client.ClientException:
            pass

        headers = {'X-Copy-From': self.path}
        try:
            client.put_object(self.storage_url,
                              self.auth_token,
                              self.container,
                              dst,
                              headers=headers,
                              http_conn=self.http_connection)
            if self.environ.get("HTTP_OVERWRITE", '') != "T":
                raise DAVError(HTTP_CREATED)
            return True
        except client.ClientException:
            return False
开发者ID:mikalv,项目名称:swiftdav,代码行数:25,代码来源:swiftdav.py


示例13: create_pseudofolder_from_prefix

def create_pseudofolder_from_prefix(storage_url, auth_token, container,
                                    prefix, prefixlist):
    #Recursively creates pseudofolders from a given prefix, if the
    #prefix is not included in the prefixlist
    subprefix = '/'.join(prefix.split('/')[0:-1])
    if subprefix == '' or prefix in prefixlist:
        return prefixlist

    prefixlist = create_pseudofolder_from_prefix(
        storage_url,
        auth_token,
        container,
        subprefix,
        prefixlist)

    content_type = 'application/directory'
    obj = None

    client.put_object(
        storage_url,
        auth_token,
        container,
        prefix + '/',
        obj,
        content_type=content_type)
    prefixlist.append(prefix)

    return prefixlist
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:28,代码来源:utils.py


示例14: convert

def convert(vid_format, videos, local_file, container, storage_url, auth_token, this_id, id_original, c):
    temp_file = videos[vid_format]['temp_file']
    headers = _get_video_headers(storage_url, auth_token, container, this_id)
    conv = c.convert(local_file, temp_file, videos[vid_format]['options'])
    for ftimecode in conv:
        timecode = int(ftimecode * 100)
        if timecode == 100:
            break
        video_keys[id_original][vid_format + 'status'] = int(timecode)
        headers['X-Object-Meta-Status'] = timecode
        client.post_object(storage_url, auth_token, container, this_id, headers=headers)
        print "Converting %s (%f) ...%s\n" % (vid_format, timecode, local_file)
    if os.path.exists(temp_file):
        size = os.path.getsize(temp_file)
        print '\n\nSIZE: ', size, '\n\n'
    headers = _get_video_headers(storage_url, auth_token, container, this_id)
    headers['X-Object-Meta-Content-Type'] = 'video/' + vid_format
    headers['X-Object-Meta-Status'] = 100
    try:
        with open(temp_file, 'r+b') as f:
            client.put_object(storage_url, auth_token, container, this_id, f, headers=headers)
    except swift_exception.ClientException as e:
        storage_url, auth_token = _reauthorize(request)
        with open(temp_file, 'r+b') as f:
            client.put_object(storage_url, auth_token, container, this_id, f, headers=headers)
    video_keys[id_original][vid_format + 'status'] = 100
    if os.path.exists(temp_file):
        os.remove(temp_file)
开发者ID:InBetween,项目名称:AssetManager,代码行数:28,代码来源:views.py


示例15: create_pseudofolder

def create_pseudofolder(request, container, prefix=None):
    """ Creates a pseudofolder (empty object of type application/directory) """
    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    form = PseudoFolderForm(request.POST)
    if form.is_valid():
        foldername = request.POST.get('foldername', None)
        if prefix:
            foldername = prefix + '/' + foldername
        foldername = os.path.normpath(foldername)
        foldername = foldername.strip('/')
        foldername += '/'

        content_type = 'application/directory'
        obj = None

        try:
            client.put_object(storage_url, auth_token,
                              container, foldername, obj,
                              content_type=content_type)
            messages.add_message(
                request,
                messages.SUCCESS,
                _(
                    "The folder " +
                    request.POST.get('foldername', None) + " was created.")
            )

        except client.ClientException:
            messages.add_message(request, messages.ERROR, _("Access denied."))

    return JsonResponse({})
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:33,代码来源:main.py


示例16: _work

 def _work(self, op):
     running_ops = self.outstanding
     self.outstanding += 1
     t1 = time()
     try:
         # client = Connection(authurl='http://192.168.16.12:8080/auth/v1.0', user='test:tester', key='testing')
         # client.put_object(self.container,'%s-%s' % (self.base, op), self.data)
         put_object(self.storage_url, token=self.token, container=self.container, name='%s-%s' % (self.base, op), contents=self.data)
         t2 = time()
         elapsed = (t2-t1) * 1000
         self.outstanding -= 1
         LOG.info("Operation #%d took %.2f ms (%.2f MB/s, %d ops outstanding on arrival)" % (op, elapsed, (self.data_size / (1024.*1024)) / (t2 - t1) , running_ops))
         entry = { "Operation": op,
                   "Arrival-time": t1,
                   "Completion-time": t2,
                   "Elapsed": elapsed,
                   "Outstanding-on-arrival": running_ops,
                   "Outstanding-on-completion": self.outstanding }
         print '%d, %f, %f, %.2f, %d, %d' % (op, t1, t2, elapsed, running_ops, self.outstanding)
         return entry
     except KeyboardInterrupt:
         self.outstanding -= 1
         self.running = False
         return None
     except Exception:
         self.errors += 1
         raise
开发者ID:Seagate,项目名称:knobs,代码行数:27,代码来源:benchmarker-swift-write.py


示例17: test_async_update_after_PUT

    def test_async_update_after_PUT(self):
        cpart, cnodes = self.container_ring.get_nodes(self.account, 'c1')
        client.put_container(self.url, self.token, 'c1',
                             headers={'X-Storage-Policy':
                                      self.policy.name})

        # put an object while one container server is stopped so that we force
        # an async update to it
        kill_server((cnodes[0]['ip'], cnodes[0]['port']), self.ipport2server)
        content = u'stuff'
        client.put_object(self.url, self.token, 'c1', 'o1', contents=content)
        meta = client.head_object(self.url, self.token, 'c1', 'o1')

        # re-start the container server and assert that it does not yet know
        # about the object
        start_server((cnodes[0]['ip'], cnodes[0]['port']), self.ipport2server)
        self.assertFalse(direct_client.direct_get_container(
            cnodes[0], cpart, self.account, 'c1')[1])

        # Run the object-updaters to be sure updates are done
        Manager(['object-updater']).once()

        # check the re-started container server has update with override values
        obj = direct_client.direct_get_container(
            cnodes[0], cpart, self.account, 'c1')[1][0]
        self.assertEqual(meta['etag'], obj['hash'])
        self.assertEqual(len(content), obj['bytes'])
开发者ID:ISCAS-VDI,项目名称:swift-base,代码行数:27,代码来源:test_object_async_update.py


示例18: _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


示例19: get_segment_number

def get_segment_number(file_name, request, container, prefix=None):
    '''Return the segment number a given file should create next. If it is 0,
    create a pseudo folder for the file. The folder is created if it doesn't
    exist. '''

    if prefix:
        foldername = prefix + '/' + file_name + '_segments'
    else:
        foldername = file_name + '_segments'

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

    foldername = os.path.normpath(foldername)
    foldername = foldername.strip('/')
    foldername += '/'

    content_type = 'application/directory'
    obj = None

    client.put_object(storage_url, auth_token, container, foldername, obj,
                      content_type=content_type)

    meta, objects = client.get_container(storage_url, auth_token, container,
                                         delimiter='/', prefix=foldername)

    pseudofolders, objs = pseudofolder_object_list(objects, prefix)

    return get_first_nonconsecutive(objs)
开发者ID:OLRC,项目名称:django-swiftbrowser,代码行数:29,代码来源:slo.py


示例20: put_SLO

    def put_SLO(self):
        # Create temp files
        assembly = []
        for i in range(1, 10):
            oname = '/tmp/slo_chunk_%d' % i
            f = open(oname, 'r')
            content_length = None
            response = dict()
            c.put_object(self.url, self.token,
                         self.container, oname, f,
                         content_length, None, None,
                         "application/octet-stream",
                         None, None, None, None, response)
            f.close()
            status = response.get('status')
            self.assertTrue(status >= 200 and status < 300)

            headers = response.get('headers')
            segment = dict()
            segment['path'] = 'myobjects/%s' % oname
            segment['size_bytes'] = 1048576
            segment['etag'] = headers['etag']
            assembly.append(segment)

        content_length = None
        response = dict()
        headers = {'x-object-meta-prop1': 'val1'}
        c.put_object(self.url, self.token, self.container,
                     'assembly', json.dumps(assembly),
                     content_length=None, etag=None, chunk_size=None,
                     headers=headers, query_string='multipart-manifest=put',
                     response_dict=response)
        status = response.get('status')
        self.assertTrue(status >= 200 and status < 300)
开发者ID:Nicolepcx,项目名称:storlets,代码行数:34,代码来源:test_SLO.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python service.SwiftService类代码示例发布时间:2022-05-27
下一篇:
Python client.put_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