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

Add ability to force-deallocate/tear down minion pools.

Nashwan Azhari 5 лет назад
Родитель
Сommit
c91370f1be

+ 5 - 2
coriolis/api/v1/minion_pool_actions.py

@@ -36,10 +36,12 @@ class MinionPoolActionsController(api_wsgi.Controller):
         context.can(
             minion_pool_policies.get_minion_pools_policy_label(
                 "tear_down_shared_resources"))
+        force = (body["tear-down-shared-resources"] or {}).get(
+            "force", False)
         try:
             return minion_pool_tasks_execution_view.single(
                 req, self.minion_pool_api.tear_down_shared_pool_resources(
-                    context, id))
+                    context, id, force=force))
         except exception.NotFound as ex:
             raise exc.HTTPNotFound(explanation=ex.msg)
         except exception.InvalidParameterValue as ex:
@@ -66,10 +68,11 @@ class MinionPoolActionsController(api_wsgi.Controller):
         context.can(
             minion_pool_policies.get_minion_pools_policy_label(
                 "deallocate_machines"))
+        force = (body["deallocate-machines"] or {}).get("force", False)
         try:
             return minion_pool_tasks_execution_view.single(
                 req, self.minion_pool_api.deallocate_machines(
-                    context, id))
+                    context, id, force=force))
         except exception.NotFound as ex:
             raise exc.HTTPNotFound(explanation=ex.msg)
         except exception.InvalidParameterValue as ex:

+ 7 - 4
coriolis/conductor/rpc/client.py

@@ -410,20 +410,23 @@ class ConductorClient(object):
             ctxt, "set_up_shared_minion_pool_resources",
             minion_pool_id=minion_pool_id)
 
-    def tear_down_shared_minion_pool_resources(self, ctxt, minion_pool_id):
+    def tear_down_shared_minion_pool_resources(
+            self, ctxt, minion_pool_id, force=False):
         return self._client.call(
             ctxt, "tear_down_shared_minion_pool_resources",
-            minion_pool_id=minion_pool_id)
+            minion_pool_id=minion_pool_id, force=force)
 
     def allocate_minion_pool_machines(self, ctxt, minion_pool_id):
         return self._client.call(
             ctxt, "allocate_minion_pool_machines",
             minion_pool_id=minion_pool_id)
 
-    def deallocate_minion_pool_machines(self, ctxt, minion_pool_id):
+    def deallocate_minion_pool_machines(
+            self, ctxt, minion_pool_id, force=False):
         return self._client.call(
             ctxt, "deallocate_minion_pool_machines",
-            minion_pool_id=minion_pool_id)
+            minion_pool_id=minion_pool_id,
+            force=force)
 
     def get_minion_pools(self, ctxt):
         return self._client.call(ctxt, 'get_minion_pools')

+ 19 - 11
coriolis/conductor/rpc/server.py

@@ -1931,7 +1931,7 @@ class ConductorServerEndpoint(object):
         LOG.debug(
             "Attempting to deallocate all minion pool machine selections "
             "for action '%s'. Afferent pools are: %s",
-            action.id, minion_pool_ids)
+            action.base_id, minion_pool_ids)
 
         with contextlib.ExitStack() as stack:
             _ = [
@@ -4029,20 +4029,25 @@ class ConductorServerEndpoint(object):
             ctxt, minion_pool_id, execution.id).to_dict()
 
     @minion_pool_synchronized
-    def tear_down_shared_minion_pool_resources(self, ctxt, minion_pool_id):
-        LOG.info(
-            "Attempting to tear down shared resources for Minion Pool '%s'.",
-            minion_pool_id)
+    def tear_down_shared_minion_pool_resources(
+            self, ctxt, minion_pool_id, force=False):
         minion_pool = db_api.get_minion_pool_lifecycle(
             ctxt, minion_pool_id, include_tasks_executions=False,
             include_machines=False)
-        if minion_pool.pool_status != constants.MINION_POOL_STATUS_DEALLOCATED:
+        if minion_pool.pool_status != (
+                constants.MINION_POOL_STATUS_DEALLOCATED) and not force:
             raise exception.InvalidMinionPoolState(
                 "Minion Pool '%s' cannot have shared resources torn down as it"
-                " is in '%s' state instead of the expected %s."% (
+                " is in '%s' state instead of the expected %s. "
+                "Please use the force flag if you are certain you want "
+                "to tear down the shared resources for this pool." % (
                     minion_pool_id, minion_pool.pool_status,
                     constants.MINION_POOL_STATUS_DEALLOCATED))
 
+        LOG.info(
+            "Attempting to tear down shared resources for Minion Pool '%s'.",
+            minion_pool_id)
+
         execution = models.TasksExecution()
         execution.id = str(uuid.uuid4())
         execution.action = minion_pool
@@ -4170,20 +4175,23 @@ class ConductorServerEndpoint(object):
                     allocated_machine_statuses))
 
     @minion_pool_synchronized
-    def deallocate_minion_pool_machines(self, ctxt, minion_pool_id):
+    def deallocate_minion_pool_machines(self, ctxt, minion_pool_id, force=False):
         LOG.info("Attempting to deallocate Minion Pool '%s'.", minion_pool_id)
         minion_pool = db_api.get_minion_pool_lifecycle(
             ctxt, minion_pool_id, include_tasks_executions=False,
             include_machines=True)
         if minion_pool.pool_status not in (
-                constants.MINION_POOL_STATUS_ALLOCATED):
+                constants.MINION_POOL_STATUS_ALLOCATED) and not force:
             raise exception.InvalidMinionPoolState(
                 "Minion Pool '%s' cannot be deallocated as it is in '%s' "
-                "state instead of the expected '%s'." % (
+                "state instead of the expected '%s'. Please use the "
+                "force flag if you are certain you want to deallocate "
+                "the minion pool's machines." % (
                     minion_pool_id, minion_pool.pool_status,
                     constants.MINION_POOL_STATUS_ALLOCATED))
 
-        self._check_all_pool_minion_machines_available(minion_pool)
+        if not force:
+            self._check_all_pool_minion_machines_available(minion_pool)
 
         execution = models.TasksExecution()
         execution.id = str(uuid.uuid4())

+ 5 - 4
coriolis/minion_pools/api.py

@@ -35,14 +35,15 @@ class API(object):
         return self._rpc_client.set_up_shared_minion_pool_resources(
             ctxt, minion_pool_id)
 
-    def tear_down_shared_pool_resources(self, ctxt, minion_pool_id):
+    def tear_down_shared_pool_resources(
+            self, ctxt, minion_pool_id, force=False):
         return self._rpc_client.tear_down_shared_minion_pool_resources(
-            ctxt, minion_pool_id)
+            ctxt, minion_pool_id, force=force)
 
     def allocate_machines(self, ctxt, minion_pool_id):
         return self._rpc_client.allocate_minion_pool_machines(
             ctxt, minion_pool_id)
 
-    def deallocate_machines(self, ctxt, minion_pool_id):
+    def deallocate_machines(self, ctxt, minion_pool_id, force=False):
         return self._rpc_client.deallocate_minion_pool_machines(
-            ctxt, minion_pool_id)
+            ctxt, minion_pool_id, force=force)