projects
/
osm
/
RO.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Removing Fog05 VIM RO Plugin
[osm/RO.git]
/
NG-RO
/
osm_ng_ro
/
validation.py
diff --git
a/NG-RO/osm_ng_ro/validation.py
b/NG-RO/osm_ng_ro/validation.py
index
060a3eb
..
efd940c
100644
(file)
--- a/
NG-RO/osm_ng_ro/validation.py
+++ b/
NG-RO/osm_ng_ro/validation.py
@@
-25,32
+25,64
@@
Validator of input data using JSON schemas
"""
# Basis schemas
"""
# Basis schemas
-name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"}
+name_schema = {
+ "type": "string",
+ "minLength": 1,
+ "maxLength": 255,
+ "pattern": "^[^,;()'\"]+$",
+}
string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
ssh_key_schema = {"type": "string", "minLength": 1}
string_schema = {"type": "string", "minLength": 1, "maxLength": 255}
ssh_key_schema = {"type": "string", "minLength": 1}
-id_schema = {"type": "string", "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"}
+id_schema = {
+ "type": "string",
+ "pattern": "^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$",
+}
bool_schema = {"type": "boolean"}
null_schema = {"type": "null"}
bool_schema = {"type": "boolean"}
null_schema = {"type": "null"}
+object_schema = {"type": "object"}
-
image
_schema = {
- "title": "
image input validation
",
+
deploy_item
_schema = {
+ "title": "
deploy item validation. Each vld, vdu, flavor, image, ...
",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
- # TODO
+ "properties": {
+ "id": string_schema,
+ "vim_info": object_schema,
+ "common_id": string_schema,
+ },
+ "additionalProperties": True,
+}
+
+deploy_item_list = {
+ "type": "array",
+ "items": deploy_item_schema,
}
}
-
flavor
_schema = {
- "title": "
image input
validation",
+
deploy_vnf
_schema = {
+ "title": "
deploy.vnf.item
validation",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
- # TODO
+ "properties": {
+ "_id": id_schema,
+ "vdur": deploy_item_list,
+ "vld": deploy_item_list,
+ },
+ "additionalProperties": True,
+ "required": ["_id"],
}
}
-
ns
_schema = {
- "title": "
image input
validation",
+
deploy_action
_schema = {
+ "title": "
deploy.action
validation",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
- # TODO
+ "properties": {
+ "action": {"enum": ["inject_ssh_key"]},
+ "key": ssh_key_schema,
+ "user": string_schema,
+ "password": string_schema,
+ },
+ "additionalProperties": False,
+ "required": ["action"],
}
deploy_schema = {
}
deploy_schema = {
@@
-59,35
+91,23
@@
deploy_schema = {
"type": "object",
"properties": {
"action_id": string_schema,
"type": "object",
"properties": {
"action_id": string_schema,
- "name": name_schema,
- "action": {"enum" ["inject_ssh_key"]},
- "key": ssh_key_schema,
- "user": name_schema,
- "password": string_schema,
+ "cloud_init_content": object_schema,
+ "name": string_schema,
+ "action": deploy_action_schema,
"vnf": {
"vnf": {
+ "type": "array",
+ "items": deploy_vnf_schema,
+ },
+ "image": deploy_item_list,
+ "flavor": deploy_item_list,
+ "ns": {
"type": "object",
"properties": {
"type": "object",
"properties": {
- "_id": id_schema,
- # TODO
+ "vld": deploy_item_list,
},
},
- "required": ["_id"],
- "additionalProperties": True,
- },
- "image": {
- "type": "array",
- "minItems": 1,
- "items": image_schema
},
},
- "flavor": {
- "type": "array",
- "minItems": 1,
- "items": flavor_schema
- },
- "ns": ns_schema,
},
},
-
- "required": ["name"],
- "additionalProperties": False
+ "additionalProperties": False,
}
}
@@
-107,12
+127,17
@@
def validate_input(indata, schema_to_use):
try:
if schema_to_use:
js_v(indata, schema_to_use)
try:
if schema_to_use:
js_v(indata, schema_to_use)
+
return None
except js_e.ValidationError as e:
if e.path:
error_pos = "at '" + ":".join(map(str, e.path)) + "'"
else:
error_pos = ""
return None
except js_e.ValidationError as e:
if e.path:
error_pos = "at '" + ":".join(map(str, e.path)) + "'"
else:
error_pos = ""
+
raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
except js_e.SchemaError:
raise ValidationError("Format error {} '{}' ".format(error_pos, e.message))
except js_e.SchemaError:
- raise ValidationError("Bad json schema {}".format(schema_to_use), http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
+ raise ValidationError(
+ "Bad json schema {}".format(schema_to_use),
+ http_code=HTTPStatus.INTERNAL_SERVER_ERROR,
+ )