|
@@ 180-206 (lines=27) @@
|
| 177 |
|
return jsonify({msg_error: |
| 178 |
|
error_list}), 409 |
| 179 |
|
|
| 180 |
|
@rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
| 181 |
|
@rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |
| 182 |
|
def disable_interface(self, interface_disable_id=None, dpid=None): |
| 183 |
|
"""Administratively disable interfaces in the topology.""" |
| 184 |
|
error_list = [] # List of interfaces that were not deactivated. |
| 185 |
|
msg_error = "Some interfaces couldn't be found and deactivated: " |
| 186 |
|
if dpid is None: |
| 187 |
|
dpid = ":".join(interface_disable_id.split(":")[:-1]) |
| 188 |
|
try: |
| 189 |
|
switch = self.controller.switches[dpid] |
| 190 |
|
except KeyError as exc: |
| 191 |
|
return jsonify(f"Switch not found: {exc}"), 404 |
| 192 |
|
|
| 193 |
|
if interface_disable_id: |
| 194 |
|
interface_number = int(interface_disable_id.split(":")[-1]) |
| 195 |
|
|
| 196 |
|
try: |
| 197 |
|
switch.interfaces[interface_number].disable() |
| 198 |
|
except KeyError as exc: |
| 199 |
|
error_list.append(f"Switch {dpid} Interface {exc}") |
| 200 |
|
else: |
| 201 |
|
for interface in switch.interfaces.values(): |
| 202 |
|
interface.disable() |
| 203 |
|
if not error_list: |
| 204 |
|
return jsonify("Operation successful"), 200 |
| 205 |
|
return jsonify({msg_error: |
| 206 |
|
error_list}), 409 |
| 207 |
|
|
| 208 |
|
@rest('v3/interfaces/<interface_id>/metadata') |
| 209 |
|
def get_interface_metadata(self, interface_id): |
|
@@ 152-178 (lines=27) @@
|
| 149 |
|
|
| 150 |
|
return jsonify({'interfaces': interfaces}) |
| 151 |
|
|
| 152 |
|
@rest('v3/interfaces/switch/<dpid>/enable', methods=['POST']) |
| 153 |
|
@rest('v3/interfaces/<interface_enable_id>/enable', methods=['POST']) |
| 154 |
|
def enable_interface(self, interface_enable_id=None, dpid=None): |
| 155 |
|
"""Administratively enable interfaces in the topology.""" |
| 156 |
|
error_list = [] # List of interfaces that were not activated. |
| 157 |
|
msg_error = "Some interfaces couldn't be found and activated: " |
| 158 |
|
if dpid is None: |
| 159 |
|
dpid = ":".join(interface_enable_id.split(":")[:-1]) |
| 160 |
|
try: |
| 161 |
|
switch = self.controller.switches[dpid] |
| 162 |
|
except KeyError as exc: |
| 163 |
|
return jsonify(f"Switch not found: {exc}"), 404 |
| 164 |
|
|
| 165 |
|
if interface_enable_id: |
| 166 |
|
interface_number = int(interface_enable_id.split(":")[-1]) |
| 167 |
|
|
| 168 |
|
try: |
| 169 |
|
switch.interfaces[interface_number].enable() |
| 170 |
|
except KeyError as exc: |
| 171 |
|
error_list.append(f"Switch {dpid} Interface {exc}") |
| 172 |
|
else: |
| 173 |
|
for interface in switch.interfaces.values(): |
| 174 |
|
interface.enable() |
| 175 |
|
if not error_list: |
| 176 |
|
return jsonify("Operation successful"), 200 |
| 177 |
|
return jsonify({msg_error: |
| 178 |
|
error_list}), 409 |
| 179 |
|
|
| 180 |
|
@rest('v3/interfaces/switch/<dpid>/disable', methods=['POST']) |
| 181 |
|
@rest('v3/interfaces/<interface_disable_id>/disable', methods=['POST']) |