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


Python Network.to_tuple方法代碼示例

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


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

示例1: add_network_cidr_mapping

# 需要導入模塊: from ipcalc import Network [as 別名]
# 或者: from ipcalc.Network import to_tuple [as 別名]
    def add_network_cidr_mapping(self,
        network_config):
        '''
        Method calculates and adds a CloudFormation mapping that is used to set VPC and Subnet CIDR blocks.  Calculated based on CIDR block sizes and additionally checks to ensure all network segments fit inside of the specified overall VPC CIDR
        @param network_config [dict] dictionary of values containing data for creating
        '''
        public_subnet_count = int(network_config.get('public_subnet_count', 2))
        private_subnet_count = int(network_config.get('private_subnet_count', 2))
        public_subnet_size = str(network_config.get('public_subnet_size', '24'))
        private_subnet_size = str(network_config.get('private_subnet_size', '22'))
        network_cidr_base = str(network_config.get('network_cidr_base', '172.16.0.0'))
        network_cidr_size = str(network_config.get('network_cidr_size', '20'))
        first_network_address_block = str(network_config.get('first_network_address_block', network_cidr_base))

        ret_val = {}
        cidr_info = Network(network_cidr_base + '/' + network_cidr_size)
        base_cidr = cidr_info.network().to_tuple()[0] + '/' + str(cidr_info.to_tuple()[1])
        ret_val['vpcBase'] = {'cidr': base_cidr}
        current_base_address = first_network_address_block
        for public_subnet_id in range(0, public_subnet_count):
            if not cidr_info.check_collision(current_base_address):
                raise RuntimeError('Cannot continue creating network--current base address is outside the range of the master Cidr block. Found on pass ' + str(public_subnet_id + 1) + ' when creating public subnet cidrs')
            ip_info = Network(current_base_address + '/' + str(public_subnet_size))
            range_info = ip_info.network().to_tuple()
            if 'subnet' + str(public_subnet_id) not in ret_val:
                ret_val['subnet' + str(public_subnet_id)] = dict()
            ret_val['subnet' + str(public_subnet_id)]['public'] = ip_info.network().to_tuple()[0] + '/' + str(ip_info.to_tuple()[1])
            current_base_address = IP(int(ip_info.host_last().hex(), 16) + 2).to_tuple()[0]
        range_reset = Network(current_base_address + '/' + str(private_subnet_size))
        current_base_address = IP(int(range_reset.host_last().hex(), 16) + 2).to_tuple()[0]
        for private_subnet_id in range(0, private_subnet_count):
            if not cidr_info.check_collision(current_base_address):
                raise RuntimeError('Cannot continue creating network--current base address is outside the range of the master Cidr block. Found on pass ' + str(private_subnet_id + 1) + ' when creating private subnet cidrs')
            ip_info = Network(current_base_address + '/' + str(private_subnet_size))
            range_info = ip_info.network().to_tuple()
            if 'subnet' + str(private_subnet_id) not in ret_val:
                ret_val['subnet' + str(private_subnet_id)] = dict()
            ret_val['subnet' + str(private_subnet_id)]['private'] = ip_info.network().to_tuple()[0] + '/' + str(ip_info.to_tuple()[1])
            current_base_address = IP(int(ip_info.host_last().hex(), 16) + 2).to_tuple()[0]
        return self.template.add_mapping('networkAddresses', ret_val)
開發者ID:JonGal,項目名稱:cloudformation-environmentbase,代碼行數:42,代碼來源:networkbase.py

示例2: Network

# 需要導入模塊: from ipcalc import Network [as 別名]
# 或者: from ipcalc.Network import to_tuple [as 別名]
    for subnet, domains in subnets.items():
        append = True
        net = Network(subnet)
        for ip_address in hosts:
            if IP(ip_address) in net:
                append = False
            if not append:
                break
        for subnet_2 in subnets:
            net_2 = Network(subnet_2)
            if net_2 in net and net_2.size() < net.size():
                append = False
            if not append:
                break
        if append:
            prefix, length = net.to_tuple()
            octets = int((length - length % 4) / 4)
            prefix = prefix.replace(':', '')[:octets]
            ptr = '*.{}.ip6.arpa'.format('.'.join(prefix[::-1]))
            for domain in domains:
                resources[section_title].append((net, ptr, domain.strip()))

for zone, params in zones.items():
    zone_network = params['prefix']
    section = params['section']
    template = Template(open(params['template_path']).read())
    hash_file = var_dir + '/' + zone + '.hash'
    sn_file = var_dir + '/' + zone + '.sn'
    params['records'] = []
    for network, record, value in resources[section]:
        if network in zone_network:
開發者ID:k-vinogradov,項目名稱:ipam-export,代碼行數:33,代碼來源:ptr_export.py


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