use of com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer in project cloudstack by apache.
the class OvmResourceBase method execute.
protected PrimaryStorageDownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
try {
URI uri = new URI(cmd.getUrl());
String secondaryStoragePath = uri.getHost() + ":" + uri.getPath();
Pair<String, Long> res = OvmStoragePool.downloadTemplate(_conn, cmd.getPoolUuid(), secondaryStoragePath);
return new PrimaryStorageDownloadAnswer(res.first(), res.second());
} catch (Exception e) {
s_logger.debug("PrimaryStorageDownloadCommand failed", e);
return new PrimaryStorageDownloadAnswer(e.getMessage());
}
}
use of com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer in project cloudstack by apache.
the class VmwareStorageManagerImpl method execute.
@Override
public Answer execute(VmwareHostService hostService, PrimaryStorageDownloadCommand cmd) {
String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
assert (secondaryStorageUrl != null);
String templateUrl = cmd.getUrl();
String templateName = null;
String mountPoint = null;
if (templateUrl.endsWith(".ova")) {
int index = templateUrl.lastIndexOf("/");
mountPoint = templateUrl.substring(0, index);
mountPoint = mountPoint.substring(secondaryStorageUrl.length() + 1);
if (!mountPoint.endsWith("/")) {
mountPoint = mountPoint + "/";
}
templateName = templateUrl.substring(index + 1).replace("." + ImageFormat.OVA.getFileExtension(), "");
if (templateName == null || templateName.isEmpty()) {
templateName = cmd.getName();
}
} else {
mountPoint = templateUrl.substring(secondaryStorageUrl.length() + 1);
if (!mountPoint.endsWith("/")) {
mountPoint = mountPoint + "/";
}
templateName = cmd.getName();
}
VmwareContext context = hostService.getServiceContext(cmd);
try {
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
String templateUuidName = UUID.nameUUIDFromBytes((templateName + "@" + cmd.getPoolUuid() + "-" + hyperHost.getMor().getValue()).getBytes("UTF-8")).toString();
// truncate template name to 32 chars to ensure they work well with vSphere API's.
templateUuidName = templateUuidName.replace("-", "");
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
VirtualMachineMO templateMo = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUuidName), true);
if (templateMo == null) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName);
}
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPoolUuid());
assert (morDs != null);
DatastoreMO primaryStorageDatastoreMo = new DatastoreMO(context, morDs);
copyTemplateFromSecondaryToPrimary(hyperHost, primaryStorageDatastoreMo, secondaryStorageUrl, mountPoint, templateName, templateUuidName, cmd.getNfsVersion());
} else {
s_logger.info("Template " + templateName + " has already been setup, skip the template setup process in primary storage");
}
return new PrimaryStorageDownloadAnswer(templateUuidName, 0);
} catch (Throwable e) {
if (e instanceof RemoteException) {
hostService.invalidateServiceContext(context);
}
String msg = "Unable to execute PrimaryStorageDownloadCommand due to exception";
s_logger.error(msg, e);
return new PrimaryStorageDownloadAnswer(msg);
}
}
use of com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer in project cloudstack by apache.
the class CitrixPrimaryStorageDownloadCommandWrapper method execute.
@Override
public Answer execute(final PrimaryStorageDownloadCommand command, final CitrixResourceBase citrixResourceBase) {
final String tmplturl = command.getUrl();
final String poolName = command.getPoolUuid();
final int wait = command.getWait();
try {
final URI uri = new URI(tmplturl);
final String tmplpath = uri.getHost() + ":" + uri.getPath();
final Connection conn = citrixResourceBase.getConnection();
SR poolsr = null;
final Set<SR> srs = SR.getByNameLabel(conn, poolName);
if (srs.size() != 1) {
final String msg = "There are " + srs.size() + " SRs with same name: " + poolName;
s_logger.warn(msg);
return new PrimaryStorageDownloadAnswer(msg);
} else {
poolsr = srs.iterator().next();
}
final String pUuid = poolsr.getUuid(conn);
final boolean isISCSI = citrixResourceBase.IsISCSI(poolsr.getType(conn));
final String uuid = citrixResourceBase.copyVhdFromSecondaryStorage(conn, tmplpath, pUuid, wait);
final VDI tmpl = citrixResourceBase.getVDIbyUuid(conn, uuid);
final VDI snapshotvdi = tmpl.snapshot(conn, new HashMap<String, String>());
final String snapshotUuid = snapshotvdi.getUuid(conn);
snapshotvdi.setNameLabel(conn, "Template " + command.getName());
final String parentuuid = citrixResourceBase.getVhdParent(conn, pUuid, snapshotUuid, isISCSI);
final VDI parent = citrixResourceBase.getVDIbyUuid(conn, parentuuid);
final Long phySize = parent.getPhysicalUtilisation(conn);
tmpl.destroy(conn);
poolsr.scan(conn);
try {
Thread.sleep(5000);
} catch (final Exception e) {
}
return new PrimaryStorageDownloadAnswer(snapshotvdi.getUuid(conn), phySize);
} catch (final Exception e) {
final String msg = "Catch Exception " + e.getClass().getName() + " on host:" + citrixResourceBase.getHost().getUuid() + " for template: " + tmplturl + " due to " + e.toString();
s_logger.warn(msg, e);
return new PrimaryStorageDownloadAnswer(msg);
}
}
use of com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer in project cloudstack by apache.
the class Ovm3StoragePool method execute.
/**
* Download from template url into primary storage ?.. is this relevant ?
*
* @param cmd
* @return
*/
public PrimaryStorageDownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
try {
Repository repo = new Repository(c);
String tmplturl = cmd.getUrl();
String poolName = cmd.getPoolUuid();
String image = repo.deDash(repo.newUuid()) + ".raw";
/* url to download from, image name, and repo to copy it to */
repo.importVirtualDisk(tmplturl, image, poolName);
return new PrimaryStorageDownloadAnswer(image);
} catch (Exception e) {
LOGGER.debug("PrimaryStorageDownloadCommand failed", e);
return new PrimaryStorageDownloadAnswer(e.getMessage());
}
}
use of com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method primaryStorageDownload.
@Override
public PrimaryStorageDownloadAnswer primaryStorageDownload(PrimaryStorageDownloadCommand cmd) {
MockVolumeVO template = findVolumeFromSecondary(cmd.getUrl(), cmd.getSecondaryStorageUrl(), MockVolumeType.TEMPLATE);
if (template == null) {
return new PrimaryStorageDownloadAnswer("Can't find primary storage");
}
MockStoragePoolVO primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPoolUuid());
if (primaryStorage == null) {
return new PrimaryStorageDownloadAnswer("Can't find primary storage");
}
String volumeName = UUID.randomUUID().toString();
MockVolumeVO newVolume = new MockVolumeVO();
newVolume.setName(volumeName);
newVolume.setPath(primaryStorage.getMountPoint() + volumeName);
newVolume.setPoolId(primaryStorage.getId());
newVolume.setSize(template.getSize());
newVolume.setType(MockVolumeType.VOLUME);
_mockVolumeDao.persist(newVolume);
return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize());
}
Aggregations