From e88d62d9d3aa059edc19784d0924d64aca71d22c Mon Sep 17 00:00:00 2001 From: Iuri Malinoski Date: Wed, 13 May 2026 13:21:06 -0300 Subject: [PATCH 1/2] Prefer SSH for load balancer deploys with multiple access types; otherwise use Netconf. --- networkapi/plugins/factory.py | 46 +++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/networkapi/plugins/factory.py b/networkapi/plugins/factory.py index 69ae9442..82bbb304 100644 --- a/networkapi/plugins/factory.py +++ b/networkapi/plugins/factory.py @@ -115,14 +115,50 @@ def factory(cls, equipment, **kwargs): marca = equipment.modelo.marca.nome modelo = equipment.modelo.nome - tipo_acesso = EquipamentoAcesso.search(None, - equipment, - ).uniqueResult() - if tipo_acesso is None: + # Check is balanceador + equipment_type = '' + if equipment.tipo_equipamento: + equipment_type = equipment.tipo_equipamento.tipo_equipamento or '' + is_load_balancer = 'BALANCEADOR' in equipment_type.upper() + + # Count access number + access_list = EquipamentoAcesso.search(None, equipment) + access_count = access_list.count() + + access_type = None + + # If unique access, get it + if access_count == 1: + access_type = access_list.uniqueResult() + elif access_count > 1: + + # If more than one access, check if is LB and get ssh access, otherwise get netconf access. + if is_load_balancer: + ssh_access = EquipamentoAcesso.search(None, equipment, 'ssh') + if ssh_access.count() > 0: + access_type = ssh_access.uniqueResult() + else: + netconf_access = EquipamentoAcesso.search( + None, equipment, 'netconf' + ) + if netconf_access.count() > 0: + access_type = netconf_access.uniqueResult() + + # If not LB or not netconf access, get the remaining access + if access_type is None: + access_type = access_list.uniqueResult() + + log.debug( + 'Equipment %s has %s access and the selected access was %s', + equipment.id, + access_count, + access_type.tipo_acesso.protocolo if access_type else 'None' + ) + if access_type is None: return 'Equipment has no Access.' - plugin_class = cls.get_plugin(modelo=modelo, marca=marca, tipo_acesso=tipo_acesso.tipo_acesso.protocolo, **kwargs) + plugin_class = cls.get_plugin(modelo=modelo, marca=marca, tipo_acesso=access_type.tipo_acesso.protocolo, **kwargs) if type(plugin_class) == type(ODLPlugin): version = 'BERYLLIUM' From d6f80f94714af30ffeffa063a238314aeb21299b Mon Sep 17 00:00:00 2001 From: Iuri Malinoski Date: Wed, 13 May 2026 13:29:01 -0300 Subject: [PATCH 2/2] better comments --- networkapi/plugins/factory.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/networkapi/plugins/factory.py b/networkapi/plugins/factory.py index 82bbb304..51f5fff0 100644 --- a/networkapi/plugins/factory.py +++ b/networkapi/plugins/factory.py @@ -135,17 +135,19 @@ def factory(cls, equipment, **kwargs): # If more than one access, check if is LB and get ssh access, otherwise get netconf access. if is_load_balancer: + # Try to get ssh ssh_access = EquipamentoAcesso.search(None, equipment, 'ssh') if ssh_access.count() > 0: access_type = ssh_access.uniqueResult() else: + # Try to get netconf netconf_access = EquipamentoAcesso.search( None, equipment, 'netconf' ) if netconf_access.count() > 0: access_type = netconf_access.uniqueResult() - # If not LB or not netconf access, get the remaining access + # If access type is not defined yet, get the first access available if access_type is None: access_type = access_list.uniqueResult()