use of com.vmware.vim25.VmConfigSpec in project cloudstack by apache.
the class VirtualMachineMO method tearDownDevices.
public void tearDownDevices(Class<?>[] deviceClasses) throws Exception {
VirtualDevice[] devices = getMatchedDevices(deviceClasses);
if (devices.length > 0) {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length];
for (int i = 0; i < devices.length; i++) {
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[i].setDevice(devices[i]);
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
vmConfigSpec.getDeviceChange().add(deviceConfigSpecArray[i]);
}
if (!configureVm(vmConfigSpec)) {
throw new Exception("Failed to detach devices");
}
}
}
use of com.vmware.vim25.VmConfigSpec in project photon-model by vmware.
the class InstanceClient method populateVAppProperties.
private boolean populateVAppProperties(VirtualMachineConfigSpec spec, ArrayOfVAppPropertyInfo currentProps) {
if (this.bootDisk == null) {
return false;
}
boolean customizationsApplied = false;
int nextKey = 1;
if (currentProps != null) {
nextKey = currentProps.getVAppPropertyInfo().stream().mapToInt(VAppPropertyInfo::getKey).max().orElse(1);
nextKey++;
}
String ovfEnv = getFileItemByPath(this.bootDisk, OVF_PROPERTY_ENV);
if (ovfEnv != null) {
@SuppressWarnings("unchecked") Map<String, String> map = Utils.fromJson(ovfEnv, Map.class);
if (!map.isEmpty()) {
customizationsApplied = true;
VmConfigSpec configSpec = new VmConfigSpec();
configSpec.getOvfEnvironmentTransport().add(OvfDeployer.TRANSPORT_ISO);
if (currentProps == null) {
currentProps = new ArrayOfVAppPropertyInfo();
}
currentProps.getVAppPropertyInfo().forEach(pi -> {
if (map.containsKey(pi.getId())) {
VAppPropertySpec ps = new VAppPropertySpec();
ps.setOperation(ArrayUpdateOperation.EDIT);
pi.setValue(map.remove(pi.getId()));
ps.setInfo(pi);
configSpec.getProperty().add(ps);
}
});
// only new key/values
for (Entry<String, String> entry : map.entrySet()) {
VAppPropertyInfo pi = new VAppPropertyInfo();
pi.setId(entry.getKey());
pi.setType("string");
pi.setKey(nextKey++);
pi.setValue(entry.getValue());
VAppPropertySpec ps = new VAppPropertySpec();
ps.setOperation(ArrayUpdateOperation.ADD);
ps.setInfo(pi);
configSpec.getProperty().add(ps);
}
spec.setVAppConfig(configSpec);
}
}
return customizationsApplied;
}
use of com.vmware.vim25.VmConfigSpec in project photon-model by vmware.
the class OvfDeployer method deployOvf.
public ManagedObjectReference deployOvf(URI ovfUri, ManagedObjectReference host, ManagedObjectReference vmFolder, String vmName, List<OvfNetworkMapping> networks, ManagedObjectReference datastore, Collection<KeyValue> ovfProps, String deploymentConfig, ManagedObjectReference resourcePool) throws Exception {
String ovfDescriptor = getRetriever().retrieveAsString(ovfUri);
OvfCreateImportSpecParams params = new OvfCreateImportSpecParams();
params.setHostSystem(host);
params.setLocale("US");
params.setEntityName(vmName);
if (deploymentConfig == null) {
deploymentConfig = "";
}
params.setDeploymentOption(deploymentConfig);
params.getNetworkMapping().addAll(networks);
params.setDiskProvisioning(OvfCreateImportSpecParamsDiskProvisioningType.THIN.name());
if (ovfProps != null) {
params.getPropertyMapping().addAll(ovfProps);
}
ManagedObjectReference ovfManager = this.connection.getServiceContent().getOvfManager();
OvfCreateImportSpecResult importSpecResult = getVimPort().createImportSpec(ovfManager, ovfDescriptor, resourcePool, datastore, params);
if (!importSpecResult.getError().isEmpty()) {
return VimUtils.rethrow(importSpecResult.getError().get(0));
}
long totalBytes = getImportSizeBytes(importSpecResult);
ManagedObjectReference lease = getVimPort().importVApp(resourcePool, importSpecResult.getImportSpec(), vmFolder, host);
LeaseProgressUpdater leaseUpdater = new LeaseProgressUpdater(this.connection, lease, totalBytes);
GetMoRef get = new GetMoRef(this.connection);
HttpNfcLeaseInfo httpNfcLeaseInfo;
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
try {
leaseUpdater.awaitReady();
logger.info("Lease ready");
// start updating the lease
leaseUpdater.start(executorService);
httpNfcLeaseInfo = get.entityProp(lease, PROP_INFO);
List<HttpNfcLeaseDeviceUrl> deviceUrls = httpNfcLeaseInfo.getDeviceUrl();
String ip = this.connection.getURI().getHost();
String basePath = extractBasePath(ovfUri);
for (HttpNfcLeaseDeviceUrl deviceUrl : deviceUrls) {
String deviceKey = deviceUrl.getImportKey();
for (OvfFileItem ovfFileItem : importSpecResult.getFileItem()) {
if (deviceKey.equals(ovfFileItem.getDeviceId())) {
logger.debug("Importing device id: {}", deviceKey);
String sourceUri = computeDiskSourceUri(basePath, ovfFileItem);
String uploadUri = makUploadUri(ip, deviceUrl);
uploadVmdkFile(ovfFileItem, sourceUri, uploadUri, leaseUpdater, this.ovfRetriever.getClient());
logger.info("Completed uploading VMDK file {}", sourceUri);
}
}
}
// complete lease
leaseUpdater.complete();
} catch (Exception e) {
leaseUpdater.abort(VimUtils.convertExceptionToFault(e));
logger.info("Error importing ovf", e);
throw e;
} finally {
executorService.shutdown();
}
httpNfcLeaseInfo = get.entityProp(lease, PROP_INFO);
ManagedObjectReference entity = httpNfcLeaseInfo.getEntity();
// as this is an OVF it makes sense to enable the OVF transport
// only the guestInfo is enabled by default
VmConfigSpec spec = new VmConfigSpec();
spec.getOvfEnvironmentTransport().add(TRANSPORT_GUESTINFO);
spec.getOvfEnvironmentTransport().add(TRANSPORT_ISO);
VirtualMachineConfigSpec reconfig = new VirtualMachineConfigSpec();
reconfig.setVAppConfig(spec);
ManagedObjectReference reconfigTask = getVimPort().reconfigVMTask(entity, reconfig);
VimUtils.waitTaskEnd(this.connection, reconfigTask);
return entity;
}
use of com.vmware.vim25.VmConfigSpec in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method tearDownDevices.
public void tearDownDevices(Class<?>[] deviceClasses) throws Exception {
VirtualDevice[] devices = getMatchedDevices(deviceClasses);
if (devices.length > 0) {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length];
for (int i = 0; i < devices.length; i++) {
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[i].setDevice(devices[i]);
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.remove);
}
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
if (!configureVm(vmConfigSpec)) {
throw new Exception("Failed to detach devices");
}
}
}
use of com.vmware.vim25.VmConfigSpec in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method setVncConfigInfo.
public boolean setVncConfigInfo(boolean enableVnc, String vncPassword, int vncPort, String keyboard) throws Exception {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
OptionValue[] vncOptions = VmwareHelper.composeVncOptions(null, enableVnc, vncPassword, vncPort, keyboard);
vmConfigSpec.setExtraConfig(vncOptions);
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, vmConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware reconfigVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
Aggregations