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


Python uuidutils.is_uuid_like方法代码示例

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


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

示例1: get_resource

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def get_resource(resource, resource_ident):
    """Get the resource from the uuid or logical name.

    :param resource: the resource type.
    :param resource_ident: the UUID or logical name of the resource.

    :returns: The resource.
    """
    resource = getattr(objects, resource)
    context = pecan.request.context
    if context.is_admin:
        context.all_projects = True
    if uuidutils.is_uuid_like(resource_ident):
        return resource.get_by_uuid(context, resource_ident)

    return resource.get_by_name(context, resource_ident) 
开发者ID:openstack,项目名称:zun,代码行数:18,代码来源:utils.py

示例2: search_volume

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def search_volume(self, volume):
        if uuidutils.is_uuid_like(volume):
            try:
                volume = self.get(volume)
            except cinder_exception.NotFound:
                raise exception.VolumeNotFound(volume=volume)
        else:
            try:
                volume = self.cinder.volumes.find(name=volume)
            except cinder_exception.NotFound:
                raise exception.VolumeNotFound(volume=volume)
            except cinder_exception.NoUniqueMatch:
                raise exception.Conflict(_(
                    'Multiple cinder volumes exist with same name. '
                    'Please use the uuid instead.'))

        return volume 
开发者ID:openstack,项目名称:zun,代码行数:19,代码来源:cinder_api.py

示例3: find_images

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def find_images(context, image_ident, tag, exact_match):
    glance = create_glanceclient(context)
    if uuidutils.is_uuid_like(image_ident):
        images = []
        try:
            image = glance.images.get(image_ident)
            if image.container_format == 'docker':
                images.append(image)
        except glance_exceptions.NotFound:
            # ignore exception
            pass
    else:
        filters = {'container_format': 'docker'}
        images = list(glance.images.list(filters=filters))
        if exact_match:
            images = [i for i in images if i.name == image_ident]
        else:
            images = [i for i in images if image_ident in i.name]
        if tag and len(images) > 0:
            if len(images) == 1:
                if images[0].tags and tag not in images[0].tags:
                    del images[0]
            else:
                images = [i for i in images if tag in i.tags]
    return images 
开发者ID:openstack,项目名称:zun,代码行数:27,代码来源:utils.py

示例4: _assert_request_matches_response

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def _assert_request_matches_response(self, req, resp, **optionals):
        self.assertTrue(uuidutils.is_uuid_like(resp.get('id')))
        req_name = req.get('name')
        req_description = req.get('description')
        if not req_name:
            self.assertEqual('', resp.get('name'))
        else:
            self.assertEqual(req.get('name'), resp.get('name'))
        if not req_description:
            self.assertEqual('', resp.get('description'))
        else:
            self.assertEqual(req.get('description'), resp.get('description'))
        self.assertEqual(constants.PENDING_CREATE,
                         resp.get('provisioning_status'))
        self.assertEqual(constants.OFFLINE, resp.get('operating_status'))
        self.assertEqual(req.get('admin_state_up', True),
                         resp.get('admin_state_up'))
        self.assertIsNotNone(resp.get('created_at'))
        self.assertIsNone(resp.get('updated_at'))
        for key, value in optionals.items():
            self.assertEqual(value, req.get(key)) 
开发者ID:openstack,项目名称:octavia,代码行数:23,代码来源:test_load_balancer.py

示例5: test_create_defaults

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def test_create_defaults(self):
        defaults = {'name': None, 'default_pool_id': None,
                    'description': None, 'admin_state_up': True,
                    'connection_limit': None,
                    'default_tls_container_ref': None,
                    'sni_container_refs': [], 'project_id': None,
                    'insert_headers': {}}
        lb_listener = {'protocol': constants.PROTOCOL_HTTP,
                       'protocol_port': 80,
                       'loadbalancer_id': self.lb_id}
        body = self._build_body(lb_listener)
        response = self.post(self.LISTENERS_PATH, body)
        listener_api = response.json['listener']
        extra_expects = {'provisioning_status': constants.PENDING_CREATE,
                         'operating_status': constants.OFFLINE}
        lb_listener.update(extra_expects)
        lb_listener.update(defaults)
        self.assertTrue(uuidutils.is_uuid_like(listener_api.get('id')))
        lb_listener['id'] = listener_api.get('id')
        self.assertIsNotNone(listener_api.pop('created_at'))
        self.assertIsNone(listener_api.pop('updated_at'))
        self.assertNotEqual(lb_listener, listener_api)
        self.assert_correct_lb_status(self.lb_id, constants.ONLINE,
                                      constants.PENDING_UPDATE)
        self.assert_final_listener_statuses(self.lb_id, listener_api['id']) 
开发者ID:openstack,项目名称:octavia,代码行数:27,代码来源:test_listener.py

示例6: test_get_all

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def test_get_all(self):
        fp1 = self.create_flavor_profile('test1', 'noop_driver',
                                         '{"image": "ubuntu"}')
        ref_fp_1 = {u'flavor_data': u'{"image": "ubuntu"}',
                    u'id': fp1.get('id'), u'name': u'test1',
                    constants.PROVIDER_NAME: u'noop_driver'}
        self.assertTrue(uuidutils.is_uuid_like(fp1.get('id')))
        fp2 = self.create_flavor_profile('test2', 'noop_driver-alt',
                                         '{"image": "ubuntu"}')
        ref_fp_2 = {u'flavor_data': u'{"image": "ubuntu"}',
                    u'id': fp2.get('id'), u'name': u'test2',
                    constants.PROVIDER_NAME: u'noop_driver-alt'}
        self.assertTrue(uuidutils.is_uuid_like(fp2.get('id')))

        response = self.get(self.FPS_PATH)
        api_list = response.json.get(self.root_tag_list)
        self.assertEqual(2, len(api_list))
        self.assertIn(ref_fp_1, api_list)
        self.assertIn(ref_fp_2, api_list) 
开发者ID:openstack,项目名称:octavia,代码行数:21,代码来源:test_flavor_profiles.py

示例7: test_get_all_fields_filter

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def test_get_all_fields_filter(self):
        fp1 = self.create_flavor_profile('test1', 'noop_driver',
                                         '{"image": "ubuntu"}')
        self.assertTrue(uuidutils.is_uuid_like(fp1.get('id')))
        fp2 = self.create_flavor_profile('test2', 'noop_driver-alt',
                                         '{"image": "ubuntu"}')
        self.assertTrue(uuidutils.is_uuid_like(fp2.get('id')))

        response = self.get(self.FPS_PATH, params={
            'fields': ['id', 'name']})
        api_list = response.json.get(self.root_tag_list)
        self.assertEqual(2, len(api_list))
        for profile in api_list:
            self.assertIn(u'id', profile)
            self.assertIn(u'name', profile)
            self.assertNotIn(constants.PROVIDER_NAME, profile)
            self.assertNotIn(constants.FLAVOR_DATA, profile) 
开发者ID:openstack,项目名称:octavia,代码行数:19,代码来源:test_flavor_profiles.py

示例8: test_delete_not_authorized

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def test_delete_not_authorized(self):
        fp = self.create_flavor_profile('test1', 'noop_driver',
                                        '{"image": "ubuntu"}')
        self.assertTrue(uuidutils.is_uuid_like(fp.get('id')))
        self.conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
        auth_strategy = self.conf.conf.api_settings.get('auth_strategy')
        self.conf.config(group='api_settings', auth_strategy=constants.TESTING)

        response = self.delete(self.FP_PATH.format(
            fp_id=fp.get('id')), status=403)
        api_fp = response.json
        self.conf.config(group='api_settings', auth_strategy=auth_strategy)
        self.assertEqual(self.NOT_AUTHORIZED_BODY, api_fp)
        response = self.get(
            self.FP_PATH.format(fp_id=fp.get('id'))).json.get(self.root_tag)
        self.assertEqual('test1', response.get('name')) 
开发者ID:openstack,项目名称:octavia,代码行数:18,代码来源:test_flavor_profiles.py

示例9: test_get_all

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def test_get_all(self):
        flavor1 = self.create_flavor('name1', 'description', self.fp.get('id'),
                                     True)
        self.assertTrue(uuidutils.is_uuid_like(flavor1.get('id')))
        ref_flavor_1 = {
            u'description': u'description', u'enabled': True,
            u'flavor_profile_id': self.fp.get('id'),
            u'id': flavor1.get('id'),
            u'name': u'name1'}
        flavor2 = self.create_flavor('name2', 'description', self.fp.get('id'),
                                     True)
        self.assertTrue(uuidutils.is_uuid_like(flavor2.get('id')))
        ref_flavor_2 = {
            u'description': u'description', u'enabled': True,
            u'flavor_profile_id': self.fp.get('id'),
            u'id': flavor2.get('id'),
            u'name': u'name2'}
        response = self.get(self.FLAVORS_PATH)
        api_list = response.json.get(self.root_tag_list)
        self.assertEqual(2, len(api_list))
        self.assertIn(ref_flavor_1, api_list)
        self.assertIn(ref_flavor_2, api_list) 
开发者ID:openstack,项目名称:octavia,代码行数:24,代码来源:test_flavors.py

示例10: test_delete_not_authorized

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def test_delete_not_authorized(self):
        flavor = self.create_flavor('name1', 'description', self.fp.get('id'),
                                    True)
        self.assertTrue(uuidutils.is_uuid_like(flavor.get('id')))
        self.conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
        auth_strategy = self.conf.conf.api_settings.get('auth_strategy')
        self.conf.config(group='api_settings', auth_strategy=constants.TESTING)

        response = self.delete(self.FLAVOR_PATH.format(
            flavor_id=flavor.get('id')), status=403)
        api_flavor = response.json
        self.conf.config(group='api_settings', auth_strategy=auth_strategy)
        self.assertEqual(self.NOT_AUTHORIZED_BODY, api_flavor)

        response = self.get(self.FLAVOR_PATH.format(
            flavor_id=flavor.get('id'))).json.get(self.root_tag)
        self.assertEqual('name1', response.get('name')) 
开发者ID:openstack,项目名称:octavia,代码行数:19,代码来源:test_flavors.py

示例11: test_get_all_fields_filter

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def test_get_all_fields_filter(self):
        fp1 = self.create_availability_zone_profile(
            'test1', 'noop_driver', '{"compute_zone": "my_az_1"}')
        self.assertTrue(uuidutils.is_uuid_like(fp1.get('id')))
        fp2 = self.create_availability_zone_profile(
            'test2', 'noop_driver-alt', '{"compute_zone": "my_az_1"}')
        self.assertTrue(uuidutils.is_uuid_like(fp2.get('id')))

        response = self.get(self.AZPS_PATH, params={
            'fields': ['id', 'name']})
        api_list = response.json.get(self.root_tag_list)
        self.assertEqual(2, len(api_list))
        for profile in api_list:
            self.assertIn(u'id', profile)
            self.assertIn(u'name', profile)
            self.assertNotIn(constants.PROVIDER_NAME, profile)
            self.assertNotIn(constants.AVAILABILITY_ZONE_DATA, profile) 
开发者ID:openstack,项目名称:octavia,代码行数:19,代码来源:test_availability_zone_profiles.py

示例12: _list_base_images

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def _list_base_images(self, base_dir):
        unexplained_images = []
        originals = []

        for entry in os.listdir(base_dir):
            file_name, extension = os.path.splitext(entry)
            # extension has a leading '.'. E.g.: '.vhdx'
            if extension.lstrip('.').lower() not in ['vhd', 'vhdx']:
                # File is not an image. Ignore it.
                # imagecache will not store images of any other formats.
                continue

            if uuidutils.is_uuid_like(file_name):
                originals.append(file_name)
            else:
                unexplained_images.append(file_name)

        return {'unexplained_images': unexplained_images,
                'originals': originals} 
开发者ID:openstack,项目名称:compute-hyperv,代码行数:21,代码来源:imagecache.py

示例13: _setup_neutron_floating_ip_pool

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def _setup_neutron_floating_ip_pool(self, name_or_id):
        if name_or_id:
            if uuidutils.is_uuid_like(name_or_id):
                # Looks like an id is provided Return as is.
                return name_or_id
            else:
                # It's a name. Changing to id.
                for net in self.clients("neutron").list_networks()["networks"]:
                    if net["name"] == name_or_id:
                        return net["id"]
                # If the name is not found in the list. Exit with error.
                raise exceptions.ContextSetupFailure(
                    ctx_name=self.get_name(),
                    msg="Could not resolve Floating IP Pool name %s to id"
                        % name_or_id)
        else:
            # Pool is not provided. Using the one set as GW for current router.

            net = self.context["tenant"]["networks"][0]
            router_id = net["router_id"]
            router = self.clients("neutron").show_router(router_id)["router"]
            net_id = router["external_gateway_info"]["network_id"]

            return net_id 
开发者ID:openstack,项目名称:rally-openstack,代码行数:26,代码来源:utils.py

示例14: add_identity_filter

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def add_identity_filter(query, value):
    """Adds an identity filter to a query.

    Filters results by ID, if supplied value is a valid integer.
    Otherwise attempts to filter results by UUID.

    :param query: Initial query to add filter to.
    :param value: Value for filtering results by.
    :return: Modified query.
    """
    if strutils.is_int_like(value):
        return query.filter_by(id=value)
    elif uuidutils.is_uuid_like(value):
        return query.filter_by(uuid=value)
    else:
        raise exception.InvalidIdentity(identity=value) 
开发者ID:openstack,项目名称:magnum,代码行数:18,代码来源:api.py

示例15: test_create_cluster_resource_limit_reached

# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import is_uuid_like [as 别名]
def test_create_cluster_resource_limit_reached(self, mock_utcnow):
        # override max_cluster_per_project to 1
        CONF.set_override('max_clusters_per_project', 1, group='quotas')

        bdict = apiutils.cluster_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        # create first cluster
        response = self.post_json('/clusters', bdict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(202, response.status_int)
        self.assertTrue(uuidutils.is_uuid_like(response.json['uuid']))

        # now try to create second cluster and make sure it fails
        response = self.post_json('/clusters', bdict, expect_errors=True)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(403, response.status_int)
        self.assertTrue(response.json['errors']) 
开发者ID:openstack,项目名称:magnum,代码行数:21,代码来源:test_cluster.py


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