Skip to content

Commit 44544ca

Browse files
author
Laura
authored
Merge pull request #304 from globocom/develop
Develop
2 parents cee0722 + 10c16e9 commit 44544ca

File tree

9 files changed

+279
-100
lines changed

9 files changed

+279
-100
lines changed

networkapi/api_interface/facade.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,82 @@ def _generate_dict(interface):
577577
else:
578578
key_dict['CHANNEL_LACP_MODE'] = 'on'
579579

580+
# Normally used in junos plugin:
581+
key_dict['LACP_SYSTEM_ID_MAC'] = __generate_lacp_system_id_mac(interface.channel.nome)
580582
else:
581583
key_dict['BOOL_INTERFACE_IN_CHANNEL'] = 0
582584

585+
# Normally used in junos plugin:
586+
key_dict['CHASSIS_ID_LEAF_NUMBER'] = __generate_chassis_id_leaf_number(interface.equipamento.nome)
587+
588+
log.info("_generate_dict return value (dict values): {}".format(key_dict))
589+
583590
return key_dict
584591

585592

593+
def __generate_chassis_id_leaf_number(equipment_name):
594+
595+
"""
596+
This function build value for CHASSIS_ID_LEAF_NUMBER, and must result 0 or 1 value.
597+
For example: LF-LAB-JUN-01 returns 0 and LF-LAB-JUN-02 returns 1
598+
599+
:param str equipment_name:
600+
ex.: LF-LAB-JUN-01 and LF-LAB-JUN-02 (last character must be 1 or 2)
601+
602+
:returns: 0, 1 or 'N/A' (to indicate information not available)
603+
"""
604+
605+
leaf_id_last_char = equipment_name[-1]
606+
if leaf_id_last_char is '1' or '2':
607+
leaf_id = int(leaf_id_last_char)
608+
result = leaf_id - 1
609+
log.info("__generate_chassis_id_leaf_number - equipment_name:{} result:{}".format(equipment_name, result))
610+
return result
611+
else:
612+
message = "Could not set CHASSIS_ID_LEAF_NUMBER from name {}. This name not ends with '1' or '2'!".format(
613+
equipment_name)
614+
log.warning(message)
615+
return 'N/A'
616+
617+
618+
def __generate_lacp_system_id_mac(channel_name):
619+
620+
"""
621+
This function build value for LACP_SYSTEM_ID_MAC Generate based on channel name.
622+
623+
:param str channel_name:
624+
ex.: '123'
625+
626+
:returns:
627+
ex.: like '00:00:00:00:01:23' or 'N/A' (to indicate information not available)
628+
"""
629+
630+
try:
631+
# Put remaining zeros, ex.: 000000000123
632+
equipment_name_zero_filled = channel_name.zfill(12)
633+
634+
# Run for equipment_name_zero_filled and generate the result with ":"s
635+
mac_address_result = ""
636+
i = 1
637+
for char in equipment_name_zero_filled:
638+
mac_address_result = mac_address_result + char
639+
if i == 2:
640+
mac_address_result = mac_address_result + ":"
641+
i = 1
642+
continue
643+
i = i + 1
644+
645+
# At this point, the result has an extra character ":" (00:00:00:00:01:23:), and the code below will removed it.
646+
mac_address_result = mac_address_result[:-1]
647+
log.info("__generate_mac_address_based_on_name - channel_name:{} result:{}".format(
648+
channel_name, mac_address_result))
649+
return mac_address_result
650+
except Exception as e:
651+
message = "Could not set LACP_SYSTEM_ID_MAC from name {}.".format(channel_name)
652+
log.warning("{} {}".format(message, e))
653+
return 'N/A'
654+
655+
586656
def get_vlan_range(interface):
587657
log.info("get_vlan_range")
588658

networkapi/api_rack/views.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,27 +201,26 @@ def post(self, *args, **kwargs):
201201

202202

203203
class RackForeman (APIView):
204+
204205
def post(self, *args, **kwargs):
205-
try:
206-
log.info('RACK Foreman.')
206+
log.info('RACK Foreman.')
207207

208+
try:
208209
rack_id = kwargs.get('rack_id')
209210
rack = facade.get_by_pk(rack_id)
210-
# Create Foreman entries for rack switches
211211
facade.api_foreman(rack)
212-
raise api_exceptions.NetworkAPIException('chegou')
213-
return Response(datas, status=status.HTTP_201_CREATED)
212+
return Response({}, status=status.HTTP_201_CREATED)
214213

215-
except exceptions.RackNumberNotFoundError, e:
214+
except exceptions.RackNumberNotFoundError as e:
216215
log.exception(e)
217216
raise exceptions.NetworkAPIException(e)
218217

219-
except var_exceptions.VariableDoesNotExistException, e:
218+
except var_exceptions.VariableDoesNotExistException as e:
220219
log.error(e)
221220
raise api_exceptions.NetworkAPIException(
222-
'Erro ao registrar o Switch no Foreman. Erro: %s' % e)
221+
'Erro ao registrar o Switch no Foreman. Erro: %s' % e)
223222

224-
except Exception, e:
223+
except Exception as e:
225224
log.exception(e)
226225
raise api_exceptions.NetworkAPIException(e)
227226

networkapi/equipamento/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,9 @@ def delete(self):
786786
for equipment_group in self.equipamentogrupo_set.all():
787787
equipment_group.delete()
788788

789+
for asn_equipment in self.asnequipment_set.all():
790+
asn_equipment.delete()
791+
789792
super(Equipamento, self).delete()
790793

791794
def remove(self, authenticated_user, equip_id):
@@ -835,6 +838,9 @@ def delete_v3(self):
835838
for equipment_group in self.equipamentogrupo_set.all():
836839
equipment_group.delete()
837840

841+
for asn_equipment in self.asnequipment_set.all():
842+
asn_equipment.delete()
843+
838844
self.delete()
839845

840846
def create_v3(self, equipment):

networkapi/plugins/Cisco/NXOS/BGP/Cli.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ class Generic(BasePlugin):
6060
WARNING_REGEX = 'config ignored|Warning'
6161
ERROR_REGEX = '[Ee][Rr][Rr][Oo][Rr]|[Ff]ail|\%|utility is occupied'
6262

63-
management_vrf = 'management'
63+
management_vrf = 'BEVrf'
6464
admin_privileges = 15
6565
VALID_TFTP_PUT_MESSAGE = 'bytes successfully copied'
66+
VALID_TFTP_PUT_MESSAGE_NXS6001 = 'Copy complete'
6667

6768
def _deploy_pre_req(self, neighbor):
6869
# Concatenate RouteMapEntries Lists
@@ -452,16 +453,18 @@ def _ensure_privilege_level(self, privilege_level=None):
452453
self.channel.send('\n')
453454
recv = self._wait_string('>|#')
454455
self.channel.send('show privilege\n')
455-
recv = self._wait_string('Current privilege level is')
456-
level = re.search(
457-
'Current privilege level is ([0-9]+).*', recv, re.DOTALL).group(1)
458-
459-
level = (level.split(' '))[-1]
460-
if int(level) < privilege_level:
461-
self.channel.send('enable\n')
462-
recv = self._wait_string('Password:')
463-
self.channel.send('%s\n' % self.equipment_access.enable_pass)
464-
recv = self._wait_string('#')
456+
if not self.waitString('Feature privilege: Disabled'):
457+
self.channel.send('show privilege\n')
458+
recv = self._wait_string('Current privilege level is')
459+
level = re.search(
460+
'Current privilege level is ([0-9]+).*', recv, re.DOTALL).group(1)
461+
462+
level = (level.split(' '))[-1]
463+
if int(level) < privilege_level:
464+
self.channel.send('enable\n')
465+
recv = self._wait_string('Password:')
466+
self.channel.send('%s\n' % self.equipment_access.enable_pass)
467+
recv = self._wait_string('#')
465468

466469
def _wait_string(self, wait_str_ok_regex='', wait_str_invalid_regex=None,
467470
wait_str_failed_regex=None):
@@ -512,5 +515,14 @@ def _wait_string(self, wait_str_ok_regex='', wait_str_invalid_regex=None,
512515
log.debug('Switch copied 0 bytes, need to try again.')
513516
raise plugin_exc.CurrentlyBusyErrorException()
514517
string_ok = 1
518+
elif re.search(self.VALID_TFTP_PUT_MESSAGE_NXS6001, output_line):
519+
520+
log.debug('Equipment output: %s' % output_line)
521+
522+
# test bug switch copying 0 bytes
523+
if output_line == 'Copy failed':
524+
log.debug('Switch copied 0 bytes, need to try again.')
525+
raise plugin_exc.CurrentlyBusyErrorException()
526+
string_ok = 1
515527

516528
return recv_string

networkapi/plugins/Dell/FTOS/BGP/Cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Generic(BasePlugin):
6363

6464
admin_privileges = 15
6565
VALID_TFTP_PUT_MESSAGE = 'bytes successfully copied'
66+
VALID_TFTP_PUT_MESSAGE_OS10 = 'Copy succeeded'
6667

6768
def _deploy_pre_req(self, neighbor):
6869
log.debug("_deploy_pre_req")
@@ -522,5 +523,14 @@ def _wait_string(self, wait_str_ok_regex='', wait_str_invalid_regex=None,
522523
log.debug('Switch copied 0 bytes, need to try again.')
523524
raise plugin_exc.CurrentlyBusyErrorException()
524525
string_ok = 1
526+
elif re.search(self.VALID_TFTP_PUT_MESSAGE_OS10, output_line):
527+
528+
log.debug('Equipment output: %s' % output_line)
529+
530+
# test bug switch copying 0 bytes
531+
if output_line == 'Copy failed':
532+
log.debug('Switch copied 0 bytes, need to try again.')
533+
raise plugin_exc.CurrentlyBusyErrorException()
534+
string_ok = 1
525535

526536
return recv_string

0 commit comments

Comments
 (0)