use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.
the class KvmStorageProcessor method attachIso.
@Override
public Answer attachIso(final AttachCommand cmd) {
final DiskTO disk = cmd.getDisk();
final TemplateObjectTO isoTo = (TemplateObjectTO) disk.getData();
final DataStoreTO store = isoTo.getDataStore();
if (!(store instanceof NfsTO)) {
return new AttachAnswer("unsupported protocol");
}
final NfsTO nfsStore = (NfsTO) store;
try {
final Connect conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
attachOrDetachIso(conn, cmd.getVmName(), nfsStore.getUrl() + File.separator + isoTo.getPath(), true);
} catch (final LibvirtException e) {
return new Answer(cmd, false, e.toString());
}
return new Answer(cmd);
}
use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.
the class DownloadManagerImpl method handleDownloadCommand.
@Override
public DownloadAnswer handleDownloadCommand(final SecondaryStorageResource resource, final DownloadCommand cmd) {
final ResourceType resourceType = cmd.getResourceType();
if (cmd instanceof DownloadProgressCommand) {
return handleDownloadProgressCmd(resource, (DownloadProgressCommand) cmd);
}
if (cmd.getUrl() == null) {
return new DownloadAnswer(resourceType.toString() + " is corrupted on storage due to an invalid url , cannot download", VMTemplateStatus.DOWNLOAD_ERROR);
}
if (cmd.getName() == null) {
return new DownloadAnswer("Invalid Name", VMTemplateStatus.DOWNLOAD_ERROR);
}
final DataStoreTO dstore = cmd.getDataStore();
String installPathPrefix = cmd.getInstallPath();
// for NFS, we need to get mounted path
if (dstore instanceof NfsTO) {
installPathPrefix = resource.getRootDir(((NfsTO) dstore).getUrl()) + File.separator + installPathPrefix;
}
String user = null;
String password = null;
if (cmd.getAuth() != null) {
user = cmd.getAuth().getUserName();
password = cmd.getAuth().getPassword();
}
// TO DO - Define Volume max size as well
final long maxDownloadSizeInBytes = cmd.getMaxDownloadSizeInBytes() == null ? TemplateDownloader.DEFAULT_MAX_TEMPLATE_SIZE_IN_BYTES : cmd.getMaxDownloadSizeInBytes();
String jobId = null;
jobId = downloadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.getAccountId(), cmd.getDescription(), cmd.getChecksum(), installPathPrefix, cmd.getInstallPath(), user, password, maxDownloadSizeInBytes, cmd.getProxy(), resourceType);
sleep();
if (jobId == null) {
return new DownloadAnswer("Internal Error", VMTemplateStatus.DOWNLOAD_ERROR);
}
return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplateSize(jobId), getDownloadCheckSum(jobId));
}
use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.
the class LibvirtRevertSnapshotCommandWrapper method execute.
@Override
public Answer execute(final RevertSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) {
final SnapshotObjectTO snapshot = command.getData();
final VolumeObjectTO volume = snapshot.getVolume();
final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
final DataStoreTO snapshotImageStore = snapshot.getDataStore();
if (!(snapshotImageStore instanceof NfsTO)) {
return new Answer(command, false, "revert snapshot on object storage is not implemented yet");
}
final NfsTO nfsImageStore = (NfsTO) snapshotImageStore;
final String secondaryStoragePoolUrl = nfsImageStore.getUrl();
final String volumePath = volume.getPath();
String snapshotPath = null;
String snapshotRelPath = null;
KvmStoragePool secondaryStoragePool = null;
try {
final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
secondaryStoragePool = storagePoolMgr.getStoragePoolByUri(secondaryStoragePoolUrl);
final String ssPmountPath = secondaryStoragePool.getLocalPath();
snapshotRelPath = snapshot.getPath();
snapshotPath = ssPmountPath + File.separator + snapshotRelPath;
final KvmPhysicalDisk snapshotDisk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), volumePath);
final KvmStoragePool primaryPool = snapshotDisk.getPool();
if (primaryPool.getType() == StoragePoolType.RBD) {
return new Answer(command, false, "revert snapshot to RBD is not implemented yet");
} else {
final Script cmd = new Script(libvirtComputingResource.manageSnapshotPath(), libvirtComputingResource.getCmdsTimeout(), s_logger);
cmd.add("-v", snapshotPath);
cmd.add("-n", snapshotDisk.getName());
cmd.add("-p", snapshotDisk.getPath());
final String result = cmd.execute();
if (result != null) {
s_logger.debug("Failed to revert snaptshot: " + result);
return new Answer(command, false, result);
}
}
return new Answer(command, true, "RevertSnapshotCommand executes successfully");
} catch (final CloudRuntimeException e) {
return new Answer(command, false, e.toString());
}
}
use of com.cloud.legacymodel.to.NfsTO in project cosmic by MissionCriticalCloud.
the class AncientDataMotionStrategy method copyVolumeFromSnapshot.
protected Answer copyVolumeFromSnapshot(final DataObject snapObj, final DataObject volObj) {
final SnapshotInfo snapshot = (SnapshotInfo) snapObj;
final StoragePool pool = (StoragePool) volObj.getDataStore();
final String basicErrMsg = "Failed to create volume from " + snapshot.getName() + " on pool " + pool;
final DataStore store = snapObj.getDataStore();
final DataStoreTO storTO = store.getTO();
DataObject srcData = snapObj;
try {
if (!(storTO instanceof NfsTO)) {
// cache snapshot to zone-wide staging store for the volume to be created
srcData = cacheSnapshotChain(snapshot, new ZoneScope(pool.getDataCenterId()));
}
final String value = configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
final int _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue()));
EndPoint ep = null;
if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
ep = selector.select(volObj);
} else {
ep = selector.select(srcData, volObj);
}
final CopyCommand cmd = new CopyCommand(srcData.getTO(), volObj.getTO(), _createVolumeFromSnapshotWait, VirtualMachineManager.ExecuteInSequence.value());
Answer answer = null;
if (ep == null) {
final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
return answer;
} catch (final Exception e) {
s_logger.error(basicErrMsg, e);
throw new CloudRuntimeException(basicErrMsg);
} finally {
if (!(storTO instanceof NfsTO)) {
// still keep snapshot on cache which may be migrated from previous secondary storage
releaseSnapshotCacheChain((SnapshotInfo) srcData);
}
}
}
use of com.cloud.legacymodel.to.NfsTO 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");
}
Aggregations