本文整理汇总了Python中ipaddr.IPNetwork.masked方法的典型用法代码示例。如果您正苦于以下问题:Python IPNetwork.masked方法的具体用法?Python IPNetwork.masked怎么用?Python IPNetwork.masked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipaddr.IPNetwork
的用法示例。
在下文中一共展示了IPNetwork.masked方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_int_v4netmaskbit
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import masked [as 别名]
def clean_int_v4netmaskbit(self):
ip = self.cleaned_data.get("int_ipv4address")
nw = self.cleaned_data.get("int_v4netmaskbit")
if not nw or not ip:
return nw
network = IPNetwork('%s/%s' % (ip, nw))
used_networks = []
qs = models.Interfaces.objects.all()
if self.instance.id:
qs = qs.exclude(id=self.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_alias_v4netmaskbit
# 需要导入模块: from ipaddr import IPNetwork [as 别名]
# 或者: from ipaddr.IPNetwork import masked [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