mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
fix kvm
This commit is contained in:
parent
0b9e0c0f3a
commit
492127c035
@ -67,6 +67,12 @@
|
||||
<artifactId>cloud-plugin-hypervisor-vmware</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-plugin-hypervisor-kvm</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
|
||||
@ -24,6 +24,7 @@ import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@ -38,6 +39,7 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
|
||||
private String secondaryStorage;
|
||||
private String imageInstallPath;
|
||||
private String scriptPath;
|
||||
private HypervisorType hypervisor;
|
||||
private Transaction txn;
|
||||
|
||||
private String s3AccessKey;
|
||||
@ -72,11 +74,14 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
|
||||
|
||||
@Parameters({"devcloud-host-uuid", "devcloud-host-gateway", "devcloud-host-cidr",
|
||||
"devcloud-host-ip", "template-url", "devcloud-local-storage-uuid",
|
||||
"primary-storage-want-to-add", "devcloud-secondary-storage", "s3-accesskey", "s3-secretkey", "s3-endpoint", "s3-template-bucket", "s3-usehttps", "image-install-path", "primary-storage-uuid-want-to-add", "script-path"})
|
||||
"primary-storage-want-to-add", "devcloud-secondary-storage", "s3-accesskey", "s3-secretkey", "s3-endpoint",
|
||||
"s3-template-bucket", "s3-usehttps", "image-install-path", "primary-storage-uuid-want-to-add", "script-path",
|
||||
"hypervisor"})
|
||||
protected void setup(String hostuuid, String gateway, String cidr,
|
||||
String hostIp, String templateUrl, String localStorageUuid,
|
||||
String primaryStorage, String secondaryStorage, String s3_accessKey, String s3_secretKey, String s3_endpoint, String s3_template_bucket,
|
||||
String s3_usehttps, String imageInstallPath, String primaryStorageUuid, String scriptPath) {
|
||||
String s3_usehttps, String imageInstallPath, String primaryStorageUuid, String scriptPath,
|
||||
String hypervisor) {
|
||||
this.hostGuid = hostuuid;
|
||||
this.hostGateway = gateway;
|
||||
this.hostCidr = cidr;
|
||||
@ -86,6 +91,7 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
|
||||
this.primaryStorageUrl = primaryStorage;
|
||||
this.primaryStorageUuid = primaryStorageUuid;
|
||||
this.imageInstallPath = imageInstallPath;
|
||||
this.hypervisor = HypervisorType.getType(hypervisor);
|
||||
this.setSecondaryStorage(secondaryStorage);
|
||||
// set S3 parameters
|
||||
this.s3AccessKey = s3_accessKey;
|
||||
@ -180,5 +186,13 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
|
||||
this.scriptPath = scriptPath;
|
||||
}
|
||||
|
||||
public HypervisorType getHypervisor() {
|
||||
return hypervisor;
|
||||
}
|
||||
|
||||
public void setHypervisor(HypervisorType hypervisor) {
|
||||
this.hypervisor = hypervisor;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -50,6 +50,7 @@ import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
|
||||
import com.cloud.hypervisor.vmware.VmwareServerDiscoverer;
|
||||
import com.cloud.hypervisor.xen.resource.XcpOssResource;
|
||||
import com.cloud.resource.ServerResource;
|
||||
@ -122,6 +123,16 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
|
||||
} catch (ConfigurationException e) {
|
||||
logger.debug("Failed to load resource:" + e.toString());
|
||||
}
|
||||
} else if (host.getHypervisorType() == HypervisorType.KVM) {
|
||||
resource = new LibvirtComputingResource();
|
||||
try {
|
||||
params.put("public.network.device", "cloudbr0");
|
||||
params.put("private.network.device", "cloudbr0");
|
||||
resource.configure(host.getName(), params);
|
||||
} catch (ConfigurationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (host.getHypervisorType() == HypervisorType.VMware) {
|
||||
ClusterVO cluster = clusterDao.findById(host.getClusterId());
|
||||
String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue();
|
||||
|
||||
@ -179,7 +179,7 @@ public class SnapshotTest extends CloudStackTestNGBase {
|
||||
podId = pod.getId();
|
||||
//create xen cluster
|
||||
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
|
||||
cluster.setHypervisorType(HypervisorType.XenServer.toString());
|
||||
cluster.setHypervisorType(this.getHypervisor().toString());
|
||||
cluster.setClusterType(ClusterType.CloudManaged);
|
||||
cluster.setManagedState(ManagedState.Managed);
|
||||
cluster = clusterDao.persist(cluster);
|
||||
@ -197,7 +197,7 @@ public class SnapshotTest extends CloudStackTestNGBase {
|
||||
host.setPodId(podId);
|
||||
host.setLastPinged(0);
|
||||
host.setResourceState(ResourceState.Enabled);
|
||||
host.setHypervisorType(HypervisorType.XenServer);
|
||||
host.setHypervisorType(this.getHypervisor());
|
||||
host.setClusterId(cluster.getId());
|
||||
|
||||
host = hostDao.persist(host);
|
||||
|
||||
@ -171,7 +171,7 @@ public class VolumeTest extends CloudStackTestNGBase {
|
||||
podId = pod.getId();
|
||||
//create xen cluster
|
||||
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
|
||||
cluster.setHypervisorType(HypervisorType.XenServer.toString());
|
||||
cluster.setHypervisorType(this.getHypervisor().toString());
|
||||
cluster.setClusterType(ClusterType.CloudManaged);
|
||||
cluster.setManagedState(ManagedState.Managed);
|
||||
cluster = clusterDao.persist(cluster);
|
||||
@ -189,7 +189,7 @@ public class VolumeTest extends CloudStackTestNGBase {
|
||||
host.setPodId(podId);
|
||||
host.setLastPinged(0);
|
||||
host.setResourceState(ResourceState.Enabled);
|
||||
host.setHypervisorType(HypervisorType.XenServer);
|
||||
host.setHypervisorType(this.getHypervisor());
|
||||
host.setClusterId(cluster.getId());
|
||||
|
||||
host = hostDao.persist(host);
|
||||
@ -320,7 +320,7 @@ public class VolumeTest extends CloudStackTestNGBase {
|
||||
return volume;
|
||||
}
|
||||
|
||||
//@Test
|
||||
@Test
|
||||
public void testCopyBaseImage() {
|
||||
DataStore primaryStore = createPrimaryDataStore();
|
||||
primaryStoreId = primaryStore.getId();
|
||||
|
||||
@ -209,10 +209,6 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(Snapshot snapshot) {
|
||||
if (snapshot.getHypervisorType() == HypervisorType.XenServer) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -461,7 +461,7 @@ ServerResource {
|
||||
}
|
||||
|
||||
protected String getDefaultDomrScriptsDir() {
|
||||
return "scripts/network/domr/kvm";
|
||||
return "scripts/network/domr";
|
||||
}
|
||||
|
||||
protected String getNetworkDirectSourceMode() {
|
||||
@ -682,7 +682,7 @@ ServerResource {
|
||||
|
||||
_localStorageUUID = (String) params.get("local.storage.uuid");
|
||||
if (_localStorageUUID == null) {
|
||||
throw new ConfigurationException("local.storage.uuid is not set! Please set this to a valid UUID");
|
||||
_localStorageUUID = UUID.nameUUIDFromBytes(_localStoragePath.getBytes()).toString();
|
||||
}
|
||||
|
||||
value = (String) params.get("scripts.timeout");
|
||||
|
||||
@ -142,7 +142,7 @@ public class KVMStorageProcessor implements StorageProcessor {
|
||||
DataTO destData = cmd.getDestTO();
|
||||
TemplateObjectTO template = (TemplateObjectTO)srcData;
|
||||
DataStoreTO imageStore = template.getDataStore();
|
||||
VolumeObjectTO volume = (VolumeObjectTO)destData;
|
||||
TemplateObjectTO volume = (TemplateObjectTO)destData;
|
||||
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
|
||||
|
||||
if (!(imageStore instanceof NfsTO)) {
|
||||
@ -195,10 +195,10 @@ public class KVMStorageProcessor implements StorageProcessor {
|
||||
KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(
|
||||
tmplVol, UUID.randomUUID().toString(), primaryPool);
|
||||
|
||||
VolumeObjectTO newVol = new VolumeObjectTO();
|
||||
newVol.setPath(primaryVol.getName());
|
||||
newVol.setSize(primaryVol.getSize());
|
||||
return new CopyCmdAnswer(newVol);
|
||||
TemplateObjectTO newTemplate = new TemplateObjectTO();
|
||||
newTemplate.setPath(primaryVol.getName());
|
||||
newTemplate.setFormat(ImageFormat.QCOW2);
|
||||
return new CopyCmdAnswer(newTemplate);
|
||||
} catch (CloudRuntimeException e) {
|
||||
return new CopyCmdAnswer(e.toString());
|
||||
} finally {
|
||||
@ -273,14 +273,7 @@ public class KVMStorageProcessor implements StorageProcessor {
|
||||
primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(),
|
||||
primaryStore.getUuid());
|
||||
|
||||
String templatePath = null;
|
||||
if (imageStore instanceof NfsTO) {
|
||||
NfsTO nfsImageStore = (NfsTO)imageStore;
|
||||
templatePath = nfsImageStore.getUrl();
|
||||
} else {
|
||||
s_logger.debug("Failed to create volume: ");
|
||||
return new CopyCmdAnswer("Unsupported protocol");
|
||||
}
|
||||
String templatePath = template.getPath();
|
||||
|
||||
if(primaryPool.getType() == StoragePoolType.CLVM) {
|
||||
vol = templateToPrimaryDownload(templatePath, primaryPool);
|
||||
@ -321,9 +314,9 @@ public class KVMStorageProcessor implements StorageProcessor {
|
||||
DataTO srcData = cmd.getSrcTO();
|
||||
DataTO destData = cmd.getDestTO();
|
||||
int wait = cmd.getWait();
|
||||
TemplateObjectTO template = (TemplateObjectTO)srcData;
|
||||
TemplateObjectTO template = (TemplateObjectTO)destData;
|
||||
DataStoreTO imageStore = template.getDataStore();
|
||||
VolumeObjectTO volume = (VolumeObjectTO)destData;
|
||||
VolumeObjectTO volume = (VolumeObjectTO)srcData;
|
||||
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
|
||||
|
||||
if (!(imageStore instanceof NfsTO)) {
|
||||
@ -425,7 +418,7 @@ public class KVMStorageProcessor implements StorageProcessor {
|
||||
loc.save();
|
||||
|
||||
TemplateObjectTO newTemplate = new TemplateObjectTO();
|
||||
newTemplate.setPath(templateFolder + templateName + ".qcow2");
|
||||
newTemplate.setPath(templateFolder + File.separator + templateName + ".qcow2");
|
||||
return new CopyCmdAnswer(newTemplate);
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Failed to create template from volume: " + e.toString());
|
||||
@ -783,8 +776,9 @@ public class KVMStorageProcessor implements StorageProcessor {
|
||||
|
||||
@Override
|
||||
public Answer createSnapshot(CreateObjectCommand cmd) {
|
||||
VolumeObjectTO volume = (VolumeObjectTO)cmd.getData();
|
||||
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
|
||||
SnapshotObjectTO snapshotTO = (SnapshotObjectTO)cmd.getData();
|
||||
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)snapshotTO.getDataStore();
|
||||
VolumeObjectTO volume = snapshotTO.getVolume();
|
||||
String snapshotName = UUID.randomUUID().toString();
|
||||
String vmName = volume.getVmName();
|
||||
try {
|
||||
|
||||
@ -48,7 +48,7 @@ is_lv() {
|
||||
# And a logical volume
|
||||
lvm lvs "${1}" > /dev/null 2>&1 && return 0
|
||||
fi
|
||||
return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
get_vg() {
|
||||
|
||||
@ -450,7 +450,15 @@ public class Script implements Callable<String> {
|
||||
|
||||
}
|
||||
|
||||
file = new File(System.getProperty("paths.script") + File.separator + path + File.separator + script);
|
||||
search = System.getProperty("paths.script");
|
||||
|
||||
search += File.separatorChar + path + File.separator;
|
||||
do {
|
||||
search = search.substring(0, search.lastIndexOf(File.separator));
|
||||
file = new File(search + File.separator + script);
|
||||
s_logger.debug("Looking for " + script + " in " + file.getAbsolutePath());
|
||||
} while (!file.exists() && search.lastIndexOf(File.separator) != -1);
|
||||
|
||||
if (file.exists()) {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user