Skip to content

Commit

Permalink
Merge pull request #304 from globocom/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Laura authored Nov 24, 2020
2 parents cee0722 + 10c16e9 commit 44544ca
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 100 deletions.
70 changes: 70 additions & 0 deletions networkapi/api_interface/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,82 @@ def _generate_dict(interface):
else:
key_dict['CHANNEL_LACP_MODE'] = 'on'

# Normally used in junos plugin:
key_dict['LACP_SYSTEM_ID_MAC'] = __generate_lacp_system_id_mac(interface.channel.nome)
else:
key_dict['BOOL_INTERFACE_IN_CHANNEL'] = 0

# Normally used in junos plugin:
key_dict['CHASSIS_ID_LEAF_NUMBER'] = __generate_chassis_id_leaf_number(interface.equipamento.nome)

log.info("_generate_dict return value (dict values): {}".format(key_dict))

return key_dict


def __generate_chassis_id_leaf_number(equipment_name):

"""
This function build value for CHASSIS_ID_LEAF_NUMBER, and must result 0 or 1 value.
For example: LF-LAB-JUN-01 returns 0 and LF-LAB-JUN-02 returns 1
:param str equipment_name:
ex.: LF-LAB-JUN-01 and LF-LAB-JUN-02 (last character must be 1 or 2)
:returns: 0, 1 or 'N/A' (to indicate information not available)
"""

leaf_id_last_char = equipment_name[-1]
if leaf_id_last_char is '1' or '2':
leaf_id = int(leaf_id_last_char)
result = leaf_id - 1
log.info("__generate_chassis_id_leaf_number - equipment_name:{} result:{}".format(equipment_name, result))
return result
else:
message = "Could not set CHASSIS_ID_LEAF_NUMBER from name {}. This name not ends with '1' or '2'!".format(
equipment_name)
log.warning(message)
return 'N/A'


def __generate_lacp_system_id_mac(channel_name):

"""
This function build value for LACP_SYSTEM_ID_MAC Generate based on channel name.
:param str channel_name:
ex.: '123'
:returns:
ex.: like '00:00:00:00:01:23' or 'N/A' (to indicate information not available)
"""

try:
# Put remaining zeros, ex.: 000000000123
equipment_name_zero_filled = channel_name.zfill(12)

# Run for equipment_name_zero_filled and generate the result with ":"s
mac_address_result = ""
i = 1
for char in equipment_name_zero_filled:
mac_address_result = mac_address_result + char
if i == 2:
mac_address_result = mac_address_result + ":"
i = 1
continue
i = i + 1

# At this point, the result has an extra character ":" (00:00:00:00:01:23:), and the code below will removed it.
mac_address_result = mac_address_result[:-1]
log.info("__generate_mac_address_based_on_name - channel_name:{} result:{}".format(
channel_name, mac_address_result))
return mac_address_result
except Exception as e:
message = "Could not set LACP_SYSTEM_ID_MAC from name {}.".format(channel_name)
log.warning("{} {}".format(message, e))
return 'N/A'


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

Expand Down
17 changes: 8 additions & 9 deletions networkapi/api_rack/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,26 @@ def post(self, *args, **kwargs):


class RackForeman (APIView):

def post(self, *args, **kwargs):
try:
log.info('RACK Foreman.')
log.info('RACK Foreman.')

try:
rack_id = kwargs.get('rack_id')
rack = facade.get_by_pk(rack_id)
# Create Foreman entries for rack switches
facade.api_foreman(rack)
raise api_exceptions.NetworkAPIException('chegou')
return Response(datas, status=status.HTTP_201_CREATED)
return Response({}, status=status.HTTP_201_CREATED)

except exceptions.RackNumberNotFoundError, e:
except exceptions.RackNumberNotFoundError as e:
log.exception(e)
raise exceptions.NetworkAPIException(e)

except var_exceptions.VariableDoesNotExistException, e:
except var_exceptions.VariableDoesNotExistException as e:
log.error(e)
raise api_exceptions.NetworkAPIException(
'Erro ao registrar o Switch no Foreman. Erro: %s' % e)
'Erro ao registrar o Switch no Foreman. Erro: %s' % e)

except Exception, e:
except Exception as e:
log.exception(e)
raise api_exceptions.NetworkAPIException(e)

Expand Down
6 changes: 6 additions & 0 deletions networkapi/equipamento/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,9 @@ def delete(self):
for equipment_group in self.equipamentogrupo_set.all():
equipment_group.delete()

for asn_equipment in self.asnequipment_set.all():
asn_equipment.delete()

super(Equipamento, self).delete()

def remove(self, authenticated_user, equip_id):
Expand Down Expand Up @@ -835,6 +838,9 @@ def delete_v3(self):
for equipment_group in self.equipamentogrupo_set.all():
equipment_group.delete()

for asn_equipment in self.asnequipment_set.all():
asn_equipment.delete()

self.delete()

def create_v3(self, equipment):
Expand Down
34 changes: 23 additions & 11 deletions networkapi/plugins/Cisco/NXOS/BGP/Cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ class Generic(BasePlugin):
WARNING_REGEX = 'config ignored|Warning'
ERROR_REGEX = '[Ee][Rr][Rr][Oo][Rr]|[Ff]ail|\%|utility is occupied'

management_vrf = 'management'
management_vrf = 'BEVrf'
admin_privileges = 15
VALID_TFTP_PUT_MESSAGE = 'bytes successfully copied'
VALID_TFTP_PUT_MESSAGE_NXS6001 = 'Copy complete'

def _deploy_pre_req(self, neighbor):
# Concatenate RouteMapEntries Lists
Expand Down Expand Up @@ -452,16 +453,18 @@ def _ensure_privilege_level(self, privilege_level=None):
self.channel.send('\n')
recv = self._wait_string('>|#')
self.channel.send('show privilege\n')
recv = self._wait_string('Current privilege level is')
level = re.search(
'Current privilege level is ([0-9]+).*', recv, re.DOTALL).group(1)

level = (level.split(' '))[-1]
if int(level) < privilege_level:
self.channel.send('enable\n')
recv = self._wait_string('Password:')
self.channel.send('%s\n' % self.equipment_access.enable_pass)
recv = self._wait_string('#')
if not self.waitString('Feature privilege: Disabled'):
self.channel.send('show privilege\n')
recv = self._wait_string('Current privilege level is')
level = re.search(
'Current privilege level is ([0-9]+).*', recv, re.DOTALL).group(1)

level = (level.split(' '))[-1]
if int(level) < privilege_level:
self.channel.send('enable\n')
recv = self._wait_string('Password:')
self.channel.send('%s\n' % self.equipment_access.enable_pass)
recv = self._wait_string('#')

def _wait_string(self, wait_str_ok_regex='', wait_str_invalid_regex=None,
wait_str_failed_regex=None):
Expand Down Expand Up @@ -512,5 +515,14 @@ def _wait_string(self, wait_str_ok_regex='', wait_str_invalid_regex=None,
log.debug('Switch copied 0 bytes, need to try again.')
raise plugin_exc.CurrentlyBusyErrorException()
string_ok = 1
elif re.search(self.VALID_TFTP_PUT_MESSAGE_NXS6001, output_line):

log.debug('Equipment output: %s' % output_line)

# test bug switch copying 0 bytes
if output_line == 'Copy failed':
log.debug('Switch copied 0 bytes, need to try again.')
raise plugin_exc.CurrentlyBusyErrorException()
string_ok = 1

return recv_string
10 changes: 10 additions & 0 deletions networkapi/plugins/Dell/FTOS/BGP/Cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Generic(BasePlugin):

admin_privileges = 15
VALID_TFTP_PUT_MESSAGE = 'bytes successfully copied'
VALID_TFTP_PUT_MESSAGE_OS10 = 'Copy succeeded'

def _deploy_pre_req(self, neighbor):
log.debug("_deploy_pre_req")
Expand Down Expand Up @@ -522,5 +523,14 @@ def _wait_string(self, wait_str_ok_regex='', wait_str_invalid_regex=None,
log.debug('Switch copied 0 bytes, need to try again.')
raise plugin_exc.CurrentlyBusyErrorException()
string_ok = 1
elif re.search(self.VALID_TFTP_PUT_MESSAGE_OS10, output_line):

log.debug('Equipment output: %s' % output_line)

# test bug switch copying 0 bytes
if output_line == 'Copy failed':
log.debug('Switch copied 0 bytes, need to try again.')
raise plugin_exc.CurrentlyBusyErrorException()
string_ok = 1

return recv_string
Loading

0 comments on commit 44544ca

Please sign in to comment.