|
@@ 318-346 (lines=29) @@
|
| 315 |
|
return jsonify({msg_error: |
| 316 |
|
error_list}), 409 |
| 317 |
|
|
| 318 |
|
@rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
| 319 |
|
@rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |
| 320 |
|
def disable_interface(self, interface_disable_id=None, dpid=None): |
| 321 |
|
"""Administratively disable interfaces in the topology.""" |
| 322 |
|
error_list = [] # List of interfaces that were not deactivated. |
| 323 |
|
msg_error = "Some interfaces couldn't be found and deactivated: " |
| 324 |
|
if dpid is None: |
| 325 |
|
dpid = ":".join(interface_disable_id.split(":")[:-1]) |
| 326 |
|
try: |
| 327 |
|
switch = self.controller.switches[dpid] |
| 328 |
|
except KeyError as exc: |
| 329 |
|
return jsonify(f"Switch not found: {exc}"), 404 |
| 330 |
|
|
| 331 |
|
if interface_disable_id: |
| 332 |
|
interface_number = int(interface_disable_id.split(":")[-1]) |
| 333 |
|
|
| 334 |
|
try: |
| 335 |
|
switch.interfaces[interface_number].disable() |
| 336 |
|
except KeyError as exc: |
| 337 |
|
error_list.append(f"Switch {dpid} Interface {exc}") |
| 338 |
|
else: |
| 339 |
|
for interface in switch.interfaces.values(): |
| 340 |
|
interface.disable() |
| 341 |
|
if not error_list: |
| 342 |
|
log.info(f"Storing administrative state for disabled interfaces.") |
| 343 |
|
self.save_status_on_storehouse() |
| 344 |
|
return jsonify("Operation successful"), 200 |
| 345 |
|
return jsonify({msg_error: |
| 346 |
|
error_list}), 409 |
| 347 |
|
|
| 348 |
|
@rest('v3/interfaces/<interface_id>/metadata') |
| 349 |
|
def get_interface_metadata(self, interface_id): |
|
@@ 288-316 (lines=29) @@
|
| 285 |
|
|
| 286 |
|
return jsonify({'interfaces': interfaces}) |
| 287 |
|
|
| 288 |
|
@rest('v3/interfaces/switch/<dpid>/enable', methods=['POST']) |
| 289 |
|
@rest('v3/interfaces/<interface_enable_id>/enable', methods=['POST']) |
| 290 |
|
def enable_interface(self, interface_enable_id=None, dpid=None): |
| 291 |
|
"""Administratively enable interfaces in the topology.""" |
| 292 |
|
error_list = [] # List of interfaces that were not activated. |
| 293 |
|
msg_error = "Some interfaces couldn't be found and activated: " |
| 294 |
|
if dpid is None: |
| 295 |
|
dpid = ":".join(interface_enable_id.split(":")[:-1]) |
| 296 |
|
try: |
| 297 |
|
switch = self.controller.switches[dpid] |
| 298 |
|
except KeyError as exc: |
| 299 |
|
return jsonify(f"Switch not found: {exc}"), 404 |
| 300 |
|
|
| 301 |
|
if interface_enable_id: |
| 302 |
|
interface_number = int(interface_enable_id.split(":")[-1]) |
| 303 |
|
|
| 304 |
|
try: |
| 305 |
|
switch.interfaces[interface_number].enable() |
| 306 |
|
except KeyError as exc: |
| 307 |
|
error_list.append(f"Switch {dpid} Interface {exc}") |
| 308 |
|
else: |
| 309 |
|
for interface in switch.interfaces.values(): |
| 310 |
|
interface.enable() |
| 311 |
|
if not error_list: |
| 312 |
|
log.info(f"Storing administrative state for enabled interfaces.") |
| 313 |
|
self.save_status_on_storehouse() |
| 314 |
|
return jsonify("Operation successful"), 200 |
| 315 |
|
return jsonify({msg_error: |
| 316 |
|
error_list}), 409 |
| 317 |
|
|
| 318 |
|
@rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
| 319 |
|
@rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |