@@ 395-420 (lines=26) @@ | ||
392 | self.notify_topology_update() |
|
393 | return jsonify("Operation successful"), 200 |
|
394 | ||
395 | @rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
|
396 | @rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |
|
397 | def disable_interface(self, interface_disable_id=None, dpid=None): |
|
398 | """Administratively disable interfaces in the topology.""" |
|
399 | if dpid is None: |
|
400 | dpid = ":".join(interface_disable_id.split(":")[:-1]) |
|
401 | try: |
|
402 | switch = self.controller.switches[dpid] |
|
403 | except KeyError as exc: |
|
404 | return jsonify(f"Switch not found: {exc}"), 404 |
|
405 | ||
406 | if interface_disable_id: |
|
407 | interface_number = int(interface_disable_id.split(":")[-1]) |
|
408 | ||
409 | try: |
|
410 | switch.interfaces[interface_number].disable() |
|
411 | except KeyError: |
|
412 | msg = f"Switch {dpid} interface {interface_number} not found" |
|
413 | return jsonify(msg), 404 |
|
414 | else: |
|
415 | for interface in switch.interfaces.values(): |
|
416 | interface.disable() |
|
417 | log.info("Storing administrative state for disabled interfaces.") |
|
418 | self.save_status_on_storehouse() |
|
419 | self.notify_topology_update() |
|
420 | return jsonify("Operation successful"), 200 |
|
421 | ||
422 | @rest('v3/interfaces/<interface_id>/metadata') |
|
423 | def get_interface_metadata(self, interface_id): |
|
@@ 368-393 (lines=26) @@ | ||
365 | ||
366 | return jsonify({'interfaces': interfaces}) |
|
367 | ||
368 | @rest('v3/interfaces/switch/<dpid>/enable', methods=['POST']) |
|
369 | @rest('v3/interfaces/<interface_enable_id>/enable', methods=['POST']) |
|
370 | def enable_interface(self, interface_enable_id=None, dpid=None): |
|
371 | """Administratively enable interfaces in the topology.""" |
|
372 | if dpid is None: |
|
373 | dpid = ":".join(interface_enable_id.split(":")[:-1]) |
|
374 | try: |
|
375 | switch = self.controller.switches[dpid] |
|
376 | except KeyError as exc: |
|
377 | return jsonify(f"Switch not found: {exc}"), 404 |
|
378 | ||
379 | if interface_enable_id: |
|
380 | interface_number = int(interface_enable_id.split(":")[-1]) |
|
381 | ||
382 | try: |
|
383 | switch.interfaces[interface_number].enable() |
|
384 | except KeyError: |
|
385 | msg = f"Switch {dpid} interface {interface_number} not found" |
|
386 | return jsonify(msg), 404 |
|
387 | else: |
|
388 | for interface in switch.interfaces.values(): |
|
389 | interface.enable() |
|
390 | log.info("Storing administrative state for enabled interfaces.") |
|
391 | self.save_status_on_storehouse() |
|
392 | self.notify_topology_update() |
|
393 | return jsonify("Operation successful"), 200 |
|
394 | ||
395 | @rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
|
396 | @rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |