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