Skip to content

Commit

Permalink
check if channels name is duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
laurapanzariello authored and laurapanzariello committed Nov 10, 2015
1 parent f5497a0 commit 8d24bb9
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions networkapi/interface/resource/InterfaceChannelResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,32 @@ def handle_post(self, request, user, *args, **kwargs):

cont = []

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

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:
sw = i.get_switch_and_router_interface_from_host_interface(i.protegida)
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")

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))
Expand All @@ -133,6 +152,8 @@ def handle_post(self, request, user, *args, **kwargs):
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:
Expand Down

0 comments on commit 8d24bb9

Please sign in to comment.