From a161e88fa78ee551d60c541ef4f7221a3bd362d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Jens=C3=A5s?= Date: Tue, 9 Mar 2021 01:38:26 +0100 Subject: [PATCH] Add commands to extract|provision net vips Add command to extract Virtual IPs information from a deployed overcloud. This writes a 'vip_data' file that should be used when managing neutron Virtual IP resources "outside" the overcloud Heat stack. Add command to provision Virtual IPs using 'vip_data' file as input. This command will output a 'vip_environment' file with the resource_registry and paramters to replace the neutron resources in the overcloud Heat stack. Depends-On: https://review.opendev.org/774857 Partial-Implements: blueprint network-data-v2-ports Change-Id: Id9b5c621c25158bb72559c3d3c52a62c840b3a6a --- setup.cfg | 2 + tripleoclient/v2/overcloud_network.py | 119 ++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/setup.cfg b/setup.cfg index 62234abd9..0de4f0cc5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -57,6 +57,8 @@ openstack.tripleoclient.v2 = overcloud_image_upload = tripleoclient.v1.overcloud_image:UploadOvercloudImage overcloud_network_extract = tripleoclient.v2.overcloud_network:OvercloudNetworkExtract overcloud_network_provision = tripleoclient.v2.overcloud_network:OvercloudNetworkProvision + overcloud_network_vip_extract = tripleoclient.v2.overcloud_network:OvercloudVirtualIPsExtract + overcloud_network_vip_provision = tripleoclient.v2.overcloud_network:OvercloudVirtualIPsProvision overcloud_node_configure = tripleoclient.v1.overcloud_node:ConfigureNode overcloud_node_delete = tripleoclient.v1.overcloud_node:DeleteNode overcloud_node_import = tripleoclient.v2.overcloud_node:ImportNode diff --git a/tripleoclient/v2/overcloud_network.py b/tripleoclient/v2/overcloud_network.py index f57df2b94..63f6edc8e 100644 --- a/tripleoclient/v2/overcloud_network.py +++ b/tripleoclient/v2/overcloud_network.py @@ -135,3 +135,122 @@ class OvercloudNetworkProvision(command.Command): verbosity=oooutils.playbook_verbosity(self=self), extra_vars=extra_vars, ) + + +class OvercloudVirtualIPsExtract(command.Command): + + log = logging.getLogger(__name__ + ".OvercloudVirtualIPsExtract") + + def get_parser(self, prog_name): + parser = super(OvercloudVirtualIPsExtract, self).get_parser(prog_name) + parser.add_argument('--stack', dest='stack', required=True, + help=_('Name of heat stack ' + '(default=Env: OVERCLOUD_STACK_NAME)'), + default=utils.env('OVERCLOUD_STACK_NAME', + default='overcloud')) + parser.add_argument('-o', '--output', required=True, + metavar='', + help=_('The output file path describing the ' + 'Virtual IP deployment')) + parser.add_argument('-y', '--yes', default=False, action='store_true', + help=_('Skip yes/no prompt for existing files ' + '(assume yes).')) + + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)" % parsed_args) + + output_path = os.path.abspath(parsed_args.output) + + overwrite = parsed_args.yes + if (os.path.exists(output_path) and not overwrite + and not oooutils.prompt_user_for_confirmation( + 'Overwrite existing file %s [y/N]?' % parsed_args.output, + self.log)): + raise oscexc.CommandError("Will not overwrite existing file:" + " %s" % parsed_args.output) + else: + overwrite = True + + extra_vars = { + "stack_name": parsed_args.stack, + "output": output_path, + "overwrite": overwrite + } + + with oooutils.TempDirs() as tmp: + oooutils.run_ansible_playbook( + playbook='cli-overcloud-network-vip-extract.yaml', + inventory='localhost,', + workdir=tmp, + playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS, + verbosity=oooutils.playbook_verbosity(self=self), + extra_vars=extra_vars, + ) + + +class OvercloudVirtualIPsProvision(command.Command): + + log = logging.getLogger(__name__ + ".OvercloudVirtualIPsProvision") + + def get_parser(self, prog_name): + parser = super(OvercloudVirtualIPsProvision, self).get_parser( + prog_name) + + parser.add_argument('vip_file', + metavar='', + help=_('Configuration file describing the network ' + 'deployment.')) + parser.add_argument('--stack', dest='stack', required=True, + help=_('Name of heat stack ' + '(default=Env: OVERCLOUD_STACK_NAME)'), + default=utils.env('OVERCLOUD_STACK_NAME', + default='overcloud')) + parser.add_argument('-o', '--output', required=True, + metavar='', + help=_('The output Virtual IP environment file ' + 'path.')) + parser.add_argument('-y', '--yes', default=False, action='store_true', + help=_('Skip yes/no prompt for existing files ' + '(assume yes).')) + + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)" % parsed_args) + + vip_file_path = os.path.abspath(parsed_args.vip_file) + output_path = os.path.abspath(parsed_args.output) + + if not os.path.exists(vip_file_path): + raise oscexc.CommandError( + "Virtual IPs configuration file does not exist:" + " %s" % parsed_args.networks_file) + + overwrite = parsed_args.yes + if (os.path.exists(output_path) and not overwrite + and not oooutils.prompt_user_for_confirmation( + 'Overwrite existing file %s [y/N]?' % parsed_args.output, + self.log)): + raise oscexc.CommandError("Will not overwrite existing file:" + " %s" % parsed_args.output) + else: + overwrite = True + + extra_vars = { + "stack_name": parsed_args.stack, + "vip_data_path": vip_file_path, + "vip_deployed_path": output_path, + "overwrite": overwrite + } + + with oooutils.TempDirs() as tmp: + oooutils.run_ansible_playbook( + playbook='cli-overcloud-network-vip-provision.yaml', + inventory='localhost,', + workdir=tmp, + playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS, + verbosity=oooutils.playbook_verbosity(self=self), + extra_vars=extra_vars, + )