use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef in project photon-model by vmware.
the class TestVSphereLibraryProvisionTaskWithDay2 method deployFromLibraryWithShutdown.
@Test
public void deployFromLibraryWithShutdown() throws Throwable {
ComputeService.ComputeState vm = provisionVMAndGetState();
try {
if (vm == null) {
return;
}
// test shutdown Guest OS resource operation
shutdownGuestOS(vm);
// Verify that the disk is resized and is reflected even for a POWERED_OFF vm
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
verifyDiskSize(vm, get, HDD_DISK_SIZE);
} finally {
if (vm != null) {
deleteVmAndWait(vm);
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef in project photon-model by vmware.
the class TestVSphereLibraryProvisionTaskWithDay2 method deployFromLibraryWithReboot.
@Test
public void deployFromLibraryWithReboot() throws Throwable {
ComputeService.ComputeState vm = provisionVMAndGetState();
try {
if (vm == null) {
return;
}
// test reboot resource operation
rebootVSphereVMAndWait(vm);
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
verifyDiskSize(vm, get, HDD_DISK_SIZE);
} finally {
if (vm != null) {
deleteVmAndWait(vm);
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef in project photon-model by vmware.
the class TestVSphereCloneTaskWithStorage method verifyBootDiskCustomizationWithStoragePolicy.
@Test
public void verifyBootDiskCustomizationWithStoragePolicy() 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);
doRefresh();
snapshotFactoryState("clone-refresh", NetworkService.class);
ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
DiskService.DiskState bootDisk = createDiskWithStoragePolicy("boot", DiskService.DiskType.HDD, 1, getDiskUri(), HDD_DISK_SIZE, buildCustomProperties());
vm = createVmState(vmDescription, true, bootDisk.documentSelfLink);
// 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, true, false);
provisionTask = createProvisionTask(clonedVm);
awaitTaskEnd(provisionTask);
clonedVm = getComputeState(clonedVm);
if (!isMock()) {
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
verifyDiskSize(vm, get, HDD_DISK_SIZE);
verifyDiskSize(clonedVm, get, CLONE_HDD_DISK_SIZE);
verifyDiskProperties(vm, get);
}
} finally {
if (!isMock()) {
cleanUpVm(vm, clonedVm);
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef in project photon-model by vmware.
the class StatsClient method createLookup.
/**
* cache perfCounters per connections. The call is slow as the response can be about 400kb
* of xml.
* @param conn
* @return
*/
private static PerfCounterLookup createLookup(Connection conn) {
return lookups.computeIfAbsent(conn.getURI(), u -> {
GetMoRef get = new GetMoRef(conn);
ArrayOfPerfCounterInfo counters;
try {
counters = get.entityProp(PERF_MGR_MOREF, PROP_PERF_COUNTER);
} catch (Exception e) {
throw new RuntimeException("cannot create lookup for " + u, e);
}
return new PerfCounterLookup(counters.getPerfCounterInfo());
});
}
use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef in project photon-model by vmware.
the class InstanceClient method deployOvf.
private ManagedObjectReference deployOvf(URI ovfUri) throws Exception {
OvfDeployer deployer = new OvfDeployer(this.connection);
CustomProperties cust = CustomProperties.of(this.ctx.child.description);
URI archiveUri = cust.getUri(OvfParser.PROP_OVF_ARCHIVE_URI);
if (archiveUri != null) {
logger.info("Prefer ova {} uri to ovf {}", archiveUri, ovfUri);
OvfRetriever retriever = deployer.getRetriever();
ovfUri = retriever.downloadIfOva(archiveUri);
}
ManagedObjectReference folder = getVmFolder();
List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(this.bootDisk);
ManagedObjectReference ds = getDataStoreForDisk(this.bootDisk, pbmSpec);
ManagedObjectReference resourcePool = getResourcePool();
String vmName = "pmt-" + deployer.getRetriever().hash(ovfUri);
GetMoRef get = new GetMoRef(this.connection);
ManagedObjectReference vm = findTemplateByName(vmName, get);
if (vm == null) {
String config = cust.getString(OvfParser.PROP_OVF_CONFIGURATION);
Lock lock = getLock(vmName);
lock.lock();
try {
vm = findTemplateByName(vmName, get);
if (vm == null) {
OvfParser parser = new OvfParser();
Document ovfDoc = parser.retrieveDescriptor(ovfUri);
List<OvfNetworkMapping> networks = mapNetworks(parser.extractNetworks(ovfDoc), ovfDoc, this.ctx.nics);
vm = deployer.deployOvf(ovfUri, getHost(), folder, vmName, networks, ds, Collections.emptyList(), config, resourcePool);
logger.info("Removing NICs from deployed template: {} ({})", vmName, vm.getValue());
ArrayOfVirtualDevice devices = get.entityProp(vm, VimPath.vm_config_hardware_device);
if (devices != null) {
VirtualMachineConfigSpec reconfig = new VirtualMachineConfigSpec();
for (VirtualDevice device : devices.getVirtualDevice()) {
if (device instanceof VirtualEthernetCard) {
VirtualDeviceConfigSpec spec = new VirtualDeviceConfigSpec();
spec.setDevice(device);
spec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
reconfig.getDeviceChange().add(spec);
}
}
ManagedObjectReference reconfigTask = getVimPort().reconfigVMTask(vm, reconfig);
VimUtils.waitTaskEnd(this.connection, reconfigTask);
}
ManagedObjectReference snapshotTask = getVimPort().createSnapshotTask(vm, "initial", null, false, false);
VimUtils.waitTaskEnd(this.connection, snapshotTask);
}
} catch (Exception e) {
logger.warn("Error deploying Ovf for template [" + vmName + "],reason:", e);
vm = awaitVM(vmName, folder, get);
} finally {
lock.unlock();
}
}
if (!isSameDatastore(ds, vm, get)) {
// make sure the original VM template is ready
Object snapshot = get.entityProp(vm, VimPath.vm_snapshot);
if (snapshot == null) {
vm = awaitVM(vmName, folder, get);
}
vm = replicateVMTemplate(resourcePool, ds, pbmSpec, folder, vmName, vm, get);
}
return cloneOvfBasedTemplate(vm, ds, folder, resourcePool, pbmSpec);
}
Aggregations