当前位置: 首页>>代码示例>>Python>>正文


Python IPAddress.__isub__方法代码示例

本文整理汇总了Python中netaddr.IPAddress.__isub__方法的典型用法代码示例。如果您正苦于以下问题:Python IPAddress.__isub__方法的具体用法?Python IPAddress.__isub__怎么用?Python IPAddress.__isub__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在netaddr.IPAddress的用法示例。


在下文中一共展示了IPAddress.__isub__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_07_add_iprange_superset

# 需要导入模块: from netaddr import IPAddress [as 别名]
# 或者: from netaddr.IPAddress import __isub__ [as 别名]
    def test_07_add_iprange_superset(self):
        """Test adding ip range superset to existing CIDR

            1.Add IP range in new CIDR
            2.Try to add ip range superset 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)
        netmask = IPAddress(self.netmask)
        superset = netmask.__isub__(mask_len)
        # Add this superset netmask to services
        self.services["vlan_ip_range"]["netmask"] = superset
        self.services["vlan_ip_range"]["startip"] = test_startIp2
        self.services["vlan_ip_range"]["endip"] = test_endIp2
        self.debug("Adding IP range super set 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("superset") > 0,
                msg="Fail: CS allowed adding ip range\
                        superset 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 superset to existing CIDR")
        return
开发者ID:Accelerite,项目名称:cloudstack,代码行数:64,代码来源:test_multiple_ip_ranges.py


注:本文中的netaddr.IPAddress.__isub__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。