protected boolean needCacheStorage(DataObject srcData, DataObject destData) { DataTO srcTO = srcData.getTO(); DataStoreTO srcStoreTO = srcTO.getDataStore(); if (srcStoreTO instanceof NfsTO || srcStoreTO.getRole() == DataStoreRole.ImageCache) { return false; } DataTO destTO = destData.getTO(); DataStoreTO destStoreTO = destTO.getDataStore(); if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) { return false; } if (s_logger.isDebugEnabled()) { s_logger.debug("needCacheStorage true, dest at " + destTO.getPath() + " dest role " + destStoreTO.getRole().toString() + srcTO.getPath() + " src role " + srcStoreTO.getRole().toString()); } return true; }
@Override public Answer introduceObject(final IntroduceObjectCmd cmd) { try { final Connection conn = hypervisorResource.getConnection(); final DataStoreTO store = cmd.getDataTO().getDataStore(); final SR poolSr = hypervisorResource.getStorageRepository(conn, store.getUuid()); poolSr.scan(conn); return new IntroduceObjectAnswer(cmd.getDataTO()); } catch (final Exception e) { s_logger.debug("Failed to introduce object", e); return new Answer(cmd, false, e.toString()); } }
protected void copyLocalToNfs(File localFile, File isoFile, DataStoreTO destData) throws ConfigurationException, IOException { String scriptsDir = "scripts/storage/secondary"; String createVolScr = Script.findScript(scriptsDir, "createvolume.sh"); if (createVolScr == null) { throw new ConfigurationException("Unable to find createvolume.sh"); } s_logger.info("createvolume.sh found in " + createVolScr); int installTimeoutPerGig = 180 * 60 * 1000; int imgSizeGigs = (int) Math.ceil(localFile.length() * 1.0d / (1024 * 1024 * 1024)); imgSizeGigs++; // add one just in case long timeout = imgSizeGigs * installTimeoutPerGig; Script scr = new Script(createVolScr, timeout, s_logger); scr.add("-s", Integer.toString(imgSizeGigs)); scr.add("-n", isoFile.getName()); scr.add("-t", getRootDir(destData.getUrl(), _nfsVersion) + "/" + isoFile.getParent()); scr.add("-f", localFile.getAbsolutePath()); scr.add("-d", "configDrive"); String result; result = scr.execute(); if (result != null) { // script execution failure throw new CloudRuntimeException("Failed to run script " + createVolScr); } }
@Override public Answer deleteVolume(DeleteCommand cmd) { LOGGER.debug("execute deleteVolume: "+ cmd.getClass()); DataTO data = cmd.getData(); VolumeObjectTO volume = (VolumeObjectTO) data; try { String poolUuid = data.getDataStore().getUuid(); String uuid = volume.getUuid(); String path = getVirtualDiskPath(uuid, poolUuid); StoragePlugin sp = new StoragePlugin(c); sp.storagePluginDestroy(poolUuid, path); LOGGER.debug("Volume deletion success: " + path); } catch (Ovm3ResourceException e) { LOGGER.info("Volume deletion failed: " + e.toString(), e); return new CreateObjectAnswer(e.toString()); } return new Answer(cmd); }
public String getVolumePath(final Connect conn, final DiskTO volume) throws LibvirtException, URISyntaxException { final DataTO data = volume.getData(); final DataStoreTO store = data.getDataStore(); if (volume.getType() == Volume.Type.ISO && data.getPath() != null && (store instanceof NfsTO || store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO && !((TemplateObjectTO) data).isDirectDownload())) { final String isoPath = store.getUrl().split("\\?")[0] + File.separator + data.getPath(); final int index = isoPath.lastIndexOf("/"); final String path = isoPath.substring(0, index); final String name = isoPath.substring(index + 1); final KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(path); final KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name); return isoVol.getPath(); } else { return data.getPath(); } }
private boolean needCacheStorage(DataObject srcData, DataObject destData) { DataTO srcTO = srcData.getTO(); DataStoreTO srcStoreTO = srcTO.getDataStore(); DataTO destTO = destData.getTO(); DataStoreTO destStoreTO = destTO.getDataStore(); // both snapshot and volume are on primary datastore - no need for a cache storage as hypervisor will copy directly if (srcStoreTO instanceof PrimaryDataStoreTO && destStoreTO instanceof PrimaryDataStoreTO) { return false; } if (srcStoreTO instanceof NfsTO || srcStoreTO.getRole() == DataStoreRole.ImageCache) { return false; } if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) { return false; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("needCacheStorage true; dest at " + destTO.getPath() + ", dest role " + destStoreTO.getRole().toString() + "; src at " + srcTO.getPath() + ", src role " + srcStoreTO.getRole().toString()); } return true; }
@Override public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtComputingResource libvirtComputingResource) { final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr(); final KVMStoragePool pool = storagePoolMgr.getStoragePool(Storage.StoragePoolType.NetworkFilesystem, command.getDestStore().getUuid()); if (pool == null) { return new Answer(command, false, "Pool not found, config drive for KVM is only supported for NFS");
return new Answer(cmd, false, "Invalid config drive ISO data"); String nfsMountPoint = getRootDir(cmd.getDestStore().getUrl(), _nfsVersion); File isoFile = new File(nfsMountPoint, cmd.getIsoFile()); if(isoFile.exists()) {
protected Answer execute(CopyCommand cmd) { DataTO srcData = cmd.getSrcTO(); DataTO destData = cmd.getDestTO(); DataStoreTO srcDataStore = srcData.getDataStore(); DataStoreTO destDataStore = destData.getDataStore(); if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) { return createTemplateFromSnapshot(cmd); } if (destDataStore instanceof NfsTO && destDataStore.getRole() == DataStoreRole.ImageCache) { NfsTO destImageStore = (NfsTO)destDataStore; if (srcDataStore instanceof S3TO) { S3TO s3 = (S3TO)srcDataStore; return copyFromS3ToNfs(cmd, srcData, s3, destData, destImageStore); } else if (srcDataStore instanceof SwiftTO) { return copyFromSwiftToNfs(cmd, srcData, (SwiftTO)srcDataStore, destData, destImageStore); } } if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole() == DataStoreRole.Image) { return copyFromNfsToImage(cmd); } return Answer.createUnsupportedCommandAnswer(cmd); }
String primaryStorageNameLabel = destData.getDataStore().getUuid();
/** * Is not used in normal operation, the SSVM takes care of this. */ @Override public Answer deleteSnapshot(DeleteCommand cmd) { LOGGER.debug("execute deleteSnapshot: "+ cmd.getClass()); DataTO data = cmd.getData(); SnapshotObjectTO snap = (SnapshotObjectTO) data; String storeUrl = data.getDataStore().getUrl(); String snapUuid = snap.getPath(); try { // snapshots/accountid/volumeid String secPoolUuid = pool.setupSecondaryStorage(storeUrl); String filePath = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + snapUuid + ".raw"; StoragePlugin sp = new StoragePlugin(c); sp.storagePluginDestroy(secPoolUuid, filePath); LOGGER.debug("Snapshot deletion success: " + filePath); return new Answer(cmd, true, "Deleted Snapshot " + filePath); } catch (Ovm3ResourceException e) { LOGGER.info("Snapshot deletion failed: " + e.toString(), e); return new CreateObjectAnswer(e.toString()); } } /**
@Override public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) { if (cmd instanceof CopyCommand) { CopyCommand c = (CopyCommand) cmd; boolean inSeq = true; if (c.getSrcTO().getObjectType() == DataObjectType.SNAPSHOT || c.getDestTO().getObjectType() == DataObjectType.SNAPSHOT) { inSeq = false; } else if (c.getDestTO().getDataStore().getRole() == DataStoreRole.Image || c.getDestTO().getDataStore().getRole() == DataStoreRole.ImageCache) { inSeq = false; } c.setExecuteInSequence(inSeq); } if (cmd instanceof StorageSubSystemCommand) { StorageSubSystemCommand c = (StorageSubSystemCommand)cmd; c.setExecuteInSequence(false); } return new Pair<Boolean, Long>(false, new Long(hostId)); }
@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"); }
(srcData.getDataStore().getRole() == DataStoreRole.Image || srcData.getDataStore().getRole() == DataStoreRole.ImageCache) && destData.getDataStore().getRole() == DataStoreRole.Primary) { } else if (srcData.getObjectType() == DataObjectType.TEMPLATE && srcDataStore.getRole() == DataStoreRole.Primary && destDataStore.getRole() == DataStoreRole.Primary) { (srcData.getDataStore().getRole() == DataStoreRole.ImageCache || srcDataStore.getRole() == DataStoreRole.Image)) { } else if (srcData.getObjectType() == DataObjectType.VOLUME && srcData.getDataStore().getRole() == DataStoreRole.Primary) { if (destData.getObjectType() == DataObjectType.VOLUME) { return processor.copyVolumeFromPrimaryToSecondary(cmd); srcData.getDataStore().getRole() == DataStoreRole.Primary) { return processor.backupSnapshot(cmd); } else if (srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.VOLUME) {
final String srName = destDataStoreTo.getUuid(); final Set<SR> srs = SR.getByNameLabel(conn, srName);
/** * Return data store URL from store */ private String getDataStoreUrlFromStore(DataStoreTO store) { if (!(store instanceof NfsTO) && (!(store instanceof PrimaryDataStoreTO) || store instanceof PrimaryDataStoreTO && !((PrimaryDataStoreTO) store).getPoolType().equals(StoragePoolType.NetworkFilesystem))) { throw new InvalidParameterValueException("unsupported protocol"); } if (store instanceof NfsTO) { NfsTO nfsStore = (NfsTO)store; return nfsStore.getUrl(); } else if (store instanceof PrimaryDataStoreTO && ((PrimaryDataStoreTO) store).getPoolType().equals(StoragePoolType.NetworkFilesystem)) { //In order to support directly downloaded ISOs String psHost = ((PrimaryDataStoreTO) store).getHost(); String psPath = ((PrimaryDataStoreTO) store).getPath(); return "nfs://" + psHost + File.separator + psPath; } return store.getUrl(); }
@Override public Answer deleteSnapshot(final DeleteCommand cmd) { final SnapshotObjectTO snapshot = (SnapshotObjectTO) cmd.getData(); final DataStoreTO store = snapshot.getDataStore(); if (store.getRole() == DataStoreRole.Primary) { final Connection conn = hypervisorResource.getConnection(); final VDI snapshotVdi = getVDIbyUuid(conn, snapshot.getPath()); if (snapshotVdi == null) { return new Answer(null); } String errMsg = null; try { deleteVDI(conn, snapshotVdi); } catch (final BadServerResponse e) { s_logger.debug("delete snapshot failed:" + e.toString()); errMsg = e.toString(); } catch (final XenAPIException e) { s_logger.debug("delete snapshot failed:" + e.toString()); errMsg = e.toString(); } catch (final XmlRpcException e) { s_logger.debug("delete snapshot failed:" + e.toString()); errMsg = e.toString(); } return new Answer(cmd, false, errMsg); } return new Answer(cmd, false, "unsupported storage type"); }