From 7adaeb0a49340e8f46e82b6526bce4d6ecefd80e Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 17 Dec 2019 16:46:12 +0000 Subject: [PATCH] Change for SDN creation parameters Change-Id: I5d0fcf0153c9ad71e0757db45df073f3abf26603 Signed-off-by: tierno --- osm_nbi/admin_topics.py | 19 +++++++++++++++++++ osm_nbi/validation.py | 11 +++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py index 670629e..7a7ace6 100644 --- a/osm_nbi/admin_topics.py +++ b/osm_nbi/admin_topics.py @@ -404,6 +404,25 @@ class SdnTopic(CommonVimWimSdn): password_to_encrypt = "password" config_to_encrypt = {} + def _obtain_url(self, input, create): + if input.get("ip") or input.get("port"): + if not input.get("ip") or not input.get("port") or input.get('url'): + raise ValidationError("You must provide both 'ip' and 'port' (deprecated); or just 'url' (prefered)") + input['url'] = "http://{}:{}/".format(input["ip"], input["port"]) + del input["ip"] + del input["port"] + elif create and not input.get('url'): + raise ValidationError("You must provide 'url'") + return input + + def _validate_input_new(self, input, force=False): + input = super()._validate_input_new(input, force) + return self._obtain_url(input, True) + + def _validate_input_edit(self, input, force=False): + input = super()._validate_input_edit(input, force) + return self._obtain_url(input, False) + class K8sClusterTopic(CommonVimWimSdn): topic = "k8sclusters" diff --git a/osm_nbi/validation.py b/osm_nbi/validation.py index 69caff7..c4f6fb7 100644 --- a/osm_nbi/validation.py +++ b/osm_nbi/validation.py @@ -480,21 +480,24 @@ wim_account_new_schema = { sdn_properties = { "name": name_schema, + "type": {"type": "string"}, + "url": {"type": "string"}, + "user": shortname_schema, + "password": passwd_schema, + "config": {"type": "object"}, "description": description_schema, + # The folowing are deprecated. Maintanied for backward compatibility "dpid": dpid_Schema, "ip": ip_schema, "port": port_schema, - "type": {"type": "string", "enum": ["opendaylight", "floodlight", "onos"]}, "version": {"type": "string", "minLength": 1, "maxLength": 12}, - "user": shortname_schema, - "password": passwd_schema } sdn_new_schema = { "title": "sdn controller information schema", "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": sdn_properties, - "required": ["name", "port", 'ip', 'dpid', 'type'], + "required": ["name", 'type'], "additionalProperties": False } sdn_edit_schema = { -- 2.25.1