use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.
the class TestVSphereOvfProvisionTaskBase method deployOvfAndReturnComputeState.
private ComputeService.ComputeState deployOvfAndReturnComputeState(boolean isStoragePolicyBased, boolean withAdditionalDisks, Map<String, String> customProperties, boolean isSnapshotLimitCase) throws Throwable {
ComputeService.ComputeState vm = null;
// Create a resource pool where the VM will be housed
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
ComputeDescriptionService.ComputeDescription computeDesc = createTemplate();
ImportOvfRequest req = new ImportOvfRequest();
req.ovfUri = this.ovfUri;
req.template = computeDesc;
Operation op = Operation.createPatch(this.host, OvfImporterService.SELF_LINK).setBody(req).setReferer(this.host.getPublicUri());
CompletableFuture<Operation> f = this.host.sendWithFuture(op);
// depending on OVF location you may want to increase the timeout
f.get(360, TimeUnit.SECONDS);
snapshotFactoryState("ovf", ComputeDescriptionService.class);
enumerateComputes(this.computeHost);
String descriptionLink = findFirstOvfDescriptionLink();
this.bootDisk = createBootDiskWithCustomProperties(CLOUD_CONFIG_DATA, isStoragePolicyBased, customProperties);
vm = createVmState(descriptionLink, withAdditionalDisks, customProperties, isSnapshotLimitCase);
// set timeout for the next step, vmdk upload may take some time
host.setTimeoutSeconds(60 * 5);
// provision
ProvisionComputeTaskService.ProvisionComputeTaskState outTask = createProvisionTask(vm);
awaitTaskEnd(outTask);
vm = getComputeState(vm);
snapshotFactoryState("ovf", ComputeService.class);
if (!isMock() && withAdditionalDisks || customProperties.get(PROVISION_TYPE) != null) {
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
if (customProperties.get(PROVISION_TYPE) != null) {
VirtualDiskType diskProvisionType = VirtualDiskType.fromValue(customProperties.get(PROVISION_TYPE));
VirtualDisk bootDisk = virtualDisks.stream().filter(vd -> vd.getUnitNumber() == 0).findFirst().orElse(null);
VirtualDiskFlatVer2BackingInfo backing = (VirtualDiskFlatVer2BackingInfo) bootDisk.getBacking();
if (VirtualDiskType.THIN == diskProvisionType) {
assertTrue(backing.isThinProvisioned());
} else if (VirtualDiskType.THICK == diskProvisionType) {
assertFalse(backing.isThinProvisioned());
} else if (VirtualDiskType.EAGER_ZEROED_THICK == diskProvisionType) {
assertFalse(backing.isThinProvisioned());
assertTrue(backing.isEagerlyScrub());
}
}
if (withAdditionalDisks) {
assertEquals(3, virtualDisks.size());
}
}
return vm;
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.
the class TestVSphereCloneTaskWithStorage method verifyBootDiskCustomization.
@Test
public void verifyBootDiskCustomization() throws Throwable {
ComputeService.ComputeState vm = null;
try {
this.auth = createAuth();
this.resourcePool = createResourcePool();
if (isMock()) {
createNetwork(networkId);
}
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
doRefresh();
snapshotFactoryState("clone-refresh", NetworkService.class);
ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
vm = createVmState(vmDescription, true, null);
// kick off a provision task to do the actual VM creation
ProvisionComputeTaskService.ProvisionComputeTaskState provisionTask = createProvisionTask(vm);
awaitTaskEnd(provisionTask);
vm = getComputeState(vm);
// put fake moref in the vm
if (isMock()) {
ManagedObjectReference moref = new ManagedObjectReference();
moref.setValue("vm-0");
moref.setType(VimNames.TYPE_VM);
CustomProperties.of(vm).put(MOREF, moref);
vm = doPost(this.host, vm, ComputeService.ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
}
if (!isMock()) {
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
verifyDiskSize(vm, get, HDD_DISK_SIZE);
verifyDiskProperties(vm, get);
}
} finally {
if (!isMock() && vm != null) {
deleteVmAndWait(vm);
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.
the class TestVSphereCloneTaskBase method createInstanceFromTemplate.
protected void createInstanceFromTemplate(boolean withAdditionalDisks) throws Throwable {
ComputeService.ComputeState vm = null;
ComputeService.ComputeState clonedVm = null;
try {
this.auth = createAuth();
this.resourcePool = createResourcePool();
if (isMock()) {
createNetwork(networkId);
}
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
doRefresh();
snapshotFactoryState("clone-refresh", NetworkService.class);
ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
vm = createVmState(vmDescription, false, null, withAdditionalDisks);
// kick off a provision task to do the actual VM creation
ProvisionComputeTaskService.ProvisionComputeTaskState provisionTask = createProvisionTask(vm);
awaitTaskEnd(provisionTask);
vm = getComputeState(vm);
// put fake moref in the vm
if (isMock()) {
ManagedObjectReference moref = new ManagedObjectReference();
moref.setValue("vm-0");
moref.setType(VimNames.TYPE_VM);
CustomProperties.of(vm).put(MOREF, moref);
vm = doPost(this.host, vm, ComputeService.ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
}
// create state & desc of the clone
ComputeDescriptionService.ComputeDescription cloneDescription = createCloneDescription(vm.documentSelfLink);
clonedVm = createCloneVmState(cloneDescription, false, withAdditionalDisks);
provisionTask = createProvisionTask(clonedVm);
awaitTaskEnd(provisionTask);
clonedVm = getComputeState(clonedVm);
if (!isMock()) {
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
if (withAdditionalDisks) {
List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
assertEquals(3, virtualDisks.size());
} else {
verifyDiskSize(clonedVm, get, CLONE_HDD_DISK_SIZE);
}
}
} finally {
if (!isMock()) {
cleanUpVm(vm, clonedVm);
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.
the class TestVSphereLibraryProvisionTaskWithStorage method deployFromLibraryWithStoragePolicy.
@Test
public void deployFromLibraryWithStoragePolicy() throws Throwable {
ComputeService.ComputeState vm = provisionVMAndGetState(true, false);
try {
if (vm == null) {
return;
}
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
verifyDiskSize(vm, get, HDD_DISK_SIZE);
verifyDiskProperties(vm, get);
} finally {
if (vm != null) {
deleteVmAndWait(vm);
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.
the class TestVSphereLibraryProvisionTaskWithDay2 method deployFromLibraryAndResetVM.
@Test
public void deployFromLibraryAndResetVM() throws Throwable {
ComputeService.ComputeState vm = provisionVMAndGetState();
try {
if (vm == null) {
return;
}
// test reset VM operation
resetVSphereVM(vm);
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
verifyDiskSize(vm, get, HDD_DISK_SIZE);
} finally {
if (vm != null) {
deleteVmAndWait(vm);
}
}
}
Aggregations