mirror of https://github.com/apache/cloudstack.git
add create volume from base image command
This commit is contained in:
parent
d99161399e
commit
9de3a1fae4
|
|
@ -41,4 +41,5 @@ public interface VolumeInfo {
|
|||
public Date getCreatedDate();
|
||||
public Date getUpdatedDate();
|
||||
public String getOwner();
|
||||
public String getName();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -270,8 +270,9 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
|||
}
|
||||
}
|
||||
|
||||
private VolumeVO createVolume(long templateId) {
|
||||
private VolumeVO createVolume(long templateId, long dataStoreId) {
|
||||
VolumeVO volume = new VolumeVO(1000, new RootDisk().toString(), UUID.randomUUID().toString(), templateId);
|
||||
volume.setPoolId(dataStoreId);
|
||||
volume = volumeDao.persist(volume);
|
||||
return volume;
|
||||
|
||||
|
|
@ -281,12 +282,12 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
|||
public void createVolumeFromTemplate() {
|
||||
TemplateEntity te = createTemplate();
|
||||
PrimaryDataStoreInfo dataStoreInfo = createPrimaryDataStore();
|
||||
VolumeVO volume = createVolume(te.getId());
|
||||
VolumeVO volume = createVolume(te.getId(), dataStoreInfo.getId());
|
||||
VolumeEntity ve = volumeService.getVolumeEntity(volume.getId());
|
||||
ve.createVolumeFromTemplate(dataStoreInfo.getId(), new VHD(), te);
|
||||
}
|
||||
|
||||
@Test(priority=3)
|
||||
//@Test(priority=3)
|
||||
public void tearDown() {
|
||||
List<PrimaryDataStoreVO> ds = primaryStoreDao.findPoolByName(this.primaryName);
|
||||
for (int i = 0; i < ds.size(); i++) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ public class VolumeTO {
|
|||
private final String path;
|
||||
private final VolumeType volumeType;
|
||||
private final VolumeDiskType diskType;
|
||||
private final PrimaryDataStoreTO dataStore;
|
||||
private PrimaryDataStoreTO dataStore;
|
||||
private final String name;
|
||||
public VolumeTO(VolumeInfo volume) {
|
||||
this.uuid = volume.getUuid();
|
||||
this.path = volume.getPath();
|
||||
|
|
@ -20,6 +21,7 @@ public class VolumeTO {
|
|||
} else {
|
||||
this.dataStore = null;
|
||||
}
|
||||
this.name = volume.getName();
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
|
|
@ -41,4 +43,12 @@ public class VolumeTO {
|
|||
public PrimaryDataStoreTO getDataStore() {
|
||||
return this.dataStore;
|
||||
}
|
||||
|
||||
public void setDataStore(PrimaryDataStoreTO dataStore) {
|
||||
this.dataStore = dataStore;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.kvm;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.CLVMValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.CLVMProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -34,7 +34,7 @@ public class KvmCLVMConfigurator extends AbstractKvmConfigurator {
|
|||
|
||||
@Override
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new CLVMValidator();
|
||||
return new CLVMProtocolTransformer();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
|||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
public class CLVMValidator implements StorageProtocolTransformer {
|
||||
public class CLVMProtocolTransformer implements StorageProtocolTransformer {
|
||||
|
||||
@Override
|
||||
public boolean normalizeUserInput(Map<String, String> params) {
|
||||
|
|
@ -26,7 +26,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
|||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
public class ISCSIValiator implements StorageProtocolTransformer {
|
||||
public class ISCSIProtocolTransformer implements StorageProtocolTransformer {
|
||||
|
||||
@Override
|
||||
public List<String> getInputParamNames() {
|
||||
|
|
@ -88,8 +88,9 @@ public class NfsProtocolTransformer implements StorageProtocolTransformer {
|
|||
|
||||
@Override
|
||||
public VolumeTO getVolumeTO(VolumeInfo volume) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
VolumeTO vol = new VolumeTO(volume);
|
||||
vol.setDataStore(this.getDataStoreTO(volume.getDataStore()));
|
||||
return vol;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.vmware;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ISCSIValiator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ISCSIProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -33,7 +33,7 @@ public class VmwareIsciConfigurator extends AbstractVmwareConfigurator {
|
|||
|
||||
@Override
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new ISCSIValiator();
|
||||
return new ISCSIProtocolTransformer();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.xen;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ISCSIValiator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ISCSIProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -34,7 +34,7 @@ public class XenIscsiConfigurator extends AbstractXenConfigurator {
|
|||
|
||||
@Override
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new ISCSIValiator();
|
||||
return new ISCSIProtocolTransformer();
|
||||
}
|
||||
|
||||
protected boolean isLocalStorageSupported() {
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
|||
}
|
||||
@Override
|
||||
public void createVolumeFromBaseImageAsync(VolumeObject volume, TemplateOnPrimaryDataStoreInfo template, AsyncCompletionCallback<CommandResult> callback) {
|
||||
VolumeTO vol = new VolumeTO(volume);
|
||||
VolumeTO vol = this.dataStore.getVolumeTO(volume);
|
||||
ImageOnPrimayDataStoreTO image = new ImageOnPrimayDataStoreTO(template);
|
||||
CreateVolumeFromBaseImageCommand cmd = new CreateVolumeFromBaseImageCommand(vol, image);
|
||||
List<EndPoint> endPoints = template.getPrimaryDataStore().getEndPoints();
|
||||
|
|
|
|||
|
|
@ -153,4 +153,9 @@ public class VolumeObject implements VolumeInfo {
|
|||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.volumeVO.getName();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
|
|||
import org.apache.cloudstack.storage.to.NfsPrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.TemplateTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpException;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
|
|
@ -97,7 +98,22 @@ public class XenServerStorageResource {
|
|||
}
|
||||
|
||||
public Answer execute(CreateVolumeFromBaseImageCommand cmd) {
|
||||
return new CreateVolumeAnswer(cmd, UUID.randomUUID().toString());
|
||||
VolumeTO volume = cmd.getVolume();
|
||||
ImageOnPrimayDataStoreTO baseImage = cmd.getImage();
|
||||
Connection conn = hypervisorResource.getConnection();
|
||||
|
||||
try {
|
||||
VDI baseVdi = VDI.getByUuid(conn, baseImage.getPathOnPrimaryDataStore());
|
||||
VDI newVol = baseVdi.createClone(conn, new HashMap<String, String>());
|
||||
newVol.setNameLabel(conn, volume.getName());
|
||||
return new CreateVolumeAnswer(cmd, newVol.getUuid(conn));
|
||||
} catch (BadServerResponse e) {
|
||||
return new Answer(cmd, false, e.toString());
|
||||
} catch (XenAPIException e) {
|
||||
return new Answer(cmd, false, e.toString());
|
||||
} catch (XmlRpcException e) {
|
||||
return new Answer(cmd, false, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected SR getNfsSR(Connection conn, NfsPrimaryDataStoreTO pool) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue