本文整理汇总了Python中oslo_utils.versionutils.convert_version_to_tuple方法的典型用法代码示例。如果您正苦于以下问题:Python versionutils.convert_version_to_tuple方法的具体用法?Python versionutils.convert_version_to_tuple怎么用?Python versionutils.convert_version_to_tuple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_utils.versionutils
的用法示例。
在下文中一共展示了versionutils.convert_version_to_tuple方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_octavia_version
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def get_octavia_version(self):
lbaas = clients.get_loadbalancer_client()
region_name = getattr(CONF.neutron, 'region_name', None)
regions = lbaas.get_all_version_data()
# If region was specified take it, otherwise just take first as default
endpoints = regions.get(region_name, list(regions.values())[0])
# Take the first endpoint
services = list(endpoints.values())[0]
# Try load-balancer service, if not take the first
versions = services.get('load-balancer', list(services.values())[0])
# Lookup the latest version. For safety, we won't look for
# version['status'] == 'CURRENT' and assume it's the maximum. Also we
# won't assume this dict is sorted.
max_ver = 0, 0
for version in versions:
v_tuple = versionutils.convert_version_to_tuple(version['version'])
if v_tuple > max_ver:
max_ver = v_tuple
LOG.debug("Detected Octavia version %d.%d", *max_ver)
return max_ver
示例2: _register_class
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def _register_class(self, cls):
def _vers_tuple(obj):
return vutils.convert_version_to_tuple(obj.VERSION)
_make_class_properties(cls)
obj_name = cls.obj_name()
for i, obj in enumerate(self._obj_classes[obj_name]):
self.registration_hook(cls, i)
if cls.VERSION == obj.VERSION:
self._obj_classes[obj_name][i] = cls
break
if _vers_tuple(cls) > _vers_tuple(obj):
# Insert before.
self._obj_classes[obj_name].insert(i, cls)
break
else:
# Either this is the first time we've seen the object or it's
# an older version than anything we'e seen.
self._obj_classes[obj_name].append(cls)
self.registration_hook(cls, 0)
示例3: _test_relationships_in_order
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def _test_relationships_in_order(self, obj_class):
for field, versions in obj_class.obj_relationships.items():
last_my_version = (0, 0)
last_child_version = (0, 0)
for my_version, child_version in versions:
_my_version = vutils.convert_version_to_tuple(my_version)
_ch_version = vutils.convert_version_to_tuple(child_version)
if not (last_my_version < _my_version and
last_child_version <= _ch_version):
raise AssertionError(('Object %s relationship %s->%s for '
'field %s is out of order') % (
obj_class.obj_name(),
my_version, child_version,
field))
last_my_version = _my_version
last_child_version = _ch_version
示例4: _get_common_version
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def _get_common_version(object_name, max_version, min_version, exc_notmatch,
exc_notsupported):
"""Returns the accepted version from the loaded OVO registry"""
reg = base.VersionedObjectRegistry.obj_classes()
if object_name not in reg:
raise exc_notmatch(name=object_name)
gotvers = []
for regobj in reg[object_name]:
gotvers.append(regobj.VERSION)
got = versionutils.convert_version_to_tuple(regobj.VERSION)
minwant = versionutils.convert_version_to_tuple(min_version)
maxwant = versionutils.convert_version_to_tuple(max_version)
if minwant <= got <= maxwant:
return regobj.VERSION
raise exc_notsupported(name=object_name,
got_versions=",".join(gotvers),
min_version=min_version,
max_version=max_version)
示例5: obj_make_compatible
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def obj_make_compatible(self, primitive, target_version):
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'request_id' in primitive:
del primitive['request_id']
示例6: obj_to_primitive
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def obj_to_primitive(self, target_version=None, version_manifest=None):
"""Simple base-case dehydration.
This calls to_primitive() for each item in fields.
"""
if target_version is None:
target_version = self.VERSION
if (vutils.convert_version_to_tuple(target_version) >
vutils.convert_version_to_tuple(self.VERSION)):
raise exception.InvalidTargetVersion(version=target_version)
primitive = dict()
for name, field in self.fields.items():
if self.obj_attr_is_set(name):
primitive[name] = field.to_primitive(self, name,
getattr(self, name))
# NOTE(danms): If we know we're being asked for a different version,
# then do the compat step. However, even if we think we're not,
# we may have sub-objects that need it, so if we have a manifest we
# have to traverse this object just in case. Previously, we
# required a parent version bump for any child, so the target
# check was enough.
if target_version != self.VERSION or version_manifest:
self.obj_make_compatible_from_manifest(primitive,
target_version,
version_manifest)
obj = {self._obj_primitive_key('name'): self.obj_name(),
self._obj_primitive_key('namespace'): (
self.OBJ_PROJECT_NAMESPACE),
self._obj_primitive_key('version'): target_version,
self._obj_primitive_key('data'): primitive}
if self.obj_what_changed():
# NOTE(cfriesen): if we're downgrading to a lower version, then
# it's possible that self.obj_what_changed() includes fields that
# no longer exist in the lower version. If so, filter them out.
what_changed = self.obj_what_changed()
changes = [field for field in what_changed if field in primitive]
if changes:
obj[self._obj_primitive_key('changes')] = changes
return obj
示例7: _get_subobject_version
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def _get_subobject_version(tgt_version, relationships, backport_func):
"""Get the version to which we need to convert a subobject.
This uses the relationships between a parent and a subobject,
along with the target parent version, to decide the version we need
to convert a subobject to. If the subobject did not exist in the parent at
the target version, TargetBeforeChildExistedException is raised. If there
is a need to backport, backport_func is called and the subobject version
to backport to is passed in.
:param tgt_version: The version we are converting the parent to
:param relationships: A list of (parent, subobject) version tuples
:param backport_func: A backport function that takes in the subobject
version
:returns: The version we need to convert the subobject to
"""
tgt = vutils.convert_version_to_tuple(tgt_version)
for index, versions in enumerate(relationships):
parent, child = versions
parent = vutils.convert_version_to_tuple(parent)
if tgt < parent:
if index == 0:
# We're backporting to a version of the parent that did
# not contain this subobject
raise exception.TargetBeforeSubobjectExistedException(
target_version=tgt_version)
else:
# We're in a gap between index-1 and index, so set the desired
# version to the previous index's version
child = relationships[index - 1][1]
backport_func(child)
return
elif tgt == parent:
# We found the version we want, so backport to it
backport_func(child)
return
示例8: _test_object_compatibility
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def _test_object_compatibility(self, obj_class, manifest=None,
init_args=None, init_kwargs=None):
init_args = init_args or []
init_kwargs = init_kwargs or {}
version = vutils.convert_version_to_tuple(obj_class.VERSION)
kwargs = {'version_manifest': manifest} if manifest else {}
for n in range(version[1] + 1):
test_version = '%d.%d' % (version[0], n)
# Run the test with OS_DEBUG=True to see this.
LOG.debug('testing obj: %s version: %s' %
(obj_class.obj_name(), test_version))
kwargs['target_version'] = test_version
obj_class(*init_args, **init_kwargs).obj_to_primitive(**kwargs)
示例9: registration_hook
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def registration_hook(self, cls, index):
# NOTE(Dinesh_Bhor): This is called when an object is registered,
# and is responsible for maintaining masakari.objects.$OBJECT
# as the highest-versioned implementation of a given object.
version = versionutils.convert_version_to_tuple(cls.VERSION)
if not hasattr(objects, cls.obj_name()):
setattr(objects, cls.obj_name(), cls)
else:
cur_version = versionutils.convert_version_to_tuple(
getattr(objects, cls.obj_name()).VERSION)
if version >= cur_version:
setattr(objects, cls.obj_name(), cls)
示例10: obj_make_compatible
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def obj_make_compatible(self, primitive, target_version):
super(Host, self).obj_make_compatible(primitive, target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version >= (1, 2) and 'failover_segment_id' in primitive:
del primitive['failover_segment_id']
示例11: obj_make_compatible
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def obj_make_compatible(self, primitive, target_version):
super(HealVnfRequest, self).obj_make_compatible(primitive,
target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'vnfc_instance_id' in primitive:
del primitive['vnfc_instance_id']
示例12: obj_make_compatible
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def obj_make_compatible(self, primitive, target_version):
super(VnfPackage, self).obj_make_compatible(primitive, target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'size' in primitive:
del primitive['size']
示例13: registration_hook
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def registration_hook(self, cls, index):
# NOTE(bhagyashris): This is called when an object is registered,
# and is responsible for maintaining tacker.objects.$OBJECT
# as the highest-versioned implementation of a given object.
version = versionutils.convert_version_to_tuple(cls.VERSION)
if not hasattr(objects, cls.obj_name()):
setattr(objects, cls.obj_name(), cls)
else:
cur_version = versionutils.convert_version_to_tuple(
getattr(objects, cls.obj_name()).VERSION)
if version >= cur_version:
setattr(objects, cls.obj_name(), cls)
示例14: registration_hook
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def registration_hook(self, cls, index):
# NOTE(danms): This is called when an object is registered,
# and is responsible for maintaining watcher.objects.$OBJECT
# as the highest-versioned implementation of a given object.
version = versionutils.convert_version_to_tuple(cls.VERSION)
if not hasattr(objects, cls.obj_name()):
setattr(objects, cls.obj_name(), cls)
else:
cur_version = versionutils.convert_version_to_tuple(
getattr(objects, cls.obj_name()).VERSION)
if version >= cur_version:
setattr(objects, cls.obj_name(), cls)
示例15: obj_make_compatible
# 需要导入模块: from oslo_utils import versionutils [as 别名]
# 或者: from oslo_utils.versionutils import convert_version_to_tuple [as 别名]
def obj_make_compatible(self, primitive, target_version):
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'supported_port_profiles' in primitive:
del primitive['supported_port_profiles']
super(HostVIFInfo, self).obj_make_compatible(primitive, '1.0')