diff --git a/networkapi/interface/models.py b/networkapi/interface/models.py index 4e5e1d784..943cb011f 100644 --- a/networkapi/interface/models.py +++ b/networkapi/interface/models.py @@ -93,6 +93,14 @@ def __init__(self, cause, message=None): InterfaceError.__init__(self, cause, message) +class InterfaceChannelForEquipmentDuplicatedError(InterfaceError): + + """Retorna exceção quando já existir uma interface do tipo canal com o mesmo nome para o equipamento informado.""" + + def __init__(self, cause, message=None): + InterfaceError.__init__(self, cause, message) + + class InterfaceUsedByOtherInterfaceError(InterfaceError): """Retorna exceção quando a interface a ser removida for utilizada por outra interface.""" diff --git a/networkapi/interface/resource/InterfaceGetResource.py b/networkapi/interface/resource/InterfaceGetResource.py index a0bcedc7e..ef7449be1 100644 --- a/networkapi/interface/resource/InterfaceGetResource.py +++ b/networkapi/interface/resource/InterfaceGetResource.py @@ -29,6 +29,7 @@ from networkapi.interface.models import Interface from networkapi.interface.models import InterfaceError from networkapi.interface.models import InterfaceNotFoundError +from networkapi.interface.models import InterfaceChannelForEquipmentDuplicatedError from networkapi.rest import RestResource from networkapi.rest import UserNotAuthorizedError from networkapi.util import is_valid_int_greater_zero_param @@ -132,6 +133,9 @@ def handle_get(self, request, user, *args, **kwargs): channel_id = get_channel[0].channel.id if get_channel else "" interfaces = Interface.objects.filter(channel__id=channel_id) if channel_id else [] for i in interfaces: + if i.equipamento.nome == equip_name: + raise InterfaceChannelForEquipmentDuplicatedError( + None, u'An interface of type channel with the same name on the same equipment already exists') equipInterface_list.append(get_new_interface_map(i)) return self.response(dumps_networkapi({'interfaces': equipInterface_list})) if equipamento is not None: