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


Python AstakosClient.user_term方法代码示例

本文整理汇总了Python中kamaki.clients.astakos.AstakosClient.user_term方法的典型用法代码示例。如果您正苦于以下问题:Python AstakosClient.user_term方法的具体用法?Python AstakosClient.user_term怎么用?Python AstakosClient.user_term使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kamaki.clients.astakos.AstakosClient的用法示例。


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

示例1: Image

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import user_term [as 别名]
class Image(livetest.Generic):
    def setUp(self):
        self.now = time.mktime(time.gmtime())
        self.cloud = 'cloud.%s' % self['testcloud']
        aurl, self.token = self[self.cloud, 'url'], self[self.cloud, 'token']
        self.auth_base = AstakosCachedClient(aurl, self.token)
        self.imgname = 'img_%s' % self.now
        url = self.auth_base.get_service_endpoints('image')['publicURL']
        self.token = self.auth_base.token
        self.client = ImageClient(url, self.token)
        cyclades_url = self.auth_base.get_service_endpoints(
            'compute')['publicURL']
        self.cyclades = CycladesClient(cyclades_url, self.token)
        self._imglist = {}
        self._imgdetails = {}

    def test_000(self):
        self._prepare_img()
        super(self.__class__, self).test_000()

    def _prepare_img(self):
        f = open(self['image', 'local_path'], 'rb')
        (token, uuid) = (self.token, self.auth_base.user_term('id'))
        purl = self.auth_base.get_service_endpoints(
            'object-store')['publicURL']
        from kamaki.clients.pithos import PithosClient
        self.pithcli = PithosClient(purl, token, uuid)
        cont = 'cont_%s' % self.now
        self.pithcli.container = cont
        self.obj = 'obj_%s' % self.now
        print('\t- Create container %s on Pithos server' % cont)
        self.pithcli.container_put()
        self.location = 'pithos://%s/%s/%s' % (uuid, cont, self.obj)
        print('\t- Upload an image at %s...\n' % self.location)
        self.pithcli.upload_object(self.obj, f)
        print('\t- ok')
        f.close()

        r = self.client.register(
            self.imgname, self.location, params=dict(is_public=True))
        self._imglist[self.imgname] = dict(
            name=r['name'], id=r['id'])
        self._imgdetails[self.imgname] = r

    def tearDown(self):
        for img in self._imglist.values():
            print('\tDeleting image %s' % img['id'])
            self.cyclades.delete_image(img['id'])
        if hasattr(self, 'pithcli'):
            print('\tDeleting container %s' % self.pithcli.container)
            try:
                self.pithcli.del_container(delimiter='/')
                self.pithcli.purge_container()
            except ClientError:
                pass

    def _get_img_by_name(self, name):
        r = self.cyclades.list_images()
        for img in r:
            if img['name'] == name:
                return img
        return None

    def test_list_public(self):
        """Test list_public"""
        self._test_list_public()

    def _test_list_public(self):
        r = self.client.list_public()
        r0 = self.client.list_public(order='-')
        self.assertTrue(len(r) > 0)
        for img in r:
            for term in (
                    'status',
                    'name',
                    'container_format',
                    'disk_format',
                    'id',
                    'size'):
                self.assertTrue(term in img)
        self.assertTrue(r, r0)
        r0.reverse()
        for i, img in enumerate(r):
            self.assert_dicts_are_equal(img, r0[i])
        r1 = self.client.list_public(detail=True)
        for img in r1:
            for term in (
                    'status',
                    'name',
                    'checksum',
                    'created_at',
                    'disk_format',
                    'updated_at',
                    'id',
                    'location',
                    'container_format',
                    'owner',
                    'is_public',
                    'deleted_at',
                    'properties',
#.........这里部分代码省略.........
开发者ID:Erethon,项目名称:kamaki,代码行数:103,代码来源:image.py

示例2: Pithos

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import user_term [as 别名]
class Pithos(livetest.Generic):

    files = []

    def setUp(self):
        self.cloud = 'cloud.%s' % self['testcloud']
        aurl, self.token = self[self.cloud, 'url'], self[self.cloud, 'token']
        self.auth_base = AstakosClient(aurl, self.token)
        purl = self.auth_base.get_service_endpoints(
            'object-store')['publicURL']
        self.uuid = self.auth_base.user_term('id')
        self.client = PithosClient(purl, self.token, self.uuid)

        self.now = time.mktime(time.gmtime())
        self.now_unformated = datetime.datetime.utcnow()
        self._init_data()

        """Prepare an object to be shared - also its container"""
        self.client.container = self.c1
        self.client.object_post(
            'test',
            update=True,
            permissions={'read': [self.client.account]})

        self.create_remote_object(self.c1, 'another.test')

    def _init_data(self):
        self.c1 = 'c1_' + unicode(self.now)
        self.c2 = 'c2_' + unicode(self.now)
        self.c3 = 'c3_' + unicode(self.now)
        try:
            self.client.create_container(self.c2)
        except ClientError:
            pass
        try:
            self.client.create_container(self.c1)
        except ClientError:
            pass
        try:
            self.client.create_container(self.c3)
        except ClientError:
            pass

        self.create_remote_object(self.c1, 'test')
        self.create_remote_object(self.c2, 'test')
        self.create_remote_object(self.c1, 'test1')
        self.create_remote_object(self.c2, 'test1')

    def create_remote_object(self, container, obj):
        self.client.container = container
        self.client.object_put(
            obj,
            content_type='application/octet-stream',
            data='file %s that lives in %s' % (obj, container),
            metadata={'incontainer': container})

    def forceDeleteContainer(self, container):
        self.client.container = container
        try:
            r = self.client.list_objects()
        except ClientError:
            return
        for obj in r:
            name = obj['name']
            self.client.del_object(name)
        r = self.client.container_delete()
        self.container = ''

    def tearDown(self):
        """Destroy test cases"""
        for f in self.files:
            f.close()
        self.forceDeleteContainer(self.c1)
        self.forceDeleteContainer(self.c2)
        try:
            self.forceDeleteContainer(self.c3)
        except ClientError:
            pass
        self.client.container = ''

    def test_000(self):
        """Prepare a full Pithos+ test"""
        print('')
        super(self.__class__, self).test_000()

    def test_account_head(self):
        """Test account_HEAD"""
        self._test_0010_account_head()

    def _test_0010_account_head(self):
        r = self.client.account_head()
        self.assertEqual(r.status_code, 204)

        r = self.client.account_head(until='1000000000')
        self.assertEqual(r.status_code, 204)

        r = self.client.get_account_info(until='1000000000')
        datestring = unicode(r['x-account-until-timestamp'])
        self.assertEqual(u'Sun, 09 Sep 2001 01:46:40 GMT', datestring)

#.........这里部分代码省略.........
开发者ID:Erethon,项目名称:kamaki,代码行数:103,代码来源:pithos.py


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