コード例 #1
0
    def images(self) -> ImagesManager:
        """Returns object for managing images stored via the Podman service.

        Returns:
            ImagesManager:
        """
        return ImagesManager(client=self.api)
コード例 #2
0
 def test_platform(self):
     rd = RegistryData(
         "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab",
         attrs=FIRST_IMAGE,
         collection=ImagesManager(client=self.client.api),
     )
     self.assertTrue(rd.has_platform("linux/amd64/fedora"))
コード例 #3
0
    def commit(self,
               repository: str = None,
               tag: str = None,
               **kwargs) -> Image:
        """Save container to given repository.

        Args:
            repository: Where to save Image
            tag: Tag to push with Image

        Keyword Args:
            author (str): Name of commit author
            changes (List[str]): Instructions to apply during commit
            comment (List[str]): Instructions to apply while committing in Dockerfile format
            conf (dict[str, Any]): Ignored.
            format (str): Format of the image manifest and metadata
            message (str): Commit message to include with Image
            pause (bool): Pause the container before committing it
        """
        params = {
            "author": kwargs.get("author"),
            "changes": kwargs.get("changes"),
            "comment": kwargs.get("comment"),
            "container": self.id,
            "format": kwargs.get("format"),
            "pause": kwargs.get("pause"),
            "repo": repository,
            "tag": tag,
        }
        response = self.client.post("/commit", params=params)
        response.raise_for_status()

        body = response.json()
        return ImagesManager(client=self.client).get(body["ID"])
コード例 #4
0
    def image(self):
        """podman.domain.images.Image: Returns Image object used to create Container."""
        if "Image" in self.attrs:
            image_id = self.attrs["Image"]

            return ImagesManager(client=self.client).get(image_id)
        return Image()
コード例 #5
0
    def test_platform_404(self):
        rd = RegistryData(
            "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab",
            attrs=FIRST_IMAGE,
            collection=ImagesManager(client=self.client.api),
        )

        self.assertFalse(rd.has_platform({"os": "COS", "architecture": "X-MP"}))
コード例 #6
0
    def test_platform_500(self):
        rd = RegistryData(
            "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab",
            attrs=FIRST_IMAGE,
            collection=ImagesManager(client=self.client.api),
        )

        with self.assertRaises(InvalidArgument):
            rd.has_platform("This/is/not/a/legal/image/name")
コード例 #7
0
ファイル: containers.py プロジェクト: FedericoRessi/podman-py
    def image(self) -> Image:
        """Returns Image object used to create Container."""
        if "Image" in self.attrs:
            image_id = self.attrs["Image"]
            if ":" in image_id:
                image_id = image_id.split(":")[1]

            return ImagesManager(client=self.client).get(image_id)
        return Image()
コード例 #8
0
 def test_init(self, mock):
     mock.get(
         "http+unix://localhost:9999/v3.0.0/libpod/images/"
         "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab/json",
         json=FIRST_IMAGE,
     )
     actual = RegistryData(
         "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab",
         client=self.client.api,
         collection=ImagesManager(client=self.client.api),
     )
     self.assertEqual(
         actual.id, "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab"
     )
コード例 #9
0
 def test_init(self, mock):
     mock.get(
         tests.LIBPOD_URL + "/images/"
         "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab/json",
         json=FIRST_IMAGE,
     )
     actual = RegistryData(
         "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab",
         client=self.client.api,
         collection=ImagesManager(client=self.client.api),
     )
     self.assertEqual(
         actual.id,
         "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab")
コード例 #10
0
    def commit(self,
               repository: str = None,
               tag: str = None,
               **kwargs) -> Image:
        """Save container to given repository using given parameters.

        Args:
            repository: Where to save Image
            tag: Tag to push with Image

        Keyword Args:
            author (str): Name of commit author
            changes (List[str]): Instructions to apply during commit
            comment (List[str]): Instructions to apply while committing in Dockerfile format
            conf (Dict[str, Any]): Ignored
            format (str): Format of the image manifest and metadata
            message (str): Commit message to include with Image
            pause (bool): Pause the container before committing it

            See https://docs.podman.io/en/latest/_static/api.html#operation/libpodCommitContainer
        """
        params = {
            "author": kwargs.get("author", None),
            "changes": kwargs.get("changes", None),
            "comment": kwargs.get("comment", None),
            "container": self.id,
            "format": kwargs.get("format", None),
            "pause": kwargs.get("pause", None),
            "repo": repository,
            "tag": tag,
        }
        response = self.client.post("/commit", params=params)
        body = response.json()

        if response.status_code != 201:
            if response.status_code == 404:
                raise NotFound(body["cause"],
                               response=response,
                               explanation=body["message"])
            raise APIError(body["cause"],
                           response=response,
                           explanation=body["message"])

        return ImagesManager(client=self.client).get(body["ID"])
コード例 #11
0
ファイル: client.py プロジェクト: hroncok/podman-py
 def images(self) -> ImagesManager:
     """Returns Manager for operations on images stored by a Podman service."""
     return ImagesManager(client=self.api)