Browse Source

Add 'BaseEndpointSourceOptionsProvider' provider class.

Nashwan Azhari 7 years ago
parent
commit
8faf59bf24
3 changed files with 64 additions and 1 deletions
  1. 1 0
      coriolis/constants.py
  2. 60 0
      coriolis/providers/base.py
  3. 3 1
      coriolis/providers/factory.py

+ 1 - 0
coriolis/constants.py

@@ -68,6 +68,7 @@ PROVIDER_TYPE_VALIDATE_MIGRATION_IMPORT = 8192
 PROVIDER_TYPE_VALIDATE_REPLICA_IMPORT = 16384
 PROVIDER_TYPE_ENDPOINT_STORAGE = 32768
 PROVIDER_TYPE_REPLICA_UPDATE = 65536
+PROVIDER_TYPE_SOURCE_ENDPOINT_OPTIONS = 131072
 
 DISK_FORMAT_VMDK = 'vmdk'
 DISK_FORMAT_RAW = 'raw'

+ 60 - 0
coriolis/providers/base.py

@@ -126,6 +126,66 @@ class BaseEndpointDestinationOptionsProvider(
         pass
 
 
+class BaseEndpointSourceOptionsProvider(
+        object, with_metaclass(abc.ABCMeta)):
+    @abc.abstractmethod
+    def get_source_environment_options(
+            self, ctxt, connection_info, env=None, option_names=None):
+        """ Returns all possible values for the source environment options, as
+        well as any settings the options might have in the configuration files.
+
+        param env: dict: optional target environment options
+        param option_names: list(str): optional list of parameter names to show
+        values for
+
+        Example returned values for the following options:
+        schema = {
+            "properties": {
+                "migr_network": {
+                    "type": "string"
+                },
+                "security_groups": {
+                    "type": "array",
+                    "items": { "type": "string" }
+                },
+                "migr_image": {
+                    "type": "object",
+                    "properties": {
+                        "id": { "type": "string" },
+                        "name": { "type": "integer" }
+                    }
+                }
+            }
+        }
+        The provider should return:
+        options = [
+            {
+                "name": "migr_network",
+                "values": ["net1", "net2", "net3"],
+                "config_default": "net2"},
+            {
+                "name": "security_groups",
+                "values": ["secgroup1", "secgroup2", "secgroup3"],
+                "config_default": ["secgroup2", "secgroup3"]},
+            {
+                "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
+              settable through that paramter (any, all or none may be set)
+            - for fields where both a name or ID may be returned, returning the
+              name will be preferred. The provider must ensure that, if there
+              are objects with the same name, the IDs of those objects are
+              offered as an option instead of two identical names.
+        """
+        pass
+
+
 class BaseInstanceProvider(BaseProvider):
 
     def get_os_morphing_tools(self, conn, osmorphing_info):

+ 3 - 1
coriolis/providers/factory.py

@@ -43,7 +43,9 @@ PROVIDER_TYPE_MAP = {
     constants.PROVIDER_TYPE_VALIDATE_REPLICA_IMPORT: (
         base.BaseReplicaImportValidationProvider),
     constants.PROVIDER_TYPE_REPLICA_UPDATE: (
-        base.BaseReplicaUpdateableProvider)
+        base.BaseReplicaUpdateableProvider),
+    constants.PROVIDER_TYPE_SOURCE_ENDPOINT_OPTIONS: (
+        base.BaseEndpointSourceOptionsProvider)
 }