_clusterId = (String) params.get("cluster");
_modifyVlanPath = Script.findScript(networkScriptsDir, "modifyvlan.sh");
if (_modifyVlanPath == null) {
throw new ConfigurationException("Unable to find modifyvlan.sh");
}
_versionstringpath = Script.findScript(kvmScriptsDir, "versions.sh");
if (_versionstringpath == null) {
throw new ConfigurationException("Unable to find versions.sh");
}
_patchViaSocketPath = Script.findScript(kvmScriptsDir + "/patch/",
"patchviasocket.pl");
if (_patchViaSocketPath == null) {
throw new ConfigurationException("Unable to find patchviasocket.pl");
}
_heartBeatPath = Script.findScript(kvmScriptsDir, "kvmheartbeat.sh");
if (_heartBeatPath == null) {
throw new ConfigurationException("Unable to find kvmheartbeat.sh");
}
_createvmPath = Script.findScript(storageScriptsDir, "createvm.sh");
if (_createvmPath == null) {
throw new ConfigurationException("Unable to find the createvm.sh");
}
_manageSnapshotPath = Script.findScript(storageScriptsDir,
"managesnapshot.sh");
if (_manageSnapshotPath == null) {
throw new ConfigurationException(
"Unable to find the managesnapshot.sh");
}
_resizeVolumePath = Script.findScript(storageScriptsDir, "resizevolume.sh");
if (_resizeVolumePath == null) {
throw new ConfigurationException(
"Unable to find the resizevolume.sh");
}
_createTmplPath = Script
.findScript(storageScriptsDir, "createtmplt.sh");
if (_createTmplPath == null) {
throw new ConfigurationException(
"Unable to find the createtmplt.sh");
}
_securityGroupPath = Script.findScript(networkScriptsDir,
"security_group.py");
if (_securityGroupPath == null) {
throw new ConfigurationException(
"Unable to find the security_group.py");
}
_routerProxyPath = Script.findScript("scripts/network/domr/",
"router_proxy.sh");
if (_routerProxyPath == null) {
throw new ConfigurationException(
"Unable to find the router_proxy.sh");
}
_ovsPvlanDhcpHostPath = Script.findScript(networkScriptsDir, "ovs-pvlan-dhcp-host.sh");
if ( _ovsPvlanDhcpHostPath == null) {
throw new ConfigurationException(
"Unable to find the ovs-pvlan-dhcp-host.sh");
}
_ovsPvlanVmPath = Script.findScript(networkScriptsDir, "ovs-pvlan-vm.sh");
if ( _ovsPvlanVmPath == null) {
throw new ConfigurationException(
"Unable to find the ovs-pvlan-vm.sh");
}
String value = (String) params.get("developer");
boolean isDeveloper = Boolean.parseBoolean(value);
if (isDeveloper) {
params.putAll(getDeveloperProperties());
}
_pool = (String) params.get("pool");
if (_pool == null) {
_pool = "/root";
}
String instance = (String) params.get("instance");
_hypervisorType = HypervisorType.getType((String) params.get("hypervisor.type"));
if (_hypervisorType == HypervisorType.None) {
_hypervisorType = HypervisorType.KVM;
}
_hypervisorURI = (String) params.get("hypervisor.uri");
if (_hypervisorURI == null) {
_hypervisorURI = LibvirtConnection.getHypervisorURI(_hypervisorType.toString());
}
_networkDirectSourceMode = (String) params.get("network.direct.source.mode");
_networkDirectDevice = (String) params.get("network.direct.device");
String startMac = (String) params.get("private.macaddr.start");
if (startMac == null) {
startMac = "00:16:3e:77:e2:a0";
}
String startIp = (String) params.get("private.ipaddr.start");
if (startIp == null) {
startIp = "192.168.166.128";
}
_pingTestPath = Script.findScript(kvmScriptsDir, "pingtest.sh");
if (_pingTestPath == null) {
throw new ConfigurationException("Unable to find the pingtest.sh");
}
_linkLocalBridgeName = (String) params.get("private.bridge.name");
if (_linkLocalBridgeName == null) {
if (isDeveloper) {
_linkLocalBridgeName = "cloud-" + instance + "-0";
} else {
_linkLocalBridgeName = "cloud0";
}
}
_publicBridgeName = (String) params.get("public.network.device");
if (_publicBridgeName == null) {
_publicBridgeName = "cloudbr0";
}
_privBridgeName = (String) params.get("private.network.device");
if (_privBridgeName == null) {
_privBridgeName = "cloudbr1";
}
_guestBridgeName = (String) params.get("guest.network.device");
if (_guestBridgeName == null) {
_guestBridgeName = _privBridgeName;
}
_privNwName = (String) params.get("private.network.name");
if (_privNwName == null) {
if (isDeveloper) {
_privNwName = "cloud-" + instance + "-private";
} else {
_privNwName = "cloud-private";
}
}
_localStoragePath = (String) params.get("local.storage.path");
if (_localStoragePath == null) {
_localStoragePath = "/var/lib/libvirt/images/";
}
File storagePath = new File(_localStoragePath);
_localStoragePath = storagePath.getAbsolutePath();
_localStorageUUID = (String) params.get("local.storage.uuid");
if (_localStorageUUID == null) {
_localStorageUUID = UUID.nameUUIDFromBytes(_localStoragePath.getBytes()).toString();
}
value = (String) params.get("scripts.timeout");
_timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000;
value = (String) params.get("stop.script.timeout");
_stopTimeout = NumbersUtil.parseInt(value, 120) * 1000;
value = (String) params.get("cmds.timeout");
_cmdsTimeout = NumbersUtil.parseInt(value, 7200) * 1000;
value = (String) params.get("host.reserved.mem.mb");
_dom0MinMem = NumbersUtil.parseInt(value, 0) * 1024 * 1024;
LibvirtConnection.initialize(_hypervisorURI);
Connect conn = null;
try {
conn = LibvirtConnection.getConnection();
if (_bridgeType == BridgeType.OPENVSWITCH) {
if (conn.getLibVirVersion() < (10 * 1000 + 0)) {
throw new ConfigurationException("LibVirt version 0.10.0 required for openvswitch support, but version "
+ conn.getLibVirVersion() + " detected");
}
}
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.getMessage());
}
if (HypervisorType.KVM == _hypervisorType) {
/* Does node support HVM guest? If not, exit */
if (!IsHVMEnabled(conn)) {
throw new ConfigurationException(
"NO HVM support on this machine, please make sure: "
+ "1. VT/SVM is supported by your CPU, or is enabled in BIOS. "
+ "2. kvm modules are loaded (kvm, kvm_amd|kvm_intel)");
}
}
_hypervisorPath = getHypervisorPath(conn);
try {
_hvVersion = conn.getVersion();
_hvVersion = (_hvVersion % 1000000) / 1000;
_hypervisorLibvirtVersion = conn.getLibVirVersion();
_hypervisorQemuVersion = conn.getVersion();
} catch (LibvirtException e) {
s_logger.trace("Ignoring libvirt error.", e);
}
_guestCpuMode = (String) params.get("guest.cpu.mode");
if (_guestCpuMode != null) {
_guestCpuModel = (String) params.get("guest.cpu.model");
if(_hypervisorLibvirtVersion < (9 * 1000 + 10)) {
s_logger.warn("LibVirt version 0.9.10 required for guest cpu mode, but version " +
prettyVersion(_hypervisorLibvirtVersion) + " detected, so it will be disabled");
_guestCpuMode = "";
_guestCpuModel = "";
}
params.put("guest.cpu.mode", _guestCpuMode);
params.put("guest.cpu.model", _guestCpuModel);
}
String[] info = NetUtils.getNetworkParams(_privateNic);
_monitor = new KVMHAMonitor(null, info[0], _heartBeatPath);
Thread ha = new Thread(_monitor);
ha.start();
_storagePoolMgr = new KVMStoragePoolManager(_storage, _monitor);
_sysvmISOPath = (String) params.get("systemvm.iso.path");
if (_sysvmISOPath == null) {
String[] isoPaths = {"/usr/share/cloudstack-common/vms/systemvm.iso"};
for (String isoPath : isoPaths) {
if (_storage.exists(isoPath)) {
_sysvmISOPath = isoPath;
break;
}
}
if (_sysvmISOPath == null) {
s_logger.debug("Can't find system vm ISO");
}
}
switch (_bridgeType) {
case OPENVSWITCH:
getOvsPifs();
break;
case NATIVE:
default:
getPifs();
break;
}
if (_pifs.get("private") == null) {
s_logger.debug("Failed to get private nic name");
throw new ConfigurationException("Failed to get private nic name");
}
if (_pifs.get("public") == null) {
s_logger.debug("Failed to get public nic name");
throw new ConfigurationException("Failed to get public nic name");
}
s_logger.debug("Found pif: " + _pifs.get("private") + " on " + _privBridgeName
+ ", pif: " + _pifs.get("public") + " on " + _publicBridgeName);