def pull_images(self, registry, username, password, only_internal=True):
        """
        This pulls all images that are mentioned in artifact.

        Args:
            registry (str): url of exposed OpenShift Docker registry
            username (str): username for for OpenShift Docker registry
            password (str): password for OpenShift Docker registry
            only_internal (bool): if True only images that are in internal
                                  OpenShift Docker registry, otherwise pulls
                                  all images (default is True)

        """
        logger.debug("Pulling images (only_internal: {}, registry:{},"
                     " login:{}:{})".format(only_internal, registry, username,
                                            password))

        ec, stdout, stderr = utils.run_cmd([
            'docker', 'login', '-u', username, '-p', password, '-e',
            "{}@{}".format(username, registry), registry
        ])

        for image_info in self.images:
            if image_info["internal"]:
                image_info["image"] = utils.replace_registry_host(
                    image_info["image"], registry)
            else:
                if only_internal:
                    # we are exporting only internal images, skip this
                    continue
            image = image_info["image"]
            logger.info("Pulling image {}".format(image))

            ec, stdout, stderr = utils.run_cmd(['docker', 'pull', image])
    def push_images(self, registry, username, password, only_internal=True):
        """
        This pushes all images that are mentioned in artifact.

        Args:
            registry (str): url of registry
            username (str): username for docker registry. If None
                            (don't autheticate to registry)
            password (str): password for docker registry
            only_internal (bool): if True only images that are in internal
                                  OpenShift Docker registry, otherwise pulls
                                  all images (default is True)

        """
        logger.debug("pushing images to registry only_internal: {}, "
                     "registry:{}, login:{}:{}".format(only_internal, registry,
                                                       username, password))

        if username and password:
            ec, stdout, stderr = utils.run_cmd(['docker', 'login',
                                                '-u', username,
                                                '-p', password,
                                                '-e', "{}@{}".format(username,
                                                                     registry),
                                                registry])

        for image_info in self.images:
            if only_internal and not image_info["internal"]:
                # skip this image
                continue
            image = image_info["image"]

            # new name of image (only replace registry part)
            name_new_registry = utils.replace_registry_host(image, registry)

            (new_name, new_name_tag, new_name_digest) = utils.parse_image_name(
                name_new_registry)

            if new_name_digest:
                # if this is image with define digest, use digest as tag
                # docker cannot push image without tag, and if images
                # is pulled with digest it doesn't have tag specified

                # if this is going to be used as tag, it cannot contain ':'
                tag = new_name_digest.replace(":", "")
            else:
                tag = new_name_tag

            new_full_name = "{}:{}".format(new_name, tag)
            image_info["image"] = new_full_name

            logger.info("Tagging image {} as {}".format(image, new_full_name))

            ec, stdout, stderr = utils.run_cmd(['docker', 'tag', '-f', image,
                                                new_full_name])

            logger.info("Pushing image {}".format(new_full_name))
            ec, stdout, stderr = utils.run_cmd(['docker', 'push', new_full_name])
    def push_images(self, registry, username, password, only_internal=True):
        """
        This pushes all images that are mentioned in artifact.

        Args:
            registry (str): url of registry
            username (str): username for docker registry. If None
                            (don't autheticate to registry)
            password (str): password for docker registry
            only_internal (bool): if True only images that are in internal
                                  OpenShift Docker registry, otherwise pulls
                                  all images (default is True)

        """
        logger.debug("pushing images to registry only_internal: {}, "
                     "registry:{}, login:{}:{}".format(only_internal, registry,
                                                       username, password))

        if username and password:
            ec, stdout, stderr = utils.run_cmd([
                'docker', 'login', '-u', username, '-p', password, '-e',
                "{}@{}".format(username, registry), registry
            ])

        for image_info in self.images:
            if only_internal and not image_info["internal"]:
                # skip this image
                continue
            image = image_info["image"]

            # new name of image (only replace registry part)
            name_new_registry = utils.replace_registry_host(image, registry)

            (new_name, new_name_tag,
             new_name_digest) = utils.parse_image_name(name_new_registry)

            if new_name_digest:
                # if this is image with define digest, use digest as tag
                # docker cannot push image without tag, and if images
                # is pulled with digest it doesn't have tag specified

                # if this is going to be used as tag, it cannot contain ':'
                tag = new_name_digest.replace(":", "")
            else:
                tag = new_name_tag

            new_full_name = "{}:{}".format(new_name, tag)
            image_info["image"] = new_full_name

            logger.info("Tagging image {} as {}".format(image, new_full_name))

            ec, stdout, stderr = utils.run_cmd(
                ['docker', 'tag', '-f', image, new_full_name])

            logger.info("Pushing image {}".format(new_full_name))
            ec, stdout, stderr = utils.run_cmd(
                ['docker', 'push', new_full_name])
    def pull_images(self, registry, username, password, only_internal=True):
        """
        This pulls all images that are mentioned in artifact.

        Args:
            registry (str): url of exposed OpenShift Docker registry
            username (str): username for for OpenShift Docker registry
            password (str): password for OpenShift Docker registry
            only_internal (bool): if True only images that are in internal
                                  OpenShift Docker registry, otherwise pulls
                                  all images (default is True)

        """
        logger.debug("Pulling images (only_internal: {}, registry:{},"
                     " login:{}:{})".format(only_internal, registry,
                                            username, password))

        docker_client = docker.Client(base_url='unix://var/run/docker.sock', version='auto')

        try:
            login_response = docker_client.login(username=username,
                                                 password=password,
                                                 registry=registry)
            logger.debug(login_response)
        except docker.errors.APIError as e:
            logger.critical(e)
            raise Exception(e)

        for image_info in self.images:
            if image_info["internal"]:
                image_info["image"] = utils.replace_registry_host(
                    image_info["image"], registry)
            else:
                if only_internal:
                    # we are exporting only internal images, skip this
                    continue
            image = image_info["image"]
            logger.info("Pulling image {}".format(image))
            for line in docker_client.pull(image, stream=True, insecure_registry=True):
                line_info = anymarkup.parse(line)
                if "progress" in line_info:
                    # don't print progress information
                    # showing status is enough for now
                    continue
                elif "status" in line_info:
                    logger.info(line_info["status"])
                elif "errorDetail" in line_info:
                    msg = line_info["errorDetail"]["message"]
                    logger.critical(msg)
                    raise Exception(msg)
    def pull_images(self, registry, username, password, only_internal=True):
        """
        This pulls all images that are mentioned in artifact.

        Args:
            registry (str): url of exposed OpenShift Docker registry
            username (str): username for for OpenShift Docker registry
            password (str): password for OpenShift Docker registry
            only_internal (bool): if True only images that are in internal
                                  OpenShift Docker registry, otherwise pulls
                                  all images (default is True)

        """
        logger.debug("Pulling images (only_internal: {}, registry:{},"
                     " login:{}:{})".format(only_internal, registry,
                                            username, password))

        ec, stdout, stderr = utils.run_cmd(['docker', 'login',
                                            '-u', username,
                                            '-p', password,
                                            '-e', "{}@{}".format(username,
                                                                 registry),
                                            registry])

        for image_info in self.images:
            if image_info["internal"]:
                image_info["image"] = utils.replace_registry_host(
                    image_info["image"], registry)
            else:
                if only_internal:
                    # we are exporting only internal images, skip this
                    continue
            image = image_info["image"]
            logger.info("Pulling image {}".format(image))

            ec, stdout, stderr = utils.run_cmd(['docker', 'pull', image])
    def push_images(self, registry, username, password, only_internal=True):
        """
        This pushes all images that are mentioned in artifact.

        Args:
            registry (str): url of registry
            username (str): username for docker registry. If None
                            (don't autheticate to registry)
            password (str): password for docker registry
            only_internal (bool): if True only images that are in internal
                                  OpenShift Docker registry, otherwise pulls
                                  all images (default is True)

        """
        logger.debug("pushing images to registry only_internal: {}, "
                     "registry:{}, login:{}:{}".format(only_internal, registry,
                                                       username, password))

        docker_client = docker.Client(base_url='unix://var/run/docker.sock', version='auto')

        if username and password:
            try:
                login_response = docker_client.login(username=username,
                                                     password=password,
                                                     registry=registry)
                logger.debug(login_response)
            except docker.errors.APIError as e:
                logger.critical(e)
                raise Exception(e)

        for image_info in self.images:
            if only_internal and not image_info["internal"]:
                # skip this image
                continue
            image = image_info["image"]

            # new name of image (only replace registry part)
            name_new_registry = utils.replace_registry_host(image, registry)

            (new_name, new_name_tag, new_name_digest) = utils.parse_image_name(
                name_new_registry)

            if new_name_digest:
                # if this is image with define digest, use digest as tag
                # docker cannot push image without tag, and if images
                # is pulled with digest it doesn't have tag specified

                # if this is going to be used as tag, it cannot contain ':'
                tag = new_name_digest.replace(":", "")
            else:
                tag = new_name_tag

            new_full_name = "{}:{}".format(new_name, tag)
            image_info["image"] = new_full_name

            logger.info("Tagging image {} as {}".format(image, new_full_name))
            try:
                tag_response = docker_client.tag(image, new_name, tag,
                                                 force=True)
                if not tag_response:
                    msg = "Error while tagging image"
                    logger.critical(msg)
                    raise Exception(msg)

            except docker.errors.APIError as e:
                logger.critical(e)
                raise Exception(e)

            logger.info("Pushing image {}".format(new_full_name))
            for line in docker_client.push(new_full_name, stream=True):
                line_info = anymarkup.parse(line)
                if "progress" in line_info:
                    # don't print progress information
                    # showing status is enough for now
                    continue
                elif "status" in line_info:
                    logger.info(line_info["status"])
                elif "errorDetail" in line_info:
                    msg = line_info["errorDetail"]["message"]
                    logger.critical(msg)
                    raise Exception(msg)