|
@@ 300-328 (lines=29) @@
|
| 297 |
|
return jsonify({msg_error: |
| 298 |
|
error_list}), 409 |
| 299 |
|
|
| 300 |
|
@rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
| 301 |
|
@rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |
| 302 |
|
def disable_interface(self, interface_disable_id=None, dpid=None): |
| 303 |
|
"""Administratively disable interfaces in the topology.""" |
| 304 |
|
error_list = [] # List of interfaces that were not deactivated. |
| 305 |
|
msg_error = "Some interfaces couldn't be found and deactivated: " |
| 306 |
|
if dpid is None: |
| 307 |
|
dpid = ":".join(interface_disable_id.split(":")[:-1]) |
| 308 |
|
try: |
| 309 |
|
switch = self.controller.switches[dpid] |
| 310 |
|
except KeyError as exc: |
| 311 |
|
return jsonify(f"Switch not found: {exc}"), 404 |
| 312 |
|
|
| 313 |
|
if interface_disable_id: |
| 314 |
|
interface_number = int(interface_disable_id.split(":")[-1]) |
| 315 |
|
|
| 316 |
|
try: |
| 317 |
|
switch.interfaces[interface_number].disable() |
| 318 |
|
except KeyError as exc: |
| 319 |
|
error_list.append(f"Switch {dpid} Interface {exc}") |
| 320 |
|
else: |
| 321 |
|
for interface in switch.interfaces.values(): |
| 322 |
|
interface.disable() |
| 323 |
|
if not error_list: |
| 324 |
|
log.info(f"Storing administrative state for disabled interfaces.") |
| 325 |
|
self.save_status_on_storehouse() |
| 326 |
|
return jsonify("Operation successful"), 200 |
| 327 |
|
return jsonify({msg_error: |
| 328 |
|
error_list}), 409 |
| 329 |
|
|
| 330 |
|
@rest('v3/interfaces/<interface_id>/metadata') |
| 331 |
|
def get_interface_metadata(self, interface_id): |
|
@@ 270-298 (lines=29) @@
|
| 267 |
|
|
| 268 |
|
return jsonify({'interfaces': interfaces}) |
| 269 |
|
|
| 270 |
|
@rest('v3/interfaces/switch/<dpid>/enable', methods=['POST']) |
| 271 |
|
@rest('v3/interfaces/<interface_enable_id>/enable', methods=['POST']) |
| 272 |
|
def enable_interface(self, interface_enable_id=None, dpid=None): |
| 273 |
|
"""Administratively enable interfaces in the topology.""" |
| 274 |
|
error_list = [] # List of interfaces that were not activated. |
| 275 |
|
msg_error = "Some interfaces couldn't be found and activated: " |
| 276 |
|
if dpid is None: |
| 277 |
|
dpid = ":".join(interface_enable_id.split(":")[:-1]) |
| 278 |
|
try: |
| 279 |
|
switch = self.controller.switches[dpid] |
| 280 |
|
except KeyError as exc: |
| 281 |
|
return jsonify(f"Switch not found: {exc}"), 404 |
| 282 |
|
|
| 283 |
|
if interface_enable_id: |
| 284 |
|
interface_number = int(interface_enable_id.split(":")[-1]) |
| 285 |
|
|
| 286 |
|
try: |
| 287 |
|
switch.interfaces[interface_number].enable() |
| 288 |
|
except KeyError as exc: |
| 289 |
|
error_list.append(f"Switch {dpid} Interface {exc}") |
| 290 |
|
else: |
| 291 |
|
for interface in switch.interfaces.values(): |
| 292 |
|
interface.enable() |
| 293 |
|
if not error_list: |
| 294 |
|
log.info(f"Storing administrative state for enabled interfaces.") |
| 295 |
|
self.save_status_on_storehouse() |
| 296 |
|
return jsonify("Operation successful"), 200 |
| 297 |
|
return jsonify({msg_error: |
| 298 |
|
error_list}), 409 |
| 299 |
|
|
| 300 |
|
@rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
| 301 |
|
@rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |