本文整理汇总了Python中oslo_utils.strutils.is_int_like方法的典型用法代码示例。如果您正苦于以下问题:Python strutils.is_int_like方法的具体用法?Python strutils.is_int_like怎么用?Python strutils.is_int_like使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_utils.strutils
的用法示例。
在下文中一共展示了strutils.is_int_like方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_identity_filter
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_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)
示例2: test_is_int_like_false
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_like [as 别名]
def test_is_int_like_false(self):
self.assertFalse(strutils.is_int_like(1.1))
self.assertFalse(strutils.is_int_like("1.1"))
self.assertFalse(strutils.is_int_like("1.1.1"))
self.assertFalse(strutils.is_int_like(None))
self.assertFalse(strutils.is_int_like("0."))
self.assertFalse(strutils.is_int_like("aaaaaa"))
self.assertFalse(strutils.is_int_like("...."))
self.assertFalse(strutils.is_int_like("1g"))
self.assertFalse(
strutils.is_int_like("0cc3346e-9fef-4445-abe6-5d2b2690ec64"))
self.assertFalse(strutils.is_int_like("a1"))
# NOTE(viktors): 12e3 - is a float number
self.assertFalse(strutils.is_int_like("12e3"))
# NOTE(viktors): Check integer numbers with base not 10
self.assertFalse(strutils.is_int_like("0o51"))
self.assertFalse(strutils.is_int_like("0xDEADBEEF"))
示例3: __init__
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_like [as 别名]
def __init__(self, options):
"""Initialize a new Infoblox object instance
Args:
options (dict): Target options dictionary
"""
config = CONF[CFG_GROUP_NAME]
reqd_opts = ['wapi_url', 'username', 'password', 'ns_group']
other_opts = ['sslverify', 'network_view', 'dns_view', 'multi_tenant']
for opt in reqd_opts + other_opts:
if opt == 'sslverify' or opt == 'multi_tenant':
# NOTE(selvakumar): This check is for sslverify option.
# type of sslverify is unicode string from designate DB
# if the value is 0 getattr called for setting default values.
# to avoid setting default values we use oslo strutils
if not strutils.is_int_like(options.get(opt)):
option_value = options.get(opt)
else:
option_value = strutils.bool_from_string(options.get(opt),
default=True)
setattr(self, opt, option_value)
continue
setattr(self, opt, options.get(opt) or getattr(config, opt))
for opt in reqd_opts:
LOG.debug("self.%s = %s", opt, getattr(self, opt))
if not getattr(self, opt):
raise exc.InfobloxIsMisconfigured(option=opt)
self.session = requests.Session()
adapter = requests.adapters.HTTPAdapter(
pool_connections=config.http_pool_connections,
pool_maxsize=config.http_pool_maxsize)
self.session.mount('http://', adapter)
self.session.mount('https://', adapter)
self.session.auth = (self.username, self.password)
self.session.verify = self.sslverify
示例4: get
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_like [as 别名]
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)
示例5: get
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_like [as 别名]
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)
示例6: get
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_like [as 别名]
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)
示例7: get
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_like [as 别名]
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)
示例8: get
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_like [as 别名]
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)
示例9: get_positive_int
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_like [as 别名]
def get_positive_int(v):
"""Util function converting/checking a value of positive integer.
:param v: A value to be checked.
:returns: (b, v) where v is (converted) value if bool is True.
b is False if the value fails validation.
"""
if strutils.is_int_like(v):
count = int(v)
if count > 0:
return True, count
return False, 0
示例10: test_is_int_like_true
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_like [as 别名]
def test_is_int_like_true(self):
self.assertTrue(strutils.is_int_like(1))
self.assertTrue(strutils.is_int_like("1"))
self.assertTrue(strutils.is_int_like("514"))
self.assertTrue(strutils.is_int_like("0"))
示例11: _validate_data_type
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import is_int_like [as 别名]
def _validate_data_type(self, target):
if not self.values:
msg = ("Rule '%(rule)s' contains empty value")
raise exception.ValidationError(msg % {"rule": self})
special_attribute = self._attribute_special_field(target)
if special_attribute:
attribute_info = target.get(special_attribute)
else:
attribute_info = target.get(self.attribute)
for value in self.values:
error = False
if attribute_info[1] == 'string' and not isinstance(value,
six.string_types):
error = True
elif attribute_info[1] == 'number':
if not strutils.is_int_like(value):
error = True
elif attribute_info[1] == 'uuid':
if not uuidutils.is_uuid_like(value):
error = True
elif attribute_info[1] == 'datetime':
try:
timeutils.parse_isotime(value)
except ValueError:
error = True
elif attribute_info[1] == 'enum':
if value not in attribute_info[3]:
msg = ("Rule '%(rule)s' contains data type '%(type)s' "
"with invalid value. It should be one of "
"%(valid_value)s")
raise exception.ValidationError(msg % {"rule": self,
"valid_value": ",".join(attribute_info[3]),
'type': attribute_info[1]})
if error:
msg = ("Rule '%(rule)s' contains invalid data type for value "
"'%(value)s'. The data type should be '%(type)s'")
raise exception.ValidationError(msg % {"rule": self,
"value": value,
'type': attribute_info[1]})
# Also, check whether the data type is supported by operator
if attribute_info[1] not in \
self.OPERATOR_SUPPORTED_DATA_TYPES.get(self.operator):
msg = ("Rule '%(rule)s' contains operator '%(operator)s' "
"which doesn't support data type '%(type)s' for "
"attribute '%(attribute)s'")
raise exception.ValidationError(msg % {"rule": self,
"operator": self.operator,
'type': attribute_info[1],
'attribute': self.attribute})