Change for SDN creation parameters 19/8419/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 17 Dec 2019 16:46:12 +0000 (16:46 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 17 Dec 2019 17:23:54 +0000 (17:23 +0000)
Change-Id: I5d0fcf0153c9ad71e0757db45df073f3abf26603
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_nbi/admin_topics.py
osm_nbi/validation.py

index 670629e..7a7ace6 100644 (file)
@@ -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"
index 69caff7..c4f6fb7 100644 (file)
@@ -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 = {