From 6de4f061e34c20efc1c8e2ac865d7fb11c999647 Mon Sep 17 00:00:00 2001 From: James Slagle Date: Wed, 23 Feb 2022 09:22:35 -0500 Subject: [PATCH] Handle port unprovision for pre-provisioned nodes Previously, if all instances in the input file were pre-provisioned (managed:False), then the unprovision step was skipped, with no way to unprovision network ports for pre-provisioned nodes. This patch adds confirmation that network ports for pre-provisioned nodes will also be unprovisioned, so that the user can confirm the set of nodes and network ports that will be unprovisioned. Unprovisioning is then executed so that network ports for pre-provisioned nodes are deleted. The related tripleo-ansible patch[1] adds the needed pre-provisioned nodes data to the confirmation file so that it can be displayed by tripleoclient. [1] Id377b2c7ed973a7e2365b33dba2c1d59a59e26b9 Change-Id: Id7ebc59948cc6ad6c2270304c35ab0475259a6c0 Signed-off-by: James Slagle (cherry picked from commit 5a3b62ceb68dc995ce0fa45c76459d0ec4deea75) --- tripleoclient/v2/overcloud_node.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tripleoclient/v2/overcloud_node.py b/tripleoclient/v2/overcloud_node.py index 48c283d2b..00381fd47 100644 --- a/tripleoclient/v2/overcloud_node.py +++ b/tripleoclient/v2/overcloud_node.py @@ -408,14 +408,36 @@ class UnprovisionNode(command.Command): ) with open(unprovision_confirm) as f: to_unprovision = json.load(f) - if not to_unprovision: + + # (TODO: slagle) unprovision_confirm was previously a list, + # but was switched to a dict so that network ports for + # pre_provisioned nodes can also be confirmed for + # unprovisioning. Check the data structure for backwards + # compatibility, When the tripleo-ansible patch is merged, + # this check can be removed. + if isinstance(to_unprovision, dict): + instances = to_unprovision.get('instances') + pre_provisioned = to_unprovision.get('pre_provisioned') + else: + instances = to_unprovision + pre_provisioned = None + + print() + if not (instances or pre_provisioned): print('Nothing to unprovision, exiting') return - self._print_nodes(to_unprovision) + print("The following nodes will be unprovisioned:") + self._print_nodes(instances) + print() + if pre_provisioned: + print("The following pre-provisioned nodes will " + "have network ports unprovisioned:") + self._print_nodes(pre_provisioned) + print() confirm = oooutils.prompt_user_for_confirmation( message=_("Are you sure you want to unprovision these %s " - "nodes [y/N]? ") % parsed_args.stack, + "nodes and ports [y/N]? ") % parsed_args.stack, logger=self.log) if not confirm: raise oscexc.CommandError("Action not confirmed, exiting.")