本文整理汇总了Python中oslo_utils.uuidutils.generate_uuid方法的典型用法代码示例。如果您正苦于以下问题:Python uuidutils.generate_uuid方法的具体用法?Python uuidutils.generate_uuid怎么用?Python uuidutils.generate_uuid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_utils.uuidutils
的用法示例。
在下文中一共展示了uuidutils.generate_uuid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def __init__(self, name, uuid=None, generation=None, parent_uuid=None):
if uuid is None:
uuid = uuidutils.generate_uuid()
self.uuid = uuid
self.name = name
self.generation = generation
self.parent_uuid = parent_uuid
# Contains a dict, keyed by uuid of child resource providers having
# this provider as a parent
self.children = {}
# dict of inventory records, keyed by resource class
self.inventory = {}
# Set of trait names
self.traits = set()
# Set of aggregate UUIDs
self.aggregates = set()
示例2: create_registry
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def create_registry(self, context, values):
# ensure defaults are present for new registries
if not values.get('uuid'):
values['uuid'] = uuidutils.generate_uuid()
original_password = values.get('password')
if original_password:
values['password'] = crypt.encrypt(values.get('password'))
registry = models.Registry()
registry.update(values)
try:
registry.save()
except db_exc.DBDuplicateEntry:
raise exception.RegistryAlreadyExists(
field='UUID', value=values['uuid'])
if original_password:
# the password is encrypted but we want to return the original
# password
registry['password'] = original_password
return registry
示例3: test_refresh
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_refresh(self):
uuid = self.fake_provider['uuid']
new_uuid = uuidutils.generate_uuid()
returns = [dict(self.fake_provider, uuid=uuid),
dict(self.fake_provider, uuid=new_uuid)]
expected = [mock.call(self.context, uuid),
mock.call(self.context, uuid)]
with mock.patch.object(self.dbapi, 'get_resource_provider',
side_effect=returns,
autospec=True) as mock_get_resource_provider:
provider = objects.ResourceProvider.get_by_uuid(self.context, uuid)
self.assertEqual(uuid, provider.uuid)
provider.refresh()
self.assertEqual(new_uuid, provider.uuid)
self.assertEqual(
expected, mock_get_resource_provider.call_args_list)
self.assertEqual(self.context, provider._context)
示例4: test_refresh
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_refresh(self):
uuid = self.fake_container['uuid']
container_type = self.fake_container['container_type']
new_uuid = uuidutils.generate_uuid()
returns = [dict(self.fake_container, uuid=uuid),
dict(self.fake_container, uuid=new_uuid)]
expected = [mock.call(self.context, container_type, uuid),
mock.call(self.context, container_type, uuid)]
with mock.patch.object(self.dbapi, 'get_container_by_uuid',
side_effect=returns,
autospec=True) as mock_get_container:
container = objects.Container.get_by_uuid(self.context, uuid)
self.assertEqual(uuid, container.uuid)
container.refresh()
self.assertEqual(new_uuid, container.uuid)
self.assertEqual(expected, mock_get_container.call_args_list)
self.assertEqual(self.context, container._context)
示例5: test_get_all_hosts_with_pagination_marker
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_get_all_hosts_with_pagination_marker(self, mock_host_list,
mock_policy):
mock_policy.return_value = True
host_list = []
for id_ in range(4):
test_host = utils.create_test_compute_node(
context=self.context,
uuid=uuidutils.generate_uuid(),
rp_uuid=uuidutils.generate_uuid())
numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
test_host['numa_topology'] = numat
host = objects.ComputeNode(self.context, **test_host)
host_list.append(host)
mock_host_list.return_value = host_list[-1:]
response = self.get('/v1/hosts?limit=3&marker=%s'
% host_list[2].uuid)
self.assertEqual(200, response.status_int)
actual_hosts = response.json['hosts']
self.assertEqual(1, len(actual_hosts))
self.assertEqual(host_list[-1].uuid,
actual_hosts[0].get('uuid'))
示例6: test_get_all_images_with_pagination_marker
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_get_all_images_with_pagination_marker(
self, mock_image_list, mock_policy_enforce):
image_list = []
for id_ in range(4):
test_image = utils.create_test_image(
context=self.context,
id=id_,
repo='testrepo' + str(id_),
uuid=uuidutils.generate_uuid())
image_list.append(objects.Image(self.context, **test_image))
mock_image_list.return_value = image_list[-1:]
response = self.get('/v1/images/?limit=3&marker=%s'
% image_list[2].uuid)
self.assertEqual(200, response.status_int)
actual_images = response.json['images']
self.assertEqual(1, len(actual_images))
self.assertEqual(image_list[-1].uuid,
actual_images[0].get('uuid'))
示例7: test_get_all_registries_with_pagination_marker
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_get_all_registries_with_pagination_marker(self,
mock_registry_list):
registry_list = []
for id_ in range(4):
test_registry = utils.create_test_registry(
id=id_, uuid=uuidutils.generate_uuid(),
name='registry' + str(id_), context=self.context)
registry_list.append(objects.Registry(self.context,
**test_registry))
mock_registry_list.return_value = registry_list[-1:]
response = self.get('/v1/registries/?limit=3&marker=%s'
% registry_list[2].uuid)
self.assertEqual(200, response.status_int)
actual_registries = response.json['registries']
self.assertEqual(1, len(actual_registries))
self.assertEqual(registry_list[-1].uuid,
actual_registries[0].get('uuid'))
示例8: test_list_resource_providers_sorted
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_list_resource_providers_sorted(self):
uuids = []
for i in range(5):
provider = utils.create_test_resource_provider(
uuid=uuidutils.generate_uuid(),
context=self.context,
name='provider' + str(i))
uuids.append(str(provider.uuid))
res = dbapi.list_resource_providers(self.context, sort_key='uuid')
res_uuids = [r.uuid for r in res]
self.assertEqual(sorted(uuids), res_uuids)
self.assertRaises(exception.InvalidParameterValue,
dbapi.list_resource_providers,
self.context,
sort_key='foo')
示例9: test_list_resource_classes_sorted
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_list_resource_classes_sorted(self):
names = []
for i in range(5):
resource = utils.create_test_resource_class(
context=self.context,
uuid=uuidutils.generate_uuid(),
name='class' + str(i))
names.append(str(resource.name))
res = dbapi.list_resource_classes(self.context, sort_key='name')
res_names = [r.name for r in res]
self.assertEqual(sorted(names), res_names)
self.assertRaises(exception.InvalidParameterValue,
dbapi.list_resource_classes,
self.context,
sort_key='foo')
示例10: test_list_compute_nodes_sorted
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_list_compute_nodes_sorted(self):
uuids = []
for i in range(5):
node = utils.create_test_compute_node(
uuid=uuidutils.generate_uuid(),
rp_uuid=uuidutils.generate_uuid(),
context=self.context,
hostname='node' + str(i))
uuids.append(str(node.uuid))
res = dbapi.list_compute_nodes(self.context, sort_key='uuid')
res_uuids = [r.uuid for r in res]
self.assertEqual(sorted(uuids), res_uuids)
self.assertRaises(exception.InvalidParameterValue,
dbapi.list_compute_nodes,
self.context,
sort_key='foo')
示例11: test_list_images_with_filters
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_list_images_with_filters(self):
image1 = utils.create_test_image(
context=self.context, repo='image-one',
uuid=uuidutils.generate_uuid())
image2 = utils.create_test_image(
context=self.context, repo='image-two',
uuid=uuidutils.generate_uuid())
res = self.dbapi.list_images(self.context,
filters={'repo': 'image-one'})
self.assertEqual([image1.id], [r.id for r in res])
res = self.dbapi.list_images(self.context,
filters={'repo': 'image-two'})
self.assertEqual([image2.id], [r.id for r in res])
res = self.dbapi.list_images(self.context,
filters={'repo': 'bad-image'})
self.assertEqual([], [r.id for r in res])
res = self.dbapi.list_images(
self.context,
filters={'repo': image1.repo})
self.assertEqual([image1.id], [r.id for r in res])
示例12: test_list_containers_sorted
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_list_containers_sorted(self):
uuids = []
for i in range(5):
container = utils.create_test_container(
uuid=uuidutils.generate_uuid(),
context=self.context,
name='container' + str(i))
uuids.append(str(container.uuid))
res = dbapi.list_containers(
self.context, consts.TYPE_CONTAINER, sort_key='uuid')
res_uuids = [r.uuid for r in res]
self.assertEqual(sorted(uuids), res_uuids)
self.assertRaises(exception.InvalidParameterValue,
dbapi.list_containers,
self.context,
consts.TYPE_CONTAINER,
sort_key='foo')
示例13: test_update_container_with_the_same_name
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_update_container_with_the_same_name(self):
CONF.set_override("unique_container_name_scope", "project",
group="compute")
container1 = utils.create_test_container(
name='container-one',
uuid=uuidutils.generate_uuid(),
context=self.context)
container2 = utils.create_test_container(
name='container-two',
uuid=uuidutils.generate_uuid(),
context=self.context)
new_name = 'new_name'
dbapi.update_container(self.context, container1.container_type,
container1.id,
{'name': new_name})
self.assertRaises(exception.ContainerAlreadyExists,
dbapi.update_container, self.context,
container2.container_type,
container2.id, {'name': new_name})
示例14: test_list_inventories
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_list_inventories(self):
totals = []
for i in range(1, 6):
provider = utils.create_test_resource_provider(
id=i,
uuid=uuidutils.generate_uuid(),
context=self.context)
inventory = utils.create_test_inventory(
id=i,
resource_provider_id=provider.id,
total=i,
context=self.context)
totals.append(inventory['total'])
res = dbapi.list_inventories(self.context)
res_totals = [r.total for r in res]
self.assertEqual(sorted(totals), sorted(res_totals))
示例15: test_list_inventories_sorted
# 需要导入模块: from oslo_utils import uuidutils [as 别名]
# 或者: from oslo_utils.uuidutils import generate_uuid [as 别名]
def test_list_inventories_sorted(self):
totals = []
for i in range(5):
provider = utils.create_test_resource_provider(
id=i,
uuid=uuidutils.generate_uuid(),
context=self.context)
inventory = utils.create_test_inventory(
id=i,
resource_provider_id=provider.id,
total=10 - i,
context=self.context)
totals.append(inventory['total'])
res = dbapi.list_inventories(self.context,
sort_key='total')
res_totals = [r.total for r in res]
self.assertEqual(sorted(totals), res_totals)
self.assertRaises(exception.InvalidParameterValue,
dbapi.list_inventories,
self.context,
sort_key='foo')