|
@@ 473-500 (lines=28) @@
|
| 470 |
|
return jsonify({msg_error: |
| 471 |
|
error_list}), 400 |
| 472 |
|
|
| 473 |
|
@rest('v1/interfaces/enable', methods=['POST']) |
| 474 |
|
def enable_lldp(self): |
| 475 |
|
"""Enable an interface to receive LLDP packets.""" |
| 476 |
|
interface_ids = self._get_data(request) |
| 477 |
|
error_list = [] # List of interfaces that were not activated. |
| 478 |
|
changed_interfaces = [] |
| 479 |
|
interface_ids = filter(None, interface_ids) |
| 480 |
|
interfaces = self._get_interfaces() |
| 481 |
|
if not interfaces: |
| 482 |
|
return jsonify("No interfaces were found."), 404 |
| 483 |
|
interfaces = self._get_interfaces_dict(interfaces) |
| 484 |
|
for id_ in interface_ids: |
| 485 |
|
interface = interfaces.get(id_) |
| 486 |
|
if interface: |
| 487 |
|
interface.lldp = True |
| 488 |
|
changed_interfaces.append(id_) |
| 489 |
|
else: |
| 490 |
|
error_list.append(id_) |
| 491 |
|
if changed_interfaces: |
| 492 |
|
self.notify_lldp_change('enabled', changed_interfaces) |
| 493 |
|
if not error_list: |
| 494 |
|
return jsonify( |
| 495 |
|
"All the requested interfaces have been enabled."), 200 |
| 496 |
|
|
| 497 |
|
# Return a list of interfaces that couldn't be enabled |
| 498 |
|
msg_error = "Some interfaces couldn't be found and activated: " |
| 499 |
|
return jsonify({msg_error: |
| 500 |
|
error_list}), 400 |
| 501 |
|
|
| 502 |
|
@rest('v1/polling_time', methods=['GET']) |
| 503 |
|
def get_time(self): |
|
@@ 444-471 (lines=28) @@
|
| 441 |
|
"""Return all the interfaces that have LLDP traffic enabled.""" |
| 442 |
|
return jsonify({"interfaces": self._get_lldp_interfaces()}), 200 |
| 443 |
|
|
| 444 |
|
@rest('v1/interfaces/disable', methods=['POST']) |
| 445 |
|
def disable_lldp(self): |
| 446 |
|
"""Disables an interface to receive LLDP packets.""" |
| 447 |
|
interface_ids = self._get_data(request) |
| 448 |
|
error_list = [] # List of interfaces that were not activated. |
| 449 |
|
changed_interfaces = [] |
| 450 |
|
interface_ids = filter(None, interface_ids) |
| 451 |
|
interfaces = self._get_interfaces() |
| 452 |
|
if not interfaces: |
| 453 |
|
return jsonify("No interfaces were found."), 404 |
| 454 |
|
interfaces = self._get_interfaces_dict(interfaces) |
| 455 |
|
for id_ in interface_ids: |
| 456 |
|
interface = interfaces.get(id_) |
| 457 |
|
if interface: |
| 458 |
|
interface.lldp = False |
| 459 |
|
changed_interfaces.append(id_) |
| 460 |
|
else: |
| 461 |
|
error_list.append(id_) |
| 462 |
|
if changed_interfaces: |
| 463 |
|
self.notify_lldp_change('disabled', changed_interfaces) |
| 464 |
|
if not error_list: |
| 465 |
|
return jsonify( |
| 466 |
|
"All the requested interfaces have been disabled."), 200 |
| 467 |
|
|
| 468 |
|
# Return a list of interfaces that couldn't be disabled |
| 469 |
|
msg_error = "Some interfaces couldn't be found and deactivated: " |
| 470 |
|
return jsonify({msg_error: |
| 471 |
|
error_list}), 400 |
| 472 |
|
|
| 473 |
|
@rest('v1/interfaces/enable', methods=['POST']) |
| 474 |
|
def enable_lldp(self): |