@Test public void testCloneVolumeFromBaseTemplate() throws Exception { }
@Override public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); final TemplateObjectTO template = (TemplateObjectTO) srcData; final DataStoreTO imageStore = template.getDataStore(); final VolumeObjectTO volume = (VolumeObjectTO) destData; final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore(); final KvmPhysicalDisk baseVolume; final KvmStoragePool primaryPool; final KvmPhysicalDisk vol; try { primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); String templatePath = template.getPath(); if (primaryPool.getType() == StoragePoolType.CLVM) { templatePath = imageStore.getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); } else if (primaryPool.getType() == StoragePoolType.LVM) { templatePath = imageStore.getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); } else { if (templatePath.contains("/mnt")) { templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1); } baseVolume = this.storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath); vol = this.storagePoolMgr.createDiskFromTemplate(baseVolume, volume.getUuid(), volume.getProvisioningType(), baseVolume.getPool(), volume.getSize(), cmd.getWaitInMillSeconds()); } if (vol == null) { return new CopyCmdAnswer(" Can't create storage volume on storage pool"); } final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setPath(vol.getName()); newVol.setSize(volume.getSize()); if (vol.getFormat() == PhysicalDiskFormat.RAW) { newVol.setFormat(ImageFormat.RAW); } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) { newVol.setFormat(ImageFormat.QCOW2); } else if (vol.getFormat() == PhysicalDiskFormat.DIR) { newVol.setFormat(ImageFormat.DIR); } return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { this.logger.debug("Failed to create volume: ", e); return new CopyCmdAnswer(e.toString()); } }
KvmStorageProcessor implements StorageProcessor { @Override public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); final TemplateObjectTO template = (TemplateObjectTO) srcData; final DataStoreTO imageStore = template.getDataStore(); final VolumeObjectTO volume = (VolumeObjectTO) destData; final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore(); final KvmPhysicalDisk baseVolume; final KvmStoragePool primaryPool; final KvmPhysicalDisk vol; try { primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); String templatePath = template.getPath(); if (primaryPool.getType() == StoragePoolType.CLVM) { templatePath = imageStore.getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); } else if (primaryPool.getType() == StoragePoolType.LVM) { templatePath = imageStore.getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); } else { if (templatePath.contains("/mnt")) { templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1); } baseVolume = this.storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath); vol = this.storagePoolMgr.createDiskFromTemplate(baseVolume, volume.getUuid(), volume.getProvisioningType(), baseVolume.getPool(), volume.getSize(), cmd.getWaitInMillSeconds()); } if (vol == null) { return new CopyCmdAnswer(" Can't create storage volume on storage pool"); } final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setPath(vol.getName()); newVol.setSize(volume.getSize()); if (vol.getFormat() == PhysicalDiskFormat.RAW) { newVol.setFormat(ImageFormat.RAW); } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) { newVol.setFormat(ImageFormat.QCOW2); } else if (vol.getFormat() == PhysicalDiskFormat.DIR) { newVol.setFormat(ImageFormat.DIR); } return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { this.logger.debug("Failed to create volume: ", e); return new CopyCmdAnswer(e.toString()); } } }
KvmStorageProcessor implements StorageProcessor { @Override public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); final TemplateObjectTO template = (TemplateObjectTO) srcData; final DataStoreTO imageStore = template.getDataStore(); final VolumeObjectTO volume = (VolumeObjectTO) destData; final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore(); final KvmPhysicalDisk baseVolume; final KvmStoragePool primaryPool; final KvmPhysicalDisk vol; try { primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); String templatePath = template.getPath(); if (primaryPool.getType() == StoragePoolType.CLVM) { templatePath = imageStore.getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); } else if (primaryPool.getType() == StoragePoolType.LVM) { templatePath = imageStore.getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); } else { if (templatePath.contains("/mnt")) { templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1); } baseVolume = this.storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath); vol = this.storagePoolMgr.createDiskFromTemplate(baseVolume, volume.getUuid(), volume.getProvisioningType(), baseVolume.getPool(), volume.getSize(), cmd.getWaitInMillSeconds()); } if (vol == null) { return new CopyCmdAnswer(" Can't create storage volume on storage pool"); } final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setPath(vol.getName()); newVol.setSize(volume.getSize()); if (vol.getFormat() == PhysicalDiskFormat.RAW) { newVol.setFormat(ImageFormat.RAW); } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) { newVol.setFormat(ImageFormat.QCOW2); } else if (vol.getFormat() == PhysicalDiskFormat.DIR) { newVol.setFormat(ImageFormat.DIR); } return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { this.logger.debug("Failed to create volume: ", e); return new CopyCmdAnswer(e.toString()); } } KvmStorageProcessor(final KvmStoragePoolManager storagePoolMgr, final LibvirtComputingResource resource); }
KvmStorageProcessor implements StorageProcessor { @Override public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); final TemplateObjectTO template = (TemplateObjectTO) srcData; final DataStoreTO imageStore = template.getDataStore(); final VolumeObjectTO volume = (VolumeObjectTO) destData; final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore(); final KvmPhysicalDisk baseVolume; final KvmStoragePool primaryPool; final KvmPhysicalDisk vol; try { primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); String templatePath = template.getPath(); if (primaryPool.getType() == StoragePoolType.CLVM) { templatePath = imageStore.getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); } else if (primaryPool.getType() == StoragePoolType.LVM) { templatePath = imageStore.getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); } else { if (templatePath.contains("/mnt")) { templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1); } baseVolume = this.storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath); vol = this.storagePoolMgr.createDiskFromTemplate(baseVolume, volume.getUuid(), volume.getProvisioningType(), baseVolume.getPool(), volume.getSize(), cmd.getWaitInMillSeconds()); } if (vol == null) { return new CopyCmdAnswer(" Can't create storage volume on storage pool"); } final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setPath(vol.getName()); newVol.setSize(volume.getSize()); if (vol.getFormat() == PhysicalDiskFormat.RAW) { newVol.setFormat(ImageFormat.RAW); } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) { newVol.setFormat(ImageFormat.QCOW2); } else if (vol.getFormat() == PhysicalDiskFormat.DIR) { newVol.setFormat(ImageFormat.DIR); } return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { this.logger.debug("Failed to create volume: ", e); return new CopyCmdAnswer(e.toString()); } } KvmStorageProcessor(final KvmStoragePoolManager storagePoolMgr, final LibvirtComputingResource resource); boolean configure(final String name, final Map<String, Object> params); @Override Answer copyTemplateToPrimaryStorage(final CopyCommand cmd); @Override Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd); @Override Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd); @Override Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd); @Override Answer createTemplateFromVolume(final CopyCommand cmd); @Override Answer createTemplateFromSnapshot(final CopyCommand cmd); @Override Answer backupSnapshot(final CopyCommand cmd); @Override Answer attachIso(final AttachCommand cmd); @Override Answer attachVolume(final AttachCommand cmd); @Override Answer dettachIso(final DettachCommand cmd); @Override Answer dettachVolume(final DettachCommand cmd); @Override Answer createVolume(final CreateObjectCommand cmd); @Override Answer createSnapshot(final CreateObjectCommand cmd); @Override Answer deleteVolume(final DeleteCommand cmd); @Override Answer createVolumeFromSnapshot(final CopyCommand cmd); @Override Answer deleteSnapshot(final DeleteCommand cmd); @Override Answer introduceObject(final IntroduceObjectCommand cmd); @Override Answer forgetObject(final ForgetObjectCommand cmd); @Override SnapshotAndCopyAnswer snapshotAndCopy(final SnapshotAndCopyCommand cmd); }
KvmStorageProcessor implements StorageProcessor { @Override public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); final TemplateObjectTO template = (TemplateObjectTO) srcData; final DataStoreTO imageStore = template.getDataStore(); final VolumeObjectTO volume = (VolumeObjectTO) destData; final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore(); final KvmPhysicalDisk baseVolume; final KvmStoragePool primaryPool; final KvmPhysicalDisk vol; try { primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); String templatePath = template.getPath(); if (primaryPool.getType() == StoragePoolType.CLVM) { templatePath = imageStore.getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); } else if (primaryPool.getType() == StoragePoolType.LVM) { templatePath = imageStore.getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); } else { if (templatePath.contains("/mnt")) { templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1); } baseVolume = this.storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath); vol = this.storagePoolMgr.createDiskFromTemplate(baseVolume, volume.getUuid(), volume.getProvisioningType(), baseVolume.getPool(), volume.getSize(), cmd.getWaitInMillSeconds()); } if (vol == null) { return new CopyCmdAnswer(" Can't create storage volume on storage pool"); } final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setPath(vol.getName()); newVol.setSize(volume.getSize()); if (vol.getFormat() == PhysicalDiskFormat.RAW) { newVol.setFormat(ImageFormat.RAW); } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) { newVol.setFormat(ImageFormat.QCOW2); } else if (vol.getFormat() == PhysicalDiskFormat.DIR) { newVol.setFormat(ImageFormat.DIR); } return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { this.logger.debug("Failed to create volume: ", e); return new CopyCmdAnswer(e.toString()); } } KvmStorageProcessor(final KvmStoragePoolManager storagePoolMgr, final LibvirtComputingResource resource); boolean configure(final String name, final Map<String, Object> params); @Override Answer copyTemplateToPrimaryStorage(final CopyCommand cmd); @Override Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd); @Override Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd); @Override Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd); @Override Answer createTemplateFromVolume(final CopyCommand cmd); @Override Answer createTemplateFromSnapshot(final CopyCommand cmd); @Override Answer backupSnapshot(final CopyCommand cmd); @Override Answer attachIso(final AttachCommand cmd); @Override Answer attachVolume(final AttachCommand cmd); @Override Answer dettachIso(final DettachCommand cmd); @Override Answer dettachVolume(final DettachCommand cmd); @Override Answer createVolume(final CreateObjectCommand cmd); @Override Answer createSnapshot(final CreateObjectCommand cmd); @Override Answer deleteVolume(final DeleteCommand cmd); @Override Answer createVolumeFromSnapshot(final CopyCommand cmd); @Override Answer deleteSnapshot(final DeleteCommand cmd); @Override Answer introduceObject(final IntroduceObjectCommand cmd); @Override Answer forgetObject(final ForgetObjectCommand cmd); @Override SnapshotAndCopyAnswer snapshotAndCopy(final SnapshotAndCopyCommand cmd);  }