Skip to content

Commit

Permalink
fix issue - Creating 2 channels with same name for equipment #132
Browse files Browse the repository at this point in the history
  • Loading branch information
laurapanzariello committed Feb 23, 2018
1 parent f15c5dd commit 59e69a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 38 deletions.
56 changes: 19 additions & 37 deletions networkapi/api_interface/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def generate_delete_file(user, equip_id, interface_list, channel):

return rel_file_to_deploy


def delete_channel(user, equip_id, interface_list, channel):

file_to_deploy = generate_delete_file(
Expand All @@ -169,7 +168,6 @@ def delete_channel(user, equip_id, interface_list, channel):

return status_deploy


def generate_and_deploy_interface_config_sync(user, id_interface):

if not is_valid_int_greater_zero_param(id_interface):
Expand All @@ -187,7 +185,6 @@ def generate_and_deploy_interface_config_sync(user, id_interface):

return status_deploy


def generate_and_deploy_channel_config_sync(user, id_channel):

if not is_valid_int_greater_zero_param(id_channel):
Expand Down Expand Up @@ -220,7 +217,6 @@ def generate_and_deploy_channel_config_sync(user, id_channel):

return status_deploy


def _generate_config_file(interfaces_list):
log.info("_generate_config_file")

Expand Down Expand Up @@ -292,7 +288,6 @@ def _generate_config_file(interfaces_list):

return rel_file_to_deploy


def _load_template_file(equipment_id, template_type):
log.info("_load_template_file")

Expand Down Expand Up @@ -331,7 +326,6 @@ def _load_template_file(equipment_id, template_type):

return template_file


def _generate_dict(interface):
log.info("_generate_dict")

Expand Down Expand Up @@ -386,7 +380,6 @@ def _generate_dict(interface):

return key_dict


def get_vlan_range(interface):
log.info("get_vlan_range")

Expand Down Expand Up @@ -433,7 +426,6 @@ def get_vlan_range(interface):

return [vlan_range, vlan_range_list]


def verificar_vlan_range(amb, vlans):
log.info("verificar_vlan_range")

Expand All @@ -450,47 +442,37 @@ def verificar_vlan_range(amb, vlans):
u'Numero de vlan fora do range '
'definido para o ambiente')


def verificar_vlan_nativa(vlan_nativa):
log.info("verificar_vlan_nativa")

if vlan_nativa is not None:
if int(vlan_nativa) < 1 or 3967 < int(vlan_nativa) < 4048 or int(vlan_nativa) >= 4096:
raise InvalidValueError(None, 'Vlan Nativa', 'Range valido: 1-3967, 4048-4095.')

def check_channel_name_on_equipment(nome, interfaces):
log.info("check_channel_name_on_equipment")

def verificar_nome_channel(nome, interfaces):
log.info("verificar_nome_channel")
for i in interfaces:

interface = Interface()
interface = Interface.objects.get(id=int(i))

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 var is not 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:
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 exceptions.InterfaceException(
u'O nome do port channel ja foi '
'utilizado no equipamento')
interface_obj = Interface.objects.filter(
channel__nome=nome,
equipamento__id=interface.equipamento.id)

if interface_obj:
raise Exception ("Channel name %s already exist on the equipment %s" % (nome, interface.equipamento.nome))

front_interface_obj = Interface.objects.filter(
channel__nome=nome,
equipamento__id=interface.ligacao_front.equipamento.id)

if front_interface_obj:
raise Exception ("Channel name %s already exist on the equipment %s" % (nome, interface.ligacao_front.equipamento.nome))

log.info("passei")

def available_channel_number (channel_name, interface_ids):
def available_channel_number(channel_name, interface_ids):
log.info("available channel")

interface_obj = Interface()
Expand Down
4 changes: 3 additions & 1 deletion networkapi/interface/resource/InterfaceChannelResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def handle_post(self, request, user, *args, **kwargs):

# verifica se o nome do port channel já existe no equipamento
interfaces = str(interfaces).split('-')
api_interface_facade.verificar_nome_channel(nome, interfaces)
api_interface_facade.check_channel_name_on_equipment(nome, interfaces)

# cria o port channel
port_channel.nome = str(nome)
Expand Down Expand Up @@ -230,6 +230,8 @@ def handle_post(self, request, user, *args, **kwargs):
return self.response_error(405, e)
except api_interface_exceptions.InterfaceException, e:
return self.response_error(405, e)
except Exception, e:
return self.response_error(405, e)

def handle_get(self, request, user, *args, **kwargs):
"""Trata uma requisição PUT para alterar informações de um channel.
Expand Down

0 comments on commit 59e69a7

Please sign in to comment.