跳转至

API 列表

1. 关闭虚拟机

1.1 接口描述

实现关闭虚拟机功能。

1.2 请求方法

PUT /v1/domain/shutdown

1.3 请求参数

1.3.1 query参数

参数名称 必选 类型 描述
proxy string 指定宿主机在哪个代理节点下
target string 指定虚拟机在哪个宿主机上

1.3.2 body参数

参数名称 必选 类型 描述
name array 需要关机的虚拟机名称的数组

1.4 请求示例

curl --header "X-Api-Key: dummy" --request PUT 'https://apiserver.example/v1/domain/shutdown?proxy=4c4c4544-0046-3110-8053-b2c04f463632&target=4c4c4544-0057-4d10-8044-c3c04f443032' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name":["game0", "game1"]
}'

1.5 响应示例

{"code":1000,"msg":"success","data":{"failed":[],"success":["game0","game1"]}}

2. 启动虚拟机

2.1 接口描述

启动已关闭的虚拟机。

2.2 请求方法

PUT /v1/domain/start

2.3 请求参数

2.3.1 query参数

参数名称 必选 类型 描述
proxy string 指定宿主机在哪个代理节点下
target string 指定虚拟机在哪个宿主机上

2.3.2 body参数

参数名称 必选 类型 描述
name array 需要关机的虚拟机名称的数组

2.4 请求示例

curl --header "X-Api-Key: dummy" --request PUT 'https://apiserver.example/v1/domain/start?proxy=4c4c4544-0046-3110-8053-b2c04f463632&target=4c4c4544-0057-4d10-8044-c3c04f443032' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name":["game0", "game1"]
}'

2.5 响应示例

{"code":1000,"msg":"success","data":{"failed":[],"success":["game0","game1"]}}

3. 重启虚拟机

3.1 接口描述

重启(reset)指定的虚拟机。

3.2 请求方法

PUT /v1/domain/reboot

3.3 请求参数

3.3.1 query 参数

参数名称 必选 类型 描述
proxy string 指定宿主机在哪个代理节点下
target string 指定虚拟机在哪个宿主机上

3.3.2 body 参数

参数名称 必选 类型 描述
name array 需要关机的虚拟机名称的数组

3.4 请求示例

curl --header "X-Api-Key: dummy" --request PUT 'https://apiserver.example/v1/domain/reboot?proxy=4c4c4544-0046-3110-8053-b2c04f463632&target=4c4c4544-0057-4d10-8044-c3c04f443032' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name":["game0", "game1"]
}'

3.5 响应示例

{"code":1000,"msg":"success","data":{"failed":[],"success":["game0","game1"]}}

4. 删除虚拟机

4.1 接口描述

在目标节点上删除指定的虚拟机。

4.2 请求方法

DELETE /v1/domain

4.3 请求参数

4.3.1 query 参数

参数名称 必选 类型 描述
proxy string 指定宿主机在哪个代理节点下
target string 指定虚拟机在哪个宿主机上

4.3.2 body 参数

参数名称 必选 类型 描述
name array 需要关机的虚拟机名称的数组
options string 删除参数,
值为"true"时表示删除虚拟机使用的存储卷,
否则,只删除虚拟机,保留虚拟机使用的存储卷

4.4 请求示例

curl --header "X-Api-Key: dummy" --request DELETE 'https://apiserver.example/v1/domain?proxy=4c4c4544-0046-3110-8053-b2c04f463632&target=4c4c4544-0057-4d10-8044-c3c04f443032' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name":["game0"],
    "options": "true"
}'

4.5 响应示例

{"code":1000,"msg":"success","data":{"failed":[],"success":["game0","game1"]}}

5. 创建虚拟机

5.1 接口描述

在指定节点上创建虚拟机。

5.2 请求方法

POST /v1/domain

5.3 请求参数

5.3.1 query 参数

参数名称 必选 类型 描述
proxy string 指定宿主机在哪个代理节点下
target string 指定虚拟机在哪个宿主机上

5.3.2 body 参数

参数名称 必选 类型 描述
name string 虚拟机名称
memory int 虚拟机内存
cpu_count int 虚拟机cpu
network string 虚拟机网络(kvm网络)
volume json 创建虚拟机所使用的信息。
sys_diskdata_disk两个参数不能同时使用。
可用字段如下:
storage_pool:存储池
backing_file:基础镜像(操作系统镜像)
backing_format:基础镜像格式
capacity:数据盘容量
format:数据盘格式(qcow2/raw)
sys_disk string 系统镜像路径。
当不使用volume参数时,必须指定一个已存在的系统镜像
data_disk string 数据镜像路径。
当不使用volume参数时,必须指定一个已存在的数据镜像
pci_devices json GPU信息。

5.4 请求示例

# 使用 volume 参数创建虚拟机
# 不用事先创建好镜像
curl --header "X-Api-Key: dummy" --request POST 'https://apiserver.example/v1/domain?proxy=4c4c4544-0046-3110-8053-b2c04f463632&target=4c4c4544-0057-4d10-8044-c3c04f443032' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "game0",
    "memory": 8388608,
    "cpu_count": 8,
    "network": "default",
    "volume": {
        "storage_pool": "vmdisk",
        "backing_file": "win.qcow2",
        "backing_format": "qcow2",
        "capacity": 100,
        "format": "qcow2"
    },
    "pci_devices": [
        {
            "domain":"0x0000",
            "bus":"0x42",
            "slot":"0x00",
            "function":"0x0"
        },
        {
            "domain":"0x0000",
            "bus":"0x42",
            "slot":"0x00",
            "function":"0x1"
        },
        {
            "domain":"0x0000",
            "bus":"0x42",
            "slot":"0x00",
            "function":"0x2"
        },
        {
            "domain":"0x0000",
            "bus":"0x42",
            "slot":"0x00",
            "function":"0x3"
        }
    ]
}'


# 使用已经创建好的镜像创建虚拟机,不能再使用volume参数
curl --header "X-Api-Key: dummy" --request POST 'https://apiserver.example/v1/domain?proxy=4c4c4544-0046-3110-8053-b2c04f463632&target=4c4c4544-0057-4d10-8044-c3c04f4430322' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "game1",
    "memory": 8388608,
    "cpu_count": 8,
    "network": "default",
    "sys_disk": "/data/test/vmdisk/game1.qcow2",
    "data_disk": "/data/test/vmdisk/game1-data.qcow2",
    "pci_devices": [
        {
            "domain":"0x0000",
            "bus":"0x05",
            "slot":"0x00",
            "function":"0x0"
        },
        {
            "domain":"0x0000",
            "bus":"0x05",
            "slot":"0x00",
            "function":"0x1"
        },
        {
            "domain":"0x0000",
            "bus":"0x05",
            "slot":"0x00",
            "function":"0x2"
        },
        {
            "domain":"0x0000",
            "bus":"0x05",
            "slot":"0x00",
            "function":"0x3"
        }
    ]
}'

5.5 响应示例

{"code":1000,"msg":"success"}