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


Python IPNetwork.__str__方法代码示例

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


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

示例1: gera_config

# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import __str__ [as 别名]

#.........这里部分代码省略.........
    try:
        FILEINSP4 = buscar_roteiro(id_sp4, "CONFIGURACAO")    
    except:
        raise RackConfigError(None,rack.nome,"Erro ao buscar o roteiro do Spine 04.")

    #Roteiro Core 01
    try:
        FILEINCR1 = buscar_roteiro(id_core1, "CONFIGURACAO")    
    except:
        raise RackConfigError(None,rack.nome,"Erro ao buscar o roteiro do Core 01.")

    #Roteiro Core 02
    try:
        FILEINCR2 = buscar_roteiro(id_core2, "CONFIGURACAO")    
    except:
        raise RackConfigError(None,rack.nome,"Erro ao buscar o roteiro do Core 02.")

    #Roteiro OOB
    try:
        FILEINOOB = buscar_roteiro(id_oob, "CONFIGURACAO")    
    except:
        raise RackConfigError(None,rack.nome,"Erro ao buscar o roteiro do switch de gerencia.")

    #Ip LF01
    try:
        ip_mgmtlf1 = buscar_ip(id_lf1)
    except:
        raise RackConfigError(None,rack.nome,"Erro ao buscar o ip de gerencia do leaf 01.")

    #Ip LF02
    try:
        ip_mgmtlf2 = buscar_ip(id_lf2)
    except:
        raise RackConfigError(None,rack.nome,"Erro ao buscar o ip de gerencia do leaf 02.")

    #Ip OOB
    try:
        ip_mgmtoob = buscar_ip(id_oob)
    except:
        raise RackConfigError(None,rack.nome,"Erro ao buscar o ip de gerencia do oob.")

    try:
        NETWORKAPI_USE_FOREMAN = int(get_variable("use_foreman"))
        NETWORKAPI_FOREMAN_URL = get_variable("foreman_url")
        NETWORKAPI_FOREMAN_USERNAME = get_variable("foreman_username")
        NETWORKAPI_FOREMAN_PASSWORD = get_variable("foreman_password")
        FOREMAN_HOSTS_ENVIRONMENT_ID = get_variable("foreman_hosts_environment_id")
    except ObjectDoesNotExist:
        raise var_exceptions.VariableDoesNotExistException("Erro buscando as variáveis relativas ao Foreman.")

    #begin - Create Foreman entries for rack switches
    if NETWORKAPI_USE_FOREMAN:
        foreman = Foreman(NETWORKAPI_FOREMAN_URL, (NETWORKAPI_FOREMAN_USERNAME, NETWORKAPI_FOREMAN_PASSWORD), api_version=2)

        #for each switch, check the switch ip against foreman know networks, finds foreman hostgroup
        # based on model and brand and inserts the host in foreman
        # if host already exists, delete and recreate with new information
        for [switch, mac] in [[rack.id_sw1, rack.mac_sw1], [rack.id_sw2, rack.mac_sw2], [rack.id_ilo, rack.mac_ilo]]:
            #Get all foremand subnets and compare with the IP address of the switches until find it
            if mac == None:
                raise RackConfigError(None, rack.nome, ("Could not create entry for %s. There is no mac address." % (switch.nome)))

            ip = buscar_ip(switch.id)
            switch_cadastrado=0
            for subnet in foreman.subnets.index()['results']:
                network = IPNetwork(ip+'/'+subnet['mask']).network
                #check if switches ip network is the same as subnet['subnet']['network'] e subnet['subnet']['mask']
                if network.__str__() == subnet['network']:
                    subnet_id = subnet['id']
                    hosts = foreman.hosts.index(search=switch.nome)['results']
                    if len(hosts) == 1:
                        foreman.hosts.destroy(id=hosts[0]['id'])
                    elif len(hosts) > 1:
                        raise RackConfigError(None, rack.nome, ("Could not create entry for %s. There are multiple entries with the sam name." % (switch.nome)))

                    #Lookup foreman hostgroup
                    #By definition, hostgroup should be Marca+"_"+Modelo
                    hostgroup_name = switch.modelo.marca.nome+"_"+switch.modelo.nome
                    hostgroups = foreman.hostgroups.index(search=hostgroup_name)
                    if len(hostgroups['results']) == 0:
                        raise RackConfigError(None, rack.nome, "Could not create entry for %s. Could not find hostgroup %s in foreman." % (switch.nome, hostgroup_name))
                    elif len(hostgroups['results'])>1:
                        raise RackConfigError(None, rack.nome, "Could not create entry for %s. Multiple hostgroups %s found in Foreman." % (switch.nome, hostgroup_name))
                    else:
                        hostgroup_id = hostgroups['results'][0]['id']

                    host = foreman.hosts.create(host={'name': switch.nome, 'ip': ip, 'mac': mac, 'environment_id': FOREMAN_HOSTS_ENVIRONMENT_ID, 'hostgroup_id': hostgroup_id, 'subnet_id': subnet_id, 'build': 'true', 'overwrite': 'true'})
                    switch_cadastrado=1
                    
            if not switch_cadastrado:
                raise RackConfigError(None, rack.nome, "Unknown error. Could not create entry for %s in foreman." % (switch.nome))
    #end - Create Foreman entries for rack switches
    var1 = autoprovision_splf(num_rack, FILEINLF1, FILEINLF2, FILEINSP1, FILEINSP2, FILEINSP3, FILEINSP4, name_lf1, name_lf2, name_oob, name_sp1, name_sp2, name_sp3, name_sp4, ip_mgmtlf1, ip_mgmtlf2, int_oob_mgmtlf1, int_oob_mgmtlf2, int_sp1, int_sp2, int_sp3, int_sp4, int_lf1_sp1, int_lf1_sp2, int_lf2_sp3, int_lf2_sp4)

    var2 = autoprovision_coreoob(num_rack, FILEINCR1, FILEINCR2, FILEINOOB, name_core1, name_core2, name_oob, name_lf1, name_lf2, ip_mgmtoob, int_oob_core1, int_oob_core2, int_core1_oob, int_core2_oob )

    if var1 and var2:
        return True

    return False
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:104,代码来源:RackConfigResource.py

示例2: len

# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import __str__ [as 别名]
    if len(sys.argv) < 2:
        sys.stderr.write("usage: " + sys.argv[0] + " config-file-path")
        sys.exit(1)

    with open(sys.argv[1], 'r') as confStream:
        return json.load(confStream)

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    logger = logging.getLogger(__name__)
    config = load_config()

    for prefix,ipnet in config['prefixes'].iteritems():
        prefixToNetwork[prefix.lower()] = IPNetwork(ipnet)

    noPrefixNetwork = IPNetwork(config['noPrefixNetwork'])

    logger.debug("Parsed configuration:")
    logger.debug("  Prefixless network: " + noPrefixNetwork.__str__())
    logger.debug("  Prefixed networks:")
    for prefix,ipnet in prefixToNetwork.iteritems():
        logger.debug("    " + prefix + ": " + ipnet.__str__())

    httpd = BaseHTTPServer.HTTPServer(('', 8080), DnsUpdateApiHandler)
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass

    httpd.server_close()
开发者ID:mgarstecki,项目名称:nsupdate-api,代码行数:32,代码来源:api.py

示例3: getCIDR

# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import __str__ [as 别名]
def getCIDR(addr, mask):

   ip = IPNetwork(str(addr) + "/" + str(mask))
   return ip.__str__()
开发者ID:dazete92,项目名称:t_work,代码行数:6,代码来源:post_exploit.py

示例4: api_foreman

# 需要导入模块: from netaddr import IPNetwork [as 别名]
# 或者: from netaddr.IPNetwork import __str__ [as 别名]
def api_foreman(rack):


    try:
        NETWORKAPI_FOREMAN_URL = get_variable("foreman_url")
        NETWORKAPI_FOREMAN_USERNAME = get_variable("foreman_username")
        NETWORKAPI_FOREMAN_PASSWORD = get_variable("foreman_password")
        FOREMAN_HOSTS_ENVIRONMENT_ID = get_variable("foreman_hosts_environment_id")
    except ObjectDoesNotExist:
        raise var_exceptions.VariableDoesNotExistException("Erro buscando as variáveis relativas ao Foreman.")

    foreman = Foreman(NETWORKAPI_FOREMAN_URL, (NETWORKAPI_FOREMAN_USERNAME, NETWORKAPI_FOREMAN_PASSWORD), api_version=2)

    # for each switch, check the switch ip against foreman know networks, finds foreman hostgroup
    # based on model and brand and inserts the host in foreman
    # if host already exists, delete and recreate with new information
    for [switch, mac] in [[rack.id_sw1, rack.mac_sw1], [rack.id_sw2, rack.mac_sw2], [rack.id_ilo, rack.mac_ilo]]:
        # Get all foremand subnets and compare with the IP address of the switches until find it
        if mac == None:
            raise RackConfigError(None, rack.nome, ("Could not create entry for %s. There is no mac address." %
                                                    switch.nome))

        ip = _buscar_ip(switch.id)
        if ip == None:
            raise RackConfigError(None, rack.nome, ("Could not create entry for %s. There is no management IP." %
                                                    switch.nome))

        switch_cadastrado = 0
        for subnet in foreman.subnets.index()['results']:
            network = IPNetwork(ip + '/' + subnet['mask']).network
            # check if switches ip network is the same as subnet['subnet']['network'] e subnet['subnet']['mask']
            if network.__str__() == subnet['network']:
                subnet_id = subnet['id']
                hosts = foreman.hosts.index(search = switch.nome)['results']
                if len(hosts) == 1:
                    foreman.hosts.destroy(id = hosts[0]['id'])
                elif len(hosts) > 1:
                    raise RackConfigError(None, rack.nome, ("Could not create entry for %s. There are multiple entries "
                                                            "with the sam name." % switch.nome))

                # Lookup foreman hostgroup
                # By definition, hostgroup should be Marca+"_"+Modelo
                hostgroup_name = switch.modelo.marca.nome + "_" + switch.modelo.nome
                hostgroups = foreman.hostgroups.index(search = hostgroup_name)
                if len(hostgroups['results']) == 0:
                    raise RackConfigError(None, rack.nome, "Could not create entry for %s. Could not find hostgroup %s "
                                                           "in foreman." % (switch.nome, hostgroup_name))
                elif len(hostgroups['results'])>1:
                    raise RackConfigError(None, rack.nome, "Could not create entry for %s. Multiple hostgroups %s found"
                                                           " in Foreman." % (switch.nome, hostgroup_name))
                else:
                    hostgroup_id = hostgroups['results'][0]['id']

                foreman.hosts.create(host = {'name': switch.nome, 'ip': ip, 'mac': mac,
                                            'environment_id': FOREMAN_HOSTS_ENVIRONMENT_ID,
                                            'hostgroup_id': hostgroup_id, 'subnet_id': subnet_id,
                                            'build': 'true', 'overwrite': 'true'})
                switch_cadastrado = 1

        if not switch_cadastrado:
            raise RackConfigError(None, rack.nome, "Unknown error. Could not create entry for %s in foreman." %
                                  switch.nome)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:64,代码来源:facade.py


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