def ensure_image_exists(module, image):
    """If image is passed, ensure it exists, if not - pull it or fail.

    Arguments:
        module {obj} -- ansible module object
        image {str} -- name of image

    Returns:
        list -- list of image actions - if it pulled or nothing was done
    """
    image_actions = []
    module_exec = module.params['executable']
    if not image:
        return image_actions
    rc, out, err = run_podman_command(module,
                                      executable=module_exec,
                                      args=['image', 'exists', image],
                                      ignore_errors=True)
    if rc == 0:
        return image_actions
    rc, out, err = run_podman_command(module,
                                      executable=module_exec,
                                      args=['image', 'pull', image],
                                      ignore_errors=True)
    if rc != 0:
        module.fail_json(msg="Can't pull image %s" % image,
                         stdout=out,
                         stderr=err)
    image_actions.append("pulled image %s" % image)
    return image_actions
示例#2
0
 def _run(self, args, expected_rc=0, ignore_errors=False):
     return run_podman_command(
         module=self.module,
         executable=self.executable,
         args=args,
         expected_rc=expected_rc,
         ignore_errors=ignore_errors)
 def get_info(self):
     """Inspect container and gather info about it."""
     rc, out, err = run_podman_command(
         module=self.module,
         executable=self.module.params['executable'],
         args=['container', 'inspect', self.name],
         ignore_errors=True)
     return json.loads(out)[0] if rc == 0 else {}
示例#4
0
 def get_info(self):
     """Inspect container and gather info about it"""
     rc, out, err = run_podman_command(
         module=self.module,
         args=["container", "inspect", self.name],
         ignore_errors=True,
     )
     return json.loads(out)[0] if rc == 0 else {}
示例#5
0
    def _perform_action(self, action):
        """Perform action with container

        Arguments:
            action {str} -- action to perform - start, create, stop, run, delete
        """
        b_command = construct_command_from_params(action, self.module.params)
        self.module.log("PODMAN-DEBUG: %s" % " ".join([to_native(i) for i in b_command]))
        rc, out, err = run_podman_command(
            module=self.module,
            args=[b'container'] + b_command,
            ignore_errors=True)
        if rc != 0:
            self.module.fail_json(
                msg="Can't %s container %s" % (action, self.name),
                stdout=out, stderr=err)