|
@@ 354-381 (lines=28) @@
|
| 351 |
|
return jsonify({msg_error: |
| 352 |
|
error_list}), 400 |
| 353 |
|
|
| 354 |
|
@rest('v1/interfaces/enable', methods=['POST']) |
| 355 |
|
def enable_lldp(self): |
| 356 |
|
"""Enable an interface to receive LLDP packets.""" |
| 357 |
|
interface_ids = self._get_data(request) |
| 358 |
|
error_list = [] # List of interfaces that were not activated. |
| 359 |
|
changed_interfaces = [] |
| 360 |
|
interface_ids = filter(None, interface_ids) |
| 361 |
|
interfaces = self._get_interfaces() |
| 362 |
|
if not interfaces: |
| 363 |
|
return jsonify("No interfaces were found."), 404 |
| 364 |
|
interfaces = self._get_interfaces_dict(interfaces) |
| 365 |
|
for id_ in interface_ids: |
| 366 |
|
interface = interfaces.get(id_) |
| 367 |
|
if interface: |
| 368 |
|
interface.lldp = True |
| 369 |
|
changed_interfaces.append(id_) |
| 370 |
|
else: |
| 371 |
|
error_list.append(id_) |
| 372 |
|
if changed_interfaces: |
| 373 |
|
self.notify_lldp_change('enabled', changed_interfaces) |
| 374 |
|
if not error_list: |
| 375 |
|
return jsonify( |
| 376 |
|
"All the requested interfaces have been enabled."), 200 |
| 377 |
|
|
| 378 |
|
# Return a list of interfaces that couldn't be enabled |
| 379 |
|
msg_error = "Some interfaces couldn't be found and activated: " |
| 380 |
|
return jsonify({msg_error: |
| 381 |
|
error_list}), 400 |
| 382 |
|
|
| 383 |
|
@rest('v1/polling_time', methods=['GET']) |
| 384 |
|
def get_time(self): |
|
@@ 325-352 (lines=28) @@
|
| 322 |
|
"""Return all the interfaces that have LLDP traffic enabled.""" |
| 323 |
|
return jsonify({"interfaces": self._get_lldp_interfaces()}), 200 |
| 324 |
|
|
| 325 |
|
@rest('v1/interfaces/disable', methods=['POST']) |
| 326 |
|
def disable_lldp(self): |
| 327 |
|
"""Disables an interface to receive LLDP packets.""" |
| 328 |
|
interface_ids = self._get_data(request) |
| 329 |
|
error_list = [] # List of interfaces that were not activated. |
| 330 |
|
changed_interfaces = [] |
| 331 |
|
interface_ids = filter(None, interface_ids) |
| 332 |
|
interfaces = self._get_interfaces() |
| 333 |
|
if not interfaces: |
| 334 |
|
return jsonify("No interfaces were found."), 404 |
| 335 |
|
interfaces = self._get_interfaces_dict(interfaces) |
| 336 |
|
for id_ in interface_ids: |
| 337 |
|
interface = interfaces.get(id_) |
| 338 |
|
if interface: |
| 339 |
|
interface.lldp = False |
| 340 |
|
changed_interfaces.append(id_) |
| 341 |
|
else: |
| 342 |
|
error_list.append(id_) |
| 343 |
|
if changed_interfaces: |
| 344 |
|
self.notify_lldp_change('disabled', changed_interfaces) |
| 345 |
|
if not error_list: |
| 346 |
|
return jsonify( |
| 347 |
|
"All the requested interfaces have been disabled."), 200 |
| 348 |
|
|
| 349 |
|
# Return a list of interfaces that couldn't be disabled |
| 350 |
|
msg_error = "Some interfaces couldn't be found and deactivated: " |
| 351 |
|
return jsonify({msg_error: |
| 352 |
|
error_list}), 400 |
| 353 |
|
|
| 354 |
|
@rest('v1/interfaces/enable', methods=['POST']) |
| 355 |
|
def enable_lldp(self): |