Fix Dockerfile.local
[osm/NBI.git] / osm_nbi / validation.py
index d93feb0..43fd84d 100644 (file)
@@ -34,6 +34,7 @@ name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^
 string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
 xml_text_schema = {"type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^']+$"}
 description_schema = {"type": ["string", "null"], "maxLength": 255, "pattern": "^[^'\"]+$"}
+long_description_schema = {"type": ["string", "null"], "maxLength": 3000, "pattern": "^[^'\"]+$"}
 id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36}
 bool_schema = {"type": "boolean"}
 null_schema = {"type": "null"}
@@ -81,6 +82,11 @@ nameshort_list_schema = {
     "items": shortname_schema,
 }
 
+description_list_schema = {
+    "type": "array",
+    "minItems": 1,
+    "items": description_schema,
+}
 
 ns_instantiate_vdu = {
     "title": "ns action instantiate input schema for vdu",
@@ -285,8 +291,9 @@ ns_instantiate = {
         "nsName": name_schema,
         "nsDescription": {"oneOf": [description_schema, null_schema]},
         "nsdId": id_schema,
+        "vcaId": id_schema,
         "vimAccountId": id_schema,
-        "wimAccountId": {"OneOf": [id_schema, bool_schema, null_schema]},
+        "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
         "placement-engine": string_schema,
         "placement-constraints": object_schema,
         "additionalParamsForNs": object_schema,
@@ -305,6 +312,7 @@ ns_instantiate = {
                 "properties": {
                     "member-vnf-index": name_schema,
                     "vimAccountId": id_schema,
+                    "vcaId": id_schema,
                     "vdu": {
                         "type": "array",
                         "minItems": 1,
@@ -328,10 +336,10 @@ ns_instantiate = {
                 "type": "object",
                 "properties": {
                     "name": string_schema,
-                    "vim-network-name": {"OneOf": [string_schema, object_schema]},
-                    "vim-network-id": {"OneOf": [string_schema, object_schema]},
+                    "vim-network-name": {"oneOf": [string_schema, object_schema]},
+                    "vim-network-id": {"oneOf": [string_schema, object_schema]},
                     "ns-net": object_schema,
-                    "wimAccountId": {"OneOf": [id_schema, bool_schema, null_schema]},
+                    "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]},
                     "ip-profile": object_schema,
                     "provider-network": provider_network_schema,
                     "vnfd-connection-point-ref": {
@@ -449,6 +457,7 @@ vim_account_edit_schema = {
         "vim_tenant_name": name_schema,
         "vim_user": shortname_schema,
         "vim_password": passwd_schema,
+        "vca": id_schema,
         "config": {"type": "object"}
     },
     "additionalProperties": False
@@ -472,6 +481,7 @@ vim_account_new_schema = {
         "vim_tenant_name": name_schema,
         "vim_user": shortname_schema,
         "vim_password": passwd_schema,
+        "vca": id_schema,
         "config": {"type": "object"}
     },
     "required": ["name", "vim_url", "vim_type", "vim_user", "vim_password", "vim_tenant_name"],
@@ -608,6 +618,7 @@ k8scluster_new_schema = {
         "description": description_schema,
         "credentials": object_schema,
         "vim_account": id_schema,
+        "vca_id": id_schema,
         "k8s_version": string_schema,
         "nets": k8scluster_nets_schema,
         "namespace": name_schema,
@@ -625,6 +636,7 @@ k8scluster_edit_schema = {
         "description": description_schema,
         "credentials": object_schema,
         "vim_account": id_schema,
+        "vca_id": id_schema,
         "k8s_version": string_schema,
         "nets": k8scluster_nets_schema,
         "namespace": name_schema,
@@ -633,6 +645,60 @@ k8scluster_edit_schema = {
     "additionalProperties": False
 }
 
+# VCA
+vca_new_schema = {
+    "title": "vca creation input schema",
+    "$schema": "http://json-schema.org/draft-04/schema#",
+    "type": "object",
+    "properties": {
+        "schema_version": schema_version,
+        "schema_type": schema_type,
+        "name": name_schema,
+        "description": description_schema,
+        "endpoints": description_list_schema,
+        "user": shortname_schema,
+        "secret": passwd_schema,
+        "cacert": long_description_schema,
+        "lxd-cloud": shortname_schema,
+        "lxd-credentials": shortname_schema,
+        "k8s-cloud": shortname_schema,
+        "k8s-credentials": shortname_schema,
+        "model-config": object_schema,
+    },
+    "required": [
+        "name",
+        "endpoints",
+        "user",
+        "secret",
+        "cacert",
+        "lxd-cloud",
+        "lxd-credentials",
+        "k8s-cloud",
+        "k8s-credentials",
+    ],
+    "additionalProperties": False,
+}
+vca_edit_schema = {
+    "title": "vca creation input schema",
+    "$schema": "http://json-schema.org/draft-04/schema#",
+    "type": "object",
+    "properties": {
+        "name": name_schema,
+        "description": description_schema,
+        "endpoints": description_list_schema,
+        "port": integer1_schema,
+        "user": shortname_schema,
+        "secret": passwd_schema,
+        "cacert": long_description_schema,
+        "lxd-cloud": shortname_schema,
+        "lxd-credentials": shortname_schema,
+        "k8s-cloud": shortname_schema,
+        "k8s-credentials": shortname_schema,
+        "model-config": object_schema,
+    },
+    "additionalProperties": False,
+}
+
 # K8s Repos
 k8srepo_types = {"enum": ["helm-chart", "juju-bundle"]}
 k8srepo_properties = {
@@ -832,7 +898,7 @@ user_edit_schema = {
 
 # PROJECTS
 topics_with_quota = ["vnfds", "nsds", "slice_templates", "pduds", "ns_instances", "slice_instances", "vim_accounts",
-                     "wim_accounts", "sdn_controllers", "k8sclusters", "k8srepos", "osmrepos"]
+                     "wim_accounts", "sdn_controllers", "k8sclusters", "vca", "k8srepos", "osmrepos", "ns_subscriptions"]
 project_new_schema = {
     "$schema": "http://json-schema.org/draft-04/schema#",
     "title": "New project schema for administrators",
@@ -938,8 +1004,8 @@ nsi_vld_instantiate = {
     "type": "object",
     "properties": {
         "name": string_schema,
-        "vim-network-name": {"OneOf": [string_schema, object_schema]},
-        "vim-network-id": {"OneOf": [string_schema, object_schema]},
+        "vim-network-name": {"oneOf": [string_schema, object_schema]},
+        "vim-network-id": {"oneOf": [string_schema, object_schema]},
         "ip-profile": object_schema,
     },
     "required": ["name"],
@@ -984,6 +1050,129 @@ nsi_terminate = {
 
 }
 
+nsinstancesubscriptionfilter_schema = {
+    "title": "instance identifier schema",
+    "$schema": "http://json-schema.org/draft-07/schema#",
+    "type": "object",
+    "properties": {
+        "nsdIds": {"type": "array"},
+        "vnfdIds": {"type": "array"},
+        "pnfdIds": {"type": "array"},
+        "nsInstanceIds": {"type": "array"},
+        "nsInstanceNames": {"type": "array"},
+    },
+}
+
+nslcmsub_schema = {
+    "title": "nslcmsubscription input schema",
+    "$schema": "http://json-schema.org/draft-07/schema#",
+    "type": "object",
+    "properties": {
+        "nsInstanceSubscriptionFilter": nsinstancesubscriptionfilter_schema,
+        "notificationTypes": {
+            "type": "array",
+            "items": {
+                "enum": ['NsLcmOperationOccurrenceNotification', 'NsChangeNotification',
+                         'NsIdentifierCreationNotification', 'NsIdentifierDeletionNotification']
+            }
+        },
+        "operationTypes": {
+            "type": "array",
+            "items": {
+                "enum": ['INSTANTIATE', 'SCALE', 'TERMINATE', 'UPDATE', 'HEAL']
+            }
+        },
+        "operationStates": {
+            "type": "array",
+            "items": {
+                "enum": ['PROCESSING', 'COMPLETED', 'PARTIALLY_COMPLETED', 'FAILED',
+                         'FAILED_TEMP', 'ROLLING_BACK', 'ROLLED_BACK']
+            }
+        },
+        "nsComponentTypes": {
+            "type": "array",
+            "items": {
+                "enum": ['VNF', 'NS', 'PNF']
+            }
+        },
+        "lcmOpNameImpactingNsComponent": {
+            "type": "array",
+            "items": {
+                "enum": ['VNF_INSTANTIATE', 'VNF_SCALE', 'VNF_SCALE_TO_LEVEL', 'VNF_CHANGE_FLAVOUR',
+                         'VNF_TERMINATE', 'VNF_HEAL', 'VNF_OPERATE', 'VNF_CHANGE_EXT_CONN', 'VNF_MODIFY_INFO',
+                         'NS_INSTANTIATE', 'NS_SCALE', 'NS_UPDATE', 'NS_TERMINATE', 'NS_HEAL']
+            }
+        },
+        "lcmOpOccStatusImpactingNsComponent": {
+            "type": "array",
+            "items": {
+                "enum": ['START', 'COMPLETED', 'PARTIALLY_COMPLETED', 'FAILED', 'ROLLED_BACK']
+            }
+        },
+    },
+    "allOf": [
+        {
+            "if": {
+                "properties": {
+                    "notificationTypes": {
+                        "contains": {"const": "NsLcmOperationOccurrenceNotification"}
+                    }
+                },
+            },
+            "then": {
+                "anyOf": [
+                    {"required": ["operationTypes"]},
+                    {"required": ["operationStates"]},
+                ]
+            } 
+        },
+        {
+            "if": {
+                "properties": {
+                    "notificationTypes": {
+                        "contains": {"const": "NsChangeNotification"}
+                    }
+                },
+            },
+            "then": {
+                "anyOf": [
+                    {"required": ["nsComponentTypes"]},
+                    {"required": ["lcmOpNameImpactingNsComponent"]},
+                    {"required": ["lcmOpOccStatusImpactingNsComponent"]},
+                ]
+            }
+        }
+    ]
+}
+
+authentication_schema = {
+    "title": "authentication schema for subscription",
+    "$schema": "http://json-schema.org/draft-07/schema#",
+    "type": "object",
+    "properties": {
+        "authType": {"enum": ["basic"]},
+        "paramsBasic": {
+            "type": "object",
+            "properties": {
+                "userName": shortname_schema,
+                "password": passwd_schema,
+            },
+        },
+    },
+}
+
+subscription = {
+    "title": "subscription input schema",
+    "$schema": "http://json-schema.org/draft-07/schema#",
+    "type": "object",
+    "properties": {
+        "filter": nslcmsub_schema,
+        "CallbackUri": description_schema,
+        "authentication": authentication_schema
+    },
+    "required": ["CallbackUri"],
+}
+
 
 class ValidationError(Exception):
     def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):