use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class OvfReader method readVmDevice.
/**
* Reads vm device attributes from OVF and stores it in the collection
*/
private VmDevice readVmDevice(XmlNode node, Guid deviceId) {
VmDevice vmDevice = new VmDevice();
vmDevice.setId(new VmDeviceId(deviceId, vmBase.getId()));
if (selectSingleNode(node, VMD_ADDRESS, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_ADDRESS, _xmlNS).innerText)) {
vmDevice.setAddress(String.valueOf(selectSingleNode(node, VMD_ADDRESS, _xmlNS).innerText));
} else {
vmDevice.setAddress("");
}
if (selectSingleNode(node, VMD_ALIAS, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_ALIAS, _xmlNS).innerText)) {
vmDevice.setAlias(String.valueOf(selectSingleNode(node, VMD_ALIAS, _xmlNS).innerText));
} else {
vmDevice.setAlias("");
}
XmlNode specParamsNode = selectSingleNode(node, VMD_SPEC_PARAMS, _xmlNS);
if (specParamsNode != null && !StringUtils.isEmpty(specParamsNode.innerText)) {
vmDevice.setSpecParams(getMapNode(specParamsNode));
} else {
// Empty map
vmDevice.setSpecParams(Collections.emptyMap());
}
if (selectSingleNode(node, VMD_TYPE, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText)) {
vmDevice.setType(VmDeviceGeneralType.forValue(String.valueOf(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText)));
} else {
int resourceType = getResourceType(node, VMD_RESOURCE_TYPE);
vmDevice.setType(VmDeviceGeneralType.forValue(VmDeviceType.getoVirtDevice(resourceType)));
}
if (selectSingleNode(node, VMD_DEVICE, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_DEVICE, _xmlNS).innerText)) {
vmDevice.setDevice(String.valueOf(selectSingleNode(node, VMD_DEVICE, _xmlNS).innerText));
} else {
setDeviceByResource(node, vmDevice);
}
if (selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS).innerText)) {
vmDevice.setPlugged(Boolean.valueOf(selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS).innerText));
} else {
vmDevice.setPlugged(Boolean.TRUE);
}
if (selectSingleNode(node, VMD_IS_READONLY, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_IS_READONLY, _xmlNS).innerText)) {
vmDevice.setReadOnly(Boolean.valueOf(selectSingleNode(node, VMD_IS_READONLY, _xmlNS).innerText));
} else {
vmDevice.setReadOnly(Boolean.FALSE);
}
if (selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS) != null && StringUtils.isNotEmpty(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)) {
vmDevice.setCustomProperties(DevicePropertiesUtils.getInstance().convertProperties(String.valueOf(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)));
} else {
vmDevice.setCustomProperties(null);
}
if (selectSingleNode(node, VMD_SNAPSHOT_PROP, _xmlNS) != null && StringUtils.isNotEmpty(selectSingleNode(node, VMD_SNAPSHOT_PROP, _xmlNS).innerText)) {
vmDevice.setSnapshotId(new Guid(String.valueOf(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)));
}
return vmDevice;
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class ImagesHandler method removeDiskFromVm.
public void removeDiskFromVm(Guid vmGuid, Guid diskId) {
vmDeviceDao.remove(new VmDeviceId(diskId, vmGuid));
baseDiskDao.remove(diskId);
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class ImagesHandler method prepareSnapshotConfigWithAlternateImage.
/**
* Prepare a single {@link org.ovirt.engine.core.common.businessentities.Snapshot} object representing a snapshot of a given VM without the given disk,
* substituting a new disk in its place if a new disk is provided to the method.
*/
public Snapshot prepareSnapshotConfigWithAlternateImage(Snapshot snapshot, Guid oldImageId, DiskImage newImage, OvfManager ovfManager) {
if (snapshot == null) {
return null;
}
try {
String snapConfig = snapshot.getVmConfiguration();
if (snapshot.isVmConfigurationAvailable() && snapConfig != null) {
VM vmSnapshot = new VM();
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vmSnapshot);
ovfManager.importVm(snapConfig, vmSnapshot, fullEntityOvfData);
// Remove the image from the disk list
Iterator<DiskImage> diskIter = fullEntityOvfData.getDiskImages().iterator();
while (diskIter.hasNext()) {
DiskImage imageInList = diskIter.next();
if (imageInList.getImageId().equals(oldImageId)) {
log.debug("Recreating vmSnapshot '{}' without the image '{}'", snapshot.getId(), oldImageId);
diskIter.remove();
break;
}
}
if (newImage != null) {
log.debug("Adding image '{}' to vmSnapshot '{}'", newImage.getImageId(), snapshot.getId());
newImage.setDiskVmElements(Collections.singletonList(diskVmElementDao.get(new VmDeviceId(newImage.getId(), vmSnapshot.getId()))));
fullEntityOvfData.getDiskImages().add(newImage);
}
final Version compatibilityVersion = Optional.ofNullable(vmSnapshot.getStaticData().getClusterCompatibilityVersionOrigin()).orElse(Version.getLowest());
FullEntityOvfData fullEntityOvfDataForExport = new FullEntityOvfData(vmSnapshot);
fullEntityOvfDataForExport.setDiskImages(fullEntityOvfData.getDiskImages());
String newOvf = ovfManager.exportVm(vmSnapshot, fullEntityOvfDataForExport, compatibilityVersion);
snapshot.setVmConfiguration(newOvf);
}
} catch (OvfReaderException e) {
log.error("Can't remove image '{}' from snapshot '{}'", oldImageId, snapshot.getId());
}
return snapshot;
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class ImagesHandler method removeLunDisk.
public void removeLunDisk(LunDisk lunDisk) {
vmDeviceDao.remove(new VmDeviceId(lunDisk.getId(), null));
LUNs lun = lunDisk.getLun();
diskLunMapDao.remove(new DiskLunMapId(lunDisk.getId(), lun.getLUNId()));
baseDiskDao.remove(lunDisk.getId());
lun.setLunConnections(new ArrayList<>(storageServerConnectionDao.getAllForLun(lun.getLUNId())));
if (!lun.getLunConnections().isEmpty()) {
storageHelperDirector.getItem(lun.getLunConnections().get(0).getStorageType()).removeLun(lun);
} else {
// if there are no connections then the lun is fcp.
storageHelperDirector.getItem(StorageType.FCP).removeLun(lun);
}
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmDeviceCommonUtils method addVideoDevice.
public static void addVideoDevice(VmBase vmBase) {
if (vmBase.getDefaultDisplayType().getDefaultVmDeviceType() == null) {
return;
}
VmDevice vmDevice = new VmDevice();
vmDevice.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
vmDevice.setType(VmDeviceGeneralType.VIDEO);
vmDevice.setDevice(vmBase.getDefaultDisplayType().getDefaultVmDeviceType().getName());
vmDevice.setManaged(true);
vmDevice.setPlugged(true);
vmDevice.setReadOnly(false);
vmDevice.setAddress("");
vmBase.getManagedDeviceMap().put(vmDevice.getDeviceId(), vmDevice);
}
Aggregations