當前位置: 首頁>>代碼示例>>Python>>正文


Python IPAddress.__iadd__方法代碼示例

本文整理匯總了Python中netaddr.IPAddress.__iadd__方法的典型用法代碼示例。如果您正苦於以下問題:Python IPAddress.__iadd__方法的具體用法?Python IPAddress.__iadd__怎麽用?Python IPAddress.__iadd__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在netaddr.IPAddress的用法示例。


在下文中一共展示了IPAddress.__iadd__方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_08_add_iprange_subset

# 需要導入模塊: from netaddr import IPAddress [as 別名]
# 或者: from netaddr.IPAddress import __iadd__ [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
開發者ID:Accelerite,項目名稱:cloudstack,代碼行數:63,代碼來源:test_multiple_ip_ranges.py


注:本文中的netaddr.IPAddress.__iadd__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。