本文整理汇总了Python中netaddr.IPAddress.__add__方法的典型用法代码示例。如果您正苦于以下问题:Python IPAddress.__add__方法的具体用法?Python IPAddress.__add__怎么用?Python IPAddress.__add__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netaddr.IPAddress
的用法示例。
在下文中一共展示了IPAddress.__add__方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_04_add_noncontiguous_ip_range
# 需要导入模块: from netaddr import IPAddress [as 别名]
# 或者: from netaddr.IPAddress import __add__ [as 别名]
def test_04_add_noncontiguous_ip_range(self):
"""Test adding non-contiguous ip range in existing cidr
1.Add ip range in new cidr
1.Add non-contigous ip range in cidr added at step1
2.Verify the ip range using list APIs
"""
# call increment_cidr function to get exiting cidr from the setup and
# increment it
ip2 = self.increment_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__(50)
test_endIp = ip.__add__(60)
# Populating services with new IP range
self.services["vlan_ip_range"]["startip"] = test_startIp
self.services["vlan_ip_range"]["endip"] = test_endIp
self.services["vlan_ip_range"]["gateway"] = test_gateway
self.services["vlan_ip_range"]["netmask"] = self.netmask
self.services["vlan_ip_range"]["zoneid"] = self.zone.id
self.services["vlan_ip_range"]["podid"] = self.pod.id
# create new vlan ip range
new_vlan = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
self.debug(
"Created new vlan range with startip:%s and endip:%s" %
(test_startIp, test_endIp))
self.cleanup.append(new_vlan)
new_vlan_res = new_vlan.list(self.apiclient, id=new_vlan.vlan.id)
# Compare list output with configured values
self.verify_vlan_range(new_vlan_res, self.services["vlan_ip_range"])
# Add non-contiguous ip range in exiting cidr
test_startIp2 = ip.__add__(10)
test_endIp2 = ip.__add__(20)
# Populating services with new IP range
self.services["vlan_ip_range"]["startip"] = test_startIp2
self.services["vlan_ip_range"]["endip"] = test_endIp2
# create new vlan ip range
self.debug("Adding non contiguous ip range")
new_vlan = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
self.debug(
"Created new vlan range with startip:%s and endip:%s" %
(test_startIp, test_endIp))
self.cleanup.append(new_vlan)
new_vlan_res = new_vlan.list(self.apiclient, id=new_vlan.vlan.id)
# Compare list output with configured values
self.verify_vlan_range(new_vlan_res, self.services["vlan_ip_range"])
return
示例2: test_01_add_ip_same_cidr
# 需要导入模块: from netaddr import IPAddress [as 别名]
# 或者: from netaddr.IPAddress import __add__ [as 别名]
def test_01_add_ip_same_cidr(self):
"""Test add guest ip range in the existing cidr
"""
# call increment_cidr function to get exiting cidr from the setup and
# increment it
ip2 = self.increment_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)
test_startIp2 = ip.__add__(11)
test_endIp2 = ip.__add__(15)
# Populating services with new IP range
self.services["vlan_ip_range"]["startip"] = test_startIp
self.services["vlan_ip_range"]["endip"] = test_endIp
self.services["vlan_ip_range"]["gateway"] = test_gateway
self.services["vlan_ip_range"]["netmask"] = self.netmask
self.services["vlan_ip_range"]["zoneid"] = self.zone.id
self.services["vlan_ip_range"]["podid"] = self.pod.id
# create new vlan ip range
self.debug("Creating new ip range with new cidr in the same vlan")
new_vlan = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
self.debug(
"Created new vlan range with startip:%s and endip:%s" %
(test_startIp, test_endIp))
self.cleanup.append(new_vlan)
new_vlan_res = new_vlan.list(self.apiclient, id=new_vlan.vlan.id)
# Compare list output with configured values
self.verify_vlan_range(new_vlan_res, self.services["vlan_ip_range"])
# Add few more ips in the same CIDR
self.services["vlan_ip_range"]["startip"] = test_startIp2
self.services["vlan_ip_range"]["endip"] = test_endIp2
self.debug("Creating new ip range in the existing CIDR")
new_vlan2 = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
self.debug(
"Created new vlan range with startip:%s and endip:%s" %
(test_startIp2, test_endIp2))
self.cleanup.append(new_vlan2)
# list new vlan ip range
new_vlan2_res = new_vlan2.list(self.apiclient, id=new_vlan2.vlan.id)
# Compare list output with configured values
self.verify_vlan_range(new_vlan2_res, self.services["vlan_ip_range"])
return
示例3: test_03_del_ip_range
# 需要导入模块: from netaddr import IPAddress [as 别名]
# 或者: from netaddr.IPAddress import __add__ [as 别名]
def test_03_del_ip_range(self):
"""Test delete ip range
Steps:
1.Add ip range in same/new cidr
2.delete the ip range added at step1
3.Verify the ip range deletion using list APIs
"""
# call increment_cidr function to get exiting cidr from the setup and
# increment it
ip2 = self.increment_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
self.services["vlan_ip_range"]["startip"] = test_startIp
self.services["vlan_ip_range"]["endip"] = test_endIp
self.services["vlan_ip_range"]["gateway"] = test_gateway
self.services["vlan_ip_range"]["netmask"] = self.netmask
self.services["vlan_ip_range"]["zoneid"] = self.zone.id
self.services["vlan_ip_range"]["podid"] = self.pod.id
# create new vlan ip range
self.debug("Creating new ip range in the new cidr")
new_vlan = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
self.debug(
"Created new vlan range with startip:%s and endip:%s" %
(test_startIp, test_endIp))
new_vlan_res = new_vlan.list(self.apiclient, id=new_vlan.vlan.id)
# Compare list output with configured values
self.verify_vlan_range(new_vlan_res, self.services["vlan_ip_range"])
# Delete the above IP range
self.debug("Deleting new ip range added in new cidr")
new_vlan.delete(self.apiclient)
# listing vlan ip ranges with the id should through exception , if not
# mark the test case as failed
try:
new_vlan.list(self.apiclient, id=new_vlan.vlan.id)
except CloudstackAPIException as cs:
self.debug(cs.errorMsg)
self.assertTrue(
cs.errorMsg.find("entity does not exist") > 0,
msg="Failed to delete IP range")
return
示例4: test_02_add_ip_diff_cidr
# 需要导入模块: from netaddr import IPAddress [as 别名]
# 或者: from netaddr.IPAddress import __add__ [as 别名]
def test_02_add_ip_diff_cidr(self):
"""Test add ip range in a new cidr
Steps:
1.Get public vlan range (guest cidr) from the setup
2.Add IP range to a new cidr
"""
# call increment_cidr function to get exiting cidr from the setup and
# increment it
ip2 = self.increment_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
self.services["vlan_ip_range"]["startip"] = test_startIp
self.services["vlan_ip_range"]["endip"] = test_endIp
self.services["vlan_ip_range"]["gateway"] = test_gateway
self.services["vlan_ip_range"]["netmask"] = self.netmask
self.services["vlan_ip_range"]["zoneid"] = self.zone.id
self.services["vlan_ip_range"]["podid"] = self.pod.id
# create new vlan ip range
self.debug("Adding new ip range in different CIDR in same vlan")
new_vlan = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
self.debug(
"Created new vlan range with startip:%s and endip:%s" %
(test_startIp, test_endIp))
self.cleanup.append(new_vlan)
new_vlan_res = new_vlan.list(self.apiclient, id=new_vlan.vlan.id)
# Compare list output with configured values
self.verify_vlan_range(new_vlan_res, self.services["vlan_ip_range"])
return
示例5: test_08_add_iprange_subset
# 需要导入模块: from netaddr import IPAddress [as 别名]
# 或者: from netaddr.IPAddress import __add__ [as 别名]
def test_08_add_iprange_subset(self):
"""Test adding ip range subset to existing CIDR
1.Add IP range in new CIDR
2.Try to add ip range subset to CIDR added in step1
"""
# call increment_cidr function to get exiting cidr from the setup and
# increment it
ip2 = self.increment_cidr()
test_nw = ip2.network
ip = IPAddress(test_nw)
# Add IP range in the new CIDR
test_gateway = ip.__add__(1)
test_startIp = ip.__add__(2)
test_endIp = ip.__add__(10)
test_startIp2 = ip.__add__(20)
test_endIp2 = ip.__add__(30)
# Populating services with new IP range
self.services["vlan_ip_range"]["startip"] = test_startIp
self.services["vlan_ip_range"]["endip"] = test_endIp
self.services["vlan_ip_range"]["gateway"] = test_gateway
self.services["vlan_ip_range"]["netmask"] = self.netmask
self.services["vlan_ip_range"]["zoneid"] = self.zone.id
self.services["vlan_ip_range"]["podid"] = self.pod.id
# create new vlan ip range
new_vlan = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
self.debug(
"Created new vlan range with startip:%s and endip:%s" %
(test_startIp, test_endIp))
self.cleanup.append(new_vlan)
new_vlan_res = new_vlan.list(self.apiclient, id=new_vlan.vlan.id)
# Compare list output with configured values
self.verify_vlan_range(new_vlan_res, self.services["vlan_ip_range"])
# Add ip range superset to the existing CIDR
# Following code finds the netmask superset to existing CIDR
cidr = ip2.cidr
mask_len = 2 ** (32 - (cidr.prefixlen + 1))
netmask = IPAddress(self.netmask)
subset = netmask.__iadd__(mask_len)
# Add this superset netmask to services
self.services["vlan_ip_range"]["netmask"] = subset
self.services["vlan_ip_range"]["startip"] = test_startIp2
self.services["vlan_ip_range"]["endip"] = test_endIp2
self.debug("Adding ip range subset to existing cidr")
try:
new_vlan2 = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
except CloudstackAPIException as cs:
self.debug(cs.errorMsg)
self.assertTrue(
cs.errorMsg.find("subset") > 0,
msg="Fail: CS allowed adding ip range subset to existing CIDR")
return
# Test will reach here if there is a bug in allowing superset ip range
self.cleanup.append(new_vlan2)
self.fail(
"CS should not allow adding ip range subset to existing CIDR")
return
示例6: test_06_add_ip_range_overlapped_with_two_ranges
# 需要导入模块: from netaddr import IPAddress [as 别名]
# 或者: from netaddr.IPAddress import __add__ [as 别名]
def test_06_add_ip_range_overlapped_with_two_ranges(self):
"""Test adding overlapped ip range with two existing cidr
1.Add ip range in new cidr e.g:10.147.40.2-10.147.40.10
2.Add another ip range in the same cidr
e.g:10.147.40.20-10.147.40.30
3.Add ip range overlapped with both the ip ranges
e.g.10.147.40.10-20
"""
# call increment_cidr function to get exiting cidr from the setup and
# increment it
ip2 = self.increment_cidr()
test_nw = ip2.network
ip = IPAddress(test_nw)
# Add IP range in the new CIDR
test_gateway = ip.__add__(1)
test_startIp = ip.__add__(2)
test_endIp = ip.__add__(5)
test_startIp2 = ip.__add__(7)
test_endIp2 = ip.__add__(10)
test_startIp3 = ip.__add__(5)
test_endIp3 = ip.__add__(7)
# Populating services with new IP range
self.services["vlan_ip_range"]["startip"] = test_startIp
self.services["vlan_ip_range"]["endip"] = test_endIp
self.services["vlan_ip_range"]["gateway"] = test_gateway
self.services["vlan_ip_range"]["netmask"] = self.netmask
self.services["vlan_ip_range"]["zoneid"] = self.zone.id
self.services["vlan_ip_range"]["podid"] = self.pod.id
# create new vlan ip range
new_vlan = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
self.debug(
"Created new vlan range with startip:%s and endip:%s" %
(test_startIp, test_endIp))
self.cleanup.append(new_vlan)
new_vlan_res = new_vlan.list(self.apiclient, id=new_vlan.vlan.id)
# Compare list output with configured values
self.verify_vlan_range(new_vlan_res, self.services["vlan_ip_range"])
# Add 2nd IP range in the same CIDR
self.services["vlan_ip_range"]["startip"] = test_startIp2
self.services["vlan_ip_range"]["endip"] = test_endIp2
new_vlan2 = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
self.debug(
"Created new vlan range with startip:%s and endip:%s" %
(test_startIp2, test_endIp2))
self.cleanup.append(new_vlan2)
# Populating services with new IP range
self.services["vlan_ip_range"]["startip"] = test_startIp3
self.services["vlan_ip_range"]["endip"] = test_endIp3
# Try to create ip range overlapped with exiting ip range
self.debug("Adding ip range overlapped with two cidrs")
try:
new_vlan3 = PublicIpRange.create(
self.apiclient,
self.services["vlan_ip_range"])
except CloudstackAPIException as cs:
self.debug(cs.errorMsg)
self.assertTrue(
cs.errorMsg.find("already has IPs that overlap with the new range") > 0,
msg="Fail:CS allowed adding overlapped ip\
ranges in guest cidr")
return
# Test will reach here if there is a bug in overlap ip range checking
self.cleanup.append(new_vlan3)
self.fail(
"CS should not accept overlapped ip ranges in guest\
traffic, but it allowed")
return