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

Add user_scripts argument to replicas API

Daniel Vincze 5 лет назад
Родитель
Сommit
a8715c8b1d

+ 30 - 4
coriolis/api/v1/replicas.py

@@ -77,6 +77,7 @@ class ReplicaController(api_wsgi.Controller):
             'destination_minion_pool_id')
             'destination_minion_pool_id')
         instance_osmorphing_minion_pool_mappings = replica.get(
         instance_osmorphing_minion_pool_mappings = replica.get(
             'instance_osmorphing_minion_pool_mappings', {})
             'instance_osmorphing_minion_pool_mappings', {})
+        user_scripts = replica.get("user_scripts", {})
 
 
         # NOTE(aznashwan): we validate the destination environment for the
         # NOTE(aznashwan): we validate the destination environment for the
         # import provider before appending the 'storage_mappings' parameter
         # import provider before appending the 'storage_mappings' parameter
@@ -97,7 +98,7 @@ class ReplicaController(api_wsgi.Controller):
                 source_environment, destination_environment, instances,
                 source_environment, destination_environment, instances,
                 network_map, storage_mappings, notes,
                 network_map, storage_mappings, notes,
                 origin_minion_pool_id, destination_minion_pool_id,
                 origin_minion_pool_id, destination_minion_pool_id,
-                instance_osmorphing_minion_pool_mappings)
+                instance_osmorphing_minion_pool_mappings, user_scripts)
 
 
     def create(self, req, body):
     def create(self, req, body):
         context = req.environ["coriolis.context"]
         context = req.environ["coriolis.context"]
@@ -107,7 +108,7 @@ class ReplicaController(api_wsgi.Controller):
          source_environment, destination_environment, instances, network_map,
          source_environment, destination_environment, instances, network_map,
          storage_mappings, notes, origin_minion_pool_id,
          storage_mappings, notes, origin_minion_pool_id,
          destination_minion_pool_id,
          destination_minion_pool_id,
-         instance_osmorphing_minion_pool_mappings) = (
+         instance_osmorphing_minion_pool_mappings, user_scripts) = (
             self._validate_create_body(context, body))
             self._validate_create_body(context, body))
 
 
         return replica_view.single(req, self._replica_api.create(
         return replica_view.single(req, self._replica_api.create(
@@ -115,7 +116,7 @@ class ReplicaController(api_wsgi.Controller):
             origin_minion_pool_id, destination_minion_pool_id,
             origin_minion_pool_id, destination_minion_pool_id,
             instance_osmorphing_minion_pool_mappings, source_environment,
             instance_osmorphing_minion_pool_mappings, source_environment,
             destination_environment, instances, network_map,
             destination_environment, instances, network_map,
-            storage_mappings, notes))
+            storage_mappings, notes, user_scripts))
 
 
     def delete(self, req, id):
     def delete(self, req, id):
         context = req.environ["coriolis.context"]
         context = req.environ["coriolis.context"]
@@ -171,12 +172,31 @@ class ReplicaController(api_wsgi.Controller):
 
 
         return storage_mappings
         return storage_mappings
 
 
+    @staticmethod
+    def _get_updated_user_scripts(original_user_scripts, new_user_scripts):
+        global_scripts = original_user_scripts.get('global', {})
+        new_global_scripts = new_user_scripts.get('global', {})
+        if new_global_scripts:
+            global_scripts.update(new_global_scripts)
+
+        instance_scripts = original_user_scripts.get('instances', {})
+        new_instance_scripts = new_user_scripts.get('instances', {})
+        if new_instance_scripts:
+            instance_scripts.update(new_instance_scripts)
+
+        user_scripts = {
+            "global": global_scripts,
+            "instances": instance_scripts,
+        }
+
+        return user_scripts
+
     def _get_merged_replica_values(self, replica, updated_values):
     def _get_merged_replica_values(self, replica, updated_values):
         """ Looks for the following keys in the original replica body and
         """ Looks for the following keys in the original replica body and
         updated values (preferring the updated values where needed, but using
         updated values (preferring the updated values where needed, but using
         `.update()` on dicts):
         `.update()` on dicts):
         "source_environment", "destination_environment", "network_map", "notes"
         "source_environment", "destination_environment", "network_map", "notes"
-        Does special merging for the "storage_mappings"
+        Does special merging for the "storage_mappings" and "user_scripts"
         Returns a dict with the merged values (or at least all if the keys
         Returns a dict with the merged values (or at least all if the keys
         having a default value of {})
         having a default value of {})
         """
         """
@@ -207,6 +227,10 @@ class ReplicaController(api_wsgi.Controller):
         final_values['storage_mappings'] = self._update_storage_mappings(
         final_values['storage_mappings'] = self._update_storage_mappings(
             original_storage_mappings, new_storage_mappings)
             original_storage_mappings, new_storage_mappings)
 
 
+        final_values['user_scripts'] = self._get_updated_user_scripts(
+            replica.get('user_scripts', {}),
+            updated_values.get('user_scripts', {}))
+
         if 'notes' in updated_values:
         if 'notes' in updated_values:
             final_values['notes'] = updated_values.get('notes', '')
             final_values['notes'] = updated_values.get('notes', '')
         else:
         else:
@@ -276,6 +300,8 @@ class ReplicaController(api_wsgi.Controller):
         api_utils.validate_storage_mappings(
         api_utils.validate_storage_mappings(
             merged_body["storage_mappings"])
             merged_body["storage_mappings"])
 
 
+        api_utils.validate_user_scripts(merged_body["user_scripts"])
+
         return merged_body
         return merged_body
 
 
     def update(self, req, id, body):
     def update(self, req, id, body):

+ 3 - 2
coriolis/conductor/rpc/client.py

@@ -161,7 +161,7 @@ class ConductorClient(rpc.BaseRPCClient):
                                  instance_osmorphing_minion_pool_mappings,
                                  instance_osmorphing_minion_pool_mappings,
                                  source_environment, destination_environment,
                                  source_environment, destination_environment,
                                  instances, network_map, storage_mappings,
                                  instances, network_map, storage_mappings,
-                                 notes=None):
+                                 notes=None, user_scripts=None):
         return self._call(
         return self._call(
             ctxt, 'create_instances_replica',
             ctxt, 'create_instances_replica',
             origin_endpoint_id=origin_endpoint_id,
             origin_endpoint_id=origin_endpoint_id,
@@ -175,7 +175,8 @@ class ConductorClient(rpc.BaseRPCClient):
             notes=notes,
             notes=notes,
             network_map=network_map,
             network_map=network_map,
             storage_mappings=storage_mappings,
             storage_mappings=storage_mappings,
-            source_environment=source_environment)
+            source_environment=source_environment,
+            user_scripts=user_scripts)
 
 
     def get_replicas(self, ctxt, include_tasks_executions=False):
     def get_replicas(self, ctxt, include_tasks_executions=False):
         return self._call(
         return self._call(

+ 5 - 1
coriolis/conductor/rpc/server.py

@@ -1397,7 +1397,8 @@ class ConductorServerEndpoint(object):
                                  instance_osmorphing_minion_pool_mappings,
                                  instance_osmorphing_minion_pool_mappings,
                                  source_environment,
                                  source_environment,
                                  destination_environment, instances,
                                  destination_environment, instances,
-                                 network_map, storage_mappings, notes=None):
+                                 network_map, storage_mappings, notes=None,
+                                 user_scripts=None):
         origin_endpoint = self.get_endpoint(ctxt, origin_endpoint_id)
         origin_endpoint = self.get_endpoint(ctxt, origin_endpoint_id)
         destination_endpoint = self.get_endpoint(ctxt, destination_endpoint_id)
         destination_endpoint = self.get_endpoint(ctxt, destination_endpoint_id)
         self._check_endpoints(ctxt, origin_endpoint, destination_endpoint)
         self._check_endpoints(ctxt, origin_endpoint, destination_endpoint)
@@ -1421,6 +1422,7 @@ class ConductorServerEndpoint(object):
         replica.storage_mappings = storage_mappings
         replica.storage_mappings = storage_mappings
         replica.instance_osmorphing_minion_pool_mappings = (
         replica.instance_osmorphing_minion_pool_mappings = (
             instance_osmorphing_minion_pool_mappings)
             instance_osmorphing_minion_pool_mappings)
+        replica.user_scripts = user_scripts
 
 
         self._check_minion_pools_for_action(ctxt, replica)
         self._check_minion_pools_for_action(ctxt, replica)
 
 
@@ -3848,6 +3850,8 @@ class ConductorServerEndpoint(object):
 
 
         self._check_replica_running_executions(ctxt, replica)
         self._check_replica_running_executions(ctxt, replica)
         self._check_valid_replica_tasks_execution(replica, force=True)
         self._check_valid_replica_tasks_execution(replica, force=True)
+        if updated_properties.get('user_scripts'):
+            replica.user_scripts = updated_properties['user_scripts']
         execution = models.TasksExecution()
         execution = models.TasksExecution()
         execution.id = str(uuid.uuid4())
         execution.id = str(uuid.uuid4())
         execution.status = constants.EXECUTION_STATUS_UNEXECUTED
         execution.status = constants.EXECUTION_STATUS_UNEXECUTED

+ 2 - 2
coriolis/replicas/api.py

@@ -12,13 +12,13 @@ class API(object):
                origin_minion_pool_id, destination_minion_pool_id,
                origin_minion_pool_id, destination_minion_pool_id,
                instance_osmorphing_minion_pool_mappings,
                instance_osmorphing_minion_pool_mappings,
                source_environment, destination_environment, instances,
                source_environment, destination_environment, instances,
-               network_map, storage_mappings, notes=None):
+               network_map, storage_mappings, notes=None, user_scripts=None):
         return self._rpc_client.create_instances_replica(
         return self._rpc_client.create_instances_replica(
             ctxt, origin_endpoint_id, destination_endpoint_id,
             ctxt, origin_endpoint_id, destination_endpoint_id,
             origin_minion_pool_id, destination_minion_pool_id,
             origin_minion_pool_id, destination_minion_pool_id,
             instance_osmorphing_minion_pool_mappings,
             instance_osmorphing_minion_pool_mappings,
             source_environment, destination_environment, instances,
             source_environment, destination_environment, instances,
-            network_map, storage_mappings, notes)
+            network_map, storage_mappings, notes, user_scripts)
 
 
     def update(self, ctxt, replica_id, updated_properties):
     def update(self, ctxt, replica_id, updated_properties):
         return self._rpc_client.update_replica(
         return self._rpc_client.update_replica(