use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class BackendDiskAttachmentsResource method attachDiskToVm.
protected Response attachDiskToVm(AbstractBackendCollectionResource resource, DiskAttachment attachment, IResolver entityResolver) {
Guid diskId = Guid.createGuidFromStringDefaultEmpty(attachment.getDisk().getId());
DiskVmElement dve = map(attachment);
dve.getId().setVmId(vmId);
dve.getId().setDeviceId(diskId);
AttachDetachVmDiskParameters params = new AttachDetachVmDiskParameters(dve);
Disk disk = attachment.getDisk();
boolean isDiskActive = false;
if (attachment.isSetActive()) {
isDiskActive = BooleanUtils.toBoolean(attachment.isActive());
}
params.setPlugUnPlug(isDiskActive);
if (disk.isSetReadOnly()) {
dve.setReadOnly(BooleanUtils.toBoolean(disk.isReadOnly()));
}
if (disk.isSetSnapshot()) {
validateParameters(disk, "snapshot.id");
params.setSnapshotId(asGuid(disk.getSnapshot().getId()));
}
return resource.performCreate(ActionType.AttachDiskToVm, params, entityResolver);
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class OvfOvaWriter method writeDisk.
@Override
protected void writeDisk(DiskImage image) {
DiskVmElement dve = image.getDiskVmElementForVm(vmBase.getId());
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "diskId", image.getId().toString());
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "capacity", String.valueOf(convertBytesToGigabyte(image.getSize())));
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "capacityAllocationUnits", "byte * 2^30");
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "populatedSize", String.valueOf(image.getActualSizeInBytes()));
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "parentRef", "");
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "fileRef", image.getImageId().toString());
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "format", getVolumeImageFormat(image.getVolumeFormat()));
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "volume-format", image.getVolumeFormat().toString());
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "volume-type", image.getVolumeType().toString());
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "disk-interface", dve.getDiskInterface().toString());
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "boot", String.valueOf(dve.isBoot()));
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "pass-discard", String.valueOf(dve.isPassDiscard()));
if (image.getDiskAlias() != null) {
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "disk-alias", image.getDiskAlias());
}
if (image.getDiskDescription() != null) {
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "disk-description", image.getDiskDescription());
}
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "wipe-after-delete", String.valueOf(image.isWipeAfterDelete()));
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "description", StringUtils.defaultString(image.getDescription()));
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "disk_storage_type", image.getDiskStorageType().name());
_writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "cinder_volume_type", StringUtils.defaultString(image.getCinderVolumeType()));
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class OvfOvirtReader method readLunDisk.
@Override
protected void readLunDisk(XmlNode node, LunDisk lun) {
lun.setDiskVmElements(Collections.singletonList(new DiskVmElement(lun.getId(), fullEntityOvfData.getVmBase().getId())));
LUNs luns = new LUNs();
consumeReadXmlAttribute(node, OVF_PREFIX + COLON + LUN_ID, val -> luns.setLUNId(val));
ArrayList<StorageServerConnections> lunConnections = new ArrayList<>();
for (XmlNode connNode : selectNodes(node, LUN_CONNECTION)) {
StorageServerConnections conn = new StorageServerConnections();
consumeReadXmlAttribute(connNode, OVF_PREFIX + COLON + LUNS_CONNECTION, val -> conn.setConnection(val));
consumeReadXmlAttribute(connNode, OVF_PREFIX + COLON + LUNS_IQN, val -> conn.setIqn(val));
consumeReadXmlAttribute(connNode, OVF_PREFIX + COLON + LUNS_PORT, val -> conn.setPort(val));
consumeReadXmlAttribute(connNode, XSI_PREFIX + COLON + LUNS_STORAGE_TYPE, val -> conn.setStorageType(StorageType.valueOf(val)));
consumeReadXmlAttribute(connNode, XSI_PREFIX + COLON + LUNS_PORTAL, val -> conn.setPortal(val));
lunConnections.add(conn);
}
luns.setLunConnections(lunConnections);
lun.setLun(luns);
DiskVmElement dve = lun.getDiskVmElementForVm(fullEntityOvfData.getVmBase().getId());
initGeneralDiskAttributes(node, lun, dve);
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class OvfOvirtWriter method writeLunDisk.
@Override
protected void writeLunDisk(LunDisk lun) {
// Lun disk does not have image id, therefor the id will be preserved with the disk ID as identifier.
_writer.writeAttributeString(getOvfUri(), "diskId", lun.getId().toString());
DiskVmElement dve = lun.getDiskVmElementForVm(vmBase.getId());
if (lun.getDiskAlias() != null) {
_writer.writeAttributeString(getOvfUri(), "disk-alias", lun.getDiskAlias());
}
if (lun.getDiskDescription() != null) {
_writer.writeAttributeString(getOvfUri(), "disk-description", lun.getDiskDescription());
}
if (FeatureSupported.passDiscardSupported(version)) {
_writer.writeAttributeString(getOvfUri(), "pass-discard", String.valueOf(dve.isPassDiscard()));
}
_writer.writeAttributeString(getOvfUri(), "fileRef", OvfParser.createLunFile(lun));
_writer.writeAttributeString(getOvfUri(), "shareable", String.valueOf(lun.isShareable()));
_writer.writeAttributeString(getOvfUri(), "boot", String.valueOf(dve.isBoot()));
_writer.writeAttributeString(getOvfUri(), "disk-interface", dve.getDiskInterface().toString());
_writer.writeAttributeString(getOvfUri(), "read-only", String.valueOf(dve.isReadOnly()));
_writer.writeAttributeString(getOvfUri(), "scsi_reservation", String.valueOf(dve.isUsingScsiReservation()));
_writer.writeAttributeString(getOvfUri(), "plugged", String.valueOf(dve.isPlugged()));
_writer.writeAttributeString(getOvfUri(), LUN_ID, String.valueOf(lun.getLun().getLUNId()));
if (lun.getLun().getLunConnections() != null) {
for (StorageServerConnections conn : lun.getLun().getLunConnections()) {
_writer.writeStartElement(LUN_CONNECTION);
_writer.writeAttributeString(getOvfUri(), LUNS_CONNECTION, conn.getConnection());
_writer.writeAttributeString(getOvfUri(), LUNS_IQN, conn.getIqn());
_writer.writeAttributeString(getOvfUri(), LUNS_PORT, conn.getPort());
_writer.writeAttributeString(XSI_URI, LUNS_STORAGE_TYPE, conn.getStorageType().name());
_writer.writeAttributeString(XSI_URI, LUNS_PORTAL, conn.getPortal());
_writer.writeEndElement();
}
}
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class OvfReader method readDisk.
protected void readDisk(XmlNode node, DiskImage image) {
image.setDiskVmElements(Collections.singletonList(new DiskVmElement(image.getId(), vmBase.getId())));
DiskVmElement dve = image.getDiskVmElementForVm(vmBase.getId());
// Default values:
image.setActive(true);
image.setImageStatus(ImageStatus.OK);
if (node.attributes.get("ovf:vm_snapshot_id") != null) {
image.setVmSnapshotId(new Guid(node.attributes.get("ovf:vm_snapshot_id").getValue()));
}
if (node.attributes.get("ovf:volume-format") != null) {
if (!StringUtils.isEmpty(node.attributes.get("ovf:volume-format").getValue())) {
image.setVolumeFormat(VolumeFormat.valueOf(node.attributes.get("ovf:volume-format").getValue()));
} else {
image.setVolumeFormat(VolumeFormat.Unassigned);
}
} else {
image.setVolumeFormat(VolumeFormat.Unassigned);
}
if (node.attributes.get("ovf:volume-type") != null) {
if (!StringUtils.isEmpty(node.attributes.get("ovf:volume-type").getValue())) {
image.setVolumeType(VolumeType.valueOf(node.attributes.get("ovf:volume-type").getValue()));
} else {
image.setVolumeType(VolumeType.Unassigned);
}
} else {
image.setVolumeType(VolumeType.Unassigned);
}
if (node.attributes.get("ovf:wipe-after-delete") != null) {
if (!StringUtils.isEmpty(node.attributes.get("ovf:wipe-after-delete").getValue())) {
image.setWipeAfterDelete(Boolean.parseBoolean(node.attributes.get("ovf:wipe-after-delete").getValue()));
}
}
initGeneralDiskAttributes(node, image, dve);
}
Aggregations