use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.
the class Ovm3VmSupport method createVbds.
/*
* Add rootdisk, datadisk and iso's
*/
public Boolean createVbds(Xen.Vm vm, VirtualMachineTO spec) {
if (spec.getDisks() == null) {
LOGGER.info("No disks defined for " + vm.getVmName());
return false;
}
for (DiskTO disk : spec.getDisks()) {
try {
if (disk.getType() == Volume.Type.ROOT) {
VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
String diskFile = processor.getVirtualDiskPath(vol.getUuid(), vol.getDataStore().getUuid());
vm.addRootDisk(diskFile);
vm.setPrimaryPoolUuid(vol.getDataStore().getUuid());
LOGGER.debug("Adding root disk: " + diskFile);
} else if (disk.getType() == Volume.Type.ISO) {
DataTO isoTO = disk.getData();
if (isoTO.getPath() != null) {
TemplateObjectTO template = (TemplateObjectTO) isoTO;
DataStoreTO store = template.getDataStore();
if (!(store instanceof NfsTO)) {
throw new CloudRuntimeException("unsupported protocol");
}
NfsTO nfsStore = (NfsTO) store;
String secPoolUuid = pool.setupSecondaryStorage(nfsStore.getUrl());
String isoPath = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + template.getPath();
vm.addIso(isoPath);
/* check if secondary storage is mounted */
LOGGER.debug("Adding ISO: " + isoPath);
}
} else if (disk.getType() == Volume.Type.DATADISK) {
VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
String diskFile = processor.getVirtualDiskPath(vol.getUuid(), vol.getDataStore().getUuid());
vm.addDataDisk(diskFile);
LOGGER.debug("Adding data disk: " + diskFile);
} else {
throw new CloudRuntimeException("Unknown disk type: " + disk.getType());
}
} catch (Exception e) {
LOGGER.debug("CreateVbds failed", e);
throw new CloudRuntimeException("Exception" + e.getMessage(), e);
}
}
return true;
}
use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.
the class Ovm3StorageProcessorTest method deleteCommandTest.
/**
* Delete an object
*
* @throws ConfigurationException
*/
@Test
public void deleteCommandTest() throws ConfigurationException {
con = prepare();
VolumeObjectTO vol = volume(ovmObject.newUuid(), ovmObject.newUuid(), linux.getRepoId(), linux.getVirtualDisksDir());
DeleteCommand delete = new DeleteCommand(vol);
Answer ra = hypervisor.executeRequest(delete);
results.basicBooleanTest(ra.getResult());
TemplateObjectTO template = template(ovmObject.newUuid(), ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
delete = new DeleteCommand(template);
ra = hypervisor.executeRequest(delete);
results.basicBooleanTest(ra.getResult(), false);
SnapshotObjectTO snap = snapshot(ovmObject.newUuid(), ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
delete = new DeleteCommand(snap);
ra = hypervisor.executeRequest(delete);
results.basicBooleanTest(ra.getResult(), false);
}
use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.
the class Ovm3StorageProcessorTest method createTemplateObjectCommandTest.
/*
* unused ?
*
* @Test
* public void createCommandTest() throws ConfigurationException {
* con = prepare();
* DiskProfile disk = diskProfile();
* String templateUrl = null;
* StoragePoolVO poolio = new StoragePoolVO();
* poolio.setPath(linux.getTemplatesDir());
* poolio.setHostAddress(linux.getRemoteHost());
*
* CreateCommand create = new CreateCommand(disk, templateUrl, poolio ,
* false);
* Answer ra = hypervisor.executeRequest(create);
* results.basicBooleanTest(ra.getResult());
* }
*/
@Test
public void createTemplateObjectCommandTest() throws ConfigurationException {
con = prepare();
String tempuuid = ovmObject.newUuid();
TemplateObjectTO template = template(tempuuid, ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
template.setSize(storageplugin.getFileSize());
String response = storageplugin.getFileCreateXml().replace(storageplugin.getFileName(), tempuuid + ".raw");
response = response.replace(storageplugin.getPoolUuid(), ovmObject.deDash(linux.getRepoId()));
con.setMethodResponse("storage_plugin_create", results.simpleResponseWrapWrapper(response));
CreateObjectCommand create = new CreateObjectCommand(template);
Answer ra = hypervisor.executeRequest(create);
results.basicBooleanTest(ra.getResult(), false);
}
use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.
the class NfsSecondaryStorageResource method copySnapshotToTemplateFromNfsToNfsXenserver.
protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData, NfsTO destDataStore) {
String srcMountPoint = getRootDir(srcDataStore.getUrl(), _nfsVersion);
String snapshotPath = srcData.getPath();
int index = snapshotPath.lastIndexOf("/");
String snapshotName = snapshotPath.substring(index + 1);
if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
snapshotName = snapshotName + ".vhd";
}
snapshotPath = snapshotPath.substring(0, index);
snapshotPath = srcMountPoint + File.separator + snapshotPath;
String destMountPoint = getRootDir(destDataStore.getUrl(), _nfsVersion);
String destPath = destMountPoint + File.separator + destData.getPath();
String errMsg = null;
try {
_storage.mkdir(destPath);
String templateUuid = UUID.randomUUID().toString();
String templateName = templateUuid + ".vhd";
Script command = new Script(createTemplateFromSnapshotXenScript, cmd.getWait() * 1000, s_logger);
command.add("-p", snapshotPath);
command.add("-s", snapshotName);
command.add("-n", templateName);
command.add("-t", destPath);
String result = command.execute();
if (result != null && !result.equalsIgnoreCase("")) {
return new CopyCmdAnswer(result);
}
Map<String, Object> params = new HashMap<String, Object>();
params.put(StorageLayer.InstanceConfigKey, _storage);
Processor processor = new VhdProcessor();
processor.configure("Vhd Processor", params);
FormatInfo info = processor.process(destPath, null, templateUuid);
TemplateLocation loc = new TemplateLocation(_storage, destPath);
loc.create(1, true, templateUuid);
loc.addFormat(info);
loc.save();
TemplateProp prop = loc.getTemplateInfo();
TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(destData.getPath() + File.separator + templateName);
newTemplate.setFormat(ImageFormat.VHD);
newTemplate.setSize(prop.getSize());
newTemplate.setPhysicalSize(prop.getPhysicalSize());
newTemplate.setName(templateUuid);
return new CopyCmdAnswer(newTemplate);
} catch (ConfigurationException e) {
s_logger.debug("Failed to create template from snapshot: " + e.toString());
errMsg = e.toString();
} catch (InternalErrorException e) {
s_logger.debug("Failed to create template from snapshot: " + e.toString());
errMsg = e.toString();
} catch (IOException e) {
s_logger.debug("Failed to create template from snapshot: " + e.toString());
errMsg = e.toString();
}
return new CopyCmdAnswer(errMsg);
}
use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.
the class NfsSecondaryStorageResource method copyFromNfsToS3.
protected Answer copyFromNfsToS3(CopyCommand cmd) {
final DataTO srcData = cmd.getSrcTO();
final DataTO destData = cmd.getDestTO();
DataStoreTO srcDataStore = srcData.getDataStore();
NfsTO srcStore = (NfsTO) srcDataStore;
DataStoreTO destDataStore = destData.getDataStore();
final S3TO s3 = (S3TO) destDataStore;
try {
final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath(), _nfsVersion);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath + " to upload to S3.");
}
final String bucket = s3.getBucketName();
File srcFile = findFile(templatePath);
if (srcFile == null) {
return new CopyCmdAnswer("Can't find src file:" + templatePath);
}
ImageFormat format = getTemplateFormat(srcFile.getName());
String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
putFile(s3, srcFile, bucket, key).waitForCompletion();
DataTO retObj = null;
if (destData.getObjectType() == DataObjectType.TEMPLATE) {
TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(key);
newTemplate.setSize(getVirtualSize(srcFile, format));
newTemplate.setPhysicalSize(srcFile.length());
newTemplate.setFormat(format);
retObj = newTemplate;
} else if (destData.getObjectType() == DataObjectType.VOLUME) {
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(key);
newVol.setSize(srcFile.length());
retObj = newVol;
} else if (destData.getObjectType() == DataObjectType.SNAPSHOT) {
SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
newSnapshot.setPath(key);
retObj = newSnapshot;
}
return new CopyCmdAnswer(retObj);
} catch (Exception e) {
s_logger.error("failed to upload" + srcData.getPath(), e);
return new CopyCmdAnswer("failed to upload" + srcData.getPath() + e.toString());
}
}
Aggregations