@@ 423-443 (lines=21) @@ | ||
420 | self.notify_metadata_changes(interface, 'added') |
|
421 | return jsonify("Operation successful"), 201 |
|
422 | ||
423 | @rest('v3/interfaces/<interface_id>/metadata/<key>', methods=['DELETE']) |
|
424 | def delete_interface_metadata(self, interface_id, key): |
|
425 | """Delete metadata from an interface.""" |
|
426 | switch_id = ":".join(interface_id.split(":")[:-1]) |
|
427 | interface_number = int(interface_id.split(":")[-1]) |
|
428 | ||
429 | try: |
|
430 | switch = self.controller.switches[switch_id] |
|
431 | except KeyError: |
|
432 | return jsonify("Switch not found"), 404 |
|
433 | ||
434 | try: |
|
435 | interface = switch.interfaces[interface_number] |
|
436 | except KeyError: |
|
437 | return jsonify("Interface not found"), 404 |
|
438 | ||
439 | if interface.remove_metadata(key) is False: |
|
440 | return jsonify("Metadata not found"), 404 |
|
441 | ||
442 | self.notify_metadata_changes(interface, 'removed') |
|
443 | return jsonify("Operation successful"), 200 |
|
444 | ||
445 | # Link related methods |
|
446 | @rest('v3/links') |
|
@@ 403-421 (lines=19) @@ | ||
400 | ||
401 | return jsonify({"metadata": interface.metadata}), 200 |
|
402 | ||
403 | @rest('v3/interfaces/<interface_id>/metadata', methods=['POST']) |
|
404 | def add_interface_metadata(self, interface_id): |
|
405 | """Add metadata to an interface.""" |
|
406 | metadata = self._get_metadata() |
|
407 | switch_id = ":".join(interface_id.split(":")[:-1]) |
|
408 | interface_number = int(interface_id.split(":")[-1]) |
|
409 | try: |
|
410 | switch = self.controller.switches[switch_id] |
|
411 | except KeyError: |
|
412 | return jsonify("Switch not found"), 404 |
|
413 | ||
414 | try: |
|
415 | interface = switch.interfaces[interface_number] |
|
416 | except KeyError: |
|
417 | return jsonify("Interface not found"), 404 |
|
418 | ||
419 | interface.extend_metadata(metadata) |
|
420 | self.notify_metadata_changes(interface, 'added') |
|
421 | return jsonify("Operation successful"), 201 |
|
422 | ||
423 | @rest('v3/interfaces/<interface_id>/metadata/<key>', methods=['DELETE']) |
|
424 | def delete_interface_metadata(self, interface_id, key): |