protected CreateAnswer execute(CreateCommand cmd) { StorageFilerTO primaryStorage = cmd.getPool(); DiskProfile disk = cmd.getDiskCharacteristics(); try { OvmVolume.Details vol = null; if (cmd.getTemplateUrl() != null) { vol = OvmVolume.createFromTemplate(_conn, primaryStorage.getUuid(), cmd.getTemplateUrl()); } else { vol = OvmVolume.createDataDsik(_conn, primaryStorage.getUuid(), Long.toString(disk.getSize()), disk.getType() == Volume.Type.ROOT); } VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(), primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(), vol.name, vol.path, vol.size, null); return new CreateAnswer(cmd, volume); } catch (Exception e) { s_logger.debug("CreateCommand failed", e); return new CreateAnswer(cmd, e.getMessage()); } }
@Test public final void testCreateCommand() { String sample = "{\"volId\":10,\"pool\":{\"id\":201,\"uuid\":\"" + s_testLocalStoreUUID + "\",\"host\":\"10.70.176.29\"" + ",\"path\":" + s_testLocalStorePathJSON + ",\"port\":0,\"type\":\"Filesystem\"}," + "\"diskCharacteristics\":{\"size\":0," + "\"tags\":[],\"type\":\"ROOT\",\"name\":\"ROOT-9\"," + "\"useLocalStorage\":true,\"recreatable\":true," + "\"diskOfferingId\":11," + "\"volumeId\":10,\"hyperType\":\"Hyperv\"}," + "\"templateUrl\":" + s_testSampleTemplateURLJSON + ",\"contextMap\":{},\"wait\":0}"; File destDir = new File(s_testLocalStorePath); Assert.assertTrue(destDir.isDirectory()); File testSampleTemplateURLFile = new File(s_testLocalStorePath + File.separator + s_gson.fromJson(s_testSampleTemplateURLJSON, String.class)); Assert.assertTrue("The template that create should make" + " volumes from is missing from path " + testSampleTemplateURLFile.getPath(), testSampleTemplateURLFile.exists()); int fileCount = destDir.listFiles().length; s_logger.debug(" test local store has " + fileCount + "files"); // Test requires there to be a template at the tempalteUrl, which is its // location in the local file system. CreateCommand cmd = s_gson.fromJson(sample, CreateCommand.class); CreateAnswer ans = (CreateAnswer)s_hypervresource.executeRequest(cmd); Assert.assertTrue(ans.getDetails(), ans.getResult()); Assert.assertTrue("CreateCommand should add a file to the folder", fileCount + 1 == destDir.listFiles().length); File newFile = new File(ans.getVolume().getPath()); Assert.assertTrue("The new file should have a size greater than zero", newFile.length() > 0); newFile.delete(); }
/** * Generates the volume path by appending the Volume UUID to the Libvirt destiny images path.</br> * Example: /var/lib/libvirt/images/f3d49ecc-870c-475a-89fa-fd0124420a9b */ @Override protected String generateDestPath(VirtualMachineTO vmTO, VolumeVO srcVolume, Host destHost, StoragePoolVO destStoragePool, VolumeInfo destVolumeInfo) { DiskOfferingVO diskOffering = _diskOfferingDao.findById(srcVolume.getDiskOfferingId()); DiskProfile diskProfile = new DiskProfile(destVolumeInfo, diskOffering, HypervisorType.KVM); String templateUuid = getTemplateUuid(destVolumeInfo.getTemplateId()); CreateCommand rootImageProvisioningCommand = new CreateCommand(diskProfile, templateUuid, destStoragePool, true); Answer rootImageProvisioningAnswer = _agentMgr.easySend(destHost.getId(), rootImageProvisioningCommand); if (rootImageProvisioningAnswer == null) { throw new CloudRuntimeException(String.format("Migration with storage of vm [%s] failed while provisioning root image", vmTO.getName())); } if (!rootImageProvisioningAnswer.getResult()) { throw new CloudRuntimeException(String.format("Unable to modify target volume on the host [host id:%s, name:%s]", destHost.getId(), destHost.getName())); } String libvirtDestImgsPath = null; if (rootImageProvisioningAnswer instanceof CreateAnswer) { libvirtDestImgsPath = ((CreateAnswer)rootImageProvisioningAnswer).getVolume().getName(); } // File.getAbsolutePath is used to keep the file separator as it should be and eliminate a verification to check if exists a file separator in the last character of libvirtDestImgsPath. return new File(libvirtDestImgsPath, destVolumeInfo.getUuid()).getAbsolutePath(); }
primaryStorage.getPath(), fileName, fp.getName(), fp.getSize(), null); return new CreateAnswer(cmd, volume); } catch (Exception e) { LOGGER.debug("CreateCommand failed", e); return new CreateAnswer(cmd, e.getMessage());
new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), vdir.nameLabel, pool.getPath(), vdir.uuid, vdir.virtualSize, null); return new CreateAnswer(command, vol); } catch (final Exception e) { s_logger.warn("Unable to create volume; Pool=" + pool + "; Disk: " + dskch, e); return new CreateAnswer(command, e);
volume.setIopsWriteRate(dskch.getIopsWriteRate()); volume.setCacheMode(dskch.getCacheMode()); return new CreateAnswer(command, volume); } catch (final CloudRuntimeException e) { s_logger.debug("Failed to create volume: " + e.toString()); return new CreateAnswer(command, e);