Added LICENSE file to root folder
[osm/openvim.git] / osm_openvim / vim_schema.py
index c2dc1e2..59225ac 100644 (file)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 ##
-# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U.
 # This file is part of openvim
 # All Rights Reserved.
 #
@@ -31,33 +31,42 @@ __date__ ="$10-jul-2014 12:07:15$"
 # SCHEMAS to validate input data
 #
 
-path_schema={"type":"string", "pattern":"^(\.){0,2}(/[^/\"':{}\(\)]+)+$"}
-http_schema={"type":"string", "pattern":"^https?://[^'\"=]+$"}
-port_schema={"type":"integer","minimum":1,"maximun":65534}
-ip_schema={"type":"string","pattern":"^([0-9]{1,3}.){3}[0-9]{1,3}$"}
-cidr_schema={"type":"string","pattern":"^([0-9]{1,3}.){3}[0-9]{1,3}/[0-9]{1,2}$"}
-name_schema={"type" : "string", "minLength":1, "maxLength":255, "pattern" : "^[^,;()'\"]+$"}
-nameshort_schema={"type" : "string", "minLength":1, "maxLength":64, "pattern" : "^[^,;()'\"]+$"}
-nametiny_schema={"type" : "string", "minLength":1, "maxLength":12, "pattern" : "^[^,;()'\"]+$"}
-xml_text_schema={"type" : "string", "minLength":1, "maxLength":1000, "pattern" : "^[^']+$"}
-description_schema={"type" : ["string","null"], "maxLength":255, "pattern" : "^[^'\"]+$"}
-id_schema_fake = {"type" : "string", "minLength":2, "maxLength":36 }  #"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[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}$"}
-pci_schema={"type":"string", "pattern":"^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\.[0-9a-fA-F]$"}
-bandwidth_schema={"type":"string", "pattern" : "^[0-9]+ *([MG]bps)?$"}
-integer0_schema={"type":"integer","minimum":0}
-integer1_schema={"type":"integer","minimum":1}
-vlan_schema={"type":"integer","minimum":1,"maximun":4095}
-vlan1000_schema={"type":"integer","minimum":1000,"maximun":4095}
-mac_schema={"type":"string", "pattern":"^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"}  #must be unicast LSB bit of MSB byte ==0 
-net_bind_schema={"oneOf":[{"type":"null"},{"type":"string", "pattern":"^(default|((bridge|macvtap):[0-9a-zA-Z\.\-]{1,50})|openflow:[/0-9a-zA-Z\.\-]{1,50}(:vlan)?)$"}]}
-yes_no_schema={"type":"string", "enum":["yes", "no"]}
-log_level_schema={"type":"string", "enum":["DEBUG", "INFO", "WARNING","ERROR","CRITICAL"]}
+path_schema = {"type": "string", "maxLength": 255, "pattern": "^(\.){0,2}(/[^/\"':{}\(\)]+)+$"}
+http_schema = {"type": "string", "pattern": "^https?://[^'\"=]+$"}
+port_schema = {"type": "integer","minimum": 1, "maximun": 65534}
+ip_schema = {"type": "string", "pattern": "^([0-9]{1,3}.){3}[0-9]{1,3}$"}
+cidr_schema = {"type": "string", "pattern": "^([0-9]{1,3}.){3}[0-9]{1,3}/[0-9]{1,2}$"}
+name_schema = {"type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[^,;()'\"]+$"}
+nameshort_schema = {"type": "string", "minLength": 1, "maxLength": 64, "pattern": "^[^,;()'\"]+$"}
+nametiny_schema = {"type": "string", "minLength": 1, "maxLength": 12, "pattern": "^[^,;()'\"]+$"}
+xml_text_schema = {"type": "string", "minLength": 1, "maxLength": 1000, "pattern": "^[^']+$"}
+description_schema = {"type": ["string", "null"], "maxLength": 255, "pattern": "^[^'\"]+$"}
+id_schema_fake = {"type": "string", "minLength": 2, "maxLength": 36}
+                  # "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[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}$"}
+pci_schema = {"type": "string", "pattern": "^[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}\.[0-9a-fA-F]$"}
+# used by VIO neutron-port-show <host_moid>-<domain>:<bus>:<device>.<function>-<VF-id>
+pci_extended_schema = {"type": "string", "pattern": "^([0-9a-fA-F]{4}-)?[0-9a-fA-F]{4}(:[0-9a-fA-F]{2}){2}"
+                                                     "\.[0-9a-fA-F](-[0-9a-fA-F]{3})?$"}
+bandwidth_schema = {"type": "string", "pattern": "^[0-9]+ *([MG]bps)?$"}
+integer0_schema = {"type": "integer", "minimum": 0}
+integer1_schema = {"type": "integer", "minimum": 1}
+vlan_schema = {"type": "integer", "minimum": 1, "maximun": 4095}
+vlan1000_schema = {"type": "integer", "minimum": 1000, "maximun": 4095}
+mac_schema = {"type": "string", "pattern": "^[0-9a-fA-F][02468aceACE](:[0-9a-fA-F]{2}){5}$"}
+            # must be unicast LSB bit of MSB byte ==0
+net_bind_schema = {"oneOf": [
+    {"type": "null"},
+    {"type": "string", "pattern":
+        "^(default|((bridge|macvtap):[0-9a-zA-Z\.\-]{1,50})|openflow:[/0-9a-zA-Z\.\-]{1,50}(:vlan)?)$"}
+]}
+yes_no_schema = {"type": "string", "enum": ["yes", "no"]}
+log_level_schema = {"type": "string", "enum":["DEBUG", "INFO", "WARNING","ERROR","CRITICAL"]}
 
 config_schema = {
-    "title":"main configuration information schema",
+    "title": "main configuration information schema",
     "$schema": "http://json-schema.org/draft-04/schema#",
-    "type":"object",
+    "type": "object",
     "properties":{
         "http_port": port_schema,
         "http_admin_port": port_schema,
@@ -65,7 +74,7 @@ config_schema = {
         "http_url_prefix": path_schema, # it does not work yet; it's supposed to be the base path to be used by bottle, but it must be explicitly declared
         "db_host": nameshort_schema,
         "db_user": nameshort_schema,
-        "db_passwd": {"type":"string"},
+        "db_passwd": {"type": "string"},
         "db_name": nameshort_schema,
         "of_controller_ip": ip_schema,
         "of_controller_port": port_schema,
@@ -75,18 +84,20 @@ config_schema = {
         "of_controller_module": {"type":"string"},
         "of_user": nameshort_schema,
         "of_password": nameshort_schema,
-        "test_mode": {"type": "boolean"}, #leave for backward compatibility
+        "test_mode": {"type": "boolean"}, # leave for backward compatibility
         "mode": {"type":"string", "enum":["normal", "host only", "OF only", "development", "test"] },
         "development_bridge": {"type":"string"},
         "tenant_id": {"type" : "string"},
-        "image_path": path_schema,
+        "image_path": path_schema,      # leave for backward compatibility
+        "host_image_path": path_schema,
+        "host_ssh_keyfile": path_schema,
         "network_vlan_range_start": vlan_schema,
         "network_vlan_range_end": vlan_schema,
         "bridge_ifaces": {
             "type": "object",
             "patternProperties": {
                 "." : {
-                    "type": "array", 
+                    "type": "array",
                     "items": integer0_schema,
                     "minItems":2,
                     "maxItems":2,
@@ -97,18 +108,19 @@ config_schema = {
         "dhcp_server": {
             "type": "object",
             "properties": {
-                "host" : name_schema,
-                "port" : port_schema,
-                "provider" : {"type": "string", "enum": ["isc-dhcp-server"]},
-                "user" : nameshort_schema,
-                "password" : {"type": "string"},
-                "key" : {"type": "string"},
-                "bridge_ifaces" :{
-                    "type": "array", 
+                "host": name_schema,
+                "port": port_schema,
+                "provider": {"type": "string", "enum": ["isc-dhcp-server"]},
+                "user": nameshort_schema,
+                "password": {"type": "string"},
+                "key": path_schema,         # for backward compatibility, use keyfile instead
+                "keyfile": path_schema,
+                "bridge_ifaces": {
+                    "type": "array",
                     "items": nameshort_schema,
                 },
-                "nets" :{
-                    "type": "array", 
+                "nets"{
+                    "type": "array",
                     "items": name_schema,
                 },
             },
@@ -119,9 +131,10 @@ config_schema = {
         "log_level_of": log_level_schema,
         "network_type": {"type": "string", "enum": ["ovs", "bridge"]},
         "ovs_controller_file_path": path_schema,
+        "ovs_controller_ip": nameshort_schema,
         "ovs_controller_user": nameshort_schema,
-
-        "ovs_controller_ip": nameshort_schema
+        "ovs_controller_password": {"type": "string"},
+        "ovs_controller_keyfile": path_schema,
     },
     "patternProperties": {
         "of_*" : {"type": ["string", "integer", "boolean"]}
@@ -142,7 +155,7 @@ metadata_schema={
         "os_type": {"type":"string"},
         "os_version": {"type":"string"},
         "bus": {"type":"string"},
-        "topology": {"type":"string", "enum": ["oneSocket"]}
+        "topology": {"type":"string", "enum": ["oneSocket", "oneSocket:hyperthreading"]}
     }
 }
 
@@ -216,7 +229,8 @@ extended_schema={
                     "vpci":pci_schema,
                     "imageRef":id_schema,
                     "xml":xml_text_schema,
-                    "dev":nameshort_schema
+                    "dev":nameshort_schema,
+                    "size":integer1_schema,
                 },
                 "additionalProperties": False,
                 "required": ["type"]
@@ -249,90 +263,100 @@ extended_schema={
 host_data_schema={
     "title":"hosts manual insertion information schema",
     "type":"object", 
-    "properties":{                  
-        "ip_name":nameshort_schema,
+    "properties":{
+        "id": id_schema,
+        "admin_state_up": {"type": "boolean"},
+        "created_at": {"type": "string"},        # ignored, just for compatibility with host-list
+        "ip_name": nameshort_schema,
         "name": name_schema,
-        "description":description_schema,
-        "user":nameshort_schema,
-        "password":nameshort_schema,
-        "features":description_schema,
-        "ranking":integer0_schema,
-        "devices":{
+        "description": description_schema,
+        "user": nameshort_schema,
+        "password": nameshort_schema,
+        "keyfile": path_schema,
+        "features": description_schema,
+        "ranking": integer0_schema,
+        "autodiscover": {"type": "boolean"},    # try to discover host parameters instead of providing in this schema
+        "hypervisors": description_schema,   #Unikernels extension
+        "devices": {
             "type": "array", 
-            "items":{
+            "items": {
                 "type": "object",
-                "properties":{
-                    "type":{"type":"string", "enum":["usb","disk"]},
-                    "vpci":pci_schema
+                "properties": {
+                    "type": {"type": "string", "enum": ["usb", "disk"]},
+                    "vpci": pci_schema
                 },
                 "additionalProperties": False,
                 "required": ["type"]
             }
         },
-        "numas":{
+        "numas": {
             "type": "array",
-            "minItems":1,
-            "items":{
+            "minItems": 1,
+            "items": {
                 "type": "object",
-                "properties":{
-                    "admin_state_up":{"type":"boolean"},
-                    "hugepages":integer0_schema,
+                "properties": {
+                    "admin_state_up": {"type": "boolean"},
+                    "hugepages": integer0_schema,
+                    "hugepages_consumed": integer0_schema,  # ignored, just for compatibility with host-list
+                    "numa_socket": integer0_schema,
+                    "memory": integer1_schema,
                     "cores":{
                         "type": "array",
-                        "minItems":2,
-                        "items":{
+                        "minItems": 2,
+                        "items": {
                             "type": "object",
-                            "properties":{
-                                "core_id":integer0_schema,
-                                "thread_id":integer0_schema,
-                                "status": {"type":"string", "enum":["noteligible"]}
+                            "properties": {
+                                "core_id": integer0_schema,
+                                "thread_id": integer0_schema,
+                                "status": {"type": "string", "enum": ["noteligible"]},
+                                "instance_id": {"type": "string"},   # ignored, just for compatibility with host-list
+                                "v_thread_id": {"type": "integer"}   # ignored, just for compatibility with host-list
                             },
                             "additionalProperties": False,
-                            "required": ["core_id","thread_id"]
+                            "required": ["core_id", "thread_id"]
                         }
                     },
-                    "interfaces":{
+                    "interfaces": {
                         "type": "array",
-                        "minItems":1,
-                        "items":{
+                        "minItems": 1,
+                        "items": {
                             "type": "object",
-                            "properties":{
-                                "source_name":nameshort_schema,
-                                "mac":mac_schema,
-                                "Mbps":integer0_schema,
-                                "pci":pci_schema,
-                                "sriovs":{
+                            "properties": {
+                                "source_name": nameshort_schema,
+                                "mac": mac_schema,
+                                "Mbps": integer0_schema,
+                                "pci": pci_schema,
+                                "sriovs": {
                                     "type": "array",
                                     "minItems":1,
-                                    "items":{
+                                    "items": {
                                         "type": "object",
-                                        "properties":{
-                                            "source_name":{"oneOf":[integer0_schema, nameshort_schema]},
-                                            "mac":mac_schema,
-                                            "vlan":integer0_schema, 
-                                            "pci":pci_schema,
+                                        "properties": {
+                                            "source_name": {"oneOf": [integer0_schema, nameshort_schema]},
+                                            "mac": mac_schema,
+                                            "vlan": integer0_schema,  # ignored, just for backward compatibility
+                                            "pci": pci_schema,
                                         },
                                         "additionalProperties": False,
-                                        "required": ["source_name","mac","pci"]
+                                        "required": ["source_name", "mac", "pci"]
                                     }
                                 },
                                 "switch_port": nameshort_schema,
                                 "switch_dpid": nameshort_schema,
+                                "switch_mac": mac_schema,
                             },
                             "additionalProperties": False,
-                            "required": ["source_name","mac","Mbps","pci"]
+                            "required": ["source_name", "mac", "Mbps", "pci"]
                         }
                     },
-                    "numa_socket":integer0_schema,
-                    "memory":integer1_schema
                 },
                 "additionalProperties": False,
-                "required": ["cores","numa_socket"]
+                "required": ["cores", "numa_socket"]
             }
         }
     },
     "additionalProperties": False,
-    "required": ["ranking", "numas","ip_name","user"]
+    "required": ["name", "user", "ip_name"]
 }
 
 host_edit_schema={
@@ -388,19 +412,7 @@ host_new_schema = {
     "$schema": "http://json-schema.org/draft-04/schema#",
     "type":"object",
     "properties":{
-        "host":{
-            "type":"object",
-            "properties":{
-                "id":id_schema,
-                "ip_name":nameshort_schema,
-                "name": name_schema,
-                "description":description_schema,
-                "user":nameshort_schema,
-                "password":nameshort_schema,
-                "admin_state_up":{"type":"boolean"},
-            },
-            "required": ["name","ip_name","user"]
-        },
+        "host": host_data_schema,
         "host-data":host_data_schema
     },
     "required": ["host"],
@@ -509,6 +521,7 @@ networks_schema={
             "vpci":pci_schema,
             "uuid":id_schema,
             "mac_address": mac_schema,
+            "ip_address": ip_schema,
             "model": {"type":"string", "enum":["virtio","e1000","ne2k_pci","pcnet","rtl8139"]},
             "type": {"type":"string", "enum":["virtual","PF","VF","VFnotShared"]}
         },
@@ -532,6 +545,8 @@ server_new_schema = {
                 "hostId":id_schema,
                 "flavorRef":id_schema,
                 "imageRef":id_schema,
+                "hypervisor":{"type":"string", "enum":["kvm","xen-unik","xenhvm"]}, #Unikernels extension
+                "osImageType":{"type":"string", "enum":["clickos","other"]}, #Unikernels extension
                 "extended": extended_schema,
                 "networks":networks_schema
             },
@@ -583,29 +598,46 @@ server_action_schema = {
 }
 
 network_new_schema = {
-    "title":"network creation information schema",
+    "title": "network creation information schema",
     "$schema": "http://json-schema.org/draft-04/schema#",
-    "type":"object",
-    "properties":{
-        "network":{
-            "type":"object",
+    "type": "object",
+    "properties": {
+        "network": {
+            "type": "object",
             "properties":{
-                "id":id_schema,
-                "name":name_schema,
-                "type":{"type":"string", "enum":["bridge_man","bridge_data","data", "ptp"]},
-                "shared":{"type":"boolean"},
-                "tenant_id":id_schema,
-                "admin_state_up":{"type":"boolean"},
-                "provider:vlan":vlan_schema,
-                "provider:physical":net_bind_schema,
-                "cidr":cidr_schema,
-                "enable_dhcp": {"type":"boolean"},
+                "id": id_schema,
+                "name": name_schema,
+                "type": {"type":"string", "enum": ["bridge_man", "bridge_data", "data", "ptp"]},
+                "shared": {"type": "boolean"},
+                "tenant_id": id_schema,
+                "admin_state_up": {"type": "boolean"},
+                "provider:vlan": vlan_schema,
+                "provider:physical": net_bind_schema,
+                "region": nameshort_schema,
+                "cidr": cidr_schema,
+                "enable_dhcp": {"type": "boolean"},
                 "dhcp_first_ip": ip_schema,
                 "dhcp_last_ip": ip_schema,
-                "bind_net":name_schema, #can be name, or uuid
-                "bind_type":{"oneOf":[{"type":"null"},{"type":"string", "pattern":"^vlan:[0-9]{1,4}$"}]}
+                "dns": {"type": "array", "items": [ip_schema]},
+                "links":    {"type": "array", "items": {"type": "object", "properties": {
+                                "nat": cidr_schema,
+                                "iface": name_schema,
+                                "vlan": vlan_schema},
+                                "required": ["iface"],
+                                "additionalProperties": False
+                                },
+
+                             },
+                "routes":   {"type": "object", "properties":  {"default": ip_schema}, "patternProperties": {
+                                                            "^([0-9]{1,3}.){3}[0-9]{1,3}/[0-9]{1,2}$": ip_schema,
+                                                            },
+                                                            "additionalProperties": False
+                             },
+
+                "bind_net": name_schema,   # can be name, or uuid
+                "bind_type": {"oneOf": [{"type": "null"}, {"type": "string", "pattern": "^vlan:[0-9]{1,4}$"}]}
             },
-            "required": ["name"]
+        "required": ["name"]
         }
     },
     "required": ["network"],
@@ -746,7 +778,7 @@ of_port_new_schema = {
         "ofc_id": id_schema,
         "region": nameshort_schema,
         "compute_node": nameshort_schema,
-        "pci": pci_schema,
+        "pci": pci_extended_schema,
         "switch_dpid": nameshort_schema,
         "switch_port": nameshort_schema,
         "switch_mac": mac_schema
@@ -764,4 +796,4 @@ of_port_map_new_schema = {
     "required": ["of_port_mapings"],
     "additionalProperties": False
 
-}
\ No newline at end of file
+}