当前位置: 首页>>代码示例>>Python>>正文


Python Checker.check_ip_range方法代码示例

本文整理汇总了Python中karesansui.lib.checker.Checker.check_ip_range方法的典型用法代码示例。如果您正苦于以下问题:Python Checker.check_ip_range方法的具体用法?Python Checker.check_ip_range怎么用?Python Checker.check_ip_range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在karesansui.lib.checker.Checker的用法示例。


在下文中一共展示了Checker.check_ip_range方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validates_network

# 需要导入模块: from karesansui.lib.checker import Checker [as 别名]
# 或者: from karesansui.lib.checker.Checker import check_ip_range [as 别名]
def validates_network(obj, network_name=None):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not network_name:
        check = False
        checker.add_error(_('Specify network name.'))

    if not is_param(obj.input, 'cidr'):
        check = False
        checker.add_error(_('Specify bridge IP address for the network.'))
    else:
        check = checker.check_ipaddr(
                _('Bridge IP Address/Netmask'),
                obj.input.cidr,
                CHECK_EMPTY | CHECK_VALID,
                ) and check

    if not is_param(obj.input, 'bridge'):
        check = False
        checker.add_error(_('Specify bridge name to create for the network.'))
    else:
        check = checker.check_netdev_name(
                _('Bridge Device Name'),
                obj.input.bridge,
                CHECK_EMPTY | CHECK_VALID,
                ) and check

    A = is_param(obj.input, 'dhcp_start')
    B = is_param(obj.input, 'dhcp_end')
    #if not ( ((not A) and (not B)) or (A and B)):
    if not (A and B):
        check = False
        checker.add_error(_('Specify both %s and %s') % (_('DHCP Start Address'), _('DHCP End Address')))

    if is_param(obj.input, 'dhcp_start'):
        check = checker.check_ipaddr(
                _('DHCP Start Address'),
                obj.input.dhcp_start,
                CHECK_EMPTY | CHECK_ONLYSPACE | CHECK_VALID,
                ) and check

    if is_param(obj.input, 'dhcp_end'):
        check = checker.check_ipaddr(
                _('DHCP End Address'),
                obj.input.dhcp_end,
                CHECK_EMPTY | CHECK_ONLYSPACE | CHECK_VALID,
                ) and check

    check = checker.check_if_ips_are_in_network(
                            [ _('DHCP Start Address'), _('DHCP End Address'), _('Bridge IP Address/Netmask')],
                            [obj.input.dhcp_start, obj.input.dhcp_end],
                            obj.input.cidr,
                            CHECK_VALID | CHECK_UNIQUE) and check

    check = checker.check_ip_range(
                            [ _('DHCP Start Address'), _('DHCP End Address'), _('Bridge IP Address/Netmask')],
                            [obj.input.dhcp_start, obj.input.dhcp_end, obj.input.cidr],
                            CHECK_VALID) and check

    check = checker.check_virt_network_address_conflict(
                            _('Bridge IP Address/Netmask'),
                            obj.input.cidr,
                            [network_name],   # names to ignore
                            CHECK_VALID) and check

    if is_param(obj.input, 'forward_mode'):
        check = checker.check_forward_mode(
                _('Forward Mode'),
                obj.input.forward_mode,
                CHECK_VALID,
                ) and check

    obj.view.alert = checker.errors
    return check
开发者ID:goura,项目名称:karesansui,代码行数:80,代码来源:hostby1networkby1.py

示例2: validates_network

# 需要导入模块: from karesansui.lib.checker import Checker [as 别名]
# 或者: from karesansui.lib.checker.Checker import check_ip_range [as 别名]
def validates_network(obj, network_name=None):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not is_param(obj.input, "name"):
        check = False
        checker.add_error(_("Specify network name."))
    else:
        check = checker.check_network_name(_("Network Name"), obj.input.name, CHECK_EMPTY | CHECK_VALID) and check

    if not is_param(obj.input, "cidr"):
        check = False
        checker.add_error(_("Specify bridge IP address for the network."))
    else:
        check = (
            checker.check_ipaddr(_("Bridge IP Address/Netmask"), obj.input.cidr, CHECK_EMPTY | CHECK_VALID) and check
        )

    if not is_param(obj.input, "bridge"):
        check = False
        checker.add_error(_("Specify bridge name to create for the network."))
    else:
        check = (
            checker.check_netdev_name(_("Bridge Device Name"), obj.input.bridge, CHECK_EMPTY | CHECK_VALID) and check
        )

    A = is_param(obj.input, "dhcp_start")
    B = is_param(obj.input, "dhcp_end")
    # if not ( ((not A) and (not B)) or (A and B)):
    if not (A and B):
        check = False
        checker.add_error(_("Specify both %s and %s") % (_("DHCP Start Address"), _("DHCP End Address")))

    if is_param(obj.input, "dhcp_start"):
        check = (
            checker.check_ipaddr(
                _("DHCP Start Address"), obj.input.dhcp_start, CHECK_EMPTY | CHECK_ONLYSPACE | CHECK_VALID
            )
            and check
        )

    if is_param(obj.input, "dhcp_end"):
        check = (
            checker.check_ipaddr(_("DHCP End Address"), obj.input.dhcp_end, CHECK_EMPTY | CHECK_ONLYSPACE | CHECK_VALID)
            and check
        )

    check = (
        checker.check_if_ips_are_in_network(
            [_("DHCP Start Address"), _("DHCP End Address"), _("Bridge IP Address/Netmask")],
            [obj.input.dhcp_start, obj.input.dhcp_end],
            obj.input.cidr,
            CHECK_VALID | CHECK_UNIQUE,
        )
        and check
    )

    check = (
        checker.check_ip_range(
            [_("DHCP Start Address"), _("DHCP End Address"), _("Bridge IP Address/Netmask")],
            [obj.input.dhcp_start, obj.input.dhcp_end, obj.input.cidr],
            CHECK_VALID,
        )
        and check
    )

    check = (
        checker.check_virt_network_address_conflict(
            _("Bridge IP Address/Netmask"), obj.input.cidr, [network_name], CHECK_VALID  # names to ignore
        )
        and check
    )

    if is_param(obj.input, "forward_mode"):
        check = checker.check_forward_mode(_("Forward Mode"), obj.input.forward_mode, CHECK_VALID) and check

    obj.view.alert = checker.errors
    return check
开发者ID:nabeken,项目名称:karesansui,代码行数:83,代码来源:hostby1network.py


注:本文中的karesansui.lib.checker.Checker.check_ip_range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。