本文整理汇总了Python中netaddr.IPNetwork.__iadd__方法的典型用法代码示例。如果您正苦于以下问题:Python IPNetwork.__iadd__方法的具体用法?Python IPNetwork.__iadd__怎么用?Python IPNetwork.__iadd__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netaddr.IPNetwork
的用法示例。
在下文中一共展示了IPNetwork.__iadd__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createNewVlanRange
# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import __iadd__ [as 别名]
def createNewVlanRange(cls):
""" Increment current cidr of vlan range present in network
and create new range
"""
publicIpRange = PublicIpRange.list(cls.api_client)
cls.startIp = publicIpRange[0].startip
cls.endIp = publicIpRange[0].endip
cls.gateway = publicIpRange[0].gateway
cls.netmask = publicIpRange[0].netmask
# Pass ip address and mask length to IPNetwork to findout the CIDR
ip = IPNetwork(cls.startIp + "/" + cls.netmask)
# Take random increment factor to avoid adding the same vlan ip range
# in each test case
networkIncrementFactor = random.randint(1,255)
new_cidr = ip.__iadd__(networkIncrementFactor)
ip2 = IPNetwork(new_cidr)
test_nw = ip2.network
ip = IPAddress(test_nw)
# Add IP range(5 IPs) in the new CIDR
test_gateway = ip.__add__(1)
test_startIp = ip.__add__(3)
test_endIp = ip.__add__(10)
# Populating services with new IP range
cls.testdata["vlan_ip_range"]["startip"] = test_startIp
cls.testdata["vlan_ip_range"]["endip"] = test_endIp
cls.testdata["vlan_ip_range"]["gateway"] = test_gateway
cls.testdata["vlan_ip_range"]["netmask"] = cls.netmask
cls.testdata["vlan_ip_range"]["zoneid"] = cls.zone.id
cls.testdata["vlan_ip_range"]["podid"] = cls.pod.id
return PublicIpRange.create(
cls.api_client,
cls.testdata["vlan_ip_range"])
示例2: increment_cidr
# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import __iadd__ [as 别名]
def increment_cidr(self):
"""Takes CIDR as input and will increment by one and returns the new CIDR
"""
publicIpRange = PublicIpRange.list(self.apiclient)
self.startIp = publicIpRange[0].startip
self.endIp = publicIpRange[0].endip
self.gateway = publicIpRange[0].gateway
self.netmask = publicIpRange[0].netmask
# Pass ip address and mask length to IPNetwork to findout the CIDR
ip = IPNetwork(self.startIp + "/" + self.netmask)
# Take random increment factor to avoid adding the same vlan ip range
# in each test case
networkIncrementFactor = random.randint(1,255)
new_cidr = ip.__iadd__(networkIncrementFactor)
ip2 = IPNetwork(new_cidr)
return ip2