mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 07:48:55 +00:00
clh: Add Generation tools for API client
cloud-hypervisor provides an API server to send commands in a qmp and Firecracker style over an Unix socket. The API is defined via OpenAPI, this commit adds scripts to help to generate a client using: https://github.com/OpenAPITools/openapi-generator This will make easy to update any change related with the API in the future. Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
This commit is contained in:
parent
62cd08044d
commit
dcac021637
@ -79,6 +79,10 @@ The `virtcontainers` package relies on hypervisors to start and stop virtual mac
|
||||
sandboxes will be running. An hypervisor is defined by an Hypervisor interface implementation,
|
||||
and the default implementation is the QEMU one.
|
||||
|
||||
### Update cloud-hypervisor client code
|
||||
|
||||
See [docs](pkg/cloud-hypervisor/README.md)
|
||||
|
||||
## Agents
|
||||
|
||||
During the lifecycle of a container, the runtime running on the host needs to interact with
|
||||
|
21
virtcontainers/pkg/cloud-hypervisor/Makefile
Normal file
21
virtcontainers/pkg/cloud-hypervisor/Makefile
Normal file
@ -0,0 +1,21 @@
|
||||
#
|
||||
# Copyright (c) 2019 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
all: | update-yaml generate-client-code
|
||||
|
||||
generate-client-code: clean-generated-code
|
||||
docker run --rm \
|
||||
--user $$(id -u):$$(id -g) \
|
||||
-v $${PWD}:/local openapitools/openapi-generator-cli generate \
|
||||
-i /local/cloud-hypervisor.yaml \
|
||||
-g go \
|
||||
-o /local/client
|
||||
|
||||
update-yaml:
|
||||
curl -OL https://raw.githubusercontent.com/cloud-hypervisor/cloud-hypervisor/master/vmm/src/api/openapi/cloud-hypervisor.yaml
|
||||
|
||||
clean-generated-code:
|
||||
rm "./client" -rf
|
13
virtcontainers/pkg/cloud-hypervisor/README.md
Normal file
13
virtcontainers/pkg/cloud-hypervisor/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Cloud Hypervisor OpenAPI generated code
|
||||
|
||||
This directory provide tools to generate code client based
|
||||
on `cloud-hypervisor` `OpenAPI` schema.
|
||||
|
||||
## Update client to match latest Cloud Hypervisor server API
|
||||
|
||||
Requirements:
|
||||
- docker: `openapi-generator` is executed in a docker container
|
||||
|
||||
```
|
||||
make all
|
||||
```
|
406
virtcontainers/pkg/cloud-hypervisor/cloud-hypervisor.yaml
Normal file
406
virtcontainers/pkg/cloud-hypervisor/cloud-hypervisor.yaml
Normal file
@ -0,0 +1,406 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: Cloud Hypervisor API
|
||||
description: Local HTTP based API for managing and inspecting a cloud-hypervisor virtual machine.
|
||||
license:
|
||||
name: Apache 2.0
|
||||
url: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
version: 0.3.0
|
||||
|
||||
servers:
|
||||
- url: http://localhost/api/v1
|
||||
|
||||
paths:
|
||||
|
||||
/vmm.ping:
|
||||
get:
|
||||
summary: Ping the VMM to check for API server availability
|
||||
responses:
|
||||
200:
|
||||
description: The VMM information
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/VmmPingResponse'
|
||||
|
||||
/vmm.shutdown:
|
||||
put:
|
||||
summary: Shuts the cloud-hypervisor VMM.
|
||||
operationId: shutdownVMM
|
||||
responses:
|
||||
204:
|
||||
description: The VMM successfully shutdown.
|
||||
|
||||
/vm.info:
|
||||
get:
|
||||
summary: Returns general information about the cloud-hypervisor Virtual Machine (VM) instance.
|
||||
responses:
|
||||
200:
|
||||
description: The VM information
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/VmInfo'
|
||||
|
||||
/vm.create:
|
||||
put:
|
||||
summary: Create the cloud-hypervisor Virtual Machine (VM) instance. The instance is not booted, only created.
|
||||
operationId: createVM
|
||||
requestBody:
|
||||
description: The VM configuration
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/VmConfig'
|
||||
required: true
|
||||
responses:
|
||||
204:
|
||||
description: The VM instance was successfully created.
|
||||
|
||||
/vm.delete:
|
||||
put:
|
||||
summary: Delete the cloud-hypervisor Virtual Machine (VM) instance.
|
||||
operationId: deleteVM
|
||||
responses:
|
||||
204:
|
||||
description: The VM instance was successfully deleted.
|
||||
|
||||
/vm.boot:
|
||||
put:
|
||||
summary: Boot the previously created VM instance.
|
||||
operationId: bootVM
|
||||
responses:
|
||||
204:
|
||||
description: The VM instance successfully booted.
|
||||
404:
|
||||
description: The VM instance could not boot because it is not created yet
|
||||
|
||||
/vm.pause:
|
||||
put:
|
||||
summary: Pause a previously booted VM instance.
|
||||
operationId: pauseVM
|
||||
responses:
|
||||
204:
|
||||
description: The VM instance successfully paused.
|
||||
404:
|
||||
description: The VM instance could not pause because it is not created yet
|
||||
405:
|
||||
description: The VM instance could not pause because it is not booted.
|
||||
|
||||
/vm.resume:
|
||||
put:
|
||||
summary: Resume a previously paused VM instance.
|
||||
operationId: resumeVM
|
||||
responses:
|
||||
204:
|
||||
description: The VM instance successfully paused.
|
||||
404:
|
||||
description: The VM instance could not resume because it is not booted yet
|
||||
405:
|
||||
description: The VM instance could not resume because it is not paused.
|
||||
|
||||
/vm.shutdown:
|
||||
put:
|
||||
summary: Shut the VM instance down.
|
||||
operationId: shutdownVM
|
||||
responses:
|
||||
204:
|
||||
description: The VM instance successfully shut down.
|
||||
404:
|
||||
description: The VM instance could not shut down because is not created.
|
||||
405:
|
||||
description: The VM instance could not shut down because it is not started.
|
||||
|
||||
/vm.reboot:
|
||||
put:
|
||||
summary: Reboot the VM instance.
|
||||
operationId: rebootVM
|
||||
responses:
|
||||
204:
|
||||
description: The VM instance successfully rebooted.
|
||||
404:
|
||||
description: The VM instance could not reboot because it is not created.
|
||||
405:
|
||||
description: The VM instance could not reboot because it is not booted.
|
||||
|
||||
components:
|
||||
schemas:
|
||||
|
||||
VmmPingResponse:
|
||||
required:
|
||||
- version
|
||||
type: object
|
||||
properties:
|
||||
version:
|
||||
type: string
|
||||
description: Virtual Machine Monitor information
|
||||
|
||||
VmInfo:
|
||||
required:
|
||||
- config
|
||||
- state
|
||||
type: object
|
||||
properties:
|
||||
config:
|
||||
$ref: '#/components/schemas/VmConfig'
|
||||
state:
|
||||
type: string
|
||||
enum: [Created, Booted, Shutdown]
|
||||
description: Virtual Machine information
|
||||
|
||||
VmConfig:
|
||||
required:
|
||||
- kernel
|
||||
- cmdline
|
||||
type: object
|
||||
properties:
|
||||
cpus:
|
||||
$ref: '#/components/schemas/CpuConfig'
|
||||
memory:
|
||||
$ref: '#/components/schemas/MemoryConfig'
|
||||
kernel:
|
||||
$ref: '#/components/schemas/KernelConfig'
|
||||
cmdline:
|
||||
$ref: '#/components/schemas/CmdLineConfig'
|
||||
disks:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/DiskConfig'
|
||||
net:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/NetConfig'
|
||||
rng:
|
||||
$ref: '#/components/schemas/RngConfig'
|
||||
fs:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/FsConfig'
|
||||
pmem:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/PmemConfig'
|
||||
serial:
|
||||
$ref: '#/components/schemas/ConsoleConfig'
|
||||
console:
|
||||
$ref: '#/components/schemas/ConsoleConfig'
|
||||
devices:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/DeviceConfig'
|
||||
vhost_user_net:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/VhostUserNetConfig'
|
||||
vhost_user_blk:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/VhostUserBlkConfig'
|
||||
vsock:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/VsockConfig'
|
||||
iommu:
|
||||
type: boolean
|
||||
default: false
|
||||
description: Virtual machine configuration
|
||||
|
||||
CpuConfig:
|
||||
required:
|
||||
- cpu_count
|
||||
type: object
|
||||
properties:
|
||||
cpu_count:
|
||||
minimum: 1
|
||||
default: 1
|
||||
type: integer
|
||||
|
||||
MemoryConfig:
|
||||
required:
|
||||
- size
|
||||
type: object
|
||||
properties:
|
||||
size:
|
||||
type: integer
|
||||
format: int64
|
||||
default: 512 MB
|
||||
file:
|
||||
type: string
|
||||
mergeable:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
KernelConfig:
|
||||
required:
|
||||
- path
|
||||
type: object
|
||||
properties:
|
||||
path:
|
||||
type: string
|
||||
|
||||
CmdLineConfig:
|
||||
required:
|
||||
- args
|
||||
type: object
|
||||
properties:
|
||||
args:
|
||||
type: string
|
||||
|
||||
DiskConfig:
|
||||
required:
|
||||
- path
|
||||
type: object
|
||||
properties:
|
||||
path:
|
||||
type: string
|
||||
iommu:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
NetConfig:
|
||||
required:
|
||||
- ip
|
||||
- mask
|
||||
- mac
|
||||
type: object
|
||||
properties:
|
||||
tap:
|
||||
type: string
|
||||
ip:
|
||||
type: string
|
||||
mask:
|
||||
type: string
|
||||
mac:
|
||||
type: string
|
||||
iommu:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
RngConfig:
|
||||
required:
|
||||
- src
|
||||
type: object
|
||||
properties:
|
||||
src:
|
||||
type: string
|
||||
default: "/dev/urandom"
|
||||
iommu:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
FsConfig:
|
||||
required:
|
||||
- tag
|
||||
- sock
|
||||
- num_queues
|
||||
- queue_size
|
||||
type: object
|
||||
properties:
|
||||
tag:
|
||||
type: string
|
||||
sock:
|
||||
type: string
|
||||
num_queues:
|
||||
type: integer
|
||||
queue_size:
|
||||
type: integer
|
||||
cache_size:
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
PmemConfig:
|
||||
required:
|
||||
- file
|
||||
- size
|
||||
type: object
|
||||
properties:
|
||||
file:
|
||||
type: string
|
||||
size:
|
||||
type: integer
|
||||
format: int64
|
||||
iommu:
|
||||
type: boolean
|
||||
default: false
|
||||
mergeable:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
ConsoleConfig:
|
||||
required:
|
||||
- mode
|
||||
type: object
|
||||
properties:
|
||||
file:
|
||||
type: string
|
||||
mode:
|
||||
type: string
|
||||
enum: [Off, Tty, File, None]
|
||||
iommu:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
DeviceConfig:
|
||||
required:
|
||||
- path
|
||||
type: object
|
||||
properties:
|
||||
path:
|
||||
type: string
|
||||
iommu:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
VhostUserConfig:
|
||||
required:
|
||||
- sock
|
||||
- num_queues
|
||||
- queue_size
|
||||
type: object
|
||||
properties:
|
||||
sock:
|
||||
type: string
|
||||
num_queues:
|
||||
type: integer
|
||||
queue:size:
|
||||
type: integer
|
||||
|
||||
VhostUserNetConfig:
|
||||
required:
|
||||
- mac
|
||||
- vu_cfg
|
||||
type: object
|
||||
properties:
|
||||
mac:
|
||||
type: string
|
||||
vu_cfg:
|
||||
$ref: '#/components/schemas/VhostUserConfig'
|
||||
|
||||
VhostUserBlkConfig:
|
||||
required:
|
||||
- wce
|
||||
- vu_cfg
|
||||
type: object
|
||||
properties:
|
||||
wce:
|
||||
type: boolean
|
||||
vu_cfg:
|
||||
$ref: '#/components/schemas/VhostUserConfig'
|
||||
|
||||
VsockConfig:
|
||||
required:
|
||||
- cid
|
||||
- sock
|
||||
type: object
|
||||
properties:
|
||||
cid:
|
||||
type: integer
|
||||
format: int64
|
||||
minimum: 3
|
||||
description: Guest Vsock CID
|
||||
sock:
|
||||
type: string
|
||||
description: Path to UNIX domain socket, used to proxy vsock connections.
|
||||
iommu:
|
||||
type: boolean
|
||||
default: false
|
Loading…
Reference in New Issue
Block a user