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


Python Interface.search方法代码示例

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


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

示例1: handle_get

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import search [as 别名]
    def handle_get(self, request, user, *args, **kwargs):

        try:



            self.log.info("INTERFACE")

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT , AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Get XML data
            equip_id = kwargs.get('id_equipamento')


            interface = Interface()
            equip_interface = interface.search(equip_id)
            interface_list = []
            
            for var in equip_interface:
                try:
                    interface_list.append(get_new_interface_map(var.get_switch_and_router_interface_from_host_interface(None)))
                except:
                    pass

            if len(interface_list)==0:
                raise InterfaceNotFoundError(None, 'Erro: O servidor deve estar conectado aos uplinks')

            return self.response(dumps_networkapi({'map': interface_list}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:37,代码来源:InterfaceGetSwRouterResource.py

示例2: verificar_nome_channel

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import search [as 别名]
def verificar_nome_channel(nome, interfaces):

    interface = Interface()

    channels = PortChannel.objects.filter(nome=nome)
    channels_id = []
    for ch in channels:
        channels_id.append(int(ch.id))
    if channels_id:
        for var in interfaces:
            if not var == "" and not var == None:
                interface_id = int(var)
        interface_id = interface.get_by_pk(interface_id)
        equip_id = interface_id.equipamento.id
        equip_interfaces = interface.search(equip_id)
        for i in equip_interfaces:
            try:
                sw = i.get_switch_and_router_interface_from_host_interface(i.protegida)
            except:
                sw = None
                pass
            if sw is not None:
                if sw.channel is not None:
                    if sw.channel.id in channels_id:
                        raise exceptions.InterfaceException(u"O nome do port channel ja foi utilizado no equipamento")
开发者ID:williamvedroni-s2it,项目名称:GloboNetworkAPI,代码行数:27,代码来源:facade.py

示例3: search_interface_of_equipment

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import search [as 别名]
    def search_interface_of_equipment(self, equipment_id, is_new):
        '''Obtém as interfaces do equipamento'''

        # Efetua a consulta das interfaces do equipamento
        results = Interface.search(equipment_id)

        if results.count() > 0:
            # Monta lista com dados retornados
            map_list = []
            for item in results:
                if is_new:
                    map_list.append(self.get_new_interface_map(item))
                else:
                    map_list.append(self.get_interface_map(item))

            # Gera response (XML) com resultados
            if is_new:
                return self.response(dumps_networkapi({'interfaces': map_list}))
            else:
                return self.response(dumps_networkapi({'interface': map_list}))

        else:
            # Gera response (XML) para resultado vazio
            return self.response(dumps_networkapi({}))
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:26,代码来源:InterfaceResource.py

示例4: get_core_name

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import search [as 别名]
def get_core_name(rack):

    name_core1 = None
    name_core2 = None

    try:
        interfaces2 = Interface.search(rack.id_ilo.id)
        for interface2 in interfaces2:
            try:
                sw = interface2.get_switch_and_router_interface_from_host_interface(None)

                if sw.equipamento.nome.split('-')[0]=='OOB':
                    if sw.equipamento.nome.split('-')[2]=='01':
                        name_core1 = sw.equipamento.nome
                    elif sw.equipamento.nome.split('-')[2]=='02':
                        name_core2 = sw.equipamento.nome

            except InterfaceNotFoundError:
                next

    except e:
        raise RackAplError(None,rack.nome,"Erro ao buscar os nomes do Core associado ao Switch de gerencia %s" % rack.id_ilo.id)

    return name_core1, name_core2
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:26,代码来源:RackAplicarConfigResource.py

示例5: gera_config

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import search [as 别名]
def gera_config(rack):

    id_core1=None
    id_core2=None
    name_sp1=None
    name_sp2=None   
    name_sp3=None   
    name_sp4=None   
    name_core1=None
    name_core2=None
    int_sp1=None
    int_sp2=None   
    int_sp3=None   
    int_sp4=None   
    int_lf1_sp1=None   
    int_lf1_sp2=None   
    int_lf2_sp3=None   
    int_lf2_sp4=None
    int_oob_mgmtlf1=None
    int_oob_mgmtlf2=None
    int_oob_core1=None  
    int_oob_core2=None  
    int_core1_oob=None  
    int_core2_oob=None  


    #Equipamentos
    num_rack = rack.numero
    try:
        id_lf1 = rack.id_sw1.id
        name_lf1 = rack.id_sw1.nome
        id_lf2 = rack.id_sw2.id
        name_lf2 = rack.id_sw2.nome
        id_oob = rack.id_ilo.id
        name_oob = rack.id_ilo.nome
    except:
        raise RackConfigError(None,rack.nome,"Erro: Rack incompleto.")


    #Interface leaf01
    try:
        interfaces = Interface.search(id_lf1)
        for interface in interfaces:
            try: 
                sw = interface.get_switch_and_router_interface_from_host_interface(None)
                if sw.equipamento.nome.split('-')[2]=='01' or sw.equipamento.nome.split('-')[2]=='1': 
                    int_lf1_sp1 = interface.interface
                    name_sp1 = sw.equipamento.nome
                    id_sp1 = sw.equipamento.id
                    int_sp1 =  sw.interface
                elif sw.equipamento.nome.split('-')[2]=='02' or sw.equipamento.nome.split('-')[2]=='2':
                    int_lf1_sp2 = interface.interface
                    name_sp2 = sw.equipamento.nome
                    id_sp2 = sw.equipamento.id
                    int_sp2 =  sw.interface 
                elif sw.equipamento.nome.split('-')[0]=='OOB':
                    int_oob_mgmtlf1 = sw.interface
            except:
                pass
    except InterfaceNotFoundError:
        raise RackConfigError(None,rack.nome,"Erro ao buscar as interfaces associadas ao Leaf 01.")

    if int_sp1==None or int_sp2==None or int_oob_mgmtlf1==None:
        raise RackConfigError(None,rack.nome,"Erro: As interfaces do Leaf01 nao foram cadastradas.")  

    #Interface leaf02
    try:
        interfaces1 = Interface.search(id_lf2)
        for interface1 in interfaces1:
            try:
                sw = interface1.get_switch_and_router_interface_from_host_interface(None)
                if sw.equipamento.nome.split('-')[2]=='03' or sw.equipamento.nome.split('-')[2]=='3':
                    int_lf2_sp3 = interface1.interface
                    name_sp3 = sw.equipamento.nome
                    id_sp3 = sw.equipamento.id
                    int_sp3 =  sw.interface
                elif sw.equipamento.nome.split('-')[2]=='04' or sw.equipamento.nome.split('-')[2]=='4':
                    int_lf2_sp4 = interface1.interface
                    name_sp4 = sw.equipamento.nome
                    id_sp4 = sw.equipamento.id
                    int_sp4 =  sw.interface
                elif sw.equipamento.nome.split('-')[0]=='OOB':
                    int_oob_mgmtlf2 = sw.interface
            except:
                pass
    except InterfaceNotFoundError:
        raise RackConfigError(None,rack.nome,"Erro ao buscar as interfaces associadas ao Leaf 02.")

    if int_sp3==None or int_sp4==None or int_oob_mgmtlf2==None:
        raise RackConfigError(None,rack.nome,"Erro: As interfaces do Leaf02 nao foram cadastradas.")

    #Interface OOB
    try:
        interfaces2 = Interface.search(id_oob)
        for interface2 in interfaces2:
            try:
                sw = interface2.get_switch_and_router_interface_from_host_interface(None)
                if sw.equipamento.nome.split('-')[0]=='OOB':
                    if sw.equipamento.nome.split('-')[2]=='01' or sw.equipamento.nome.split('-')[2]=='1':
                        int_oob_core1 = interface2.interface
#.........这里部分代码省略.........
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:103,代码来源:RackConfigResource.py

示例6: handle_post

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import search [as 别名]
    def handle_post(self, request, user, *args, **kwargs):
        """Treat requests POST to add Rack.
        URL: channel/inserir/
        """
        try:
            self.log.info("Inserir novo Channel")

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag  of XML request.')

            channel_map = networkapi_map.get('channel')
            if channel_map is None:
                return self.response_error(3, u'There is no value to the channel tag  of XML request.')

            # Get XML data
            interfaces = channel_map.get('interfaces')
            nome = channel_map.get('nome')
            lacp = channel_map.get('lacp')
            int_type = channel_map.get('int_type')
            vlans = channel_map.get('vlan')
            envs = channel_map.get('envs')

            port_channel = PortChannel()
            interface = Interface()
            amb = Ambiente()

            cont = []

            interfaces = str(interfaces).split('-')
            interface_id = None

            # verifica a vlan_nativa
            vlan = vlans.get('vlan_nativa')
            if vlan is not None:
                if int(vlan) < 1 or int(vlan) > 4096:
                    raise InvalidValueError(None, "Vlan Nativa", "Range valido: 1 - 4096.")
                if int(vlan) < 1 or 3967 < int(vlan) < 4048 or int(vlan)==4096:
                    raise InvalidValueError(None, "Vlan Nativa" ,"Range reservado: 3968-4047;4094.")

            # verifica se o nome do port channel já existe no equipamento
            channels = PortChannel.objects.filter(nome=nome)
            channels_id = []
            for ch in channels:
                channels_id.append(int(ch.id))
            if channels_id:
                for var in interfaces:
                    if not var=="" and not var==None:
                        interface_id = int(var)
                interface_id = interface.get_by_pk(interface_id)
                equip_id = interface_id.equipamento.id
                equip_interfaces = interface.search(equip_id)
                for i in equip_interfaces:
                    try:
                        sw = i.get_switch_and_router_interface_from_host_interface(i.protegida)
                    except:
                        sw = None
                        pass
                    if sw.channel is not None:
                        if sw.channel.id in channels_id:
                            raise InterfaceError("O nome do port channel ja foi utilizado no equipamento")

            #cria o port channel
            port_channel.nome = str(nome)
            port_channel.lacp = convert_string_or_int_to_boolean(lacp)
            port_channel.create(user)

            int_type = TipoInterface.get_by_name(str(int_type))

            for var in interfaces:
                if not var=="" and not var==None:
                    interf = interface.get_by_pk(int(var))

                    try:
                        sw_router = interf.get_switch_and_router_interface_from_host_interface(interf.protegida)
                    except:
                        raise InterfaceError("Interface não conectada")

                    if sw_router.channel is not None:
                        raise InterfaceError("Interface %s já está em um Channel" % sw_router.interface)

                    if cont is []:
                        cont.append(int(sw_router.equipamento.id))
                    elif not sw_router.equipamento.id in cont:
                        cont.append(int(sw_router.equipamento.id))
                        if len(cont) > 2:
                            raise InterfaceError("Mais de dois equipamentos foram selecionados")

                    if sw_router.ligacao_front is not None:
                        ligacao_front_id = sw_router.ligacao_front.id
                    else:
#.........这里部分代码省略.........
开发者ID:jotagesales,项目名称:GloboNetworkAPI,代码行数:103,代码来源:InterfaceChannelResource.py

示例7: handle_put

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import search [as 别名]
    def handle_put(self, request, user, *args, **kwargs):
        """Treat requests POST to add Rack.

        URL: channel/editar/
        """
        try:
            self.log.info("Editar Channel")

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag  of XML request.')

            channel_map = networkapi_map.get('channel')
            if channel_map is None:
                return self.response_error(3, u'There is no value to the channel tag  of XML request.')

            # Get XML data
            id_channel = channel_map.get('id_channel')
            nome = channel_map.get('nome')
            if not is_valid_int_greater_zero_param(nome):
                raise InvalidValueError(None, "Numero do Channel", "Deve ser um numero inteiro.")
            lacp = channel_map.get('lacp')
            int_type = channel_map.get('int_type')
            vlans = channel_map.get('vlan')
            envs = channel_map.get('envs')
            ids_interface = channel_map.get('ids_interface')


            if ids_interface is None:
                raise InterfaceError("Nenhuma interface selecionada")

            # verifica a vlan_nativa
            vlan = vlans.get('vlan_nativa')
            if vlan is not None:
                if int(vlan) < 1 or int(vlan) > 4096:
                    raise InvalidValueError(None, "Vlan Nativa", "Range valido: 1 - 4096.")
                if int(vlan) < 1 or 3967 < int(vlan) < 4048 or int(vlan)==4096:
                    raise InvalidValueError(None, "Vlan Nativa" ,"Range reservado: 3968-4047;4094.")

            port_channel = PortChannel()
            interface = Interface()
            amb = Ambiente()

            # verifica se o nome do port channel está sendo usado no equipamento
            channels = PortChannel.objects.filter(nome=nome)
            channels_id = []
            for ch in channels:
                channels_id.append(int(ch.id))
            if len(channels_id)>1:
                if type(ids_interface) is list:
                    for var in ids_interface:
                        if not var=="" and not var==None:
                            interface_id = int(var)
                else:
                    interface_id = int(ids_interface)
                interface_id = interface.get_by_pk(interface_id)
                equip_id = interface_id.equipamento.id
                equip_interfaces = interface.search(equip_id)
                for i in equip_interfaces:
                    try:
                        sw = i.get_switch_and_router_interface_from_host_interface(i.protegida)
                    except:
                        sw = None
                        pass
                    if sw is not None:
                        if sw.channel is not None:
                            if sw.channel.id in channels_id and sw.channel.id is not id_channel:
                                raise InterfaceError("O nome do port channel ja foi utilizado no equipamento")

            #buscar interfaces do channel
            interfaces = Interface.objects.all().filter(channel__id=id_channel)
            ids_list = []
            for i in interfaces:
                ids_list.append(i.id)

            ids_list = [ int(y) for y in ids_list ]
            if type(ids_interface) is list:
                ids_interface = [ int(x) for x in ids_interface ]
                desassociar = set(ids_list) - set(ids_interface)
                for item in desassociar:
                    item = interface.get_by_pk(int(item))
                    item.channel = None
                    item.save()
            else:
                if ids_interface is not None:
                    ids_interface = int(ids_interface)
                    if ids_interface is not None:
                        for item in ids_list:
                            item = interface.get_by_pk(int(item))
                            item.channel = None
                            item.save()
#.........这里部分代码省略.........
开发者ID:jotagesales,项目名称:GloboNetworkAPI,代码行数:103,代码来源:InterfaceChannelResource.py

示例8: handle_get

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import search [as 别名]
    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to find all Racks

        URLs: /rack/find/
        """

        self.log.info('Get Rack by equipment id')

        try:

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Get XML data
            equip_id = kwargs.get('equip_id')
            equip_id = int(equip_id)
            rack_map = []
            interface = Interface()

            try:
                racks = Rack.objects.filter(id_sw1__id=equip_id)
                for cont in racks:
                    rack_map.append(model_to_dict(cont))
                    return self.response(dumps_networkapi({'rack': rack_map}))
            except:
                pass

            try:
                racks = Rack.objects.filter(id_sw2__id=equip_id)
                for cont in racks:
                    rack_map.append(model_to_dict(cont))
                    return self.response(dumps_networkapi({'rack': rack_map}))
            except:
                pass

            try:
                racks = Rack.objects.filter(id_ilo__id=equip_id)
                for cont in racks:
                    rack_map.append(model_to_dict(cont))
                    return self.response(dumps_networkapi({'rack': rack_map}))
            except:
                pass

            try:
                interfaces = interface.search(equip_id)
                for interf in interfaces:
                    sw_router = interf.get_switch_and_router_interface_from_host_interface(
                        interf.protegida)
                    try:
                        racks = Rack.objects.filter(
                            id_sw1__id=sw_router.equipamento.id)
                        for cont in racks:
                            rack_map.append(model_to_dict(cont))
                            return self.response(dumps_networkapi({'rack': rack_map}))
                    except:
                        pass
                    try:
                        racks = Rack.objects.filter(
                            id_sw2__id=sw_router.equipamento.id)
                        for cont in racks:
                            rack_map.append(model_to_dict(cont))
                            return self.response(dumps_networkapi({'rack': rack_map}))
                    except:
                        pass
                    try:
                        racks = Rack.objects.filter(
                            id_ilo__id=sw_router.equipamento.id)
                        for cont in racks:
                            rack_map.append(model_to_dict(cont))
                            return self.response(dumps_networkapi({'rack': rack_map}))
                    except:
                        pass
            except:
                pass

            return self.response(dumps_networkapi({'rack': rack_map}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except RackError:
            return self.response_error(1)

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:90,代码来源:RackGetByEquipResource.py

示例9: handle_post

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import search [as 别名]
    def handle_post(self, request, user, *args, **kwargs):
        """Treat requests POST to add Rack.

        URL: channel/inserir/
        """
        try:
            self.log.info("Inserir novo Channel")

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag  of XML request.')

            channel_map = networkapi_map.get('channel')
            if channel_map is None:
                return self.response_error(3, u'There is no value to the channel tag  of XML request.')

            # Get XML data
            interfaces = channel_map.get('interfaces')
            nome = channel_map.get('nome')
            lacp = channel_map.get('lacp')
            int_type = channel_map.get('int_type')
            vlan = channel_map.get('vlan')
            envs = channel_map.get('envs')
            port_channel = PortChannel()
            interface = Interface()
            amb = Ambiente()

            cont = []

            port_channel.nome = str(nome)
            port_channel.lacp = convert_string_or_int_to_boolean(lacp)
            port_channel.create(user)

            interfaces = str(interfaces).split('-')

            int_type = TipoInterface.get_by_name(str(int_type))
            for var in interfaces:
                if not var=="" and not var==None:
                    interf = interface.get_by_pk(int(var))
                    try:
                        sw_router = interf.get_switch_and_router_interface_from_host_interface(interf.protegida)
                    except:
                        raise InterfaceError("Interface não conectada")

                    if sw_router.channel is not None:
                        raise InterfaceError("Interface %s já está em um Channel" % sw_router.interface)

                    for i in interface.search(sw_router.equipamento.id):
                        if i.channel is not None:
                            raise InterfaceError("Equipamento %s já possui um Channel" % sw_router.equipamento.nome)

                    if cont is []:
                        cont.append(int(sw_router.equipamento.id))
                    elif not sw_router.equipamento.id in cont:
                        cont.append(int(sw_router.equipamento.id))
                        if len(cont) > 2:
                            raise InterfaceError("Mais de dois equipamentos foram selecionados")

                    if sw_router.ligacao_front is not None:
                        ligacao_front_id = sw_router.ligacao_front.id
                    else:
                        ligacao_front_id = None
                    if sw_router.ligacao_back is not None:
                        ligacao_back_id = sw_router.ligacao_back.id
                    else:
                        ligacao_back_id = None

                    Interface.update(user,
                                     sw_router.id,
                                     interface=sw_router.interface,
                                     protegida=sw_router.protegida,
                                     descricao=sw_router.descricao,
                                     ligacao_front_id=ligacao_front_id,
                                     ligacao_back_id=ligacao_back_id,
                                     tipo=int_type,
                                     vlan_nativa=vlan,
                                     channel=port_channel)

                    if "trunk" in int_type.tipo:
                        interface_list = EnvironmentInterface.objects.all().filter(interface=sw_router.id)
                        for int_env in interface_list:
                            int_env.delete(user)
                        if envs is not None:
                            if not type(envs)==unicode:
                                for env in envs:
                                    amb_int = EnvironmentInterface()
                                    amb_int.interface = sw_router
                                    amb_int.ambiente = amb.get_by_pk(int(env))
                                    amb_int.create(user)
                            else:
#.........这里部分代码省略.........
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:103,代码来源:InterfaceChannelResource.py

示例10: gerar_arquivo_config

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import search [as 别名]
def gerar_arquivo_config(ids):
    log.debug("gerar_arquivo_config")

    for id in ids:
        rack = Rack().get_rack(idt=id)
        equips = list()
        lf1 = dict()
        lf2 = dict()
        oob = dict()

        # Equipamentos
        try:
            lf1["sw"] = 1
            lf1["id"] = rack.id_sw1.id
            lf1["nome"] = rack.id_sw1.nome
            lf1["mac"] = rack.mac_sw1
            lf1["marca"] = rack.id_sw1.modelo.marca.nome
            lf1["modelo"] = rack.id_sw1.modelo.nome
            equips.append(lf1)
            lf2["sw"] = 2
            lf2["id"] = rack.id_sw2.id
            lf2["nome"] = rack.id_sw2.nome
            lf2["mac"] = rack.mac_sw2
            lf2["marca"] = rack.id_sw2.modelo.marca.nome
            lf2["modelo"] = rack.id_sw2.modelo.nome
            equips.append(lf2)
            oob["sw"] = 3
            oob["id"] = rack.id_ilo.id
            oob["nome"] = rack.id_ilo.nome
            oob["mac"] = rack.mac_ilo
            oob["marca"] = rack.id_ilo.modelo.marca.nome
            oob["modelo"] = rack.id_ilo.modelo.nome
            equips.append(oob)
        except:
            raise Exception("Erro: Informações incompletas. Verifique o cadastro do Datacenter, do Fabric e do Rack")

        prefixspn = "SPN"
        prefixlf = "LF-"
        prefixoob = "OOB"

        # Interface e Roteiro
        for equip in equips:
            try:
                interfaces = Interface.search(equip.get("id"))
                equip["interfaces"] = list()
                for interface in interfaces:
                    dic = dict()
                    try:
                        sw = interface.get_switch_and_router_interface_from_host_interface(None)
                        if sw.equipamento.nome[:3] in [prefixlf, prefixoob, prefixspn]:
                            dic["nome"] = sw.equipamento.nome
                            dic["id"] = sw.equipamento.id
                            dic["ip_mngt"] = _buscar_ip(sw.equipamento.id)
                            dic["interface"] = sw.interface
                            dic["eq_interface"] = interface.interface
                            dic["roteiro"] = _buscar_roteiro(sw.equipamento.id, "CONFIGURACAO")
                            equip["interfaces"].append(dic)
                    except:
                        pass
            except:
                raise Exception("Erro ao buscar o roteiro de configuracao ou as interfaces associadas ao equipamento: "
                                "%s." % equip.get("nome"))
            try:
                equip["roteiro"] = _buscar_roteiro(equip.get("id"), "CONFIGURACAO")
                equip["ip_mngt"] = _buscar_ip(equip.get("id"))
            except:
                raise Exception("Erro ao buscar os roteiros do equipamento: %s" % equip.get("nome"))

        autoprovision.autoprovision_splf(rack, equips)
        autoprovision.autoprovision_coreoob(rack, equips)

    return True
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:74,代码来源:facade.py


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