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

Translation to english and exception refactoring #384

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
18 changes: 9 additions & 9 deletions networkapi/api_channel/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create(self, data):
vlan_nativa = data.get('vlan')
envs_vlans = data.get('envs_vlans')

api_interface_facade.verificar_vlan_nativa(vlan_nativa)
api_interface_facade.verify_native_vlan(vlan_nativa)

# Checks if Port Channel name already exists on equipment
api_interface_facade.check_channel_name_on_equipment(nome, interfaces)
Expand All @@ -79,7 +79,7 @@ def create(self, data):
if iface.channel:
raise InterfaceError(
'Interface %s is already a Channel' % iface.interface
)
)

if iface.equipamento.id not in ifaces_on_channel:
ifaces_on_channel.append(int(iface.equipamento.id))
Expand Down Expand Up @@ -107,7 +107,7 @@ def _update_interfaces_from_a_channel(self, iface, vlan_nativa,
if iface.channel:
raise InterfaceError(
'Interface %s is already a Channel' % iface.interface
)
)

if iface.equipamento.id not in ifaces_on_channel:
ifaces_on_channel.append(int(iface.equipamento.id))
Expand Down Expand Up @@ -190,12 +190,12 @@ def update(self, data):
raise InvalidValueError(None, 'Channel number',
'must be integer.')

api_interface_facade.verificar_vlan_nativa(vlan_nativa)
api_interface_facade.verify_native_vlan(vlan_nativa)

# Dissociate old interfaces
interfaces_old = Interface.objects.filter(
channel__id=int(id_channel)
)
)
log.debug(interfaces_old)
server = None
for i in interfaces_old:
Expand Down Expand Up @@ -229,14 +229,14 @@ def update(self, data):
raise InterfaceError(
'Interface %s is already in a Channel'
% iface.interface
)
)

if iface.equipamento.id not in ifaces_on_channel:
ifaces_on_channel.append(int(iface.equipamento.id))
if len(ifaces_on_channel) > 2:
raise InterfaceError(
'More than one equipment selected.'
)
)

iface.channel = self.channel
iface.tipo = type_obj
Expand Down Expand Up @@ -327,7 +327,7 @@ def _get_equipment_dict(self, interfaces):
for equip_id in [i.equipamento.id for i in interfaces]:

equip_dict[str(equip_id)] = interfaces.filter(
equipamento__id=equip_id)
equipamento__id=equip_id)

return equip_dict

Expand Down Expand Up @@ -356,7 +356,7 @@ def _update_equipments(self, equip_dict, iface_type, user, channel):
ligacao_back_id=back,
tipo=iface_type,
vlan_nativa='1'
)
)

api_interface_facade.delete_channel(
self.user, equip_id, ifaces, channel)
Expand Down
10 changes: 4 additions & 6 deletions networkapi/api_interface/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,10 @@ def verificar_vlan_range(amb, vlans):
'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 verify_native_vlan(native_vlan):
if native_vlan is not None:
if int(native_vlan) < 1 or int(native_vlan) > 3967 or int(native_vlan) < 4048 or int(native_vlan) >= 4096:
raise InvalidValueError(None, 'Vlan Nativa', 'Valid range: 1-3967, 4048-4095.')


def check_channel_name_on_equipment(nome, interfaces):
Expand Down
18 changes: 9 additions & 9 deletions networkapi/interface/resource/InterfaceChannelResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def handle_post(self, request, user, *args, **kwargs):
amb = Ambiente()
cont = []

api_interface_facade.verificar_vlan_nativa(vlan_nativa)
api_interface_facade.verify_native_vlan(vlan_nativa)

# verifica se o nome do port channel já existe no equipamento
interfaces = str(interfaces).split('-')
Expand Down Expand Up @@ -405,7 +405,7 @@ def handle_put(self, request, user, *args, **kwargs):
interface = Interface()
amb = Ambiente()

api_interface_facade.verificar_vlan_nativa(vlan_nativa)
api_interface_facade.verify_native_vlan(vlan_nativa)

# verifica se o nome do port channel já existe no equipamento
channel = port_channel.get_by_pk(int(id_channel))
Expand Down Expand Up @@ -487,10 +487,10 @@ def handle_put(self, request, user, *args, **kwargs):

return self.response(dumps_networkapi({'port_channel': port_channel_map}))

except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
except XMLError, x:
self.log.error(u'Erro ao ler o XML da requisição.')
return self.response_error(3, x)
except InterfaceError, e:
return self.response_error(406, e)
except InvalidValueError as invalid_value_error:
return self.response_error(269, invalid_value_error.param, invalid_value_error.value)
except XMLError as xml_error:
self.log.error('Error reading the request XML.')
return self.response_error(3, xml_error)
except InterfaceError as interface_error:
return self.response_error(406, interface_error)