api-ref: add API reference for capsule

Change-Id: I298c1e9dfdab01b55504895b6279437089014c08
This commit is contained in:
Hongbin Lu 2019-05-13 03:31:17 +00:00
parent d1684a6795
commit 125f2a25b6
7 changed files with 1080 additions and 4 deletions

385
api-ref/source/capsules.inc Normal file
View File

@ -0,0 +1,385 @@
.. -*- rst -*-
=======================
Manage Capsules (Pods)
=======================
Lists, creates, shows details for, and deletes capsules.
Capsules is a collection of containers that can run on a host.
It is basically a Zun implementation of Kubernetes Pod.
Containers inside a capsule share the Neutron network and Cinder volumes.
Create new capsule
==================
.. rest_method:: POST /v1/capsules/
Create new capsule.
Response Codes
--------------
.. rest_status_code:: success status.yaml
- 202
.. rest_status_code:: error status.yaml
- 400
- 401
- 403
Request
-------
Capsule Template
^^^^^^^^^^^^^^^^
.. rest_parameters:: parameters.yaml
- template: capsule-template-request
- kind: capsule-kind-request
- metadata: capsule-metadata-request
- metadata.labels: capsule-labels-request
- metadata.name: capsule-name-request
- spec: capsule-spec-request
.. _create-capsule-spec:
Capsule Spec
^^^^^^^^^^^^
.. rest_parameters:: parameters.yaml
- containers: capsule-containers-request
- initContainers: capsule-initContainers-request
- restartPolicy: capsule-restartPolicy-request
- volumes: capsule-volumes-request
.. _create-capsule-container:
Capsule Container
^^^^^^^^^^^^^^^^^
.. rest_parameters:: parameters.yaml
- image: image
- command: capsule-command-request
- args: capsule-args-request
- env: environment-request
- name: capsule-container-name-request
- ports: capsule-ports-request
- ports.containerPort: capsule-ports-containerPort
- ports.protocol: capsule-ports-protocol
- resources: capsule-resources-request
- resources.cpu: capsule-resources-cpu
- resources.memory: capsule-resources-memory
- volumeMounts: capsule-volumeMounts-request
- volumeMounts.name: capsule-volumeMounts-name
- volumeMounts.mountPath: capsule-volumeMounts-mountPath
- workDir: workdir-request
.. _create-capsule-volume:
Capsule Volume
^^^^^^^^^^^^^^
.. rest_parameters:: parameters.yaml
- name: capsule-volume-name-request
- cinder: capsule-cinder-request
- cinder.volumeID: capsule-cinder-volumeID
- cinder.size: capsule-cinder-size
- cinder.autoRemove: capsule-cinder-autoRemove
Request Example
---------------
.. literalinclude:: samples/capsule-create-req.json
:language: javascript
Response
--------
Capsule
^^^^^^^
.. rest_parameters:: parameters.yaml
- addresses: capsule-addresses
- containers: capsule-containers-create
- cpu: capsule-cpu
- memory: capsule-memory
- uuid: capsule-uuid
- name: capsule-name
- labels: capsule-labels
- restart_policy: capsule-restart_policy
- created_at: created_at
- updated_at: updated_at
- user_id: capsule-user_id
- project_id: capsule-project_id
- status: capsule-status
- status_reason: capsule-status_reason
- links: capsule-links
.. _create-capsule-container-response:
Capsule Container
^^^^^^^^^^^^^^^^^
.. rest_parameters:: parameters.yaml
- addresses: addresses
- image: image
- labels: labels
- disk: disk
- security_groups: security_groups
- task_state: task_state
- user_id: user_id
- uuid: container_uuid
- hostname: hostname
- environment: environment
- memory: memory
- project_id: container-project_id
- status: status
- environment: environment
- workdir: workdir
- healthcheck: healthcheck
- auto_remove: auto_remove
- auto_heal: auto_heal
- cpu_policy: cpu_policy
- image_driver: image_driver
- status_detail: status_detail
- status_reason: status_reason
- name: name
- restart_policy: restart_policy
- cpu: cpu
- command: command
- registry_id: registry_id
- ports: ports
- interactive: interactive
Response Example
----------------
.. literalinclude:: samples/capsule-create-resp.json
:language: javascript
List all capsules
=================
.. rest_method:: GET /v1/capsules/
List all available capsules in Zun.
Response Codes
--------------
.. rest_status_code:: success status.yaml
- 200
.. rest_status_code:: error status.yaml
- 401
- 403
Request
-------
This request does not contain anything in the request body.
Response
--------
Capsule
^^^^^^^
.. rest_parameters:: parameters.yaml
- addresses: capsule-addresses
- containers: capsule-containers-list
- cpu: capsule-cpu
- memory: capsule-memory
- uuid: capsule-uuid
- name: capsule-name
- labels: capsule-labels
- restart_policy: capsule-restart_policy
- created_at: created_at
- updated_at: updated_at
- user_id: capsule-user_id
- project_id: capsule-project_id
- status: capsule-status
- status_reason: capsule-status_reason
- links: capsule-links
.. _list-capsule-container-response:
Capsule Container
^^^^^^^^^^^^^^^^^
.. rest_parameters:: parameters.yaml
- addresses: addresses
- image: image
- labels: labels
- disk: disk
- security_groups: security_groups
- task_state: task_state
- user_id: user_id
- uuid: container_uuid
- hostname: hostname
- environment: environment
- memory: memory
- project_id: container-project_id
- status: status
- environment: environment
- workdir: workdir
- healthcheck: healthcheck
- auto_remove: auto_remove
- auto_heal: auto_heal
- cpu_policy: cpu_policy
- image_driver: image_driver
- status_detail: status_detail
- status_reason: status_reason
- name: name
- restart_policy: restart_policy
- cpu: cpu
- command: command
- registry_id: registry_id
- ports: ports
- interactive: interactive
Response Example
----------------
.. literalinclude:: samples/capsule-get-all-resp.json
:language: javascript
Show details of a capsule
=========================
.. rest_method:: GET /v1/capsules/{capsule_ident}
Get all information of a capsule in Zun.
Response Codes
--------------
.. rest_status_code:: success status.yaml
- 200
.. rest_status_code:: error status.yaml
- 401
- 403
- 404
Request
-------
.. rest_parameters:: parameters.yaml
- capsule_ident: capsule_ident
Response
--------
Capsule
^^^^^^^
.. rest_parameters:: parameters.yaml
- addresses: capsule-addresses
- containers: capsule-containers-show
- cpu: capsule-cpu
- memory: capsule-memory
- uuid: capsule-uuid
- name: capsule-name
- labels: capsule-labels
- restart_policy: capsule-restart_policy
- created_at: created_at
- updated_at: updated_at
- user_id: capsule-user_id
- project_id: capsule-project_id
- status: capsule-status
- status_reason: capsule-status_reason
- links: capsule-links
.. _show-capsule-container-response:
Capsule Container
^^^^^^^^^^^^^^^^^
.. rest_parameters:: parameters.yaml
- addresses: addresses
- image: image
- labels: labels
- disk: disk
- security_groups: security_groups
- task_state: task_state
- user_id: user_id
- uuid: container_uuid
- hostname: hostname
- environment: environment
- memory: memory
- project_id: container-project_id
- status: status
- environment: environment
- workdir: workdir
- healthcheck: healthcheck
- auto_remove: auto_remove
- auto_heal: auto_heal
- cpu_policy: cpu_policy
- image_driver: image_driver
- status_detail: status_detail
- status_reason: status_reason
- name: name
- restart_policy: restart_policy
- cpu: cpu
- command: command
- registry_id: registry_id
- ports: ports
- interactive: interactive
Response Example
----------------
.. literalinclude:: samples/capsule-show-resp.json
:language: javascript
Delete a capsule
================
.. rest_method:: DELETE /v1/capsules/{capsule_ident}
Delete a capsule.
Response Codes
--------------
.. rest_status_code:: success status.yaml
- 204
.. rest_status_code:: error status.yaml
- 401
- 403
- 404
- 409
Request
-------
.. rest_parameters:: parameters.yaml
- capsule_ident: capsule_ident
Response
--------
This request does not return anything in the response body.

View File

@ -7,6 +7,7 @@
.. rest_expand_all::
.. include:: urls.inc
.. include:: capsules.inc
.. include:: containers.inc
.. include:: images.inc
.. include:: services.inc

View File

@ -5,6 +5,12 @@ request_id:
description: |
A unique ID for tracking service request. The request ID associated
with the request by default appears in the service logs.
capsule_ident:
description: |
The UUID or name of capsule in Zun.
in: path
required: true
type: string
container_ident:
description: |
The UUID or name of container in Zun.
@ -291,7 +297,7 @@ auto_heal-request:
type: boolean
auto_remove:
description: |
enable auto-removal of the container on daemon side
Enable auto-removal of the container on daemon side
when the container's process exits.
in: body
required: true
@ -315,6 +321,333 @@ binary:
required: true
description: |
The name of the binary form of the Zun service.
capsule-addresses:
type: string
description: |
IP address of the capsule. This includes both ipv4 and/or ipv6 addresses.
in: body
required: true
capsule-args-request:
description: |
The arguments to the command.
in: body
required: false
type: array
capsule-cinder-autoRemove:
description: |
Whether to remove the volume when the capsule is deleted.
in: body
required: false
type: string
capsule-cinder-request:
description: |
The Cinder volume configuration.
There are two options to configure the volume: use an existing volume
or dynamically create one.
To specify an existing volume, set the ``volumeID`` key with
the UUID of the Cinder volume as value. For example:
.. code-block:: javascript
"cinder": {
"volumeID": "9e5b5387-ed3b-4b9d-ab1e-0ce1e9dd86a1",
"autoRemove": false
}
To create a volume, set the ``size`` key with its size as value.
For example:
.. code-block:: javascript
"cinder": {
"size": 1,
"autoRemove": true
}
The ``autoRemove`` key is optional for deciding the cleanup of the
volume.
in: body
required: true
type: object
capsule-cinder-size:
description: |
The size of the Cinder volume.
in: body
required: false
type: string
capsule-cinder-volumeID:
description: |
The UUID of the Cinder volume.
in: body
required: false
type: string
capsule-command-request:
description: |
The command of the container.
in: body
required: false
type: array
capsule-container-name-request:
description: |
The name of the container.
in: body
required: false
type: string
capsule-containers-create:
description: |
List of :ref:`containers<create-capsule-container-response>` belonging
to the capsule. There must be at least one container in a capsule.
in: body
required: true
type: object
capsule-containers-list:
description: |
List of :ref:`containers<list-capsule-container-response>` belonging
to the capsule. There must be at least one container in a capsule.
in: body
required: true
type: object
capsule-containers-request:
description: |
A list of :ref:`containers <create-capsule-container>` objects.
in: body
required: true
type: array
capsule-containers-show:
description: |
List of :ref:`containers<show-capsule-container-response>` belonging
to the capsule. There must be at least one container in a capsule.
in: body
required: true
type: object
capsule-cpu:
description: |
The number of virtual cpus of the capsule.
in: body
required: true
type: float
capsule-initContainers-request:
description: |
A list of :ref:`init containers <create-capsule-container>` objects.
in: body
required: false
type: array
capsule-kind-request:
description: |
A string value representing the type of this object.
Its value is ``capsule``.
in: body
required: true
type: string
capsule-labels:
description: |
The labels of the capsule.
in: body
required: true
type: object
capsule-labels-request:
description: |
The labels added to the capsule.
in: body
required: false
type: object
capsule-links:
description: |
A list of relative links.
in: body
required: true
type: string
capsule-memory:
description: |
The capsule memory size in MiB.
in: body
required: true
type: string
capsule-metadata-request:
description: |
Capsule metadata in key-value format.
Keys can be ``name`` or ``labels``.
An example format would look as follows:
.. code-block:: javascript
"metadata": {
"labels": {"app": "web"},
"name": "demo"
}
in: body
required: false
type: object
capsule-name:
description: |
The name of the capsule.
in: body
required: true
type: string
capsule-name-request:
description: |
The name of the capsule.
in: body
required: false
type: string
capsule-ports-containerPort:
description: |
The port to open in container.
Its value must be a number between ``1`` and ``65535``.
in: body
required: false
type: integer
capsule-ports-protocol:
description: |
The protocol. Its value can be ``TCP`` or ``UDP``.
Default is ``TCP``.
in: body
required: false
type: string
capsule-ports-request:
description: |
List of ports to expose from the container.
Each item is a dictionary must contain a ``containerPort`` key.
Optionally, it can contain a ``protocol`` key.
An example format would look as follows:
.. code-block:: javascript
"ports": [{
"protocol": "TCP",
"containerPort": 80
}]
in: body
required: false
type: array
capsule-project_id:
description: |
The UUID of the project to which this capsule belongs.
in: body
required: true
type: string
capsule-resources-cpu:
description: |
The number of virtual CPU.
in: body
required: false
type: float
capsule-resources-memory:
description: |
The amount of memory in MiB.
in: body
required: false
type: integer
capsule-resources-request:
description: |
Compute Resources required by this container.
Supported compute resources are ``cpu`` and ``memory``.
An example format would look as follows:
.. code-block:: javascript
"resources": {
"requests": {
"cpu": 0.1,
"memory": 128
}}
in: body
required: false
type: object
capsule-restart_policy:
description: |
Restart policy for all containers within the capsule.
in: body
required: true
type: object
capsule-restartPolicy-request:
description: |
Restart policy for all containers within the capsule.
Its value can be ``Always``, ``OnFailure``, or ``Never``.
in: body
required: false
type: string
capsule-spec-request:
description: |
Specification of the desired behavior of the capsule.
See :ref:`create-capsule-spec`.
in: body
required: true
type: object
capsule-status:
description: |
The current state of the capsule.
in: body
required: true
type: string
capsule-status_reason:
description: |
The reason of capsule current status.
in: body
required: true
type: string
capsule-template-request:
description: |
A template for capsule.
in: body
required: true
type: object
capsule-user_id:
description: |
The user ID of the user who owns the capsule.
in: body
required: true
type: string
capsule-uuid:
description: |
The UUID of the capsule.
in: body
required: true
type: string
capsule-volume-name-request:
description: |
The name of the volume.
in: body
required: true
type: string
capsule-volumeMounts-mountPath:
description: |
The path within the container at which the volume should be mounted.
in: body
required: false
type: string
capsule-volumeMounts-name:
description: |
The name of the volume
in: body
required: false
type: string
capsule-volumeMounts-request:
description: |
List of volumes to mount into the container's filesystem.
Each item must contain a ``name`` key and a ``mountPath`` key.
An example format would look as follows:
.. code-block:: javascript
"volumeMounts": [{
"mountPath": "/work-dir",
"name": "workdir"
}]
in: body
required: false
type: array
capsule-volumes-request:
description: |
List of :ref:`volumes<create-capsule-volume>` that can be mounted by
containers in this capsule.
in: body
required: false
type: array
command:
description: |
Send command to the container.
@ -327,6 +660,12 @@ command-request:
in: body
required: false
type: string
container-project_id:
description: |
The UUID of the project to which this container belongs.
in: body
required: true
type: string
container-request:
description: |
The number of containers
@ -379,9 +718,15 @@ container_list:
required: true
description: |
The list of all containers in Zun.
container_uuid:
description: |
The UUID of the container.
in: body
required: true
type: string
cpu:
description: |
The number of virtual cpus.
The number of virtual cpus of the container.
in: body
required: true
type: float
@ -398,6 +743,13 @@ cpu-response:
in: body
required: true
type: object
cpu_policy:
description: |
The CPU policy of the container. Its value can be ``dedicated`` or
``shared``.
in: body
required: true
type: string
created_at:
description: |
The date and time when the resource was created.
@ -435,6 +787,12 @@ disabled_reason:
in: body
required: true
type: string
disk:
description: |
The container disk size in GiB.
in: body
required: true
type: integer
disk-request:
description: |
The number of gigabytes of container disk
@ -456,13 +814,13 @@ enable_cpu_pinning:
type: object
environment:
description: |
The environment variables.
The environment variables to set in the container.
in: body
required: true
type: object
environment-request:
description: |
The environment variables.
The environment variables to set in the container.
in: body
required: false
type: object
@ -901,6 +1259,12 @@ ps_output:
in: body
required: true
type: dict
registry_id:
description: |
The ID of the image registry used by the container.
in: body
required: true
type: string
report_count:
description: |
The total number of report.

View File

@ -0,0 +1,76 @@
{
"template": {
"kind": "capsule",
"spec": {
"restartPolicy": "Always",
"initContainers": [
{
"workDir": "/",
"command": [
"wget",
"-O",
"/work-dir/index.html",
"https://www.openstack.org/"
],
"env": {
"ENV1": "env1-value1"
},
"image": "busybox",
"volumeMounts": [
{
"mountPath": "/work-dir",
"name": "workdir"
}
],
"resources": {
"requests": {
"cpu": 0.1,
"memory": 128
}
}
}
],
"containers": [
{
"workDir": "/",
"env": {
"ENV2": "env2-value"
},
"image": "nginx",
"volumeMounts": [
{
"mountPath": "/usr/share/nginx/html",
"name": "workdir"
}
],
"ports": [
{
"protocol": "TCP",
"containerPort": 80
}
],
"resources": {
"requests": {
"cpu": 0.5,
"memory": 512
}
}
}
],
"volumes": [
{
"cinder": {
"size": 1
},
"name": "workdir"
}
]
},
"metadata": {
"labels": {
"app": "web"
},
"name": "demo"
}
}
}

View File

@ -0,0 +1,67 @@
{
"status": "Creating",
"user_id": "c863491f37984815bf740836c86e9310",
"uuid": "a4bad62a-f3ba-4b14-b2ab-2af470a2f32c",
"links": [
{
"href": "http://openstack.example.com/v1/capsules/a4bad62a-f3ba-4b14-b2ab-2af470a2f32c",
"rel": "self"
},
{
"href": "http://openstack.example.com/capsules/a4bad62a-f3ba-4b14-b2ab-2af470a2f32c",
"rel": "bookmark"
}
],
"created_at": "2019-05-18 21:02:12.304734",
"labels": {
"app": "web"
},
"restart_policy": {
"MaximumRetryCount": "0",
"Name": "always"
},
"updated_at": null,
"name": "demo",
"memory": "512",
"project_id": "493378c3aa3e4315a39fe8b125f9eaaa",
"status_reason": null,
"cpu": 0.5,
"containers": [
{
"addresses": {},
"image": "nginx",
"labels": {},
"disk": 0,
"security_groups": [],
"task_state": null,
"user_id": "c863491f37984815bf740836c86e9310",
"uuid": "6df062d2-293c-4c35-af81-22d27ce47887",
"hostname": null,
"environment": {
"ENV2": "env2-value"
},
"memory": "512",
"project_id": "493378c3aa3e4315a39fe8b125f9eaaa",
"status": "Creating",
"workdir": "/",
"healthcheck": {},
"auto_remove": false,
"auto_heal": false,
"cpu_policy": "shared",
"image_driver": null,
"status_detail": null,
"status_reason": null,
"name": "capsule-demo-pi-9",
"restart_policy": {
"MaximumRetryCount": "10",
"Name": "on-failure"
},
"cpu": 0.5,
"command": [],
"registry_id": null,
"ports": [],
"interactive": true
}
],
"addresses": null
}

View File

@ -0,0 +1,95 @@
{
"capsules": [
{
"status": "Running",
"user_id": "c863491f37984815bf740836c86e9310",
"uuid": "a4bad62a-f3ba-4b14-b2ab-2af470a2f32c",
"links": [
{
"href": "http://openstack.example.com/v1/capsules/a4bad62a-f3ba-4b14-b2ab-2af470a2f32c",
"rel": "self"
},
{
"href": "http://openstack.example.com/capsules/a4bad62a-f3ba-4b14-b2ab-2af470a2f32c",
"rel": "bookmark"
}
],
"created_at": "2019-05-18 21:02:12",
"labels": {
"app": "web"
},
"restart_policy": {
"MaximumRetryCount": "0",
"Name": "always"
},
"updated_at": "2019-05-18 21:02:30",
"name": "demo",
"memory": "512",
"project_id": "493378c3aa3e4315a39fe8b125f9eaaa",
"status_reason": null,
"cpu": 0.5,
"containers": [
{
"addresses": {},
"image": "nginx",
"labels": {},
"disk": 0,
"security_groups": [],
"task_state": null,
"user_id": "c863491f37984815bf740836c86e9310",
"uuid": "6df062d2-293c-4c35-af81-22d27ce47887",
"hostname": "dce8bbff358a",
"environment": {
"ENV2": "env2-value"
},
"memory": "512",
"project_id": "493378c3aa3e4315a39fe8b125f9eaaa",
"status": "Running",
"workdir": "/",
"healthcheck": {},
"auto_remove": false,
"auto_heal": false,
"cpu_policy": "shared",
"image_driver": null,
"status_detail": null,
"status_reason": null,
"name": "capsule-demo-pi-9",
"restart_policy": {
"MaximumRetryCount": "10",
"Name": "on-failure"
},
"cpu": 0.5,
"command": [
"nginx",
"-g",
"daemon off;"
],
"registry_id": null,
"ports": [
80
],
"interactive": true
}
],
"addresses": {
"86f0b398-414f-4e6a-b569-21d3452eb769": [
{
"subnet_id": "48bdf0e5-49d0-4668-9dcf-c47ea69fb4c3",
"version": 4,
"preserve_on_delete": false,
"addr": "10.0.0.21",
"port": "d19617f2-6984-4c00-a914-da02b39fdc52"
},
{
"subnet_id": "54f53848-66fc-4697-ab31-a97579691312",
"version": 6,
"preserve_on_delete": false,
"addr": "fddf:ec1e:34b4:0:f816:3eff:feb3:6c0e",
"port": "d19617f2-6984-4c00-a914-da02b39fdc52"
}
]
}
}
],
"next": null
}

View File

@ -0,0 +1,88 @@
{
"status": "Running",
"user_id": "c863491f37984815bf740836c86e9310",
"uuid": "a4bad62a-f3ba-4b14-b2ab-2af470a2f32c",
"links": [
{
"href": "http://openstack.example.com/v1/capsules/a4bad62a-f3ba-4b14-b2ab-2af470a2f32c",
"rel": "self"
},
{
"href": "http://openstack.example.com/capsules/a4bad62a-f3ba-4b14-b2ab-2af470a2f32c",
"rel": "bookmark"
}
],
"created_at": "2019-05-18 21:02:12",
"labels": {
"app": "web"
},
"restart_policy": {
"MaximumRetryCount": "0",
"Name": "always"
},
"updated_at": "2019-05-18 21:02:30",
"name": "demo",
"memory": "512",
"project_id": "493378c3aa3e4315a39fe8b125f9eaaa",
"status_reason": null,
"cpu": 0.5,
"containers": [
{
"addresses": {},
"image": "nginx",
"labels": {},
"disk": 0,
"security_groups": [],
"task_state": null,
"user_id": "c863491f37984815bf740836c86e9310",
"uuid": "6df062d2-293c-4c35-af81-22d27ce47887",
"hostname": "dce8bbff358a",
"environment": {
"ENV2": "env2-value"
},
"memory": "512",
"project_id": "493378c3aa3e4315a39fe8b125f9eaaa",
"status": "Running",
"workdir": "/",
"healthcheck": {},
"auto_remove": false,
"auto_heal": false,
"cpu_policy": "shared",
"image_driver": null,
"status_detail": null,
"status_reason": null,
"name": "capsule-demo-pi-9",
"restart_policy": {
"MaximumRetryCount": "10",
"Name": "on-failure"
},
"cpu": 0.5,
"command": [
"nginx",
"-g",
"daemon off;"
],
"registry_id": null,
"ports": [80],
"interactive": true
}
],
"addresses": {
"86f0b398-414f-4e6a-b569-21d3452eb769": [
{
"subnet_id": "48bdf0e5-49d0-4668-9dcf-c47ea69fb4c3",
"version": 4,
"preserve_on_delete": false,
"addr": "10.0.0.21",
"port": "d19617f2-6984-4c00-a914-da02b39fdc52"
},
{
"subnet_id": "54f53848-66fc-4697-ab31-a97579691312",
"version": 6,
"preserve_on_delete": false,
"addr": "fddf:ec1e:34b4:0:f816:3eff:feb3:6c0e",
"port": "d19617f2-6984-4c00-a914-da02b39fdc52"
}
]
}
}