本文整理汇总了Python中karesansui.lib.checker.Checker.check_unique_key方法的典型用法代码示例。如果您正苦于以下问题:Python Checker.check_unique_key方法的具体用法?Python Checker.check_unique_key怎么用?Python Checker.check_unique_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karesansui.lib.checker.Checker
的用法示例。
在下文中一共展示了Checker.check_unique_key方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validates_storage_pool
# 需要导入模块: from karesansui.lib.checker import Checker [as 别名]
# 或者: from karesansui.lib.checker.Checker import check_unique_key [as 别名]
def validates_storage_pool(obj, uuid=None):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if uuid:
check = checker.check_unique_key(_('Target UUID'),
uuid,
CHECK_EMPTY | CHECK_VALID,
) and check
else:
check = False
checker.add_error(_('"%s" is required.') %_('Target UUID'))
obj.view.alert = checker.errors
return check
示例2: validates_host_add
# 需要导入模块: from karesansui.lib.checker import Checker [as 别名]
# 或者: from karesansui.lib.checker.Checker import check_unique_key [as 别名]
def validates_host_add(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if not is_param(obj.input, 'm_name'):
check = False
checker.add_error(_('Parameter m_name does not exist.'))
else:
check = checker.check_string(
_('Machine Name'),
obj.input.m_name,
CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE,
None,
min = MACHINE_NAME_MIN_LENGTH,
max = MACHINE_NAME_MAX_LENGTH,
) and check
if not is_param(obj.input, 'm_hostname'):
check = False
checker.add_error(_('"%s" is required.') % _('FQDN'))
else:
m_hostname_parts = obj.input.m_hostname.split(":")
if len(m_hostname_parts) > 2:
check = False
checker.add_error(_('%s contains too many colon(:)s.') % _('FQDN'))
else:
check = checker.check_domainname(
_('FQDN'),
m_hostname_parts[0],
CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID,
min = FQDN_MIN_LENGTH,
max = FQDN_MAX_LENGTH,
) and check
try:
check = checker.check_number(
_('Port Number'),
m_hostname_parts[1],
CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
PORT_MIN_NUMBER,
PORT_MAX_NUMBER,
) and check
except IndexError:
# when reach here, 'm_hostname' has only host name
pass
if not is_param(obj.input, 'm_uuid'):
check = False
checker.add_error(_('"%s" is required.') % _('Unique Key'))
else:
check = checker.check_unique_key(
_('Unique Key'),
obj.input.m_uuid,
CHECK_EMPTY | CHECK_VALID
) and check
if is_param(obj.input, 'note_title'):
check = checker.check_string(
_('Title'),
obj.input.note_title,
CHECK_LENGTH | CHECK_ONLYSPACE,
None,
min = NOTE_TITLE_MIN_LENGTH,
max = NOTE_TITLE_MAX_LENGTH,
) and check
if is_param(obj.input, 'note_value'):
check = checker.check_string(
_('Note'),
obj.input.note_value,
CHECK_ONLYSPACE,
None,
None,
None,
) and check
if is_param(obj.input, 'tags'):
for tag in comma_split(obj.input.tags):
check = checker.check_string(
_('Tag'),
tag,
CHECK_LENGTH | CHECK_ONLYSPACE,
None,
min = TAG_MIN_LENGTH,
max = TAG_MAX_LENGTH,
) and check
obj.view.alert = checker.errors
return check
示例3: validates_server
# 需要导入模块: from karesansui.lib.checker import Checker [as 别名]
# 或者: from karesansui.lib.checker.Checker import check_unique_key [as 别名]
def validates_server(obj):
checker = Checker()
check = True
_ = obj._
checker.errors = []
if not is_param(obj.input, "uniqkey"):
check = False
checker.add_error(_('"%s" is required.') % _("Unique Key"))
else:
check = checker.check_unique_key(_("Unique Key"), obj.input.uniqkey, CHECK_EMPTY | CHECK_VALID) and check
if not is_param(obj.input, "port"):
check = False
checker.add_error(_('"%s" is required.') % _("Port Number"))
else:
check = (
checker.check_number(
_("Port Number"),
obj.input.port,
CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
PORT_MIN_NUMBER,
PORT_MAX_NUMBER,
)
and check
)
if not is_param(obj.input, "access"):
check = False
checker.add_error(_('"%s" is required.') % _("Access Policy"))
else:
if obj.input.access == "all":
check = True and check
elif obj.input.access == "network":
if not obj.input.has_key("network"):
check = False
checker.add_error(_('"%s" is required.') % _("Permit access from same network"))
else:
check = (
checker.check_cidr(
_("Permit Access From Same Network"), obj.input.network, CHECK_EMPTY | CHECK_VALID
)
and check
)
elif obj.input.access == "ipaddress":
if not obj.input.has_key("access_ipaddress"):
check = False
checker.add_error(_('"%s" is required.') % _("Permit access from specified IP address"))
else:
obj.input.ip_list = obj.input.access_ipaddress.split()
obj.input.ip_list = get_no_overlap_list(obj.input.ip_list)
if len(obj.input.ip_list) == 0:
check = False
checker.add_error(_('"%s" is required.') % _("IP Address"))
for input_ip in obj.input.ip_list:
check = (
checker.check_ipaddr(_("Permit specified IP address"), input_ip, CHECK_EMPTY | CHECK_VALID)
and check
)
else:
check = False
if not is_param(obj.input, "ssl_status"):
check = False
checker.add_error(_('"%s" is required.') % _("SSL Settings"))
else:
if obj.input.ssl_status == "enable":
check = True and check
elif obj.input.ssl_status == "disable":
check = True and check
else:
check = False
obj.view.alert = checker.errors
return check