@@ 459-479 (lines=21) @@ | ||
456 | self.notify_metadata_changes(interface, 'added') |
|
457 | return jsonify("Operation successful"), 201 |
|
458 | ||
459 | @rest('v3/interfaces/<interface_id>/metadata/<key>', methods=['DELETE']) |
|
460 | def delete_interface_metadata(self, interface_id, key): |
|
461 | """Delete metadata from an interface.""" |
|
462 | switch_id = ":".join(interface_id.split(":")[:-1]) |
|
463 | interface_number = int(interface_id.split(":")[-1]) |
|
464 | ||
465 | try: |
|
466 | switch = self.controller.switches[switch_id] |
|
467 | except KeyError: |
|
468 | return jsonify("Switch not found"), 404 |
|
469 | ||
470 | try: |
|
471 | interface = switch.interfaces[interface_number] |
|
472 | except KeyError: |
|
473 | return jsonify("Interface not found"), 404 |
|
474 | ||
475 | if interface.remove_metadata(key) is False: |
|
476 | return jsonify("Metadata not found"), 404 |
|
477 | ||
478 | self.notify_metadata_changes(interface, 'removed') |
|
479 | return jsonify("Operation successful"), 200 |
|
480 | ||
481 | # Link related methods |
|
482 | @rest('v3/links') |
|
@@ 439-457 (lines=19) @@ | ||
436 | ||
437 | return jsonify({"metadata": interface.metadata}), 200 |
|
438 | ||
439 | @rest('v3/interfaces/<interface_id>/metadata', methods=['POST']) |
|
440 | def add_interface_metadata(self, interface_id): |
|
441 | """Add metadata to an interface.""" |
|
442 | metadata = self._get_metadata() |
|
443 | switch_id = ":".join(interface_id.split(":")[:-1]) |
|
444 | interface_number = int(interface_id.split(":")[-1]) |
|
445 | try: |
|
446 | switch = self.controller.switches[switch_id] |
|
447 | except KeyError: |
|
448 | return jsonify("Switch not found"), 404 |
|
449 | ||
450 | try: |
|
451 | interface = switch.interfaces[interface_number] |
|
452 | except KeyError: |
|
453 | return jsonify("Interface not found"), 404 |
|
454 | ||
455 | interface.extend_metadata(metadata) |
|
456 | self.notify_metadata_changes(interface, 'added') |
|
457 | return jsonify("Operation successful"), 201 |
|
458 | ||
459 | @rest('v3/interfaces/<interface_id>/metadata/<key>', methods=['DELETE']) |
|
460 | def delete_interface_metadata(self, interface_id, key): |