Background tasks

Add a task

POST /api/v1/background/(string: category)
Parameters:
  • categorycreate, application, application_upgrade, image_download, image_remove, image_push, image_export, container_import, container_export

Create a container

POST /api/v1/background/create

For create category request:

Other JSON parameters are the same as POST /api/v1/container.
Request JSON Object:
 
  • repository (string) – image is from dockerhub, qnap, private [required]
  • name (string) – container name [required]
  • image (string) – image name [required]
  • tag (string) – image tag. For LXC is latest [required]
  • type (string) – lxc, lxd, docker [required]
  • registry_name (string) – Private registry name
  • download (object) – image metadata
  • description (string) – description of this image
  • location (string) – url of this image
  • icon (string) – icon source of this image
  • fingerprint (string) – LXD image ID (For LXD only)
  • privileged (boolean) – give extended privileges to this container
  • autostart (boolean) – automatically start the container after reboot
  • network (object) – container network setting
  • resource (object) – container resource setting
  • volume (object) – container volume setting

Example request of create a LXC container

$ curl -sq -XPOST -b cookies.txt -d \
    '{
        "type": "lxc",
        "repository": "qnap",
        "name": "ctest",
        "image": "ubuntu-bionic",
        "tag": "latest"
    }' \
    http://${QIP}:${QPORT}/container-station/api/v1/background/create

Example response of create a LXC container

{
    "category": "create",
    "deletable": false,
    "detail_state": "",
    "id": 3,
    "init": 1628700570,
    "name": "ctest",
    "params": {
        "image": "ubuntu-bionic",
        "name": "ctest",
        "repository": "qnap",
        "tag": "latest",
        "type": "lxc"
    },
    "state": "waiting",
    "user": "admin"
}

Example request of create a LXD container

$ curl -sq -XPOST -b cookies.txt -d \
    '{
        "type": "lxd",
        "name": "lxdTest",
        "image": "ubuntu",
        "tag": "bionic",
        "repository": "lxd",
        "autostart": true,
        "network": {
            "port": [
                [
                    12345,
                    1234,
                    "udp"
                ]
            ]
        },
        "resource": {
            "device": [
                [
                    "allow",
                    "video4linux_(81)",
                    "rw"
                ]
            ],
            "limit": {
                "cputime": 512,
                "memory": "768m"
            }
        },
        "volume": {
            "host": {
                "/test/selenium": {
                    "bind": "/mnt/vol1",
                    "ro": true
                }
            }
        }
    }' http://${QIP}:${QPORT}/container-station/api/v1/background/create

Example response of create a LXD container

{
    "category": "create",
    "deletable": false,
    "detail_state": "",
    "id": 4,
    "init": 1628700572,
    "name": "lxdTest",
    "params": {
        "autostart": true,
        "image": "ubuntu",
        "name": "lxdTest",
        "network": {
            "port": [
                [
                    12345,
                    1234,
                    "udp"
                ]
            ]
        },
        "repository": "lxd",
        "resource": {
            "device": [
                [
                    "allow",
                    "video4linux_(81)",
                    "rw"
                ]
            ],
            "limit": {
                "cputime": 512,
                "memory": "768m"
            }
        },
        "tag": "bionic",
        "type": "lxd",
        "volume": {
            "host": {
                "/test/selenium": {
                    "bind": "/mnt/vol1",
                    "ro": true
                }
            }
        }
    },
    "state": "waiting",
    "user": "admin"
}

Example request of create a Docker container

$ curl -sq -XPOST -b cookies.txt  -d \
    '{
        "type": "docker",
        "repository": "dockerhub",
        "name": "dtest",
        "image": "ubuntu",
        "tag": "latest",
        "download": {
            "description": "I am description.",
            "location": "https://hub.docker.com/_/ubuntu/",
            "icon": "http://download.qnap.com/QPKG/images/QPKG/container/ubuntu_icon.png"
        }
    }' \
    http://${QIP}:${QPORT}/container-station/api/v1/background/create

Example response of create a Docker contaienr

{
    "category": "create",
    "deletable": false,
    "detail_state": "",
    "id": 5,
    "init": 1628700573,
    "name": "dtest",
    "params": {
        "download": {
            "description": "I am description.",
            "icon": "http://download.qnap.com/QPKG/images/QPKG/container/ubuntu_icon.png",
            "location": "https://hub.docker.com/_/ubuntu/"
        },
        "image": "ubuntu",
        "name": "dtest",
        "repository": "dockerhub",
        "tag": "latest",
        "type": "docker"
    },
    "state": "waiting",
    "user": "admin"
}

Create an application

POST /api/v1/background/application

For application category request:

Request JSON Object:
 
  • template (string) – Application name [required]
  • name (string) – Custom application name [required]
  • autostart (boolean) – Start application when container-station started
  • virtual_path (string) –
  • port (int) –
  • binding (object) – Application binding data

Example request of create a Joomla application

$ curl -sq -XPOST -b cookies.txt -d \
    '{
        "template": "joomla",
        "name": "joomla"
    }' \
    http://${QIP}:${QPORT}/container-station/api/v1/background/application

Example response of create a Joomla application

{
    "category": "application",
    "deletable": false,
    "detail_state": "",
    "id": 6,
    "init": 1628700574,
    "name": "joomla",
    "params": {
        "binding": {},
        "name": "joomla",
        "template": "joomla"
    },
    "state": "waiting",
    "user": "admin"
}

Upgrade an application

POST /api/v1/background/application_upgrade

For application_upgrade category request:

Request JSON Object:
 
  • template (string) – Application template name [required]
  • name (string) – Custom application name [required]

Download an image

POST /api/v1/background/image_download

For image_download category request:

Request JSON Object:
 
  • repository (string) – image is from dockerhub, qnap, private [required]
  • image (string) – image name [required]
  • tag (string) – image tag. For LXC is latest [required]
  • type (string) – lxc, lxd, docker [required]
  • registry_name (string) – Private registry name
  • download (object) – image metadata

Example request of image download

$ curl -sq -XPOST -b cookies.txt  -d \
    '{
        "type": "docker",
        "repository": "dockerhub",
        "image": "busybox",
        "tag": "latest"
    }' \
    http://${QIP}:${QPORT}/container-station/api/v1/background/image_download

Example response of image download

{
    "category": "image_download",
    "deletable": false,
    "detail_state": "",
    "id": 7,
    "init": 1628700575,
    "name": "busybox:latest",
    "params": {
        "image": "busybox",
        "repository": "dockerhub",
        "tag": "latest",
        "type": "docker"
    },
    "state": "waiting",
    "user": "admin"
}

Remove an image

POST /api/v1/background/image_remove

For image_remove category request:

Request JSON Object:
 
  • type (string) – lxc, lxd, docker [required]
  • image (string) – image name [required]
  • tag (string) – image tag [required]
  • id (string) – image id [required]

Example request of image remove

$ curl -sq -XPOST -b cookies.txt  -d \
    '[
        {
            "type": "docker",
            "image": "busybox",
            "tag": "latest",
            "id": "fake_id"
        }
    ]' \
    http://${QIP}:${QPORT}/container-station/api/v1/background/image_remove

Example response of image remove

{
    "category": "image_remove",
    "deletable": false,
    "detail_state": "",
    "id": 8,
    "init": 1628700575,
    "name": "busybox:latest",
    "params": [
        {
            "id": "fake_id",
            "image": "busybox",
            "tag": "latest",
            "type": "docker"
        }
    ],
    "state": "waiting",
    "user": "admin"
}

Push an image to registry

POST /api/v1/background/image_push

For image_push category request:

Request JSON Object:
 
  • type (string) – docker only [required]
  • image (string) – image name [required]
  • tag (string) – image tag [required]
  • newImage (string) – The repository to set [required]
  • newTag (string) – The new tag name [required]
  • registry (string) – registry name [required] Default is `Docker Hub`
  • username (string) – registry username [required if registry is Docker Hub]
  • password (string) – registry password [required if registry is Docker Hub]
  • rememberme (boolean) – Remember it

Example request of image push

$ curl -sq -XPOST -b cookies.txt  -d \
    '{
        "type": "docker",
        "image": "busybox",
        "tag": "latest",
        "newImage": "mybusybox",
        "newTag": "test",
        "registry": "Docker Hub",
        "username": "qcsuser",
        "password": "qcspassword",
        "rememberme": true
    }' \
    http://${QIP}:${QPORT}/container-station/api/v1/background/image_push

Export an image

POST /api/v1/background/image_export

For image_export category request:

Request JSON Object:
 
  • type (string) – docker only [required]
  • image (string) – image name [required]
  • tag (string) – image tag [required]
  • path (string) – file path [required]
  • compress (boolean) – Compress export file or not. [required]

Example request of image export

$ curl -sq -XPOST -b cookies.txt -d \
    '{
        "type": "docker",
        "image": "ubuntu",
        "tag": "latest",
        "path": "test/a.tgz",
        "compress": true
    }' \
    http://${QIP}:${QPORT}/container-station/api/v1/background/image_export

Import a container

POST /api/v1/background/container_import

For container_import category request:

Create an import task if name is given. The JSON parameters are the same as POST /api/v1/container.

Request JSON Object:
 
  • type (string) – lxc, docker [required]
  • name (string) – container name [required]
  • image (string) – image name [required]
  • path (string) – file path [required]
  • ... (object) – other parameters

Example request of container import

$ curl -sq -XPOST -b cookies.txt  -d \
    '{
        "type": "lxc",
        "name": "utest_import1",
        "image": "utest",
        "path": "test/c.tgz",
        "network": {
            "hostname": "CustomHostName"
        },
        "resource": {
            "device": [
                [
                    "allow",
                    "video4linux_(81)",
                    "rw"
                ]
            ],
            "limit": {
                "cputime": 512,
                "cpuweight": 512,
                "memory": "768m"
            }
        }
    }'\
    http://${QIP}:${QPORT}/container-station/api/v1/background/container_import

Export a container

POST /api/v1/background/container_export

For container_export category request:

Request JSON Object:
 
  • type (string) – lxc, docker [required]
  • name (string) – container name [required]
  • id (string) – container id [required]
  • path (string) – file path [required]
  • compress (boolean) – Compress export file or not. Default is false

Example request of container export

$ curl -sq -XPOST -b cookies.txt  -d \
    '{
        "type": "lxc",
        "id": "ubuntu-bionic-1",
        "name": "ubuntu-bionic-1",
        "path": "test/c.tgz",
        "compress": true
    }' \
    http://${QIP}:${QPORT}/container-station/api/v1/background/container_export

$ curl -sq -XPOST -b cookies.txt -d \
    '{
        "type": "docker",
        "id": "a4af24dfe4329015e3adebbc169cbb04bb771f458167b41b07ebf98c882cce59",
        "name": "busybox-6",
        "path": "test/d.tgz",
        "compress": true
    }' \
    http://${QIP}:${QPORT}/container-station/api/v1/background/container_export

List tasks

GET /api/v1/background/

Get background tasks list.

Query Parameters:
 
  • category – (optional) Task category
Response JSON Object:
 
  • id (int) – unique task id
  • init (int) – time of initial request
  • start (int) – time of starting in epoch
  • end (int) – time of completion in epoch
  • result (int) – 0 means success
  • deletable (boolean) – It can be delete or not during running state
  • category (string) – background task category, the same as POST /api/v1/background/(string:category)
  • state (string) – one of waiting, running, completed, error
  • detail_state (string) – Detail of task progress
  • user (string) – request user name
  • params (string) – request parameters

Example request

$ curl -sq -XGET -b cookies.txt \
    "http://${QIP}:${QPORT}/container-station/api/v1/background/?category=image_remove"

$ curl -sq -XGET -b cookies.txt http://${QIP}:${QPORT}/container-station/api/v1/background/

Example response of all tasks

[
    {
        "category": "image_remove",
        "deletable": false,
        "detail_state": "",
        "id": 8,
        "init": 1628700575,
        "name": "busybox:latest",
        "params": [
            {
                "id": "fake_id",
                "image": "busybox",
                "tag": "latest",
                "type": "docker"
            }
        ],
        "state": "waiting",
        "user": "admin"
    }
]

Example response of all tasks

[
    {
        "category": "image_remove",
        "deletable": false,
        "detail_state": "",
        "id": 8,
        "init": 1628700575,
        "name": "busybox:latest",
        "params": [
            {
                "id": "fake_id",
                "image": "busybox",
                "tag": "latest",
                "type": "docker"
            }
        ],
        "state": "waiting",
        "user": "admin"
    },
    {
        "category": "image_download",
        "deletable": false,
        "detail_state": "",
        "id": 7,
        "init": 1628700575,
        "name": "busybox:latest",
        "params": {
            "image": "busybox",
            "repository": "dockerhub",
            "tag": "latest",
            "type": "docker"
        },
        "state": "waiting",
        "user": "admin"
    },
    {
        "category": "application",
        "deletable": false,
        "detail_state": "",
        "id": 6,
        "init": 1628700574,
        "name": "joomla",
        "params": {
            "binding": {},
            "name": "joomla",
            "template": "joomla"
        },
        "state": "waiting",
        "user": "admin"
    },
    {
        "category": "create",
        "deletable": false,
        "detail_state": "",
        "id": 5,
        "init": 1628700573,
        "name": "dtest",
        "params": {
            "download": {
                "description": "I am description.",
                "icon": "http://download.qnap.com/QPKG/images/QPKG/container/ubuntu_icon.png",
                "location": "https://hub.docker.com/_/ubuntu/"
            },
            "image": "ubuntu",
            "name": "dtest",
            "repository": "dockerhub",
            "tag": "latest",
            "type": "docker"
        },
        "state": "waiting",
        "user": "admin"
    },
    {
        "category": "create",
        "deletable": false,
        "detail_state": "",
        "id": 4,
        "init": 1628700572,
        "name": "lxdTest",
        "params": {
            "autostart": true,
            "image": "ubuntu",
            "name": "lxdTest",
            "network": {
                "port": [
                    [
                        12345,
                        1234,
                        "udp"
                    ]
                ]
            },
            "repository": "lxd",
            "resource": {
                "device": [
                    [
                        "allow",
                        "video4linux_(81)",
                        "rw"
                    ]
                ],
                "limit": {
                    "cputime": 512,
                    "memory": "768m"
                }
            },
            "tag": "bionic",
            "type": "lxd",
            "volume": {
                "host": {
                    "/test/selenium": {
                        "bind": "/mnt/vol1",
                        "ro": true
                    }
                }
            }
        },
        "state": "waiting",
        "user": "admin"
    },
    {
        "category": "create",
        "deletable": false,
        "detail_state": "Download image:15%",
        "id": 3,
        "init": 1628700570,
        "name": "ctest",
        "params": {
            "image": "ubuntu-bionic",
            "name": "ctest",
            "repository": "qnap",
            "tag": "latest",
            "type": "lxc"
        },
        "start": 1628700570,
        "state": "running",
        "user": "admin"
    },
    {
        "category": "application",
        "deletable": false,
        "detail_state": "",
        "end": 1628700468,
        "id": 2,
        "init": 1628700357,
        "name": "joomla",
        "params": {
            "binding": {},
            "name": "joomla",
            "template": "joomla"
        },
        "result": 0,
        "start": 1628700357,
        "state": "completed",
        "user": "admin"
    },
    {
        "category": "create",
        "deletable": false,
        "detail_state": "",
        "end": 1628700297,
        "id": 1,
        "init": 1628700218,
        "name": "ubuntu-1",
        "params": {
            "autostart": true,
            "changed": {},
            "download": {
                "description": "Ubuntu bionic amd64 (20210810_07:42)"
            },
            "environment": [],
            "fingerprint": "3b0756c739364ef5d05b18c0675eefcba7235f74062a3947a3d0b6c34416202f",
            "gpu": false,
            "image": "ubuntu",
            "image_from": {
                "from": "nas",
                "local": "",
                "nas": "",
                "upload_folder": ""
            },
            "links": {},
            "name": "ubuntu-1",
            "network": {
                "mode": "nat",
                "port": []
            },
            "privileged": false,
            "repository": "lxd",
            "resource": {
                "device": [],
                "gpu": [],
                "limit": {}
            },
            "restart": {
                "checked": true,
                "required": false
            },
            "tag": "bionic",
            "type": "lxd",
            "volume": {
                "container": [],
                "host": {},
                "new": []
            }
        },
        "result": 0,
        "start": 1628700218,
        "state": "completed",
        "user": "admin"
    }
]

Delete tasks

DELETE /api/v1/background/(string: category)

It can delete completed and error tasks. Also can delete task with specific task ID or task category.

If task is is running state, it cannot be delete unless this task with deletable capability.

Parameters:
  • task_id – task ID
Response JSON Object:
 
  • object (array) – task ID which have been deleted.

Example request

$ curl -sq -XDELETE -b cookies.txt http://${QIP}:${QPORT}/container-station/api/v1/background/

Example response

[
    1,
    2
]