Ejemplo n.º 1
0
    def list_images(self):
        """
        List all available buildah images.

        :return: collection of instances of :class:`conu.BuildahImage`
        """
        images = []
        for image in self._list_all_buildah_images():
            try:
                i_name, tag = parse_reference(image["names"][0])
            except (IndexError, TypeError):
                i_name, tag = None, None
            d_im = BuildahImage(i_name,
                                tag=tag,
                                identifier=image["id"],
                                pull_policy=BuildahImagePullPolicy.NEVER)
            images.append(d_im)

        return images
Ejemplo n.º 2
0
    def get_metadata(self):
        """
        Convert dictionary returned after podman inspect command into instance of ContainerMetadata class
        :return: ContainerMetadata, container metadata instance
        """
        if self._metadata is None:
            inspect_data = self.inspect(refresh=True)
            self._metadata = buildah_container_inspect_to_metadata(inspect_data)

            # this is a hack to avoid circular imports: feel free to fix it
            if self.ImageClass:
                image_id = graceful_get(inspect_data, "FromImageID")
                image_name = graceful_get(inspect_data, "FromImage")
                if image_name:
                    image_repo, tag = parse_reference(image_name)
                else:
                    image_repo, tag = None, None
                self._metadata.image = self.ImageClass(image_repo, tag=tag, identifier=image_id)
        return self._metadata
Ejemplo n.º 3
0
    def list_containers(self):
        """
        List all available podman containers.

        :return: collection of instances of :class:`conu.PodmanContainer`
        """
        containers = []
        for container in self._list_podman_containers():
            identifier = container["ID"]
            name = container["Names"]
            image_name = container["Image"]

            try:
                image_name, image_tag = parse_reference(image_name)
            except (IndexError, TypeError):
                image_name, image_tag = None, None

            image = PodmanImage(image_name, tag=image_tag, identifier=None)
            container = PodmanContainer(image, identifier, name=name)
            containers.append(container)

        return containers
Ejemplo n.º 4
0
    def list_images(self):
        """
        List all available docker images.

        Image objects returned from this methods will contain a limited
        amount of metadata in property `short_metadata`. These are just a subset
        of `.inspect()`, but don't require an API call against dockerd.

        :return: collection of instances of :class:`conu.DockerImage`
        """
        response = []
        for im in self.d.images():
            try:
                i_name, tag = parse_reference(im["RepoTags"][0])
            except (IndexError, TypeError):
                i_name, tag = None, None
            d_im = DockerImage(i_name,
                               tag=tag,
                               identifier=im["Id"],
                               pull_policy=DockerImagePullPolicy.NEVER)
            inspect_to_metadata(d_im.metadata, im)

            response.append(d_im)
        return response
Ejemplo n.º 5
0
def test_parse_reference(reference, result):
    assert parse_reference(reference) == result