Import and Export¶
Export [Deprecated]¶
Deprecated since version 1.6: Use POST /api/v1/background/container_export
instead.
-
POST
/api/v1/container/
(string: container_type)/
(string: container_id)/export
¶ Create an export task for container id
container_id
of container typecontainer_type
. For JSON fields, checkGET /api/v1/export/
. The path must be under the folders byGET /api/v1/sharefolder/
.Parameters: - container_type –
lxc
,docker
- container_id – container id
Request JSON Object: - path (string) – file path [required]
- compress (boolean) – Compress export file or not. Default is false
- force (boolean) – Force rewrite file or not. Default is false
- container_type –
Note
- Input check for
path
Extract filename and filename extensions from
path
Filename extensions are
tar
,tgz
^([a-zA-Z0-9-_]{1,45})$
only [a-zA-Z0-9-_] are allowed, size between 1 and 45
Example request of LXC
$ curl -sq -XPOST -b cookies.txt -d \ '{ "path": "Public/c.tgz", "compress": true }' http://${QIP}:${QPORT}/api/v1/container/lxc/utest/export
Example response of LXC
{ "cid": "utest", "cname": "utest", "compress": true, "id": 3, "init": 1474455936, "path": "/Public/c.tgz", "state": "waiting", "type": "lxc", "user": "admin" }
Example request of Docker
$ curl -sq -XPOST -b cookies.txt -d \ '{ "path": "Public/d.tgz", "compress": true }' http://${QIP}:${QPORT}/api/v1/container/docker/<container_id>/export
Example response of Docker
{ "cid": "066c083fa24961088ff88e0d92e1e87e505a852c0c17e36c273c9f304a33d75f", "cname": "DockerTestAPI", "compress": true, "id": 4, "init": 1474455937, "path": "/Public/d.tgz", "state": "waiting", "type": "docker", "user": "admin" }
-
GET
/api/v1/export/
¶ Get export tasks list.
Response JSON Object: - id (int) – unique task id
- state (string) – one of
waiting
,running
,completed
,aborted
- result (int) – 0 means success
- type (string) – container type
- cid (string) – container id
- user (string) – request user name
- path (string) – file path
- compress (boolean) – compress or not
- init (int) – time of initial request
- start (int) – time of starting in epoch
- end (int) – time of completion in epoch
- progress (int) – running progress [-1, 99]. -1 means no available progress.
Example request
$ curl -sq -XGET -b cookies.txt http://${QIP}:${QPORT}/api/v1/export/
Example response
[ { "cid": "066c083fa24961088ff88e0d92e1e87e505a852c0c17e36c273c9f304a33d75f", "cname": "DockerTestAPI", "compress": true, "id": 4, "init": 1474455937, "path": "/Public/d.tgz", "state": "waiting", "type": "docker", "user": "admin" }, { "cid": "utest", "cname": "utest", "compress": true, "id": 3, "init": 1474455936, "path": "/Public/c.tgz", "progress": 0, "start": 1474455936, "state": "running", "type": "lxc", "user": "admin" }, { "cid": "5b5122f4e7a56f3f8c77d7b80a4ddb62f97472b8577b990d318d2cfeea2f8c25", "cname": "DockerTestAPI", "compress": true, "end": 1474407004, "id": 2, "init": 1474406973, "path": "/Public/d.tgz", "result": 0, "start": 1474406991, "state": "completed", "type": "docker", "user": "admin" }, { "cid": "utest", "cname": "utest", "compress": true, "end": 1474406991, "id": 1, "init": 1474406972, "path": "/Public/c.tgz", "result": 0, "start": 1474406973, "state": "completed", "type": "lxc", "user": "admin" } ]
-
GET
/api/v1/export/progress
¶ It’s a long polling that returns when progress changed of tasks. This method only returns progress changing, where the task state changed, then the event will be triggered by
GET /api/v1/event
.Example request
$ curl -sq -m 5 -XGET -b cookies.txt http://${QIP}:${QPORT}/api/v1/export/progress
Example response
[ { "cid": "utest", "cname": "utest", "compress": true, "id": 3, "init": 1474455936, "path": "/Public/c.tgz", "progress": 16, "start": 1474455936, "state": "running", "type": "lxc", "user": "admin" } ]
-
DELETE
/api/v1/export/
¶ Clear completed/aborted tasks in database. It will response with task ID which have been deleted.
Example request
$ curl -sq -XDELETE -b cookies.txt http://${QIP}:${QPORT}/api/v1/export/
Example response
[ 1, 2 ]
Import [Deprecated]¶
Deprecated since version 1.6: Use POST /api/v1/background/container_import
instead.
-
GET
/api/v1/import/config
¶ Given container archive path, query the configure
Query Parameters: - path – archive file relative parent path in NAS
- name – archive file name
Example request
$ curl -sq -XGET -b cookies.txt "http://${QIP}:${QPORT}/api/v1/import/config?path=Public&name=c.tgz"
Example response
{ "arch": "amd64", "autostart": false, "image": "ubuntu-trusty", "name": "utest", "network": {}, "resource": {}, "source": "qnap_export", "type": "lxc", "version": "latest", "volume": {} }
-
POST
/api/v1/import/
¶ Create an import task if name is given. The JSON parameters are the same as
POST /api/v1/container
.Query Parameters: - path – archive file relative parent path in NAS
- name – archive file name
Example request
$ curl -sq -XPOST -b cookies.txt -d \ '{ "type": "lxc", "name": "utest_import", "image": "utest", "network": { "hostname": "CustomHostName", "port": [ [ 12345, 1234, "udp" ] ] }, "resource": { "device": [ [ "allow", "video4linux_(81)", "rw" ] ], "limit": { "cputime": 512, "cpuweight": 512, "memory": "768m" } }, "volume": { "host": { "/var": { "bind": "/mnt/vol1", "ro": true }, "/tmp": { "bind": "/mnt/vol2", "ro": false } } } }' "http://${QIP}:${QPORT}/api/v1/import/?path=${QTEST_FOLDER}&name=c.tgz"
Example response
{ "cid": "utest_import", "cname": "utest_import", "create_params": { "image": "utest", "name": "utest_import", "network": { "hostname": "CustomHostName", "port": [ [ 12345, 1234, "udp" ] ] }, "resource": { "device": [ [ "allow", "video4linux_(81)", "rw" ] ], "limit": { "cputime": 512, "cpuweight": 512, "memory": "768m" } }, "type": "lxc", "volume": { "host": { "/share/tmp": { "bind": "/mnt/vol2", "ro": false }, "/share/var": { "bind": "/mnt/vol1", "ro": true } } } }, "id": 2, "image": "utest", "init": 1474455972, "path": "/Public/c.tgz", "state": "waiting", "type": "lxc", "user": "admin" }
-
GET
/api/v1/import/
¶ Get import tasks list.
Response JSON Object: - id (int) – unique id
- state (string) – one of
waiting
,running
,completed
,aborted
- result (int) – 0 means success
- type (string) – container type
- cid (string) – container id
- path (string) – file path
- user (string) – request user name
- start (int) – time of starting in epoch
- end (int) – time of completion in epoch
- progress (int) – running progress [-1, 99]. -1 means no available progress.
Example request
$ curl -sq -XGET -b cookies.txt http://${QIP}:${QPORT}/api/v1/import/
Example response
[ { "cid": "utest_import", "cname": "utest_import", "create_params": "{u'resource': {u'device': [[u'allow', u'video4linux_(81)', u'rw']], u'limit': {u'memory': u'768m', u'cputime': 512, u'cpuweight': 512}}, u'name': u'utest_import', u'image': u'utest', u'volume': {u'host': {u'/share/tmp': {u'bind': u'/mnt/vol2', u'ro': False}, u'/share/var': {u'bind': u'/mnt/vol1', u'ro': True}}}, u'type': u'lxc', u'network': {u'hostname': u'CustomHostName', u'port': [[12345, 1234, u'udp']]}}", "id": 2, "image": "utest", "init": 1474455972, "path": "/Public/c.tgz", "progress": 1, "start": 1474455972, "state": "running", "type": "lxc", "user": "admin" }, { "cid": "utest_import", "cname": "utest_import", "create_params": "{u'resource': {u'device': [[u'allow', u'video4linux_(81)', u'rw']], u'limit': {u'memory': u'768m', u'cputime': 512, u'cpuweight': 512}}, u'name': u'utest_import', u'image': u'utest', u'volume': {u'host': {u'/share/tmp': {u'bind': u'/mnt/vol2', u'ro': False}, u'/share/var': {u'bind': u'/mnt/vol1', u'ro': True}}}, u'type': u'lxc', u'network': {u'hostname': u'CustomHostName', u'port': [[12345, 1234, u'udp']]}}", "end": 1474407035, "id": 1, "image": "utest", "init": 1474407007, "path": "/Public/c.tgz", "result": 0, "start": 1474407007, "state": "completed", "type": "lxc", "user": "admin" } ]
-
GET
/api/v1/import/progress
¶ It’s a long polling that returns when progress changed of tasks. This method only returns progress changing, where the task state changed, then the event will be triggered by
GET /api/v1/event
.Example request
$ curl -sq -m 5 -XGET -b cookies.txt http://${QIP}:${QPORT}/api/v1/import/progress
Example response
[ { "cid": "utest_import", "cname": "utest_import", "create_params": "{u'resource': {u'device': [[u'allow', u'video4linux_(81)', u'rw']], u'limit': {u'memory': u'768m', u'cputime': 512, u'cpuweight': 512}}, u'name': u'utest_import', u'image': u'utest', u'volume': {u'host': {u'/share/tmp': {u'bind': u'/mnt/vol2', u'ro': False}, u'/share/var': {u'bind': u'/mnt/vol1', u'ro': True}}}, u'type': u'lxc', u'network': {u'hostname': u'CustomHostName', u'port': [[12345, 1234, u'udp']]}}", "id": 2, "image": "utest", "init": 1474455972, "path": "/Public/c.tgz", "progress": 5, "start": 1474455972, "state": "running", "type": "lxc", "user": "admin" } ]
-
DELETE
/api/v1/import/
¶ Clear completed/aborted tasks in database.
Response JSON Object: - object (array) – task ID which have been deleted.
Example request
$ curl -sq -XDELETE -b cookies.txt http://${QIP}:${QPORT}/api/v1/import/
Example response
[ 1 ]
File operations¶
List shared folders.
Query Parameters: - path – path of a folder
- size – Get the total size and used size of root directory.
Response JSON Object: - name (string) – directory name or file name
- type (string) –
d
is directory,f
is file. [Deprecated] - isDir (boolean) – is directory or not
- totalSize (string) – Total size of root directory
- usedSize (string) – Used size of root directory
- write (boolean) – write permission
Example request
$ curl -sq -b cookies.txt http://${QIP}:${QPORT}/api/v1/sharefolder/ $ curl -sq -b cookies.txt "http://${QIP}:${QPORT}/api/v1/sharefolder/?size=true" $ curl -sq -b cookies.txt "http://${QIP}:${QPORT}/api/v1/sharefolder/?path=test" $ curl -sq -b cookies.txt "http://${QIP}:${QPORT}/api/v1/sharefolder/?path=Public"
Example response
[ { "isDir": true, "name": "aaa", "type": "d", "write": true }, { "isDir": true, "name": "bbb", "type": "d", "write": true }, { "isDir": true, "name": "sharefolder", "type": "d", "write": true }, { "isDir": true, "name": "eee", "type": "d", "write": true }, { "isDir": true, "name": "test", "type": "d", "write": true }, { "isDir": true, "name": "llllllllllllllllllllllllllllllllllllllllllllllllllll", "type": "d", "write": true }, { "isDir": true, "name": "wcb", "type": "d", "write": true }, { "isDir": true, "name": "Public", "type": "d", "write": true }, { "isDir": true, "name": "ccc", "type": "d", "write": true }, { "isDir": true, "name": "ddd", "type": "d", "write": true } ] [ { "isDir": true, "name": "aaa", "totalSize": "326.1G", "type": "d", "usedSize": "12M", "write": true }, { "isDir": true, "name": "bbb", "totalSize": "326.1G", "type": "d", "usedSize": "12K", "write": true }, { "isDir": true, "name": "sharefolder", "totalSize": "326.1G", "type": "d", "usedSize": "8.0K", "write": true }, { "isDir": true, "name": "eee", "totalSize": "326.1G", "type": "d", "usedSize": "12K", "write": true }, { "isDir": true, "name": "test", "totalSize": "326.1G", "type": "d", "usedSize": "20K", "write": true }, { "isDir": true, "name": "llllllllllllllllllllllllllllllllllllllllllllllllllll", "totalSize": "326.1G", "type": "d", "usedSize": "12K", "write": true }, { "isDir": true, "name": "wcb", "totalSize": "326.1G", "type": "d", "usedSize": "12K", "write": true }, { "isDir": true, "name": "Public", "totalSize": "326.1G", "type": "d", "usedSize": "11G", "write": true }, { "isDir": true, "name": "ccc", "totalSize": "326.1G", "type": "d", "usedSize": "12K", "write": true }, { "isDir": true, "name": "ddd", "totalSize": "326.1G", "type": "d", "usedSize": "12K", "write": true } ] [ { "isDir": true, "name": "@Recycle", "type": "d" }, { "isDir": true, "name": "selenium", "type": "d" }, { "isDir": true, "name": "spec", "type": "d" } ] [ { "isDir": true, "name": "12345#6789", "type": "d" }, { "isDir": true, "name": "@Recycle", "type": "d" }, { "isDir": true, "name": "Public", "type": "d" }, { "isDir": true, "name": "app", "type": "d" }, { "isDir": true, "name": "backup", "type": "d" }, { "isDir": true, "name": "cde-package", "type": "d" }, { "isDir": true, "name": "consul-data", "type": "d" }, { "isDir": true, "name": "container-station-data", "type": "d" }, { "isDir": true, "name": "convoy", "type": "d" }, { "isDir": true, "name": "docker-volume-netshare_0.11_linux_amd64", "type": "d" }, { "isDir": true, "name": "ebs_test", "type": "d" }, { "isDir": true, "name": "serf", "type": "d" }, { "isDir": true, "name": "sharefolder", "type": "d" }, { "isDir": true, "name": "test", "type": "d" }, { "isDir": true, "name": "\u4e2d \u6587\uff41\u3000\uff44\u3000\uff4d\u3000\uff49\u3000\uff4e\u65b9\u306a\u3069-!@#$^&\u311c", "type": "d" }, { "isDir": true, "name": "\u6587\uff41\u3000\uff44\u3000\uff4d\u3000\uff49\u3000\uff4e\u65b9\u306a\u3069-!@$^&\u311c", "type": "d" }, { "isDir": false, "name": "a.sh", "type": "f" }, { "isDir": false, "name": "a.tar", "type": "f" }, { "isDir": false, "name": "a.tbz", "type": "f" }, { "isDir": false, "name": "busybox-1.tar", "type": "f" }, { "isDir": false, "name": "busybox-123.tar", "type": "f" }, { "isDir": false, "name": "busybox.tar", "type": "f" }, { "isDir": false, "name": "busybox_unstripped", "type": "f" }, { "isDir": false, "name": "c.tgz", "type": "f" }, { "isDir": false, "name": "centos-1.tar", "type": "f" }, { "isDir": false, "name": "container-station.sh", "type": "f" }, { "isDir": false, "name": "container-station_1.7.1722_x86.qpkg", "type": "f" }, { "isDir": false, "name": "d.tgz", "type": "f" }, { "isDir": false, "name": "disk-image", "type": "f" }, { "isDir": false, "name": "insmod_iptables.sh", "type": "f" }, { "isDir": false, "name": "iptable_mangle.ko", "type": "f" }, { "isDir": false, "name": "ltrace", "type": "f" }, { "isDir": false, "name": "osd", "type": "f" }, { "isDir": false, "name": "strace", "type": "f" }, { "isDir": false, "name": "ttyjs_0.1.1_amd64.qpkg", "type": "f" }, { "isDir": false, "name": "ubuntu-1.tar", "type": "f" }, { "isDir": false, "name": "ubuntu-123.tar", "type": "f" }, { "isDir": false, "name": "xt_CHECKSUM.ko", "type": "f" } ]
Create the directory or file, if they do not already exist.
Parameters: - dirname – directory name
- basename – the base name of dirname path
Request JSON Object: - name (string) – name of directory or file [required]
- isDir (boolean) – is directory or not [required]
- content (string) – context of file [required]
Example request
$ curl -sq -XPOST -b cookies.txt -d '{"name":"new_folder", "isDir":true}' \ http://${QIP}:${QPORT}/api/v1/sharefolder/Public/ $ curl -sq -XPOST -b cookies.txt \ -d '{"name":"new_file.json", "isDir":false, "context": ""}' \ http://${QIP}:${QPORT}/api/v1/sharefolder/Public/new_folder/ $ curl -sq -XPOST -b cookies.txt \ -d '{"name":"new_file.txt", "isDir":false, "context":"I am context."}' \ http://${QIP}:${QPORT}/api/v1/sharefolder/Public/new_folder/
Example response
{} {} {}
Delete selected file
Parameters: - dirname – directory name
- basename – the base name of dirname path
Example request
$ curl -sq -XDELETE -b cookies.txt \ http://${QIP}:${QPORT}/api/v1/sharefolder/Public/new_folder/new_file.json
Example response
Delete directories and their contents
Parameters: - dirname – directory name
- basename – the base name of dirname path
Example request
$ curl -sq -XDELETE -b cookies.txt \ http://${QIP}:${QPORT}/api/v1/sharefolder/Public/new_folder/
Example response
{}