Skip to content

Commit

Permalink
fix channel edit
Browse files Browse the repository at this point in the history
  • Loading branch information
laurapanzariello authored and laurapanzariello committed Nov 27, 2015
1 parent d84f33f commit 1699c60
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions networkapi/interface/resource/InterfaceChannelResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ def handle_post(self, request, user, *args, **kwargs):
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)
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")
Expand Down Expand Up @@ -291,6 +295,9 @@ def handle_delete(self, request, user, *args, **kwargs):
for e in equip_list:
equip_dict[str(e)] = interfaces.filter(equipamento__id=e)

tipo = TipoInterface()
tipo = tipo.get_by_name("access")

for e in equip_dict:
for i in equip_dict.get(e):
try:
Expand All @@ -310,15 +317,17 @@ def handle_delete(self, request, user, *args, **kwargs):
descricao=i.descricao,
ligacao_front_id=front,
ligacao_back_id=back,
tipo=i.tipo,
vlan_nativa=i.vlan_nativa)
tipo=tipo,
vlan_nativa="1")

api_interface_facade.delete_channel(user, e, equip_dict.get(e), channel)
status = api_interface_facade.delete_channel(user, e, equip_dict.get(e), channel)

channel.delete(user)

return self.response(dumps_networkapi({}))

except api_interface_exceptions.InterfaceException, e:
return api_interface_exceptions.InterfaceException(e)
except api_interface_exceptions.InvalidKeyException, e:
return api_interface_exceptions.InvalidKeyException(e)
except var_exceptions.VariableDoesNotExistException, e:
Expand All @@ -331,6 +340,7 @@ def handle_delete(self, request, user, *args, **kwargs):
self.log.error(u'Erro ao ler o XML da requisição.')
return self.response_error(3, x)


def handle_put(self, request, user, *args, **kwargs):
"""Treat requests POST to add Rack.
Expand Down Expand Up @@ -397,10 +407,15 @@ def handle_put(self, request, user, *args, **kwargs):
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")
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 InterfaceError("O nome do port channel ja foi utilizado no equipamento")

#buscar interfaces do channel
interfaces = Interface.objects.all().filter(channel__id=id_channel)
Expand Down

0 comments on commit 1699c60

Please sign in to comment.