|
@@ 371-399 (lines=29) @@
|
| 368 |
|
return jsonify({msg_error: |
| 369 |
|
error_list}), 409 |
| 370 |
|
|
| 371 |
|
@rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
| 372 |
|
@rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |
| 373 |
|
def disable_interface(self, interface_disable_id=None, dpid=None): |
| 374 |
|
"""Administratively disable interfaces in the topology.""" |
| 375 |
|
error_list = [] # List of interfaces that were not deactivated. |
| 376 |
|
msg_error = "Some interfaces couldn't be found and deactivated: " |
| 377 |
|
if dpid is None: |
| 378 |
|
dpid = ":".join(interface_disable_id.split(":")[:-1]) |
| 379 |
|
try: |
| 380 |
|
switch = self.controller.switches[dpid] |
| 381 |
|
except KeyError as exc: |
| 382 |
|
return jsonify(f"Switch not found: {exc}"), 404 |
| 383 |
|
|
| 384 |
|
if interface_disable_id: |
| 385 |
|
interface_number = int(interface_disable_id.split(":")[-1]) |
| 386 |
|
|
| 387 |
|
try: |
| 388 |
|
switch.interfaces[interface_number].disable() |
| 389 |
|
except KeyError as exc: |
| 390 |
|
error_list.append(f"Switch {dpid} Interface {exc}") |
| 391 |
|
else: |
| 392 |
|
for interface in switch.interfaces.values(): |
| 393 |
|
interface.disable() |
| 394 |
|
if not error_list: |
| 395 |
|
log.info(f"Storing administrative state for disabled interfaces.") |
| 396 |
|
self.save_status_on_storehouse() |
| 397 |
|
return jsonify("Operation successful"), 200 |
| 398 |
|
return jsonify({msg_error: |
| 399 |
|
error_list}), 409 |
| 400 |
|
|
| 401 |
|
@rest('v3/interfaces/<interface_id>/metadata') |
| 402 |
|
def get_interface_metadata(self, interface_id): |
|
@@ 341-369 (lines=29) @@
|
| 338 |
|
|
| 339 |
|
return jsonify({'interfaces': interfaces}) |
| 340 |
|
|
| 341 |
|
@rest('v3/interfaces/switch/<dpid>/enable', methods=['POST']) |
| 342 |
|
@rest('v3/interfaces/<interface_enable_id>/enable', methods=['POST']) |
| 343 |
|
def enable_interface(self, interface_enable_id=None, dpid=None): |
| 344 |
|
"""Administratively enable interfaces in the topology.""" |
| 345 |
|
error_list = [] # List of interfaces that were not activated. |
| 346 |
|
msg_error = "Some interfaces couldn't be found and activated: " |
| 347 |
|
if dpid is None: |
| 348 |
|
dpid = ":".join(interface_enable_id.split(":")[:-1]) |
| 349 |
|
try: |
| 350 |
|
switch = self.controller.switches[dpid] |
| 351 |
|
except KeyError as exc: |
| 352 |
|
return jsonify(f"Switch not found: {exc}"), 404 |
| 353 |
|
|
| 354 |
|
if interface_enable_id: |
| 355 |
|
interface_number = int(interface_enable_id.split(":")[-1]) |
| 356 |
|
|
| 357 |
|
try: |
| 358 |
|
switch.interfaces[interface_number].enable() |
| 359 |
|
except KeyError as exc: |
| 360 |
|
error_list.append(f"Switch {dpid} Interface {exc}") |
| 361 |
|
else: |
| 362 |
|
for interface in switch.interfaces.values(): |
| 363 |
|
interface.enable() |
| 364 |
|
if not error_list: |
| 365 |
|
log.info(f"Storing administrative state for enabled interfaces.") |
| 366 |
|
self.save_status_on_storehouse() |
| 367 |
|
return jsonify("Operation successful"), 200 |
| 368 |
|
return jsonify({msg_error: |
| 369 |
|
error_list}), 409 |
| 370 |
|
|
| 371 |
|
@rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
| 372 |
|
@rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |