diff --git a/kollacli/api/control_plane.py b/kollacli/api/control_plane.py index 2d33110..7e33cbb 100644 --- a/kollacli/api/control_plane.py +++ b/kollacli/api/control_plane.py @@ -54,6 +54,21 @@ class ControlPlaneApi(object): serial_flag, verbose_level, servicenames) return Job(ansible_job) + @staticmethod + def pull(verbose_level=1): + """Pull. + + Pull container images onto appropriate hosts. + + :param verbose_level: the higher the number, the more verbose + :type verbose_level: integer + :return: Job object + :rtype: Job + """ + check_arg(verbose_level, u._('Verbose level'), int) + ansible_job = actions.pull(verbose_level) + return Job(ansible_job) + @staticmethod def upgrade(verbose_level=1, servicenames=[]): # type: (int, List[str]) -> Job diff --git a/kollacli/commands/pull.py b/kollacli/commands/pull.py new file mode 100644 index 0000000..aa01087 --- /dev/null +++ b/kollacli/commands/pull.py @@ -0,0 +1,46 @@ +# Copyright(c) 2017, Oracle and/or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import logging +import traceback + +from cliff.command import Command + +import kollacli.i18n as u + +from kollacli.api.client import ClientApi +from kollacli.commands.exceptions import CommandError + +CLIENT = ClientApi() +LOG = logging.getLogger(__name__) + + +class Pull(Command): + """Pull enabled service images onto appropriate hosts.""" + def take_action(self, parsed_args): + try: + verbose_level = self.app.options.verbose_level + job = CLIENT.pull(verbose_level) + status = job.wait() + if verbose_level > 2: + LOG.info('\n\n' + 80 * '=') + LOG.info(u._('DEBUG command output:\n{out}') + .format(out=job.get_console_output())) + if status == 0: + LOG.info(u._('Success')) + else: + raise CommandError(u._('Job failed:\n{msg}') + .format(msg=job.get_error_message())) + + except Exception: + raise Exception(traceback.format_exc()) \ No newline at end of file diff --git a/kollacli/common/ansible/actions.py b/kollacli/common/ansible/actions.py index d3fc96b..62362c7 100644 --- a/kollacli/common/ansible/actions.py +++ b/kollacli/common/ansible/actions.py @@ -95,6 +95,19 @@ def precheck(hostnames, verbose_level=1): return job +def pull(verbose_level=1): + '''run pull action against all hosts''' + playbook = AnsiblePlaybook() + kolla_home = get_kolla_home() + playbook.playbook_path = os.path.join(kolla_home, + 'ansible/site.yml') + playbook.extra_vars = 'action=pull' + playbook.verbose_level = verbose_level + + job = playbook.run() + return job + + def stop_hosts(hostnames=[], verbose_level=1): '''stop containers on a set of hosts. diff --git a/kollacli/shell.py b/kollacli/shell.py index 00aaa14..66825da 100755 --- a/kollacli/shell.py +++ b/kollacli/shell.py @@ -28,7 +28,7 @@ from kollacli.common.utils import get_kollacli_etc LOG = logging.getLogger(__name__) -VERSION = '0.3' +VERSION = '4.0' class KollaCli(App): diff --git a/setup.cfg b/setup.cfg index d216c7e..9ad845b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,6 +54,7 @@ kolla.cli = property_clear = kollacli.commands.property:PropertyClear property_list = kollacli.commands.property:PropertyList property_set = kollacli.commands.property:PropertySet + pull = kollacli.commands.pull:Pull reconfigure = kollacli.commands.reconfigure:Reconfigure service_addgroup = kollacli.commands.service:ServiceAddGroup service_list = kollacli.commands.service:ServiceList