CloneVmInstance

API Request

URLs
PUT zstack/v1/vm-instances/{vmInstanceUuid}/actions
Headers
Authorization: OAuth the-session-uuid
Body
{
  "cloneVmInstance": {
    "strategy": "InstantStart",
    "names": [
      "vm1",
      "vm2"
    ],
    "full": false
  },
  "systemTags": [],
  "userTags": []
}
Note: In the preceding sample, both systemTags and userTags are optional. These two fields can be included in the body structure.
Curl Sample
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"cloneVmInstance":{"strategy":"InstantStart","names":["vm1","vm2"],"full":false}}' \
http://localhost:8080/zstack/v1/vm-instances/c4d628c203433f64b062ad07c8edf10d/actions
Request Parameters
Name Type Location Description Optional Value Starting Version
vmInstanceUuid String url The VM instance UUID. 0.6
strategy String body (contained in the cloneVmInstance structure) Optional. The strategy.
  • InstantStart
  • JustCreate
0.6
names List body (contained in the cloneVmInstance structure) The VM instance name list. 0.6
full Boolean body (contained in the cloneVmInstance structure) Optional. Whether to clone the data volume that is attached to the VM instance. 2.5.0
systemTags List body Optional. The system tags. 0.6
userTags List body Optional. The user tags. 0.6
Note:
  • When you clone a VM instance in ZStack Cloud, you can specify an affinity group by adding the affinityGroup option to SystemTags.
    • Format of the affinityGroup option: affinityGroupUuid::UUID
    • Example: affinityGroupUuid::5fd71606d5af451d981413f35367a8d6
  • When you clone a VM instance in ZStack Cloud, you can specify the volume provisioning strategy by adding the volumeProvisioningStrategy option to SystemTags. The SystemTag is passed by using the rootVolumeSystemTags parameter.
    • Format of the volumeProvisioningStrategy option: volumeProvisioningStrategy::ThinProvisioning, volumeProvisioningStrategy::ThickProvisioning
    • Example: volumeProvisioningStrategy::ThinProvisioning, volumeProvisioningStrategy::ThickProvisioning

API Response

Note:

If the API operation succeeds, the success element in the API response is true. The number of VM instances that were successfully cloned is contained in the numberOfClonedVm element. In your actual practice, some VM instances might fail to be cloned due to resource constraints. The reason for the clone failure of each VM instance is contained in the error field in inventories.

Sample Response
{
  "result": {
    "numberOfClonedVm": 1.0,
    "inventories": [
      {
        "inventory": {
          "uuid": "327b60d6b8cd31489ade6f4830bcec16",
          "name": "new vm name",
          "description": "web server VM",
          "zoneUuid": "d886a09330e13282b7a320a98d0a53ec",
          "clusterUuid": "f6f07dff7ede3b8cac7c8595a1698832",
          "imageUuid": "3b7ff22eb60d38318835817ba6a2b6a2",
          "hostUuid": "70c0f5223d083dfea2f1a02f69906306",
          "lastHostUuid": "123f7f85f82f3e99940836d97ae18e04",
          "instanceOfferingUuid": "001537d10c433857a7a98ae0a362c910",
          "rootVolumeUuid": "c8be7ec6a8573d98a580b457a7245141",
          "platform": "Linux",
          "defaultL3NetworkUuid": "2ac50b85591b3e87b2686c529cf062f9",
          "type": "UserVm",
          "hypervisorType": "KVM",
          "memorySize": 8.589934592E9,
          "cpuNum": 1.0,
          "allocatorStrategy": "LastHostPreferredAllocatorStrategy",
          "createDate": "Nov 14, 2017 10:20:57 PM",
          "lastOpDate": "Nov 14, 2017 10:20:57 PM",
          "state": "Running",
          "allVolumes": [
            {
              "uuid": "c8be7ec6a8573d98a580b457a7245141",
              "name": "Root-Volume-For-VM-327b60d6b8cd31489ade6f4830bcec16",
              "primaryStorageUuid": "c2a27c5268493a5cba84b94e37b86b4d",
              "vmInstanceUuid": "327b60d6b8cd31489ade6f4830bcec16",
              "diskOfferingUuid": "358e00e7245a39b9aa1c1849d6ba9701",
              "rootImageUuid": "3b7ff22eb60d38318835817ba6a2b6a2",
              "installPath": "/Cloud_ps/rootVolumes/acct-36c27e8ff05c4780bf6d2fa65700f22e/vol-c8be7ec6a8573d98a580b457a7245141/c8be7ec6a8573d98a580b457a7245141.qcow2",
              "type": "Root",
              "format": "qcow2",
              "size": 1.073741824E11,
              "actualSize": 2.147483648E10,
              "deviceId": 0.0,
              "state": "Enabled",
              "status": "Ready",
              "createDate": "Nov 14, 2017 10:20:57 PM",
              "lastOpDate": "Nov 14, 2017 10:20:57 PM"
            }
          ]
        },
        "started": false
      }
    ]
  }
}
Name Type Description Starting Version
success boolean 0.6
error ErrorCode The error code. If not null, the operation fails, or vice versa. For more information, see error. 0.6
result CloneVmInstanceResults See result. 0.6
error ErrorCode See error. 0.6
#error
Name Type Description Starting Version
code String The error code, which is a numbered or alphanumeric code that specifies an error. For example, SYS.1000, HOST.1001. 0.6
description String The brief description of the error. 0.6
details String The details about the error. 0.6
elaboration String The reserved field. Default value: null. 0.6
opaque LinkedHashMap The reserved field. Default value: null. 0.6
cause ErrorCode The root error, which is the associated root cause of the current error. If no root error exists, this parameter is null. 0.6
#result
Name Type Description Starting Version
numberOfClonedVm int 0.6
inventories List See inventories. 0.6
#inventories
Name Type Description Starting Version
error ErrorCode See error. 0.6
inventory VmInstanceInventory See inventory. 0.6
#error
Name Type Description Starting Version
code String The error code, which is a numbered or alphanumeric code that specifies an error. For example, SYS.1000, HOST.1001. 0.6
description String The brief description of the error. 0.6
details String The details about the error. 0.6
elaboration String The reserved field. Default value: null. 0.6
opaque LinkedHashMap The reserved field. Default value: null. 0.6
cause ErrorCode The root error, which is the associated root cause of the current error. If no root error exists, this parameter is null. 0.6
#inventory
Name Type Description Starting Version
uuid String The resource UUID. 0.6
name String The resource name. 0.6
description String The detailed description of the resource. 0.6
zoneUuid String The zone UUID. 0.6
clusterUuid String The cluster UUID. 0.6
imageUuid String The image UUID. 0.6
hostUuid String The host UUID. 0.6
lastHostUuid String 0.6
instanceOfferingUuid String The instance offering UUID. 0.6
rootVolumeUuid String The root volume UUID. 0.6
platform 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 The creation date. 0.6
lastOpDate Timestamp The last operation date. 0.6
state String 0.6
vmNics List See vmNics. 0.6
allVolumes List See allVolumes. 0.6
#vmNics
Name Type Description Starting Version
uuid String The resource UUID. 0.6
vmInstanceUuid String The VM instance UUID. 0.6
l3NetworkUuid String The L3 network UUID. 0.6
ip String 0.6
mac String 0.6
netmask String 0.6
gateway String 0.6
metaData String 0.6
deviceId Integer 0.6
createDate Timestamp The creation date. 0.6
lastOpDate Timestamp The last operation date. 0.6
#allVolumes
Name Type Description Starting Version
uuid String The resource UUID. 0.6
name String The resource name. 0.6
description String The detailed description of the resource. 0.6
primaryStorageUuid String The primary storage UUID. 0.6
vmInstanceUuid String The VM instance UUID. 0.6
diskOfferingUuid String The disk offering UUID. 0.6
rootImageUuid String 0.6
installPath String 0.6
type String 0.6
format String 0.6
size Long 0.6
actualSize Long 0.6
deviceId Integer 0.6
state String 0.6
status String 0.6
createDate Timestamp The creation date. 0.6
lastOpDate Timestamp The last operation date. 0.6
isShareable Boolean 0.6

SDK Sample

Java SDK
CloneVmInstanceAction action = new CloneVmInstanceAction();
action.vmInstanceUuid = "c4d628c203433f64b062ad07c8edf10d";
action.strategy = "InstantStart";
action.names = asList("vm1","vm2");
action.full = false;
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
CloneVmInstanceAction.Result res = action.call();
Python SDK
CloneVmInstanceAction action = CloneVmInstanceAction()
action.vmInstanceUuid = "c4d628c203433f64b062ad07c8edf10d"
action.strategy = "InstantStart"
action.names = [vm1, vm2]
action.full = false
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
CloneVmInstanceAction.Result res = action.call()