use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class VolumeOrchestrator method prepareForMigration.
@Override
public void prepareForMigration(final VirtualMachineProfile vm, final DeployDestination dest) {
final List<VolumeVO> vols = this._volsDao.findUsableVolumesForInstance(vm.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Preparing " + vols.size() + " volumes for " + vm);
}
for (final VolumeVO vol : vols) {
final DataTO volTO = this.volFactory.getVolume(vol.getId()).getTO();
final DiskTO disk = new DiskTO(volTO, vol.getDeviceId(), vol.getPath(), vol.getVolumeType(), vol.getDiskController(), vol.getFormat());
final VolumeInfo volumeInfo = this.volFactory.getVolume(vol.getId());
final DataStore dataStore = this.dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
disk.setDetails(getDetails(volumeInfo, dataStore));
vm.addDisk(disk);
}
// if (vm.getType() == VirtualMachine.Type.User && vm.getTemplate().getFormat() == ImageFormat.ISO) {
if (vm.getType() == VirtualMachineType.User) {
this._tmpltMgr.prepareIsoForVmProfile(vm);
// DataTO dataTO = tmplFactory.getTemplate(vm.getTemplate().getId(), DataStoreRole.Image, vm.getVirtualMachine().getDataCenterId()).getTO();
// DiskTO iso = new DiskTO(dataTO, 3L, null, Volume.Type.ISO);
// vm.addDisk(iso);
}
}
use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method copyTemplateToPrimaryStorage.
@Override
public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) {
final DataTO srcDataTo = cmd.getSrcTO();
final DataTO destDataTo = cmd.getDestTO();
final int wait = cmd.getWait();
final DataStoreTO srcDataStoreTo = srcDataTo.getDataStore();
try {
if (srcDataStoreTo instanceof NfsTO && srcDataTo.getObjectType() == DataObjectType.TEMPLATE) {
final NfsTO srcImageStore = (NfsTO) srcDataStoreTo;
final TemplateObjectTO srcTemplateObjectTo = (TemplateObjectTO) srcDataTo;
final String storeUrl = srcImageStore.getUrl();
final URI uri = new URI(storeUrl);
final String tmplPath = uri.getHost() + ":" + uri.getPath() + "/" + srcDataTo.getPath();
final DataStoreTO destDataStoreTo = destDataTo.getDataStore();
boolean managed = false;
String storageHost = null;
String managedStoragePoolName = null;
String managedStoragePoolRootVolumeName = null;
String managedStoragePoolRootVolumeSize = null;
String chapInitiatorUsername = null;
String chapInitiatorSecret = null;
if (destDataStoreTo instanceof PrimaryDataStoreTO) {
final PrimaryDataStoreTO destPrimaryDataStoreTo = (PrimaryDataStoreTO) destDataStoreTo;
final Map<String, String> details = destPrimaryDataStoreTo.getDetails();
if (details != null) {
managed = Boolean.parseBoolean(details.get(PrimaryDataStoreTO.MANAGED));
if (managed) {
storageHost = details.get(PrimaryDataStoreTO.STORAGE_HOST);
managedStoragePoolName = details.get(PrimaryDataStoreTO.MANAGED_STORE_TARGET);
managedStoragePoolRootVolumeName = details.get(PrimaryDataStoreTO.MANAGED_STORE_TARGET_ROOT_VOLUME);
managedStoragePoolRootVolumeSize = details.get(PrimaryDataStoreTO.VOLUME_SIZE);
chapInitiatorUsername = details.get(PrimaryDataStoreTO.CHAP_INITIATOR_USERNAME);
chapInitiatorSecret = details.get(PrimaryDataStoreTO.CHAP_INITIATOR_SECRET);
}
}
}
final Connection conn = hypervisorResource.getConnection();
final SR sr;
if (managed) {
final Map<String, String> details = new HashMap<>();
details.put(DiskTO.STORAGE_HOST, storageHost);
details.put(DiskTO.IQN, managedStoragePoolName);
details.put(DiskTO.VOLUME_SIZE, managedStoragePoolRootVolumeSize);
details.put(DiskTO.CHAP_INITIATOR_USERNAME, chapInitiatorUsername);
details.put(DiskTO.CHAP_INITIATOR_SECRET, chapInitiatorSecret);
sr = hypervisorResource.prepareManagedSr(conn, details);
} else {
final String srName = destDataStoreTo.getUuid();
final Set<SR> srs = SR.getByNameLabel(conn, srName);
if (srs.size() != 1) {
final String msg = "There are " + srs.size() + " SRs with same name: " + srName;
s_logger.warn(msg);
return new CopyCmdAnswer(msg);
} else {
sr = srs.iterator().next();
}
}
final String srUuid = sr.getUuid(conn);
final String tmplUuid = copy_vhd_from_secondarystorage(conn, tmplPath, srUuid, wait);
final VDI tmplVdi = getVDIbyUuid(conn, tmplUuid);
final String uuidToReturn;
final Long physicalSize = tmplVdi.getPhysicalUtilisation(conn);
if (managed) {
uuidToReturn = tmplUuid;
tmplVdi.setNameLabel(conn, managedStoragePoolRootVolumeName);
} else {
final VDI snapshotVdi = tmplVdi.snapshot(conn, new HashMap<>());
uuidToReturn = snapshotVdi.getUuid(conn);
snapshotVdi.setNameLabel(conn, "Template " + srcTemplateObjectTo.getName());
tmplVdi.destroy(conn);
}
sr.scan(conn);
try {
Thread.sleep(5000);
} catch (final InterruptedException e) {
}
final TemplateObjectTO newVol = new TemplateObjectTO();
newVol.setUuid(uuidToReturn);
newVol.setPath(uuidToReturn);
if (physicalSize != null) {
newVol.setSize(physicalSize);
}
newVol.setFormat(ImageFormat.VHD);
return new CopyCmdAnswer(newVol);
}
} catch (final Exception e) {
final String msg = "Catch Exception " + e.getClass().getName() + " for template + " + " due to " + e.toString();
s_logger.warn(msg, e);
return new CopyCmdAnswer(msg);
}
return new CopyCmdAnswer("not implemented yet");
}
use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method cloneVolumeFromBaseTemplate.
@Override
public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final DataTO srcData = cmd.getSrcTO();
final DataTO destData = cmd.getDestTO();
final VolumeObjectTO volume = (VolumeObjectTO) destData;
VDI vdi = null;
try {
VDI tmpltvdi = null;
tmpltvdi = getVDIbyUuid(conn, srcData.getPath());
vdi = tmpltvdi.createClone(conn, new HashMap<>());
vdi.setNameLabel(conn, volume.getName());
final VDI.Record vdir;
vdir = vdi.getRecord(conn);
s_logger.debug("Succesfully created VDI: Uuid = " + vdir.uuid);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setName(vdir.nameLabel);
newVol.setSize(vdir.virtualSize);
newVol.setPath(vdir.uuid);
return new CopyCmdAnswer(newVol);
} catch (final Exception e) {
s_logger.warn("Unable to create volume; Pool=" + destData + "; Disk: ", e);
return new CopyCmdAnswer(e.toString());
}
}
use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method createVolumeFromSnapshot.
@Override
public Answer createVolumeFromSnapshot(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final DataTO srcData = cmd.getSrcTO();
final SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
final DataTO destData = cmd.getDestTO();
final DataStoreTO imageStore = srcData.getDataStore();
if (srcData.getDataStore() instanceof PrimaryDataStoreTO && destData.getDataStore() instanceof PrimaryDataStoreTO) {
return createVolumeFromSnapshot2(cmd);
}
if (!(imageStore instanceof NfsTO)) {
return new CopyCmdAnswer("unsupported protocol");
}
final NfsTO nfsImageStore = (NfsTO) imageStore;
final String primaryStorageNameLabel = destData.getDataStore().getUuid();
final String secondaryStorageUrl = nfsImageStore.getUrl();
final int wait = cmd.getWait();
boolean result = false;
// Generic error message.
String details = null;
String volumeUUID = null;
if (secondaryStorageUrl == null) {
details += " because the URL passed: " + secondaryStorageUrl + " is invalid.";
return new CopyCmdAnswer(details);
}
try {
final SR primaryStorageSR = hypervisorResource.getSRByNameLabelandHost(conn, primaryStorageNameLabel);
if (primaryStorageSR == null) {
throw new InternalErrorException("Could not create volume from snapshot because the primary Storage SR could not be created from the name label: " + primaryStorageNameLabel);
}
// Get the absolute path of the snapshot on the secondary storage.
String snapshotInstallPath = snapshot.getPath();
final int index = snapshotInstallPath.lastIndexOf(nfsImageStore.getPathSeparator());
final String snapshotName = snapshotInstallPath.substring(index + 1);
if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
snapshotInstallPath = snapshotInstallPath + ".vhd";
}
final URI snapshotURI = new URI(secondaryStorageUrl + nfsImageStore.getPathSeparator() + snapshotInstallPath);
final String snapshotPath = snapshotURI.getHost() + ":" + snapshotURI.getPath();
final String srUuid = primaryStorageSR.getUuid(conn);
volumeUUID = copy_vhd_from_secondarystorage(conn, snapshotPath, srUuid, wait);
result = true;
final VDI volume = VDI.getByUuid(conn, volumeUUID);
final VDI.Record vdir = volume.getRecord(conn);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(volumeUUID);
newVol.setSize(vdir.virtualSize);
return new CopyCmdAnswer(newVol);
} catch (final XenAPIException e) {
details += " due to " + e.toString();
s_logger.warn(details, e);
} catch (final Exception e) {
details += " due to " + e.getMessage();
s_logger.warn(details, e);
}
if (!result) {
// Is this logged at a higher level?
s_logger.error(details);
}
// In all cases return something.
return new CopyCmdAnswer(details);
}
use of com.cloud.legacymodel.to.DataTO in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method deleteVolume.
@Override
public Answer deleteVolume(final DeleteCommand cmd) {
final DataTO volume = cmd.getData();
final Connection conn = hypervisorResource.getConnection();
String errorMsg = null;
try {
final VDI vdi = VDI.getByUuid(conn, volume.getPath());
deleteVDI(conn, vdi);
return new Answer(null);
} catch (final BadServerResponse e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
} catch (final XenAPIException e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
} catch (final XmlRpcException e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
}
return new Answer(null, false, errorMsg);
}
Aggregations