From 96f5956b3daada5e79130fc3a75a5a866e97aa54 Mon Sep 17 00:00:00 2001 From: zhulingjie Date: Fri, 9 Aug 2019 23:24:31 +0800 Subject: [PATCH] Add --hosts and --services support for reconfigure action Change-Id: Ib84a45116b0975b8866499ff30cd1499c309e6af --- kolla_cli/api/control_plane.py | 19 ++++++++++++++++--- kolla_cli/commands/kolla_action.py | 16 +++++++++++++++- kolla_cli/common/ansible/actions.py | 4 +++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/kolla_cli/api/control_plane.py b/kolla_cli/api/control_plane.py index 77dc2e3..229f1df 100644 --- a/kolla_cli/api/control_plane.py +++ b/kolla_cli/api/control_plane.py @@ -215,22 +215,35 @@ class ControlPlaneApi(object): return Job(ansible_job) @staticmethod - def reconfigure(verbose_level=1): - # type: (int) -> Job + def reconfigure(verbose_level=1, hostnames=[], servicenames=[]): + # type: (int, List[str], List[str]) -> Job """Reconfigure. Reconfigure OpenStack service. + :param hostnames: host names + :type hostnames: list :param verbose_level: the higher the number, the more verbose :type verbose_level: integer + :param servicenames: services to prechecks. + :type servicenames: list of strings :return: Job object :rtype: Job """ + check_arg(hostnames, u._('Host names'), list, + empty_ok=True, none_ok=True) check_arg(verbose_level, u._('Verbose level'), int) + check_arg(servicenames, u._('Service names'), list, + empty_ok=True, none_ok=True) + hostnames = safe_decode(hostnames) + servicenames = safe_decode(servicenames) + + check_kolla_args(hostnames=hostnames, + servicenames=servicenames) action = KollaAction(verbose_level=verbose_level, playbook_name='site.yml') - ansible_job = action.reconfigure() + ansible_job = action.reconfigure(hostnames, servicenames) return Job(ansible_job) @staticmethod diff --git a/kolla_cli/commands/kolla_action.py b/kolla_cli/commands/kolla_action.py index 4f0f993..fd7f452 100644 --- a/kolla_cli/commands/kolla_action.py +++ b/kolla_cli/commands/kolla_action.py @@ -164,12 +164,26 @@ class Reconfigure(Command): """Reconfigure OpenStack service.""" def get_parser(self, prog_name): parser = super(Reconfigure, self).get_parser(prog_name) + parser.add_argument('--hosts', nargs='?', + metavar='', + help=u._('Reconfigure host list')) + parser.add_argument('--services', nargs='?', + metavar='', + help=u._('Reconfigure service list')) return parser def take_action(self, parsed_args): + hosts = [] + services = [] try: verbose_level = self.app.options.verbose_level - job = CLIENT.reconfigure(verbose_level) + if parsed_args.hosts: + host_list = parsed_args.hosts.strip() + hosts = host_list.split(',') + if parsed_args.services: + service_list = parsed_args.services.strip() + services = service_list.split(',') + job = CLIENT.reconfigure(verbose_level, hosts, services) status = job.wait() handers_action_result(job, status, verbose_level) except Exception: diff --git a/kolla_cli/common/ansible/actions.py b/kolla_cli/common/ansible/actions.py index dad7fe3..245341a 100644 --- a/kolla_cli/common/ansible/actions.py +++ b/kolla_cli/common/ansible/actions.py @@ -64,9 +64,11 @@ class KollaAction(object): job = self.playbook.run() return job - def reconfigure(self): + def reconfigure(self, hostnames=[], servicenames=[]): '''Reconfigure OpenStack service.''' + self.playbook.hosts = hostnames + self.playbook.services = servicenames self.playbook.extra_vars = 'kolla_action=reconfigure' self._run_deploy_rules(self.playbook)