X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fvalidation.py;h=a17e2410e82b7e32e28ccc76eb11f4e9c4951eee;hp=c5f3ef244315545dbfb39b55957fdf60b7d4cf41;hb=HEAD;hpb=f2feafd63f9ca5f5a4aacde951cef64f2e890e6c diff --git a/osm_nbi/validation.py b/osm_nbi/validation.py index c5f3ef2..620272f 100644 --- a/osm_nbi/validation.py +++ b/osm_nbi/validation.py @@ -35,6 +35,10 @@ shortname_schema = { "pattern": "^[^,;()\\.\\$'\"]+$", } passwd_schema = {"type": "string", "minLength": 1, "maxLength": 60} +user_passwd_schema = { + "type": "string", + "pattern": "^.*(?=.{8,})((?=.*[!@#$%^&*()\\-_=+{};:,<.>]){1})(?=.*\\d)((?=.*[a-z]){1})((?=.*[A-Z]){1}).*$", +} name_schema = { "type": "string", "minLength": 1, @@ -94,6 +98,10 @@ ip_schema = { "type": "string", "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", } +ipv6_schema = { + "type": "string", + "pattern": "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))", # noqa: W605 +} ip_prefix_schema = { "type": "string", "pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}" @@ -133,6 +141,7 @@ ns_instantiate_vdu = { "type": "object", "properties": { "id": name_schema, + "vim-flavor-id": name_schema, "volume": { "type": "array", "minItems": 1, @@ -153,7 +162,7 @@ ns_instantiate_vdu = { "type": "object", "properties": { "name": name_schema, - "ip-address": ip_schema, + "ip-address": {"oneOf": [ip_schema, ipv6_schema]}, "mac-address": mac_schema, "floating-ip-required": bool_schema, }, @@ -172,7 +181,7 @@ ip_profile_dns_schema = { "items": { "type": "object", "properties": { - "address": ip_schema, + "address": {"oneOf": [ip_schema, ipv6_schema]}, }, "required": ["address"], "additionalProperties": False, @@ -190,19 +199,6 @@ ip_profile_dhcp_schema = { } ip_profile_schema = { - "title": "ip profile validation schema", - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "properties": { - "ip-version": {"enum": ["ipv4", "ipv6"]}, - "subnet-address": ip_prefix_schema, - "gateway-address": ip_schema, - "dns-server": ip_profile_dns_schema, - "dhcp-params": ip_profile_dhcp_schema, - }, -} - -ip_profile_update_schema = { "title": "ip profile validation schema", "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", @@ -242,14 +238,14 @@ provider_network_schema = { } ns_instantiate_internal_vld = { - "title": "ns action instantiate input schema for vdu", + "title": "ns action instantiate input schema for vld", "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "name": name_schema, "vim-network-name": name_schema, "vim-network-id": name_schema, - "ip-profile": ip_profile_update_schema, + "ip-profile": ip_profile_schema, "provider-network": provider_network_schema, "internal-connection-point": { "type": "array", @@ -312,6 +308,19 @@ additional_params_for_vnf = { "additionalProperties": False, }, }, + "affinity-or-anti-affinity-group": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": name_schema, + "vim-affinity-group-id": name_schema, + }, + "required": ["id"], + "minProperties": 2, + "additionalProperties": False, + }, + }, }, "required": ["member-vnf-index"], "minProperties": 2, @@ -330,7 +339,6 @@ 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]}, "placement-engine": string_schema, @@ -351,7 +359,6 @@ ns_instantiate = { "properties": { "member-vnf-index": name_schema, "vimAccountId": id_schema, - "vcaId": id_schema, "vdu": { "type": "array", "minItems": 1, @@ -379,7 +386,7 @@ ns_instantiate = { "vim-network-id": {"oneOf": [string_schema, object_schema]}, "ns-net": object_schema, "wimAccountId": {"oneOf": [id_schema, bool_schema, null_schema]}, - "ip-profile": object_schema, + "ip-profile": ip_profile_schema, "provider-network": provider_network_schema, "vnfd-connection-point-ref": { "type": "array", @@ -389,7 +396,7 @@ ns_instantiate = { "properties": { "member-vnf-index-ref": name_schema, "vnfd-connection-point-ref": name_schema, - "ip-address": ip_schema, + "ip-address": {"oneOf": [ip_schema, ipv6_schema]}, # "mac-address": mac_schema, }, "required": [ @@ -425,6 +432,62 @@ ns_terminate = { "additionalProperties": False, } +ns_update = { + "title": "ns update input schema", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "lcmOperationType": string_schema, + "nsInstanceId": id_schema, + "timeout_ns_update": integer1_schema, + "updateType": { + "enum": [ + "CHANGE_VNFPKG", + "REMOVE_VNF", + "MODIFY_VNF_INFORMATION", + "OPERATE_VNF", + ] + }, + "modifyVnfInfoData": { + "type": "object", + "properties": { + "vnfInstanceId": id_schema, + "vnfdId": id_schema, + }, + "required": ["vnfInstanceId", "vnfdId"], + }, + "removeVnfInstanceId": id_schema, + "changeVnfPackageData": { + "type": "object", + "properties": { + "vnfInstanceId": id_schema, + "vnfdId": id_schema, + }, + "required": ["vnfInstanceId", "vnfdId"], + }, + "operateVnfData": { + "type": "object", + "properties": { + "vnfInstanceId": id_schema, + "changeStateTo": name_schema, + "additionalParam": { + "type": "object", + "properties": { + "run-day1": bool_schema, + "vdu_id": name_schema, + "count-index": integer0_schema, + }, + "required": ["vdu_id", "count-index"], + "additionalProperties": False, + }, + }, + "required": ["vnfInstanceId", "changeStateTo"], + }, + }, + "required": ["updateType"], + "additionalProperties": False, +} + ns_action = { # TODO for the moment it is only contemplated the vnfd primitive execution "title": "ns action input schema", "$schema": "http://json-schema.org/draft-04/schema#", @@ -444,6 +507,7 @@ ns_action = { # TODO for the moment it is only contemplated the vnfd primitive "required": ["primitive", "primitive_params"], # TODO add member_vnf_index "additionalProperties": False, } + ns_scale = { # TODO for the moment it is only VDU-scaling "title": "ns scale input schema", "$schema": "http://json-schema.org/draft-04/schema#", @@ -478,6 +542,121 @@ ns_scale = { # TODO for the moment it is only VDU-scaling "additionalProperties": False, } +ns_migrate = { + "title": "ns migrate input schema", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "lcmOperationType": string_schema, + "nsInstanceId": id_schema, + "vnfInstanceId": id_schema, + "migrateToHost": string_schema, + "vdu": { + "type": "object", + "properties": { + "vduId": name_schema, + "vduCountIndex": integer0_schema, + }, + "required": ["vduId"], + "additionalProperties": False, + }, + }, + "required": ["vnfInstanceId"], + "additionalProperties": False, +} + +ns_heal = { + "title": "ns heal input schema", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "lcmOperationType": string_schema, + "nsInstanceId": id_schema, + "timeout_ns_heal": integer1_schema, + "healVnfData": { + "type": "array", + "items": { + "type": "object", + "properties": { + "vnfInstanceId": id_schema, + "cause": description_schema, + "additionalParams": { + "type": "object", + "properties": { + "run-day1": bool_schema, + "vdu": { + "type": "array", + "items": { + "type": "object", + "properties": { + "run-day1": bool_schema, + "vdu-id": name_schema, + "count-index": integer0_schema, + }, + "required": ["vdu-id"], + "additionalProperties": False, + }, + }, + }, + "additionalProperties": False, + }, + }, + "required": ["vnfInstanceId"], + "additionalProperties": False, + }, + }, + }, + "required": ["healVnfData"], + "additionalProperties": False, +} + +ns_verticalscale = { + "title": "vertial scale input schema", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "lcmOperationType": string_schema, + "verticalScale": string_schema, + "nsInstanceId": id_schema, + "changeVnfFlavorData": { + "type": "object", + "properties": { + "vnfInstanceId": id_schema, + "additionalParams": { + "type": "object", + "properties": { + "vduid": string_schema, + "vduCountIndex": integer0_schema, + "virtualMemory": integer1_schema, + "sizeOfStorage": integer0_schema, + "numVirtualCpu": integer1_schema, + }, + }, + }, + "required": ["vnfInstanceId", "additionalParams"], + "additionalProperties": False, + }, + }, + "required": ["lcmOperationType", "verticalScale", "nsInstanceId"], + "additionalProperties": False, +} + +nslcmop_cancel = { + "title": "Cancel nslcmop input schema", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "nsLcmOpOccId": id_schema, + "cancelMode": { + "enum": [ + "GRACEFUL", + "FORCEFUL", + ] + }, + }, + "required": ["cancelMode"], + "additionalProperties": False, +} schema_version = {"type": "string", "enum": ["1.0"]} schema_type = {"type": "string"} @@ -501,6 +680,7 @@ vim_account_edit_schema = { "vim_password": passwd_schema, "vca": id_schema, "config": {"type": "object"}, + "prometheus-config": {"type": "object"}, }, "additionalProperties": False, } @@ -525,6 +705,7 @@ vim_account_new_schema = { "vim_password": passwd_schema, "vca": id_schema, "config": {"type": "object"}, + "prometheus-config": {"type": "object"}, }, "required": [ "name", @@ -549,7 +730,7 @@ wim_account_edit_schema = { "wim": name_schema, "wim_type": wim_type, "wim_url": description_schema, - "user": shortname_schema, + "user": string_schema, "password": passwd_schema, "config": {"type": "object"}, }, @@ -568,7 +749,7 @@ wim_account_new_schema = { "wim": name_schema, "wim_type": wim_type, "wim_url": description_schema, - "user": shortname_schema, + "user": string_schema, "password": passwd_schema, "config": { "type": "object", @@ -583,7 +764,7 @@ sdn_properties = { "name": name_schema, "type": {"type": "string"}, "url": {"type": "string"}, - "user": shortname_schema, + "user": string_schema, "password": passwd_schema, "config": {"type": "object"}, "description": description_schema, @@ -646,6 +827,17 @@ sdn_external_port_schema = { } # K8s Clusters +k8scluster_deploy_method_schema = { + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Deployment methods for K8s cluster", + "type": "object", + "properties": { + "juju-bundle": {"type": "boolean"}, + "helm-chart-v3": {"type": "boolean"}, + }, + "additionalProperties": False, + "minProperties": 2, +} k8scluster_nets_schema = { "title": "k8scluster nets input schema", "$schema": "http://json-schema.org/draft-04/schema#", @@ -668,6 +860,7 @@ k8scluster_new_schema = { "vca_id": id_schema, "k8s_version": string_schema, "nets": k8scluster_nets_schema, + "deployment_methods": k8scluster_deploy_method_schema, "namespace": name_schema, "cni": nameshort_list_schema, }, @@ -703,7 +896,7 @@ vca_new_schema = { "name": name_schema, "description": description_schema, "endpoints": description_list_schema, - "user": shortname_schema, + "user": string_schema, "secret": passwd_schema, "cacert": long_description_schema, "lxd-cloud": shortname_schema, @@ -734,7 +927,7 @@ vca_edit_schema = { "description": description_schema, "endpoints": description_list_schema, "port": integer1_schema, - "user": shortname_schema, + "user": string_schema, "secret": passwd_schema, "cacert": long_description_schema, "lxd-cloud": shortname_schema, @@ -753,6 +946,10 @@ k8srepo_properties = { "description": description_schema, "type": k8srepo_types, "url": description_schema, + "cacert": long_description_schema, + "user": string_schema, + "password": passwd_schema, + "oci": bool_schema, } k8srepo_new_schema = { "title": "k8scluster creation input schema", @@ -777,7 +974,7 @@ osmrepo_properties = { "description": description_schema, "type": osmrepo_types, "url": description_schema - # "user": shortname_schema, + # "user": string_schema, # "password": passwd_schema } osmrepo_new_schema = { @@ -803,7 +1000,7 @@ pdu_interface = { "name": shortname_schema, "mgmt": bool_schema, "type": {"enum": ["overlay", "underlay"]}, - "ip-address": ip_schema, + "ip-address": {"oneOf": [ip_schema, ipv6_schema]}, # TODO, add user, password, ssh-key "mac-address": mac_schema, "vim-network-name": shortname_schema, # interface is connected to one vim network, or switch port @@ -907,9 +1104,9 @@ user_new_schema = { "title": "New user schema", "type": "object", "properties": { - "username": shortname_schema, + "username": string_schema, "domain_name": shortname_schema, - "password": passwd_schema, + "password": user_passwd_schema, "projects": nameshort_list_schema, "project_role_mappings": project_role_mappings, }, @@ -921,12 +1118,16 @@ user_edit_schema = { "title": "User edit schema for administrators", "type": "object", "properties": { - "password": passwd_schema, - "username": shortname_schema, # To allow User Name modification + "password": user_passwd_schema, + "old_password": passwd_schema, + "username": string_schema, # To allow User Name modification "projects": {"oneOf": [nameshort_list_schema, array_edition_schema]}, "project_role_mappings": project_role_mappings, "add_project_role_mappings": project_role_mappings, "remove_project_role_mappings": project_role_mappings_optional, + "system_admin_id": id_schema, + "unlock": bool_schema, + "renew": bool_schema, }, "minProperties": 1, "additionalProperties": False, @@ -1030,6 +1231,8 @@ nbi_new_input_schemas = { "ns_instantiate": ns_instantiate, "ns_action": ns_action, "ns_scale": ns_scale, + "ns_update": ns_update, + "ns_heal": ns_heal, "pdus": pdu_new_schema, } @@ -1216,7 +1419,7 @@ authentication_schema = { "paramsBasic": { "type": "object", "properties": { - "userName": shortname_schema, + "userName": string_schema, "password": passwd_schema, }, }, @@ -1235,6 +1438,77 @@ subscription = { "required": ["CallbackUri"], } +vnflcmsub_schema = { + "title": "vnflcmsubscription input schema", + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "VnfInstanceSubscriptionFilter": { + "type": "object", + "properties": { + "vnfdIds": {"type": "array"}, + "vnfInstanceIds": {"type": "array"}, + }, + }, + "notificationTypes": { + "type": "array", + "items": { + "enum": [ + "VnfIdentifierCreationNotification", + "VnfLcmOperationOccurrenceNotification", + "VnfIdentifierDeletionNotification", + ] + }, + }, + "operationTypes": { + "type": "array", + "items": { + "enum": [ + "INSTANTIATE", + "SCALE", + "SCALE_TO_LEVEL", + "CHANGE_FLAVOUR", + "TERMINATE", + "HEAL", + "OPERATE", + "CHANGE_EXT_CONN", + "MODIFY_INFO", + "CREATE_SNAPSHOT", + "REVERT_TO_SNAPSHOT", + "CHANGE_VNFPKG", + ] + }, + }, + "operationStates": { + "type": "array", + "items": { + "enum": [ + "STARTING", + "PROCESSING", + "COMPLETED", + "FAILED_TEMP", + "FAILED", + "ROLLING_BACK", + "ROLLED_BACK", + ] + }, + }, + }, + "required": ["VnfInstanceSubscriptionFilter", "notificationTypes"], +} + +vnf_subscription = { + "title": "vnf subscription input schema", + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "filter": vnflcmsub_schema, + "CallbackUri": description_schema, + "authentication": authentication_schema, + }, + "required": ["filter", "CallbackUri"], +} + class ValidationError(Exception): def __init__(self, message, http_code=HTTPStatus.UNPROCESSABLE_ENTITY):