Python oslo_utils.uuidutils.is_uuid_like() Examples
The following are 30
code examples of oslo_utils.uuidutils.is_uuid_like().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_utils.uuidutils
, or try the search function
.
Example #1
Source File: test_load_balancer.py From octavia with Apache License 2.0 | 6 votes |
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))
Example #2
Source File: api.py From magnum with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: test_flavor_profiles.py From octavia with Apache License 2.0 | 6 votes |
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)
Example #4
Source File: test_flavor_profiles.py From octavia with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: test_flavors.py From octavia with Apache License 2.0 | 6 votes |
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'))
Example #6
Source File: utils.py From rally-openstack with Apache License 2.0 | 6 votes |
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
Example #7
Source File: test_cluster.py From magnum with Apache License 2.0 | 6 votes |
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'])
Example #8
Source File: test_flavor_profiles.py From octavia with Apache License 2.0 | 6 votes |
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'))
Example #9
Source File: test_listener.py From octavia with Apache License 2.0 | 6 votes |
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'])
Example #10
Source File: imagecache.py From compute-hyperv with Apache License 2.0 | 6 votes |
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}
Example #11
Source File: test_bay.py From magnum with Apache License 2.0 | 6 votes |
def test_create_bay(self, mock_utcnow): bdict = apiutils.bay_post_data() test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json('/bays', bdict) self.assertEqual('application/json', response.content_type) self.assertEqual(201, response.status_int) # Check location header self.assertIsNotNone(response.location) self.assertTrue(uuidutils.is_uuid_like(response.json['uuid'])) self.assertNotIn('updated_at', response.json.keys) return_created_at = timeutils.parse_isotime( response.json['created_at']).replace(tzinfo=None) self.assertEqual(test_time, return_created_at) self.assertEqual(bdict['bay_create_timeout'], response.json['bay_create_timeout'])
Example #12
Source File: utils.py From zun with Apache License 2.0 | 6 votes |
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
Example #13
Source File: cinder_api.py From zun with Apache License 2.0 | 6 votes |
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
Example #14
Source File: test_availability_zone_profiles.py From octavia with Apache License 2.0 | 6 votes |
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)
Example #15
Source File: utils.py From zun with Apache License 2.0 | 6 votes |
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)
Example #16
Source File: test_flavors.py From octavia with Apache License 2.0 | 6 votes |
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)
Example #17
Source File: test_cluster.py From magnum with Apache License 2.0 | 5 votes |
def test_create_cluster_generate_uuid(self): bdict = apiutils.cluster_post_data() del bdict['uuid'] 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']))
Example #18
Source File: cluster_template.py From magnum with Apache License 2.0 | 5 votes |
def get(cls, context, cluster_template_id): """Find and return ClusterTemplate object based on its id or uuid. :param cluster_template_id: the id *or* uuid of a ClusterTemplate. :param context: Security context :returns: a :class:`ClusterTemplate` object. """ if strutils.is_int_like(cluster_template_id): return cls.get_by_id(context, cluster_template_id) elif uuidutils.is_uuid_like(cluster_template_id): return cls.get_by_uuid(context, cluster_template_id) else: raise exception.InvalidIdentity(identity=cluster_template_id)
Example #19
Source File: nodegroup.py From magnum with Apache License 2.0 | 5 votes |
def get(cls, context, cluster_id, nodegroup_id): """Find a nodegroup based on its id or uuid and return a NodeGroup. :param cluster_id: the of id a cluster. :param nodegroup_id: the id of a nodegroup. :param context: Security context :returns: a :class:`NodeGroup` object. """ if strutils.is_int_like(nodegroup_id): return cls.get_by_id(context, cluster_id, nodegroup_id) elif uuidutils.is_uuid_like(nodegroup_id): return cls.get_by_uuid(context, cluster_id, nodegroup_id) else: return cls.get_by_name(context, cluster_id, nodegroup_id)
Example #20
Source File: x509keypair.py From magnum with Apache License 2.0 | 5 votes |
def get(cls, context, x509keypair_id): """Find a X509KeyPair based on its id or uuid. Find X509KeyPair by id or uuid and return a X509KeyPair object. :param x509keypair_id: the id *or* uuid of a x509keypair. :param context: Security context :returns: a :class:`X509KeyPair` object. """ if strutils.is_int_like(x509keypair_id): return cls.get_by_id(context, x509keypair_id) elif uuidutils.is_uuid_like(x509keypair_id): return cls.get_by_uuid(context, x509keypair_id) else: raise exception.InvalidIdentity(identity=x509keypair_id)
Example #21
Source File: federation.py From magnum with Apache License 2.0 | 5 votes |
def get(cls, context, federation_id): """Find a federation based on its id or uuid and return it. :param federation_id: the id *or* uuid of a federation. :param context: Security context :returns: a :class:`Federation` object. """ if strutils.is_int_like(federation_id): return cls.get_by_id(context, federation_id) elif uuidutils.is_uuid_like(federation_id): return cls.get_by_uuid(context, federation_id) else: raise exception.InvalidIdentity(identity=federation_id)
Example #22
Source File: utils.py From magnum with Apache License 2.0 | 5 votes |
def get_openstack_resource(manager, resource_ident, resource_type): """Get the openstack resource from the uuid or logical name. :param manager: the resource manager class. :param resource_ident: the UUID or logical name of the resource. :param resource_type: the type of the resource :returns: The openstack resource. :raises: ResourceNotFound if the openstack resource is not exist. Conflict if multi openstack resources have same name. """ if uuidutils.is_uuid_like(resource_ident): resource_data = manager.get(resource_ident) else: filters = {'name': resource_ident} matches = list(manager.list(filters=filters)) if len(matches) == 0: raise exception.ResourceNotFound(name=resource_type, id=resource_ident) if len(matches) > 1: msg = ("Multiple %(resource_type)s exist with same name " "%(resource_ident)s. Please use the resource id " "instead." % {'resource_type': resource_type, 'resource_ident': resource_ident}) raise exception.Conflict(msg) resource_data = matches[0] return resource_data
Example #23
Source File: cluster.py From magnum with Apache License 2.0 | 5 votes |
def get(cls, context, cluster_id): """Find a cluster based on its id or uuid and return a Cluster object. :param cluster_id: the id *or* uuid of a cluster. :param context: Security context :returns: a :class:`Cluster` object. """ if strutils.is_int_like(cluster_id): return cls.get_by_id(context, cluster_id) elif uuidutils.is_uuid_like(cluster_id): return cls.get_by_uuid(context, cluster_id) else: raise exception.InvalidIdentity(identity=cluster_id)
Example #24
Source File: executions.py From python-mistralclient with Apache License 2.0 | 5 votes |
def create(self, workflow_identifier='', namespace='', workflow_input=None, description='', source_execution_id=None, **params): self._ensure_not_empty( workflow_identifier=workflow_identifier or source_execution_id ) data = {'description': description} if uuidutils.is_uuid_like(source_execution_id): data.update({'source_execution_id': source_execution_id}) if workflow_identifier: if uuidutils.is_uuid_like(workflow_identifier): data.update({'workflow_id': workflow_identifier}) else: data.update({'workflow_name': workflow_identifier}) if namespace: data.update({'workflow_namespace': namespace}) if workflow_input: if isinstance(workflow_input, str): data.update({'input': workflow_input}) else: data.update({'input': jsonutils.dumps(workflow_input)}) if params: data.update({'params': jsonutils.dumps(params)}) return self._create('/executions', data)
Example #25
Source File: cron_triggers.py From python-mistralclient with Apache License 2.0 | 5 votes |
def create(self, name, workflow_identifier, workflow_input=None, workflow_params=None, pattern=None, first_time=None, count=None): self._ensure_not_empty( name=name, workflow_identifier=workflow_identifier ) data = { 'name': name, 'pattern': pattern, 'first_execution_time': first_time, 'remaining_executions': count } if uuidutils.is_uuid_like(workflow_identifier): data.update({'workflow_id': workflow_identifier}) else: data.update({'workflow_name': workflow_identifier}) if workflow_input: data.update({'workflow_input': jsonutils.dumps(workflow_input)}) if workflow_params: data.update({'workflow_params': jsonutils.dumps(workflow_params)}) return self._create('/cron_triggers', data)
Example #26
Source File: vmops.py From compute-hyperv with Apache License 2.0 | 5 votes |
def list_instance_uuids(self): instance_uuids = [] for (instance_name, notes) in self._vmutils.list_instance_notes(): if notes and uuidutils.is_uuid_like(notes[0]): instance_uuids.append(str(notes[0])) else: LOG.debug("Notes not found or not resembling a GUID for " "instance: %s", instance_name) return instance_uuids
Example #27
Source File: pathutils.py From compute-hyperv with Apache License 2.0 | 5 votes |
def get_vm_config_file(self, path): for dir_file in os.listdir(path): file_name, file_ext = os.path.splitext(dir_file) if (file_ext.lower() in ['.vmcx', '.xml'] and uuidutils.is_uuid_like(file_name)): config_file = os.path.join(path, dir_file) LOG.debug("Found VM config file: %s", config_file) return config_file raise exception.NotFound( _("Folder %s does not contain any VM config data file.") % path)
Example #28
Source File: utils.py From designate with Apache License 2.0 | 5 votes |
def validate_uuid(*check): """ A wrapper to ensure that API controller methods arguments are valid UUID's. Usage: @validate_uuid('zone_id') def get_all(self, zone_id): return {} """ def inner(f): def wrapper(*args, **kwargs): arg_spec = inspect.getargspec(f).args # Ensure that we have the exact number of parameters that the # function expects. This handles URLs like # /v2/zones/<UUID - valid or invalid>/invalid # get, patch and delete return a 404, but Pecan returns a 405 # for a POST at the same URL if (len(arg_spec) != len(args)): raise exceptions.NotFound() # Ensure that we have non-empty parameters in the cases where we # have sub controllers - i.e. controllers at the 2nd level # This is for URLs like /v2/zones/nameservers # Ideally Pecan should be handling these cases, but until then # we handle those cases here. if (len(args) <= len(check)): raise exceptions.NotFound() for name in check: pos = arg_spec.index(name) if not is_uuid_like(args[pos]): msg = 'Invalid UUID %s: %s' % (name, args[pos]) raise exceptions.InvalidUUID(msg) return f(*args, **kwargs) return functools.wraps(f)(wrapper) return inner
Example #29
Source File: utils.py From designate with Apache License 2.0 | 5 votes |
def is_uuid_like(val): """Returns validation of a value as a UUID. For our purposes, a UUID is a canonical form string: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa """ return uuidutils.is_uuid_like(val)
Example #30
Source File: test_network_noop_driver.py From octavia with Apache License 2.0 | 5 votes |
def test_get_security_group(self): FAKE_SG_NAME = 'fake_sg_name' result = self.driver.get_security_group(FAKE_SG_NAME) self.assertEqual((FAKE_SG_NAME, 'get_security_group'), self.driver.driver.networkconfigconfig[FAKE_SG_NAME]) self.assertTrue(uuidutils.is_uuid_like(result.id))