|
1 | 1 | package org.zstack.header.vm;
|
2 | 2 |
|
| 3 | +import org.zstack.header.allocator.HostAllocatorConstant; |
3 | 4 | import org.zstack.header.message.APIEvent;
|
4 | 5 | import org.zstack.header.rest.RestResponse;
|
| 6 | +import org.zstack.header.volume.VolumeInventory; |
| 7 | +import org.zstack.header.volume.VolumeState; |
| 8 | +import org.zstack.header.volume.VolumeStatus; |
| 9 | +import org.zstack.header.volume.VolumeType; |
| 10 | +import org.zstack.utils.data.SizeUnit; |
| 11 | + |
| 12 | +import java.sql.Timestamp; |
| 13 | + |
| 14 | +import static org.codehaus.groovy.runtime.InvokerHelper.asList; |
5 | 15 |
|
6 | 16 | /**
|
7 | 17 | * @apiResult api event for message :ref:`APICreateVmInstanceMsg`
|
@@ -116,4 +126,70 @@ public VmInstanceInventory getInventory() {
|
116 | 126 | public void setInventory(VmInstanceInventory inventory) {
|
117 | 127 | this.inventory = inventory;
|
118 | 128 | }
|
| 129 | + |
| 130 | + public static APICreateVmInstanceEvent __example__() { |
| 131 | + APICreateVmInstanceEvent evt = new APICreateVmInstanceEvent(); |
| 132 | + |
| 133 | + String defaultL3Uuid = uuid(); |
| 134 | + String rootVolumeUuid = uuid(); |
| 135 | + |
| 136 | + VmInstanceInventory vm = new VmInstanceInventory(); |
| 137 | + vm.setName("Test-VM"); |
| 138 | + vm.setUuid(uuid()); |
| 139 | + vm.setAllocatorStrategy(HostAllocatorConstant.LAST_HOST_PREFERRED_ALLOCATOR_STRATEGY_TYPE); |
| 140 | + vm.setClusterUuid(uuid()); |
| 141 | + vm.setCpuNum(1); |
| 142 | + vm.setCreateDate(new Timestamp(System.currentTimeMillis())); |
| 143 | + vm.setDefaultL3NetworkUuid(defaultL3Uuid); |
| 144 | + vm.setDescription("web server VM"); |
| 145 | + vm.setHostUuid(uuid()); |
| 146 | + vm.setHypervisorType("KVM"); |
| 147 | + vm.setImageUuid(uuid()); |
| 148 | + vm.setInstanceOfferingUuid(uuid()); |
| 149 | + vm.setLastHostUuid(uuid()); |
| 150 | + vm.setMemorySize(SizeUnit.GIGABYTE.toByte(8)); |
| 151 | + vm.setPlatform("Linux"); |
| 152 | + vm.setRootVolumeUuid(rootVolumeUuid); |
| 153 | + vm.setState(VmInstanceState.Running.toString()); |
| 154 | + vm.setType(VmInstanceConstant.USER_VM_TYPE); |
| 155 | + vm.setLastOpDate(new Timestamp(System.currentTimeMillis())); |
| 156 | + vm.setZoneUuid(uuid()); |
| 157 | + |
| 158 | + VolumeInventory vol = new VolumeInventory(); |
| 159 | + vol.setName(String.format("Root-Volume-For-VM-%s", vm.getUuid())); |
| 160 | + vol.setCreateDate(new Timestamp(System.currentTimeMillis())); |
| 161 | + vol.setLastOpDate(new Timestamp(System.currentTimeMillis())); |
| 162 | + vol.setType(VolumeType.Root.toString()); |
| 163 | + vol.setUuid(rootVolumeUuid); |
| 164 | + vol.setSize(SizeUnit.GIGABYTE.toByte(100)); |
| 165 | + vol.setActualSize(SizeUnit.GIGABYTE.toByte(20)); |
| 166 | + vol.setDeviceId(0); |
| 167 | + vol.setState(VolumeState.Enabled.toString()); |
| 168 | + vol.setFormat("qcow2"); |
| 169 | + vol.setDiskOfferingUuid(uuid()); |
| 170 | + vol.setInstallPath(String.format("/zstack_ps/rootVolumes/acct-36c27e8ff05c4780bf6d2fa65700f22e/vol-%s/%s.qcow2", rootVolumeUuid, rootVolumeUuid)); |
| 171 | + vol.setStatus(VolumeStatus.Ready.toString()); |
| 172 | + vol.setPrimaryStorageUuid(uuid()); |
| 173 | + vol.setVmInstanceUuid(vm.getUuid()); |
| 174 | + vol.setRootImageUuid(vm.getImageUuid()); |
| 175 | + vm.setAllVolumes(asList(vol)); |
| 176 | + |
| 177 | + VmNicInventory nic = new VmNicInventory(); |
| 178 | + nic.setVmInstanceUuid(vm.getUuid()); |
| 179 | + nic.setCreateDate(vm.getCreateDate()); |
| 180 | + nic.setLastOpDate(vm.getLastOpDate()); |
| 181 | + nic.setDeviceId(0); |
| 182 | + nic.setGateway("192.168.1.1"); |
| 183 | + nic.setIp("192.168.1.10"); |
| 184 | + nic.setL3NetworkUuid(defaultL3Uuid); |
| 185 | + nic.setNetmask("255.255.255.0"); |
| 186 | + nic.setMac("00:0c:29:bd:99:fc"); |
| 187 | + nic.setUsedIpUuid(uuid()); |
| 188 | + nic.setUuid(uuid()); |
| 189 | + vm.setVmNics(asList(nic)); |
| 190 | + |
| 191 | + evt.setInventory(vm); |
| 192 | + |
| 193 | + return evt; |
| 194 | + } |
119 | 195 | }
|
0 commit comments