Add host support for pull action

Change-Id: Icc60f135c7b3d7d9d38b73a3ae04e18c3078c287
This commit is contained in:
gujin 2019-07-29 23:56:57 +08:00
parent 50ffbe5188
commit 6b38a92c80
3 changed files with 16 additions and 4 deletions

View File

@ -60,25 +60,30 @@ class ControlPlaneApi(object):
return Job(ansible_job)
@staticmethod
def pull(verbose_level=1, servicenames=[]):
def pull(verbose_level=1, hostnames=[], servicenames=[]):
"""Pull.
Pull all images for containers (only pulls, no running container).
:param verbose_level: the higher the number, the more verbose
:param hostnames: hosts to pull to. If empty, then pull to all.
:type hostnames: list of strings
:type verbose_level: integer
:param servicenames: services to pull. If empty, then pull all.
: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)
aciton = KollaAction(verbose_level=verbose_level,
playbook_name='site.yml')
ansible_job = aciton.pull(servicenames)
ansible_job = aciton.pull(hostnames, servicenames)
return Job(ansible_job)
@staticmethod

View File

@ -103,6 +103,9 @@ class Pull(Command):
"""Pull all images for containers (only pulls, no running container)."""
def get_parser(self, prog_name):
parser = super(Pull, self).get_parser(prog_name)
parser.add_argument('--hosts', nargs='?',
metavar='<host_list>',
help=u._('Pull host list'))
parser.add_argument('--services', nargs='?',
metavar='<service_list>',
help=u._('Pull service list'))
@ -112,10 +115,13 @@ class Pull(Command):
services = []
try:
verbose_level = self.app.options.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.pull(verbose_level, services)
job = CLIENT.pull(verbose_level, hosts, services)
status = job.wait()
handers_action_result(job, status, verbose_level)
except Exception:

View File

@ -117,9 +117,10 @@ class KollaAction(object):
job = self.playbook.run()
return job
def pull(self, servicenames=[]):
def pull(self, hostnames=[], servicenames=[]):
'''run pull action against all hosts'''
self.playbook.hosts = hostnames
self.playbook.services = servicenames
self.playbook.extra_vars = 'kolla_action=pull'
self.playbook.print_output = True