|
@@ 388-415 (lines=28) @@
|
| 385 |
|
return jsonify({msg_error: |
| 386 |
|
error_list}), 400 |
| 387 |
|
|
| 388 |
|
@rest('v1/interfaces/enable', methods=['POST']) |
| 389 |
|
def enable_lldp(self): |
| 390 |
|
"""Enable an interface to receive LLDP packets.""" |
| 391 |
|
interface_ids = self._get_data(request) |
| 392 |
|
error_list = [] # List of interfaces that were not activated. |
| 393 |
|
changed_interfaces = [] |
| 394 |
|
interface_ids = filter(None, interface_ids) |
| 395 |
|
interfaces = self._get_interfaces() |
| 396 |
|
if not interfaces: |
| 397 |
|
return jsonify("No interfaces were found."), 404 |
| 398 |
|
interfaces = self._get_interfaces_dict(interfaces) |
| 399 |
|
for id_ in interface_ids: |
| 400 |
|
interface = interfaces.get(id_) |
| 401 |
|
if interface: |
| 402 |
|
interface.lldp = True |
| 403 |
|
changed_interfaces.append(id_) |
| 404 |
|
else: |
| 405 |
|
error_list.append(id_) |
| 406 |
|
if changed_interfaces: |
| 407 |
|
self.notify_lldp_change('enabled', changed_interfaces) |
| 408 |
|
if not error_list: |
| 409 |
|
return jsonify( |
| 410 |
|
"All the requested interfaces have been enabled."), 200 |
| 411 |
|
|
| 412 |
|
# Return a list of interfaces that couldn't be enabled |
| 413 |
|
msg_error = "Some interfaces couldn't be found and activated: " |
| 414 |
|
return jsonify({msg_error: |
| 415 |
|
error_list}), 400 |
| 416 |
|
|
| 417 |
|
@rest('v1/polling_time', methods=['GET']) |
| 418 |
|
def get_time(self): |
|
@@ 359-386 (lines=28) @@
|
| 356 |
|
"""Return all the interfaces that have LLDP traffic enabled.""" |
| 357 |
|
return jsonify({"interfaces": self._get_lldp_interfaces()}), 200 |
| 358 |
|
|
| 359 |
|
@rest('v1/interfaces/disable', methods=['POST']) |
| 360 |
|
def disable_lldp(self): |
| 361 |
|
"""Disables an interface to receive LLDP packets.""" |
| 362 |
|
interface_ids = self._get_data(request) |
| 363 |
|
error_list = [] # List of interfaces that were not activated. |
| 364 |
|
changed_interfaces = [] |
| 365 |
|
interface_ids = filter(None, interface_ids) |
| 366 |
|
interfaces = self._get_interfaces() |
| 367 |
|
if not interfaces: |
| 368 |
|
return jsonify("No interfaces were found."), 404 |
| 369 |
|
interfaces = self._get_interfaces_dict(interfaces) |
| 370 |
|
for id_ in interface_ids: |
| 371 |
|
interface = interfaces.get(id_) |
| 372 |
|
if interface: |
| 373 |
|
interface.lldp = False |
| 374 |
|
changed_interfaces.append(id_) |
| 375 |
|
else: |
| 376 |
|
error_list.append(id_) |
| 377 |
|
if changed_interfaces: |
| 378 |
|
self.notify_lldp_change('disabled', changed_interfaces) |
| 379 |
|
if not error_list: |
| 380 |
|
return jsonify( |
| 381 |
|
"All the requested interfaces have been disabled."), 200 |
| 382 |
|
|
| 383 |
|
# Return a list of interfaces that couldn't be disabled |
| 384 |
|
msg_error = "Some interfaces couldn't be found and deactivated: " |
| 385 |
|
return jsonify({msg_error: |
| 386 |
|
error_list}), 400 |
| 387 |
|
|
| 388 |
|
@rest('v1/interfaces/enable', methods=['POST']) |
| 389 |
|
def enable_lldp(self): |