从虚拟机模板创建虚拟机
Headers
Authorization: OAuth the-session-uuidBody
{
"params": {
"names": [
"vm1",
"vm2"
],
"strategy": "InstantStart"
},
"systemTags": [],
"userTags": []
}上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"names":["vm1","vm2"],"strategy":"InstantStart"}}' \
http://localhost:8080/zstack/v1/vm-instances/36b46cb654273e779b0a260932eff9e4/create-vmInstance-from-templated-vmInstance参数列表
名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
name | List | body(包含在 | 虚拟机名称清单 |
| 4.2.6 |
templatedVmInstanceUuid | String | url | 模板虚拟机UUID |
| 4.2.6 |
strategy (可选) | String | body(包含在 | 创建策略 |
| 4.2.6 |
description (可选) | String | body(包含在 | 资源的详细描述 |
| 4.2.6 |
cpuNum (可选) | Integer | body(包含在 | CPU核数 |
| 4.2.6 |
memorySize (可选) | Long | body(包含在 | 内存大小 |
| 4.2.6 |
reservedMemorySize (可选) | Long | body(包含在 | 保留内存大小 |
| 4.2.6 |
l3NetworkUuids (可选) | List | body(包含在 | 分布式端口组UUID列表。可以指定一个或多个分布式端口组,虚拟机会在每个网络上创建一个网卡 |
| 4.2.6 |
defaultL3NetworkUuid (可选) | String | body(包含在 | 默认分布式端口组UUID |
| 4.2.6 |
vmNicParams (可选) | String | body(包含在 | 网卡信息 |
| 4.2.6 |
diskAOs (可选) | List | body(包含在 | 硬盘 |
| 4.2.6 |
zoneUuid (可选) | String | body(包含在 | 数据中心UUID |
| 4.2.6 |
clusterUuid (可选) | String | body(包含在 | 集群UUID |
| 4.2.6 |
hostUuid (可选) | String | body(包含在 | 主机UUID |
| 4.2.6 |
instanceOfferingUuid (可选) | String | body(包含在 | 计算规格UUID |
| 4.2.6 |
type (可选) | String | body(包含在 | 虚拟机类型 |
| 4.2.6 |
vmCustomSpecification (可选) | VmCustomSpecificationStruct | body(包含在 | 虚拟机自定义操作系统 |
| 4.10.18 |
systemTags (可选) | List | body | 系统标签 |
| 4.2.6 |
userTags (可选) | List | body | 用户标签 |
| 4.2.6 |
resetTpm (可选) | Boolean | body(包含在 | 创建的虚拟机是否重置 TPM 状态 |
| 5.0.0 |
API返回
返回示例
{
"result": {
"numberOfClonedVm": 1,
"inventories": [
{
"inventory": {
"uuid": "ab705dd924a9364f894ae26e809ec49b",
"name": "new vm name",
"description": "web server VM",
"zoneUuid": "b46d69aa62a6367ab22697617734ad20",
"clusterUuid": "bdbde667b79b341391c61492d6710585",
"imageUuid": "3d0ed05e73e43bd1ac7be7e083286977",
"hostUuid": "f356b94b091c33619e50ee93c63ea1e2",
"lastHostUuid": "0accca7bf978353a852a0dba7379efc6",
"instanceOfferingUuid": "e41ee31d1eae3f239d2f8736ac2eda2d",
"rootVolumeUuid": "7367b12147a5355fbdbcdc3379a4f776",
"platform": "Linux",
"defaultL3NetworkUuid": "31f5ccd03eb031e3a652fe24cc6483f3",
"type": "UserVm",
"hypervisorType": "KVM",
"memorySize": 8589934592,
"cpuNum": 1,
"allocatorStrategy": "LastHostPreferredAllocatorStrategy",
"createDate": "Nov 14, 2017 2:20:57 PM",
"lastOpDate": "Nov 14, 2017 2:20:57 PM",
"state": "Running",
"allVolumes": [
{
"uuid": "7367b12147a5355fbdbcdc3379a4f776",
"name": "Root-Volume-For-VM-ab705dd924a9364f894ae26e809ec49b",
"primaryStorageUuid": "6d24676efd2c3b028ea6bfdef66cc6a1",
"vmInstanceUuid": "ab705dd924a9364f894ae26e809ec49b",
"diskOfferingUuid": "3431860972293269988a28f4b6f8ad68",
"rootImageUuid": "3d0ed05e73e43bd1ac7be7e083286977",
"installPath": "/zstack_ps/rootVolumes/acct-36c27e8ff05c4780bf6d2fa65700f22e/vol-7367b12147a5355fbdbcdc3379a4f776/7367b12147a5355fbdbcdc3379a4f776.qcow2",
"type": "Root",
"format": "qcow2",
"size": 107374182400,
"actualSize": 21474836480,
"deviceId": 0,
"state": "Enabled",
"status": "Ready",
"createDate": "Nov 14, 2017 2:20:57 PM",
"lastOpDate": "Nov 14, 2017 2:20:57 PM"
}
]
}
}
]
}
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| success | boolean | 4.2.6 | |
| result | CloneVmInstanceResults | 详情参考result | 4.2.6 |
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 4.2.6 |
result
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| numberOfClonedVm | int | 4.2.6 | |
| inventories | List | 详情参考inventories | 4.2.6 |
inventories
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 4.2.6 |
| inventory | VmInstanceInventory | 详情参考inventory | 4.2.6 |
error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| name | String | 资源名称 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| zoneUuid | String | 数据中心UUID | 0.6 |
| clusterUuid | String | 集群UUID | 0.6 |
| imageUuid | String | 镜像UUID | 0.6 |
| hostUuid | String | 主机UUID | 0.6 |
| lastHostUuid | String | 0.6 | |
| instanceOfferingUuid | String | 计算规格UUID | 0.6 |
| rootVolumeUuid | String | 根硬盘UUID | 0.6 |
| platform | String | 0.6 | |
| architecture | String | 0.6 | |
| defaultL3NetworkUuid | String | 0.6 | |
| type | String | 0.6 | |
| hypervisorType | String | 0.6 | |
| memorySize | Long | 0.6 | |
| cpuNum | Integer | 0.6 | |
| cpuSpeed | Long | 0.6 | |
| allocatorStrategy | String | 0.6 | |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
| state | String | 0.6 | |
| guestOsType | String | 4.1.2 | |
| vmNics | List | 详情参考vmNics | 0.6 |
| allVolumes | List | 详情参考allVolumes | 0.6 |
| vmCdRoms | List | 详情参考vmCdRoms | 0.6 |
vmNics
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 4.7.13 |
| vmInstanceUuid | String | 虚拟机UUID | 4.7.13 |
| l3NetworkUuid | String | 分布式端口组UUID | 4.7.13 |
| ip | String | 4.7.13 | |
| mac | String | 4.7.13 | |
| hypervisorType | String | 4.7.13 | |
| netmask | String | 4.7.13 | |
| gateway | String | 4.7.13 | |
| metaData | String | 4.7.13 | |
| ipVersion | Integer | 4.7.13 | |
| driverType | String | 4.7.13 | |
| internalName | String | 4.7.13 | |
| deviceId | Integer | 4.7.13 | |
| type | String | 4.7.13 | |
| state | String | 网卡状态 | 4.7.13 |
| createDate | Timestamp | 创建时间 | 4.7.13 |
| lastOpDate | Timestamp | 最后一次修改时间 | 4.7.13 |
| usedIps | List | 详情参考usedIps | 4.7.13 |
usedIps
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 4.7.13 |
| ipRangeUuid | String | IP段UUID | 4.7.13 |
| l3NetworkUuid | String | 分布式端口组UUID | 4.7.13 |
| ipVersion | Integer | 4.7.13 | |
| ip | String | 4.7.13 | |
| netmask | String | 4.7.13 | |
| gateway | String | 4.7.13 | |
| usedFor | String | 4.7.13 | |
| ipInLong | long | 4.7.13 | |
| vmNicUuid | String | 虚拟机网卡UUID | 4.7.13 |
| createDate | Timestamp | 创建时间 | 4.7.13 |
| lastOpDate | Timestamp | 最后一次修改时间 | 4.7.13 |
allVolumes
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 4.7.13 |
| name | String | 资源名称 | 4.7.13 |
| description | String | 资源的详细描述 | 4.7.13 |
| primaryStorageUuid | String | 数据存储UUID | 4.7.13 |
| vmInstanceUuid | String | 虚拟机UUID | 4.7.13 |
| diskOfferingUuid | String | 硬盘规格UUID | 4.7.13 |
| rootImageUuid | String | 4.7.13 | |
| installPath | String | 4.7.13 | |
| type | String | 4.7.13 | |
| format | String | 4.7.13 | |
| size | Long | 4.7.13 | |
| actualSize | Long | 4.7.13 | |
| deviceId | Integer | 4.7.13 | |
| state | String | 4.7.13 | |
| status | String | 4.7.13 | |
| createDate | Timestamp | 创建时间 | 4.7.13 |
| lastOpDate | Timestamp | 最后一次修改时间 | 4.7.13 |
| isShareable | Boolean | 4.7.13 | |
| volumeQos | String | 4.7.13 | |
| lastDetachDate | Timestamp | 4.7.13 | |
| lastVmInstanceUuid | String | 4.7.13 |
vmCdRoms
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 4.7.13 |
| vmInstanceUuid | String | 虚拟机UUID | 4.7.13 |
| deviceId | Integer | 4.7.13 | |
| isoUuid | String | 4.7.13 | |
| isoInstallPath | String | 4.7.13 | |
| name | String | 资源名称 | 4.7.13 |
| description | String | 资源的详细描述 | 4.7.13 |
| createDate | Timestamp | 创建时间 | 4.7.13 |
| lastOpDate | Timestamp | 最后一次修改时间 | 4.7.13 |
error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
SDK示例
Java SDK
CreateVmInstanceFromTemplatedVmInstanceAction action = new CreateVmInstanceFromTemplatedVmInstanceAction();
action.names = asList("vm1","vm2");
action.templatedVmInstanceUuid = "ff09d4fb092a31e681abdfda0e709900";
action.strategy = "InstantStart";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
CreateVmInstanceFromTemplatedVmInstanceAction.Result res = action.call();Python SDK
action = CreateVmInstanceFromTemplatedVmInstanceAction()
action.names = [vm1, vm2]
action.templatedVmInstanceUuid = "ff09d4fb092a31e681abdfda0e709900"
action.strategy = "InstantStart"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()