Просмотр исходного кода

Add schema validation for destination environment options.

Nashwan Azhari 8 лет назад
Родитель
Сommit
2ac63f363f

+ 10 - 6
coriolis/providers/base.py

@@ -86,18 +86,22 @@ class BaseEndpointDestinationOptionsProvider(
             }
         }
         The provider should return:
-        options = {
-            "migr_network": {
-                "values": ["net1", "net2", "net3"], "config_default": "net2"},
-            "security_groups": {
+        options = [
+            {
+                "name": "migr_network",
+                "values": ["net1", "net2", "net3"],
+                "config_default": "net2"},
+            {
+                "name": "security_groups",
                 "values": ["secgroup1", "secgroup2", "secgroup3"],
                 "config_default": ["secgroup2", "secgroup3"]},
-            "migr_image": {
+            {
+                "name": "migr_image",
                 "values": [
                     {"name": "testimage1", "id": 101},
                     {"name": "testimg2", "id": 4}],
                 "config_default": {"name": "testimg2", "id": 4}}}
-        }
+        ]
         Observations:
             - base types such as 'integer' or 'string' are preserved
             - 'array' types will return an array with all the options which are

+ 4 - 0
coriolis/schemas.py

@@ -25,6 +25,7 @@ _CORIOLIS_VM_INSTANCE_INFO_SCHEMA_NAME = "vm_instance_info_schema.json"
 _CORIOLIS_OS_MORPHING_RES_SCHEMA_NAME = "os_morphing_resources_schema.json"
 _CORIOLIS_VM_NETWORK_SCHEMA_NAME = "vm_network_schema.json"
 _SCHEDULE_API_BODY_SCHEMA_NAME = "replica_schedule_schema.json"
+_CORIOLIS_DESTINATION_OPTIONS_SCHEMA_NAME = "destination_options_schema.json"
 
 
 def get_schema(package_name, schema_name,
@@ -84,3 +85,6 @@ CORIOLIS_VM_NETWORK_SCHEMA = get_schema(
 
 SCHEDULE_API_BODY_SCHEMA = get_schema(
     __name__, _SCHEDULE_API_BODY_SCHEMA_NAME)
+
+CORIOLIS_DESTINATION_ENVIRONMENT = get_schema(
+    __name__, _CORIOLIS_DESTINATION_OPTIONS_SCHEMA_NAME)

+ 22 - 0
coriolis/schemas/destination_options_schema.json

@@ -0,0 +1,22 @@
+{
+  "$schema": "http://cloudbase.it/coriolis/schemas/endpoint_destination_options#",
+  "type": "array",
+  "items": {
+    "type:": "object",
+    "properties": {
+      "name": {
+        "type": "string",
+        "help": "The name of the destination environment parameter."
+      },
+      "values": {
+        "type": "array",
+        "help": "A list of possible values of the given destination environment parameter."
+      },
+      "config_default": {
+        "help": "The default value set in the Coriolis service's configuration file."
+      }
+    },
+    "required": ["name", "values"],
+    "additionalProperties": false
+  }
+}

+ 3 - 0
coriolis/worker/rpc/server.py

@@ -212,6 +212,9 @@ class WorkerServerEndpoint(object):
         options = provider.get_target_environment_options(
             ctxt, secret_connection_info, env=env, option_names=option_names)
 
+        schemas.validate_value(
+            options, schemas.CORIOLIS_DESTINATION_ENVIRONMENT)
+
         return options
 
     def get_endpoint_networks(self, ctxt, platform_name, connection_info, env):