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