本文整理汇总了Python中ipaddr.IPNetwork.overlaps方法的典型用法代码示例。如果您正苦于以下问题:Python IPNetwork.overlaps方法的具体用法?Python IPNetwork.overlaps怎么用?Python IPNetwork.overlaps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipaddr.IPNetwork
的用法示例。
在下文中一共展示了IPNetwork.overlaps方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_alias_v4netmaskbit
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import overlaps [as 别名]
def clean_alias_v4netmaskbit(self):
vip = self.cleaned_data.get("alias_vip")
ip = self.cleaned_data.get("alias_v4address")
nw = self.cleaned_data.get("alias_v4netmaskbit")
if not nw or not ip:
return nw
network = IPNetwork("%s/%s" % (ip, nw))
if vip:
if not network.overlaps(IPNetwork("%s/%s" % (vip, nw))):
raise forms.ValidationError(_("Virtual IP is not in the same network"))
if self.instance.id and self.instance.alias_interface.int_interface.startswith("carp"):
return nw
used_networks = []
qs = models.Interfaces.objects.all().exclude(int_interface__startswith="carp")
if self.instance.id:
qs = qs.exclude(id=self.instance.alias_interface.id)
elif self.parent.instance.id:
qs = qs.exclude(id=self.parent.instance.id)
for iface in qs:
if iface.int_v4netmaskbit:
used_networks.append(IPNetwork("%s/%s" % (iface.int_ipv4address, iface.int_v4netmaskbit)))
for alias in iface.alias_set.all():
if alias.alias_v4netmaskbit:
used_networks.append(IPNetwork("%s/%s" % (alias.alias_v4address, alias.alias_v4netmaskbit)))
for unet in used_networks:
if unet.overlaps(network):
raise forms.ValidationError(_("The network %s is already in use by another NIC.") % (network.masked(),))
return nw
示例2: clean
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import overlaps [as 别名]
def clean(self):
cdata = self.cleaned_data
ipv4key = 'int_ipv4address'
ipv4addr = cdata.get(ipv4key)
ipv4addr_b = cdata.get('int_ipv4address_b')
ipv4net = cdata.get("int_v4netmaskbit")
if ipv4addr and ipv4addr_b and ipv4net:
network = IPNetwork('%s/%s' % (ipv4addr, ipv4net))
if not network.overlaps(
IPNetwork('%s/%s' % (ipv4addr_b, ipv4net))
):
self._errors['int_ipv4address_b'] = self.error_class([
_('The IP must be within the same network')
])
ipv6addr = cdata.get("int_ipv6address")
ipv6net = cdata.get("int_v6netmaskbit")
ipv4 = True if ipv4addr and ipv4net else False
ipv6 = True if ipv6addr and ipv6net else False
# IF one field of ipv4 is entered, require the another
if (ipv4addr or ipv4net) and not ipv4:
if not (ipv4addr or ipv4addr_b) and not self._errors.get(ipv4key):
self._errors[ipv4key] = self.error_class([
_("You have to specify IPv4 address as well"),
])
if not ipv4net and 'int_v4netmaskbit' not in self._errors:
self._errors['int_v4netmaskbit'] = self.error_class([
_("You have to choose IPv4 netmask as well"),
])
# IF one field of ipv6 is entered, require the another
if (ipv6addr or ipv6net) and not ipv6:
if not ipv6addr and not self._errors.get('int_ipv6address'):
self._errors['int_ipv6address'] = self.error_class([
_("You have to specify IPv6 address as well"),
])
if not ipv6net:
self._errors['int_v6netmaskbit'] = self.error_class([
_("You have to choose IPv6 netmask as well"),
])
if ipv6 and ipv4:
self._errors['__all__'] = self.error_class([
_("You have to choose between IPv4 or IPv6"),
])
vip = cdata.get("int_vip")
if vip and not ipv4addr_b:
self._errors['int_ipv4address_b'] = self.error_class([
_("This field is required for failover")
])
if vip and not ipv4addr:
self._errors['int_ipv4address'] = self.error_class([
_("This field is required for failover")
])
return cdata
示例3: clean
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import overlaps [as 别名]
def clean(self):
cdata = self.cleaned_data
ipv4vip = cdata.get("alias_vip")
ipv4addr = cdata.get("alias_v4address")
ipv4net = cdata.get("alias_v4netmaskbit")
ipv6addr = cdata.get("alias_v6address")
ipv6net = cdata.get("alias_v6netmaskbit")
ipv4 = True if ipv4addr and ipv4net else False
ipv6 = True if ipv6addr and ipv6net else False
# IF one field of ipv4 is entered, require the another
if (ipv4addr or ipv4net) and not ipv4:
if not ipv4addr and not self._errors.get('alias_v4address'):
self._errors['alias_v4address'] = self.error_class([
_("You have to specify IPv4 address as well per alias"),
])
if not ipv4net and 'alias_v4netmaskbit' not in self._errors:
self._errors['alias_v4netmaskbit'] = self.error_class([
_("You have to choose IPv4 netmask as well per alias"),
])
# IF one field of ipv6 is entered, require the another
if (ipv6addr or ipv6net) and not ipv6:
if not ipv6addr and not self._errors.get('alias_v6address'):
self._errors['alias_v6address'] = self.error_class([
_("You have to specify IPv6 address as well per alias"),
])
if not ipv6net:
self._errors['alias_v6netmaskbit'] = self.error_class([
_("You have to choose IPv6 netmask as well per alias"),
])
if ipv6 and ipv4:
self._errors['__all__'] = self.error_class([
_("You have to choose between IPv4 or IPv6 per alias"),
])
configured_vip = False
if ipv4vip and hasattr(self, 'parent'):
iface = self.parent.instance
ip = IPNetwork('%s/32' % ipv4vip)
network = IPNetwork('%s/%s' % (
iface.int_ipv4address,
iface.int_v4netmaskbit,
))
if ip.overlaps(network):
configured_vip = True
if (
not configured_vip and not ipv6 and not (ipv6addr or ipv6net) and
not ipv4 and not (ipv4addr or ipv4net)
):
self._errors['__all__'] = self.error_class([
_("You must specify either an valid IPv4 or IPv6 with maskbit "
"per alias"),
])
return cdata
示例4: clean
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import overlaps [as 别名]
def clean(self):
cdata = self.cleaned_data
_n = notifier()
if not _n.is_freenas() and _n.failover_licensed():
from freenasUI.failover.models import Failover
try:
if Failover.objects.all()[0].disabled is False:
self._errors["__all__"] = self.error_class(
[_("Failover needs to be disabled to perform network " "changes.")]
)
except:
log.warn("Failed to verify failover status", exc_info=True)
ipv4key = "int_ipv4address"
ipv4addr = cdata.get(ipv4key)
ipv4addr_b = cdata.get("int_ipv4address_b")
ipv4net = cdata.get("int_v4netmaskbit")
if ipv4addr and ipv4addr_b and ipv4net:
network = IPNetwork("%s/%s" % (ipv4addr, ipv4net))
if not network.overlaps(IPNetwork("%s/%s" % (ipv4addr_b, ipv4net))):
self._errors["int_ipv4address_b"] = self.error_class([_("The IP must be within the same network")])
ipv6addr = cdata.get("int_ipv6address")
ipv6net = cdata.get("int_v6netmaskbit")
ipv4 = True if ipv4addr and ipv4net else False
ipv6 = True if ipv6addr and ipv6net else False
# IF one field of ipv4 is entered, require the another
if (ipv4addr or ipv4net) and not ipv4:
if not (ipv4addr or ipv4addr_b) and not self._errors.get(ipv4key):
self._errors[ipv4key] = self.error_class([_("You have to specify IPv4 address as well")])
if not ipv4net and "int_v4netmaskbit" not in self._errors:
self._errors["int_v4netmaskbit"] = self.error_class([_("You have to choose IPv4 netmask as well")])
# IF one field of ipv6 is entered, require the another
if (ipv6addr or ipv6net) and not ipv6:
if not ipv6addr and not self._errors.get("int_ipv6address"):
self._errors["int_ipv6address"] = self.error_class([_("You have to specify IPv6 address as well")])
if not ipv6net:
self._errors["int_v6netmaskbit"] = self.error_class([_("You have to choose IPv6 netmask as well")])
if ipv6 and ipv4:
self._errors["__all__"] = self.error_class([_("You have to choose between IPv4 or IPv6")])
vip = cdata.get("int_vip")
dhcp = cdata.get("int_dhcp")
if not dhcp:
if vip and not ipv4addr_b:
self._errors["int_ipv4address_b"] = self.error_class([_("This field is required for failover")])
if vip and not ipv4addr:
self._errors["int_ipv4address"] = self.error_class([_("This field is required for failover")])
return cdata
示例5: clean
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import overlaps [as 别名]
def clean(self):
cdata = self.cleaned_data
_n = notifier()
if (
not _n.is_freenas() and _n.failover_licensed() and
_n.failover_status() != 'SINGLE' and (
self.instance.id and self.instance.int_vip
)
):
from freenasUI.failover.models import Failover
try:
if Failover.objects.all()[0].disabled is False:
self._errors['__all__'] = self.error_class([_(
'Failover needs to be disabled to perform network '
'changes.'
)])
except:
log.warn('Failed to verify failover status', exc_info=True)
ipv4key = 'int_ipv4address'
ipv4addr = cdata.get(ipv4key)
ipv4addr_b = cdata.get('int_ipv4address_b')
ipv4net = cdata.get("int_v4netmaskbit")
if ipv4addr and ipv4addr_b and ipv4net:
network = IPNetwork('%s/%s' % (ipv4addr, ipv4net))
if not network.overlaps(
IPNetwork('%s/%s' % (ipv4addr_b, ipv4net))
):
self._errors['int_ipv4address_b'] = self.error_class([
_('The IP must be within the same network')
])
ipv6addr = cdata.get("int_ipv6address")
ipv6net = cdata.get("int_v6netmaskbit")
ipv4 = True if ipv4addr and ipv4net else False
ipv6 = True if ipv6addr and ipv6net else False
# IF one field of ipv4 is entered, require the another
if (ipv4addr or ipv4net) and not ipv4:
if not (ipv4addr or ipv4addr_b) and not self._errors.get(ipv4key):
self._errors[ipv4key] = self.error_class([
_("You have to specify IPv4 address as well"),
])
if not ipv4net and 'int_v4netmaskbit' not in self._errors:
self._errors['int_v4netmaskbit'] = self.error_class([
_("You have to choose IPv4 netmask as well"),
])
# IF one field of ipv6 is entered, require the another
if (ipv6addr or ipv6net) and not ipv6:
if not ipv6addr and not self._errors.get('int_ipv6address'):
self._errors['int_ipv6address'] = self.error_class([
_("You have to specify IPv6 address as well"),
])
if not ipv6net:
self._errors['int_v6netmaskbit'] = self.error_class([
_("You have to choose IPv6 netmask as well"),
])
vip = cdata.get("int_vip")
dhcp = cdata.get("int_dhcp")
if not dhcp:
if vip and not ipv4addr_b:
self._errors['int_ipv4address_b'] = self.error_class([
_("This field is required for failover")
])
if vip and not ipv4addr:
self._errors['int_ipv4address'] = self.error_class([
_("This field is required for failover")
])
else:
cdata['int_ipv4address'] = ''
cdata['int_v4netmaskbit'] = ''
# API backward compatibility
options = cdata.get('int_options')
if options:
reg = RE_MTU.search(options)
if reg:
cdata['int_mtu'] = int(reg.group(1))
cdata['int_options'] = options.replace(reg.group(0), '')
return cdata