Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to fix #132 #347

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions networkapi/interface/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
4 changes: 4 additions & 0 deletions networkapi/interface/resource/InterfaceGetResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down