本文整理匯總了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)
示例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
示例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
示例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))
示例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'])
示例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)
示例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)
示例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'))
示例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)
示例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'))
示例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)
示例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}
示例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
示例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)
示例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'])