Page MenuHomeVyOS Platform

API output of show container image broken
Closed, ResolvedPublicBUG

Description

API Support for container functions came with T4880.

I tried to retrieve existing images aka show container images via the API (https://vyos-host/container-image)
unfortunately only the header is returned while the show command on the console works correct.
(Also the output is not json format)

vyos@vyos:~$ curl -k --location --request POST 'https://127.0.0.1/container-image' --form data='{"op": "show"}' --form key='test' --header "Accept: application/json"
{"success": true, "data": "REPOSITORY                        TAG         IMAGE ID      CREATED       SIZE\ndocker.io/pschiffe/pdns-recursor  latest      2d51170c95fe  6 months ago  259 MB\n", "error": null}

vyos@vyos:~$ show container image
REPOSITORY                        TAG         IMAGE ID      CREATED       SIZE
docker.io/pschiffe/pdns-recursor  latest      2d51170c95fe  6 months ago  259 MB

/Markus

Details

Difficulty level
Unknown (require assessment)
Version
1.4, 1.5
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Unspecified (please specify)

Revisions and Commits

Event Timeline

adestis added a commit: Restricted Diffusion Commit.

Seems like I was wrong, the content is returned but not in structured json format.
For further automation it would be nice to have json objects instead of a string which needs to be parsed by the client.

The implementation in file container.py has the command podman image ls which is ok when called from shell.
When called from API it should have been podman image ls --format='{{json .}}'

But I am not so familiar with the automatic api function creation so best would be if someone with more insights will fix it.

Seems like it's the same for the other functions
sudo podman ps --all vs. sudo podman ps --all --format='{{json .}}'
sudo podman network ls vs. sudo podman network ls --format='{{json .}}'

You can use GraphQL query. It shows you what does container.py for raw format

set service https api graphql
set service https api keys id KID key 'foo'

Query

curl -k --raw 'https://localhost/graphql' \
    -H 'Content-Type: application/json' \
    -d '{"query":" { ShowImageContainer (data: {key: \"foo\"}) {\n  success\n  errors\n  data {\n    result\n  }\n}\n}\n"}'

For example

vyos@r4:~$ curl -k --raw 'https://localhost/graphql'    -H 'Content-Type: application/json'    -d '{"query":" { ShowImageContainer (data: {key: \"foo\"}) {\n  success\n  errors\n  data {\n    result\n  }\n}\n}\n"}' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4834  100  4720  100   114  87920   2123 --:--:-- --:--:-- --:--:-- 91207
{
  "data": {
    "ShowImageContainer": {
      "success": true,
      "errors": null,
      "data": {
        "result": [
          {
            "id": "b6a47125b929e1d67ab2decf6569b15fdf319783397ef0af70e5542fd286e57b",
            "parent_id": "ce56935cf06d1e74810492b5b813c39bd6c56fb86027766871f93d70debf3d0b",
            "repo_tags": null,
            "repo_digests": [
              "localhost/openconfig@sha256:6746a6f3eb64d743cfb2e9b813cffa8c91298b48b060f2041d0c0a9b5e48d4a1"
            ],
            "size": 217905898,
            "shared_size": 0,
            "virtual_size": 217905898,
            "labels": {
              "io_buildah_version": "1.28.2",
              "maintainer": "Viachelav Hletenko"
            },
            "containers": 1,
            "names": [
              "localhost/openconfig:one"
            ],
            "digest": "sha256:6746a6f3eb64d743cfb2e9b813cffa8c91298b48b060f2041d0c0a9b5e48d4a1",
            "history": [
              "localhost/openconfig:one"
            ],
...
dmbaturin claimed this task.