Skip to content

Commit d239b5c

Browse files
Merge pull request #460 from globocom/develop
Develop
2 parents 7d5bc33 + b5a2d9d commit d239b5c

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

networkapi/api_interface/facade.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,21 @@ def get_interface_by_ids(interface_ids):
290290

291291

292292
def generate_delete_file(user, equip_id, interface_list, channel):
293+
294+
log.info("generate_delete_file equip_id:%s interface_list:%s channel:%s", equip_id, interface_list, channel)
295+
293296
try:
294297
INTERFACE_CONFIG_TOAPPLY_REL_PATH = get_variable(
295298
'interface_config_toapply_rel_path')
296299
INTERFACE_CONFIG_FILES_PATH = get_variable(
297300
'interface_config_files_path')
298301
TEMPLATE_REMOVE_CHANNEL = get_variable('template_remove_channel')
299302
TEMPLATE_REMOVE_INTERFACE = get_variable('template_remove_interface')
303+
304+
log.debug('INTERFACE_CONFIG_TOAPPLY_REL_PATH:%s', INTERFACE_CONFIG_TOAPPLY_REL_PATH)
305+
log.debug('INTERFACE_CONFIG_FILES_PATH:%s', INTERFACE_CONFIG_FILES_PATH)
306+
log.debug('TEMPLATE_REMOVE_CHANNEL:%s', TEMPLATE_REMOVE_CHANNEL)
307+
log.debug('TEMPLATE_REMOVE_INTERFACE:%s', TEMPLATE_REMOVE_INTERFACE)
300308
except ObjectDoesNotExist:
301309
raise var_exceptions.VariableDoesNotExistException(
302310
'Erro buscando a variável INTERFACE_CONFIG_TEMPLATE_PATH,'
@@ -350,9 +358,12 @@ def generate_delete_file(user, equip_id, interface_list, channel):
350358

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

361+
log.info('delete_channel equip_id:%s interface_list:%s channel:%s', equip_id, interface_list, channel)
362+
353363
file_to_deploy = generate_delete_file(
354364
user, equip_id, interface_list, channel)
355365

366+
log.debug('file_to_deploy: %s', file_to_deploy)
356367
# TODO Deploy config file
357368
try:
358369
lockvar = LOCK_EQUIPMENT % (equip_id)
@@ -510,6 +521,7 @@ def _load_template_file(equipment_id, template_type):
510521

511522
filename_in = INTERFACE_CONFIG_TEMPLATE_PATH + \
512523
equipment_template.roteiro.roteiro
524+
log.debug("filename_in: %s", filename_in)
513525

514526
# Read contents from file
515527
try:

networkapi/interface/resource/InterfaceChannelResource.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,15 @@ def handle_get(self, request, user, *args, **kwargs):
277277
return self.response_error(1)
278278

279279
def handle_delete(self, request, user, *args, **kwargs):
280-
"""Trata uma requisição DELETE para excluir um port channel
281-
URL: /channel/delete/<channel_name>/<interface_id>
280+
"""
281+
Delete port channel from interface id (table 'interfaces'), ex.:
282+
DELETE /channel/delete/73886/
283+
284+
Not tested:
285+
DELETE /channel/delete/<channel_name>/<interface_id>
282286
"""
283287
try:
284-
self.log.info('Delete Channel')
288+
self.log.debug('Delete Channel request:%s', request)
285289

286290
# User permission
287291
if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
@@ -290,30 +294,39 @@ def handle_delete(self, request, user, *args, **kwargs):
290294
raise UserNotAuthorizedError(None)
291295

292296
interface_id = kwargs.get('channel_name')
297+
self.log.info('interface_id: %s', interface_id)
293298
interface = Interface.get_by_pk(int(interface_id))
294299
equip_list = []
295300

301+
# Getting port channel
296302
try:
297303
interface.channel.id
298304
channel = interface.channel
299305
except:
300306
channel = interface.ligacao_front.channel
301307
pass
308+
self.log.debug('channel id:%s name:%s', channel.id, channel)
309+
310+
# Getting all interfaces used by port channel
302311
try:
303312
interfaces = Interface.objects.all().filter(channel__id=channel.id)
304313
except:
305314
return self.response(dumps_networkapi({}))
315+
self.log.debug('interfaces: %s', interfaces)
306316

317+
# Getting all equipment from interfaces (switches, ex.: LF-CM-AH18-1 and LF-CM-AH18-2)
307318
for i in interfaces:
308319
equip_list.append(i.equipamento.id)
309320
equip_list = set(equip_list)
310321
equip_dict = dict()
322+
self.log.debug('equip_list: %s', equip_list)
311323
for e in equip_list:
312324
equip_dict[str(e)] = interfaces.filter(equipamento__id=e)
313325

314326
tipo = TipoInterface()
315327
tipo = tipo.get_by_name('access')
316328

329+
# For each equipment (leaf), remove port channel
317330
for e in equip_dict:
318331
for i in equip_dict.get(e):
319332
try:

0 commit comments

Comments
 (0)