use of com.cloud.legacymodel.to.NfsTO 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.NfsTO in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method createTemplateFromVolume.
@Override
public Answer createTemplateFromVolume(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final VolumeObjectTO volume = (VolumeObjectTO) cmd.getSrcTO();
final TemplateObjectTO template = (TemplateObjectTO) cmd.getDestTO();
final NfsTO destStore = (NfsTO) cmd.getDestTO().getDataStore();
final int wait = cmd.getWait();
final String secondaryStoragePoolURL = destStore.getUrl();
final String volumeUUID = volume.getPath();
final String userSpecifiedName = template.getName();
String details = null;
SR tmpltSR = null;
boolean result = false;
String secondaryStorageMountPath = null;
String installPath = null;
try {
final URI uri = new URI(secondaryStoragePoolURL);
secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
installPath = template.getPath();
if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath)) {
details = " Filed to create folder " + installPath + " in secondary storage";
s_logger.warn(details);
return new CopyCmdAnswer(details);
}
final VDI vol = getVDIbyUuid(conn, volumeUUID);
// create template SR
final URI tmpltURI = new URI(secondaryStoragePoolURL + "/" + installPath);
tmpltSR = hypervisorResource.createNfsSRbyURI(conn, tmpltURI, false);
// copy volume to template SR
final VDI tmpltVDI = hypervisorResource.cloudVDIcopy(conn, vol, tmpltSR, wait);
// scan makes XenServer pick up VDI physicalSize
tmpltSR.scan(conn);
if (userSpecifiedName != null) {
tmpltVDI.setNameLabel(conn, userSpecifiedName);
}
final String tmpltUUID = tmpltVDI.getUuid(conn);
final String tmpltFilename = tmpltUUID + ".vhd";
final long virtualSize = tmpltVDI.getVirtualSize(conn);
final long physicalSize = tmpltVDI.getPhysicalUtilisation(conn);
// create the template.properties file
final String templatePath = secondaryStorageMountPath + "/" + installPath;
result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, tmpltFilename, tmpltUUID, userSpecifiedName, null, physicalSize, virtualSize, template.getId());
if (!result) {
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI);
}
installPath = installPath + "/" + tmpltFilename;
hypervisorResource.removeSR(conn, tmpltSR);
tmpltSR = null;
final TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(installPath);
newTemplate.setFormat(ImageFormat.VHD);
newTemplate.setSize(virtualSize);
newTemplate.setPhysicalSize(physicalSize);
newTemplate.setName(tmpltUUID);
final CopyCmdAnswer answer = new CopyCmdAnswer(newTemplate);
return answer;
} catch (final Exception e) {
if (tmpltSR != null) {
hypervisorResource.removeSR(conn, tmpltSR);
}
if (secondaryStorageMountPath != null) {
hypervisorResource.deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath);
}
details = "Creating template from volume " + volumeUUID + " failed due to " + e.toString();
s_logger.error(details, e);
}
return new CopyCmdAnswer(details);
}
use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method copyVolumeFromImageCacheToPrimary.
@Override
public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final DataTO srcData = cmd.getSrcTO();
final DataTO destData = cmd.getDestTO();
final int wait = cmd.getWait();
final VolumeObjectTO srcVolume = (VolumeObjectTO) srcData;
final VolumeObjectTO destVolume = (VolumeObjectTO) destData;
final DataStoreTO srcStore = srcVolume.getDataStore();
if (srcStore instanceof NfsTO) {
final NfsTO nfsStore = (NfsTO) srcStore;
try {
final SR primaryStoragePool = hypervisorResource.getStorageRepository(conn, destVolume.getDataStore().getUuid());
final String srUuid = primaryStoragePool.getUuid(conn);
final URI uri = new URI(nfsStore.getUrl());
final String volumePath = uri.getHost() + ":" + uri.getPath() + nfsStore.getPathSeparator() + srcVolume.getPath();
final String uuid = copy_vhd_from_secondarystorage(conn, volumePath, srUuid, wait);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(uuid);
newVol.setSize(srcVolume.getSize());
return new CopyCmdAnswer(newVol);
} catch (final Exception e) {
final String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
s_logger.warn(msg, e);
return new CopyCmdAnswer(e.toString());
}
}
s_logger.debug("unsupported protocol");
return new CopyCmdAnswer("unsupported protocol");
}
use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.
the class XenServerStorageProcessor method copyVolumeFromPrimaryToSecondary.
@Override
public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final VolumeObjectTO srcVolume = (VolumeObjectTO) cmd.getSrcTO();
final VolumeObjectTO destVolume = (VolumeObjectTO) cmd.getDestTO();
final int wait = cmd.getWait();
final DataStoreTO destStore = destVolume.getDataStore();
if (destStore instanceof NfsTO) {
SR secondaryStorage = null;
try {
final NfsTO nfsStore = (NfsTO) destStore;
final URI uri = new URI(nfsStore.getUrl());
// Create the volume folder
if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath())) {
throw new InternalErrorException("Failed to create the volume folder.");
}
// Create a SR for the volume UUID folder
secondaryStorage = hypervisorResource.createNfsSRbyURI(conn, new URI(nfsStore.getUrl() + nfsStore.getPathSeparator() + destVolume.getPath()), false);
// Look up the volume on the source primary storage pool
final VDI srcVdi = getVDIbyUuid(conn, srcVolume.getPath());
// Copy the volume to secondary storage
final VDI destVdi = hypervisorResource.cloudVDIcopy(conn, srcVdi, secondaryStorage, wait);
final String destVolumeUUID = destVdi.getUuid(conn);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(destVolume.getPath() + nfsStore.getPathSeparator() + destVolumeUUID + ".vhd");
newVol.setSize(srcVolume.getSize());
return new CopyCmdAnswer(newVol);
} catch (final Exception e) {
s_logger.debug("Failed to copy volume to secondary: " + e.toString());
return new CopyCmdAnswer("Failed to copy volume to secondary: " + e.toString());
} finally {
hypervisorResource.removeSR(conn, secondaryStorage);
}
}
return new CopyCmdAnswer("unsupported protocol");
}
use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.
the class Xenserver625StorageProcessor method copyVolumeFromPrimaryToSecondary.
@Override
public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final VolumeObjectTO srcVolume = (VolumeObjectTO) cmd.getSrcTO();
final VolumeObjectTO destVolume = (VolumeObjectTO) cmd.getDestTO();
final int wait = cmd.getWait();
final DataStoreTO destStore = destVolume.getDataStore();
if (destStore instanceof NfsTO) {
SR secondaryStorage = null;
Task task = null;
try {
final NfsTO nfsStore = (NfsTO) destStore;
final URI uri = new URI(nfsStore.getUrl());
// Create the volume folder
if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath())) {
throw new InternalErrorException("Failed to create the volume folder.");
}
// Create a SR for the volume UUID folder
secondaryStorage = createFileSr(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath());
// Look up the volume on the source primary storage pool
final VDI srcVdi = getVDIbyUuid(conn, srcVolume.getPath());
// Copy the volume to secondary storage
task = srcVdi.copyAsync(conn, secondaryStorage, null, null);
// poll every 1 seconds ,
hypervisorResource.waitForTask(conn, task, 1000, wait * 1000);
hypervisorResource.checkForSuccess(conn, task);
final VDI destVdi = Types.toVDI(task, conn);
final String destVolumeUUID = destVdi.getUuid(conn);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(destVolume.getPath() + File.separator + destVolumeUUID + ".vhd");
newVol.setSize(srcVolume.getSize());
return new CopyCmdAnswer(newVol);
} catch (final Exception e) {
s_logger.debug("Failed to copy volume to secondary: " + e.toString());
return new CopyCmdAnswer("Failed to copy volume to secondary: " + e.toString());
} finally {
if (task != null) {
try {
task.destroy(conn);
} catch (final Exception e) {
s_logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString());
}
}
hypervisorResource.removeSR(conn, secondaryStorage);
}
}
return new CopyCmdAnswer("unsupported protocol");
}
Aggregations