Import and Export¶
Export¶
-
POST/api/v1/container/(string: container_type)/(string: container_id)/export¶ Create an export task for container id
container_idof container typecontainer_type. For JSON fields, checkGET /api/v1/export/. The path must be under the folders byGET /api/v1/sharefolder/(string:path).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: false
- force (boolean) – Force rewrite file or not. Default: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,20})$- only [a-zA-Z0-9-_] are allowed, size between 1 and 20
- Extract filename and filename extensions from
Example request of LXC
$ curl -sq -XPOST -b cookies.txt -d \ '{ "path": "test/c.tgz", "compress": true }' http://${QIP}:${QPORT}/api/v1/container/lxc/utest/export
Example response of LXC
{ "cid": "utest", "cname": "utest", "compress": true, "id": 1, "init": 1432022721, "path": "/test/c.tgz", "state": "waiting", "type": "lxc", "user": "Anonymous" }
Example request of Docker
$ curl -sq -XPOST -b cookies.txt -d \ '{ "path": "test/d.tgz", "compress": true }' http://${QIP}:${QPORT}/api/v1/container/docker/<container_id>/export
Example response of Docker
{ "cid": "1753ab55c36e99195042ddc875e59d4f877f1c140d25196ad34a5bece9f1cf3a", "cname": "DockerTestAPI", "compress": true, "id": 2, "init": 1432022721, "path": "/test/d.tgz", "state": "waiting", "type": "docker", "user": "Anonymous" }
-
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 (bool) – 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": "1753ab55c36e99195042ddc875e59d4f877f1c140d25196ad34a5bece9f1cf3a", "cname": "DockerTestAPI", "compress": true, "id": 2, "init": 1432022721, "path": "/test/d.tgz", "state": "waiting", "type": "docker", "user": "Anonymous" }, { "cid": "utest", "cname": "utest", "compress": true, "id": 1, "init": 1432022721, "path": "/test/c.tgz", "progress": 0, "start": 1432022721, "state": "running", "type": "lxc", "user": "Anonymous" } ]
-
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": 1, "init": 1432022721, "path": "/test/c.tgz", "progress": 50, "start": 1432022721, "state": "running", "type": "lxc", "user": "Anonymous" } ]
-
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
[]
Import¶
-
GET/api/v1/import/(string: dirpath)/¶ Given container archive path, query the configure
Parameters: - dirpath – archive file relative parent path in NAS
Query Parameters: - name – archive file name
Example request
$ curl -sq -XGET -b cookies.txt http://${QIP}:${QPORT}/api/v1/import/test/?name=c.tgz
Example response
{ "arch": "amd64", "autostart": false, "image": "ubuntu-trusty", "name": "utest", "network": {}, "resource": {}, "type": "lxc", "volume": {} }
-
POST/api/v1/import/(string: dirpath)/¶ Create an import task if name is given. The JSON parameters are the same as
POST /api/v1/container.Parameters: - dirpath – archive file relative parent path in NAS
Query Parameters: - 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/test/?name=c.tgz
Example response
{ "cid": "utest_import", "cname": "utest_import", "create_params": { "image": "import", "name": "utest_import", "network": { "hostname": "CustomHostName", "port": [ [ 12345, 1234, "udp" ] ] }, "resource": { "device": [ [ "allow", "video4linux_(81)", "rw" ] ], "limit": { "cputime": 512, "cpuweight": 512, "memory": "768m" } }, "tag": "latest", "type": "lxc", "volume": { "host": { "null": { "bind": "/mnt/vol1", "ro": true } } } }, "id": 1, "image": "import", "init": 1432022743, "path": "/test/c.tgz", "state": "waiting", "type": "lxc", "user": "Anonymous" }
-
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': 'import', u'volume': {u'host': {None: {u'bind': u'/mnt/vol1', u'ro': True}}}, 'tag': 'latest', u'type': u'lxc', u'network': {u'hostname': u'CustomHostName', u'port': [[12345, 1234, u'udp']]}}", "id": 1, "image": "import", "init": 1432022743, "path": "/test/c.tgz", "progress": 4, "start": 1432022743, "state": "running", "type": "lxc", "user": "Anonymous" } ]
-
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': 'import', u'volume': {u'host': {None: {u'bind': u'/mnt/vol1', u'ro': True}}}, 'tag': 'latest', u'type': u'lxc', u'network': {u'hostname': u'CustomHostName', u'port': [[12345, 1234, u'udp']]}}", "id": 1, "image": "import", "init": 1432022743, "path": "/test/c.tgz", "progress": 9, "start": 1432022743, "state": "running", "type": "lxc", "user": "Anonymous" } ]
-
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
[]
File operations¶
List shared folders. If
pathdoes not exist, it will return 400 error.Parameters: - path – path of a folder
Response JSON Object: - name (string) – directory name or file name
- type (string) –
dis directory,fis file. [Deprecated] - is_dir (bool) – is directory or not
- write (bool) – 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/test $ curl -sq -b cookies.txt http://${QIP}:${QPORT}/api/v1/sharefolder/Public
Example response
[ { "is_dir": true, "name": "test", "totalsize": "40G", "type": "d", "usedsize": "143M", "write": true } ] [ { "is_dir": true, "name": "backup", "type": "d" }, { "is_dir": true, "name": "selenium", "type": "d" }, { "is_dir": true, "name": "spec", "type": "d" }, { "is_dir": false, "name": "c.tgz", "type": "f" }, { "is_dir": false, "name": "d.tgz", "type": "f" }, { "is_dir": false, "name": "runner.html", "type": "f" } ] { "error": { "code": 400, "message": "Public" } }
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]
- is_dir (bool) – is directory or not [required]
- content (string) – context of file [required]
Example request
$ curl -sq -XPOST -b cookies.txt -d '{"name":"new_folder", "is_dir":true}' \ http://${QIP}:${QPORT}/api/v1/sharefolder/test/ $ curl -sq -XPOST -b cookies.txt \ -d '{"name":"new_file.json", "is_dir":false, "context": ""}' \ http://${QIP}:${QPORT}/api/v1/sharefolder/test/new_folder/ $ curl -sq -XPOST -b cookies.txt \ -d '{"name":"new_file.txt", "is_dir":false, "context":"I am context."}' \ http://${QIP}:${QPORT}/api/v1/sharefolder/test/new_folder/
Example response
[ { "is_dir": true, "name": "backup", "type": "d" }, { "is_dir": true, "name": "new_folder", "type": "d" }, { "is_dir": true, "name": "selenium", "type": "d" }, { "is_dir": true, "name": "spec", "type": "d" }, { "is_dir": false, "name": "c.tgz", "type": "f" }, { "is_dir": false, "name": "d.tgz", "type": "f" }, { "is_dir": false, "name": "runner.html", "type": "f" } ] [ { "is_dir": false, "name": "new_file.json", "type": "f" } ] [ { "is_dir": false, "name": "new_file.json", "type": "f" }, { "is_dir": false, "name": "new_file.txt", "type": "f" } ] curl -sq -XPOST -b cookies.txt -d '{"name":"new_folder", "is_dir":true}' \ http://${QIP}:${QPORT}/api/v1/sharefolder/test/ | python -m json.tool; curl -sq -XPOST -b cookies.txt -d '{"name":"new_file.json", "is_dir":false, "context": ""}' \ http://${QIP}:${QPORT}/api/v1/sharefolder/test/new_folder/ | python -m json.tool; curl -sq -XPOST -b cookies.txt -d '{"name":"new_file.txt", "is_dir":false, "context":"I am context."}' \ http://${QIP}:${QPORT}/api/v1/sharefolder/test/new_folder/ | python -m json.tool;
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/test/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/test/new_folder/
Example response
{}