|
@@ 365-391 (lines=27) @@
|
| 362 |
|
self.notify_topology_update() |
| 363 |
|
return jsonify("Operation successful"), 200 |
| 364 |
|
|
| 365 |
|
@rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
| 366 |
|
@rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |
| 367 |
|
def disable_interface(self, interface_disable_id=None, dpid=None): |
| 368 |
|
"""Administratively disable interfaces in the topology.""" |
| 369 |
|
if dpid is None: |
| 370 |
|
dpid = ":".join(interface_disable_id.split(":")[:-1]) |
| 371 |
|
try: |
| 372 |
|
switch = self.controller.switches[dpid] |
| 373 |
|
except KeyError as exc: |
| 374 |
|
return jsonify(f"Switch not found: {exc}"), 404 |
| 375 |
|
|
| 376 |
|
if interface_disable_id: |
| 377 |
|
interface_number = int(interface_disable_id.split(":")[-1]) |
| 378 |
|
|
| 379 |
|
try: |
| 380 |
|
interface = switch.interfaces[interface_number] |
| 381 |
|
self.topo_controller.disable_interface(interface.id) |
| 382 |
|
interface.disable() |
| 383 |
|
except KeyError: |
| 384 |
|
msg = f"Switch {dpid} interface {interface_number} not found" |
| 385 |
|
return jsonify(msg), 404 |
| 386 |
|
else: |
| 387 |
|
for interface in switch.interfaces.values(): |
| 388 |
|
interface.disable() |
| 389 |
|
self.topo_controller.upsert_switch(switch.id, switch.as_dict()) |
| 390 |
|
self.notify_topology_update() |
| 391 |
|
return jsonify("Operation successful"), 200 |
| 392 |
|
|
| 393 |
|
@rest('v3/interfaces/<interface_id>/metadata') |
| 394 |
|
def get_interface_metadata(self, interface_id): |
|
@@ 337-363 (lines=27) @@
|
| 334 |
|
|
| 335 |
|
return jsonify({'interfaces': interfaces}) |
| 336 |
|
|
| 337 |
|
@rest('v3/interfaces/switch/<dpid>/enable', methods=['POST']) |
| 338 |
|
@rest('v3/interfaces/<interface_enable_id>/enable', methods=['POST']) |
| 339 |
|
def enable_interface(self, interface_enable_id=None, dpid=None): |
| 340 |
|
"""Administratively enable interfaces in the topology.""" |
| 341 |
|
if dpid is None: |
| 342 |
|
dpid = ":".join(interface_enable_id.split(":")[:-1]) |
| 343 |
|
try: |
| 344 |
|
switch = self.controller.switches[dpid] |
| 345 |
|
except KeyError as exc: |
| 346 |
|
return jsonify(f"Switch not found: {exc}"), 404 |
| 347 |
|
|
| 348 |
|
if interface_enable_id: |
| 349 |
|
interface_number = int(interface_enable_id.split(":")[-1]) |
| 350 |
|
|
| 351 |
|
try: |
| 352 |
|
interface = switch.interfaces[interface_number] |
| 353 |
|
self.topo_controller.enable_interface(interface.id) |
| 354 |
|
interface.enable() |
| 355 |
|
except KeyError: |
| 356 |
|
msg = f"Switch {dpid} interface {interface_number} not found" |
| 357 |
|
return jsonify(msg), 404 |
| 358 |
|
else: |
| 359 |
|
for interface in switch.interfaces.values(): |
| 360 |
|
interface.enable() |
| 361 |
|
self.topo_controller.upsert_switch(switch.id, switch.as_dict()) |
| 362 |
|
self.notify_topology_update() |
| 363 |
|
return jsonify("Operation successful"), 200 |
| 364 |
|
|
| 365 |
|
@rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
| 366 |
|
@rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |