mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Summary: Begone pesky tabs
This commit is contained in:
parent
f09d453efe
commit
2d69a1855d
@ -86,7 +86,7 @@ public class BridgeVifDriver extends VifDriverBase {
|
||||
vlanId = broadcastUri.getHost();
|
||||
}
|
||||
else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
|
||||
throw new InternalErrorException("Nicira NVP Logicalswitches are not supported by the BridgeVifDriver");
|
||||
throw new InternalErrorException("Nicira NVP Logicalswitches are not supported by the BridgeVifDriver");
|
||||
}
|
||||
String trafficLabel = nic.getName();
|
||||
if (nic.getType() == Networks.TrafficType.Guest) {
|
||||
|
||||
@ -364,7 +364,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
private int _dom0MinMem;
|
||||
|
||||
protected enum BridgeType {
|
||||
NATIVE, OPENVSWITCH
|
||||
NATIVE, OPENVSWITCH
|
||||
}
|
||||
|
||||
protected enum defineOps {
|
||||
@ -483,10 +483,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
|
||||
String bridgeType = (String) params.get("network.bridge.type");
|
||||
if (bridgeType == null) {
|
||||
_bridgeType = BridgeType.NATIVE;
|
||||
_bridgeType = BridgeType.NATIVE;
|
||||
}
|
||||
else {
|
||||
_bridgeType = BridgeType.valueOf(bridgeType.toUpperCase());
|
||||
_bridgeType = BridgeType.valueOf(bridgeType.toUpperCase());
|
||||
}
|
||||
|
||||
params.put("domr.scripts.dir", domrScriptsDir);
|
||||
@ -664,19 +664,18 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
|
||||
LibvirtConnection.initialize(_hypervisorURI);
|
||||
Connect conn = null;
|
||||
try {
|
||||
conn = LibvirtConnection.getConnection();
|
||||
try {
|
||||
conn = LibvirtConnection.getConnection();
|
||||
|
||||
if (_bridgeType == BridgeType.OPENVSWITCH) {
|
||||
if (conn.getLibVirVersion() < (9 * 1000 + 11)) {
|
||||
throw new ConfigurationException(
|
||||
"LibVirt version 0.9.11 required for openvswitch support, but version "
|
||||
+ conn.getLibVirVersion() + " detected");
|
||||
}
|
||||
}
|
||||
} catch (LibvirtException e) {
|
||||
throw new CloudRuntimeException(e.getMessage());
|
||||
}
|
||||
if (_bridgeType == BridgeType.OPENVSWITCH) {
|
||||
if (conn.getLibVirVersion() < (9 * 1000 + 11)) {
|
||||
throw new ConfigurationException("LibVirt version 0.9.11 required for openvswitch support, but version "
|
||||
+ conn.getLibVirVersion() + " detected");
|
||||
}
|
||||
}
|
||||
} catch (LibvirtException e) {
|
||||
throw new CloudRuntimeException(e.getMessage());
|
||||
}
|
||||
|
||||
/* Does node support HVM guest? If not, exit */
|
||||
if (!IsHVMEnabled(conn)) {
|
||||
@ -720,14 +719,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
}
|
||||
|
||||
switch (_bridgeType) {
|
||||
case NATIVE:
|
||||
getPifs();
|
||||
break;
|
||||
case OPENVSWITCH:
|
||||
getOvsPifs();
|
||||
break;
|
||||
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");
|
||||
@ -786,31 +786,29 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
// Load the vif driver
|
||||
String vifDriverName = (String) params.get("libvirt.vif.driver");
|
||||
if (vifDriverName == null) {
|
||||
if (_bridgeType == BridgeType.OPENVSWITCH) {
|
||||
s_logger.info("No libvirt.vif.driver specififed. Defaults to OvsVifDriver.");
|
||||
vifDriverName = "com.cloud.hypervisor.kvm.resource.OvsVifDriver";
|
||||
}
|
||||
else {
|
||||
s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver.");
|
||||
vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver";
|
||||
}
|
||||
if (_bridgeType == BridgeType.OPENVSWITCH) {
|
||||
s_logger.info("No libvirt.vif.driver specififed. Defaults to OvsVifDriver.");
|
||||
vifDriverName = "com.cloud.hypervisor.kvm.resource.OvsVifDriver";
|
||||
} else {
|
||||
s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver.");
|
||||
vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver";
|
||||
}
|
||||
}
|
||||
|
||||
params.put("libvirt.computing.resource", (Object) this);
|
||||
|
||||
try {
|
||||
Class<?> clazz = Class.forName(vifDriverName);
|
||||
_vifDriver = (VifDriver) clazz.newInstance();
|
||||
_vifDriver.configure(params);
|
||||
Class<?> clazz = Class.forName(vifDriverName);
|
||||
_vifDriver = (VifDriver) clazz.newInstance();
|
||||
_vifDriver.configure(params);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ConfigurationException("Unable to find class for libvirt.vif.driver " + e);
|
||||
throw new ConfigurationException("Unable to find class for libvirt.vif.driver " + e);
|
||||
} catch (InstantiationException e) {
|
||||
throw new ConfigurationException("Unable to instantiate class for libvirt.vif.driver " + e);
|
||||
throw new ConfigurationException("Unable to instantiate class for libvirt.vif.driver " + e);
|
||||
} catch (Exception e) {
|
||||
throw new ConfigurationException("Failed to initialize libvirt.vif.driver " + e);
|
||||
throw new ConfigurationException("Failed to initialize libvirt.vif.driver " + e);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -834,15 +832,16 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
}
|
||||
|
||||
private void getOvsPifs() {
|
||||
String cmdout = Script.runSimpleBashScript("ovs-vsctl list-br | sed '{:q;N;s/\\n/%/g;t q}'");
|
||||
String cmdout = Script.runSimpleBashScript("ovs-vsctl list-br | sed '{:q;N;s/\\n/%/g;t q}'");
|
||||
s_logger.debug("cmdout was " + cmdout);
|
||||
List<String> bridges = Arrays.asList(cmdout.split("%"));
|
||||
for (String bridge : bridges) {
|
||||
s_logger.debug("looking for pif for bridge " + bridge);
|
||||
//String pif = getOvsPif(bridge);
|
||||
// Not really interested in the pif name at this point for ovs bridges
|
||||
// String pif = getOvsPif(bridge);
|
||||
// Not really interested in the pif name at this point for ovs
|
||||
// bridges
|
||||
String pif = bridge;
|
||||
if(_publicBridgeName != null && bridge.equals(_publicBridgeName)){
|
||||
if (_publicBridgeName != null && bridge.equals(_publicBridgeName)) {
|
||||
_pifs.put("public", pif);
|
||||
}
|
||||
if (_guestBridgeName != null && bridge.equals(_guestBridgeName)) {
|
||||
@ -850,7 +849,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
}
|
||||
_pifs.put(bridge, pif);
|
||||
}
|
||||
s_logger.debug("done looking for pifs, no more bridges");
|
||||
s_logger.debug("done looking for pifs, no more bridges");
|
||||
}
|
||||
|
||||
private String getPif(String bridge) {
|
||||
@ -875,10 +874,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
}
|
||||
|
||||
if (_bridgeType == BridgeType.OPENVSWITCH) {
|
||||
return checkOvsNetwork(networkName);
|
||||
return checkOvsNetwork(networkName);
|
||||
}
|
||||
else {
|
||||
return checkBridgeNetwork(networkName);
|
||||
return checkBridgeNetwork(networkName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -897,11 +896,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
||||
}
|
||||
|
||||
private boolean checkOvsNetwork(String networkName) {
|
||||
s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge");
|
||||
if (networkName == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge");
|
||||
if (networkName == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Script command = new Script("/bin/sh", _timeout);
|
||||
command.add("-c");
|
||||
command.add("ovs-vsctl br-exists " + networkName);
|
||||
|
||||
@ -700,27 +700,27 @@ public class LibvirtVMDef {
|
||||
}
|
||||
|
||||
public void setVirtualPortType(String virtualPortType) {
|
||||
_virtualPortType = virtualPortType;
|
||||
_virtualPortType = virtualPortType;
|
||||
}
|
||||
|
||||
|
||||
public String getVirtualPortType() {
|
||||
return _virtualPortType;
|
||||
return _virtualPortType;
|
||||
}
|
||||
|
||||
|
||||
public void setVirtualPortInterfaceId(String virtualPortInterfaceId) {
|
||||
_virtualPortInterfaceId = virtualPortInterfaceId;
|
||||
_virtualPortInterfaceId = virtualPortInterfaceId;
|
||||
}
|
||||
|
||||
|
||||
public String getVirtualPortInterfaceId() {
|
||||
return _virtualPortInterfaceId;
|
||||
return _virtualPortInterfaceId;
|
||||
}
|
||||
|
||||
|
||||
public void setVlanTag(int vlanTag) {
|
||||
_vlanTag = vlanTag;
|
||||
_vlanTag = vlanTag;
|
||||
}
|
||||
|
||||
|
||||
public int getVlanTag() {
|
||||
return _vlanTag;
|
||||
return _vlanTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -742,14 +742,14 @@ public class LibvirtVMDef {
|
||||
netBuilder.append("<model type='" + _model + "'/>\n");
|
||||
}
|
||||
if (_virtualPortType != null) {
|
||||
netBuilder.append("<virtualport type='" + _virtualPortType + "'>\n");
|
||||
if (_virtualPortInterfaceId != null) {
|
||||
netBuilder.append("<parameters interfaceid='" + _virtualPortInterfaceId + "'/>\n");
|
||||
}
|
||||
netBuilder.append("</virtualport>\n");
|
||||
netBuilder.append("<virtualport type='" + _virtualPortType + "'>\n");
|
||||
if (_virtualPortInterfaceId != null) {
|
||||
netBuilder.append("<parameters interfaceid='" + _virtualPortInterfaceId + "'/>\n");
|
||||
}
|
||||
netBuilder.append("</virtualport>\n");
|
||||
}
|
||||
if (_vlanTag != -1) {
|
||||
netBuilder.append("<vlan trunk='no'>\n<tag id='" + _vlanTag + "'/>\n</vlan>");
|
||||
netBuilder.append("<vlan trunk='no'>\n<tag id='" + _vlanTag + "'/>\n</vlan>");
|
||||
}
|
||||
netBuilder.append("</interface>\n");
|
||||
return netBuilder.toString();
|
||||
|
||||
@ -36,16 +36,15 @@ import com.cloud.utils.script.OutputInterpreter;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
public class OvsVifDriver extends VifDriverBase {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(OvsVifDriver.class);
|
||||
private static final Logger s_logger = Logger.getLogger(OvsVifDriver.class);
|
||||
private int _timeout;
|
||||
private String _modifyVlanPath;
|
||||
|
||||
@Override
|
||||
public void configure(Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(params);
|
||||
@Override
|
||||
public void configure(Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(params);
|
||||
|
||||
String networkScriptsDir = (String) params.get("network.scripts.dir");
|
||||
String networkScriptsDir = (String) params.get("network.scripts.dir");
|
||||
if (networkScriptsDir == null) {
|
||||
networkScriptsDir = "scripts/vm/network/vnet";
|
||||
}
|
||||
@ -58,12 +57,12 @@ public class OvsVifDriver extends VifDriverBase {
|
||||
throw new ConfigurationException("Unable to find modifyvlan.sh");
|
||||
}
|
||||
|
||||
createControlNetwork(_bridges.get("linklocal"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceDef plug(NicTO nic, String guestOsType)
|
||||
throws InternalErrorException, LibvirtException {
|
||||
createControlNetwork(_bridges.get("linklocal"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceDef plug(NicTO nic, String guestOsType)
|
||||
throws InternalErrorException, LibvirtException {
|
||||
s_logger.debug("plugging nic=" + nic);
|
||||
|
||||
LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef();
|
||||
@ -76,7 +75,7 @@ public class OvsVifDriver extends VifDriverBase {
|
||||
vlanId = broadcastUri.getHost();
|
||||
}
|
||||
else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
|
||||
logicalSwitchUuid = nic.getBroadcastUri().getSchemeSpecificPart();
|
||||
logicalSwitchUuid = nic.getBroadcastUri().getSchemeSpecificPart();
|
||||
}
|
||||
String trafficLabel = nic.getName();
|
||||
if (nic.getType() == Networks.TrafficType.Guest) {
|
||||
@ -91,11 +90,11 @@ public class OvsVifDriver extends VifDriverBase {
|
||||
intf.setVlanTag(Integer.parseInt(vlanId));
|
||||
}
|
||||
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
|
||||
s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid);
|
||||
intf.setVirtualPortInterfaceId(nic.getUuid());
|
||||
String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private");
|
||||
s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid);
|
||||
intf.setVirtualPortInterfaceId(nic.getUuid());
|
||||
String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private");
|
||||
intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType));
|
||||
}
|
||||
}
|
||||
else {
|
||||
intf.defBridgeNet(_bridges.get("guest"), null, nic.getMac(), getGuestNicModel(guestOsType));
|
||||
}
|
||||
@ -127,11 +126,11 @@ public class OvsVifDriver extends VifDriverBase {
|
||||
return intf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unplug(InterfaceDef iface) {
|
||||
// Libvirt apparently takes care of this, see BridgeVifDriver unplug
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unplug(InterfaceDef iface) {
|
||||
// Libvirt apparently takes care of this, see BridgeVifDriver unplug
|
||||
}
|
||||
|
||||
private String setVnetBrName(String pifName, String vnetId) {
|
||||
String brName = "br" + pifName + "-"+ vnetId;
|
||||
String oldStyleBrName = "cloudVirBr" + vnetId;
|
||||
@ -167,14 +166,13 @@ public class OvsVifDriver extends VifDriverBase {
|
||||
NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " + NetUtils.getLinkLocalGateway());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void createControlNetwork(String privBrName) {
|
||||
deleteExitingLinkLocalRoutTable(privBrName);
|
||||
if (!isBridgeExists(privBrName)) {
|
||||
Script.runSimpleBashScript("ovs-vsctl add-br " + privBrName + "; ifconfig " + privBrName + " up; ifconfig " +
|
||||
privBrName + " 169.254.0.1", _timeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isBridgeExists(String bridgeName) {
|
||||
|
||||
@ -38,10 +38,10 @@ public class KVMStoragePoolManager {
|
||||
private final Map<String, StorageAdaptor> _storageMapper = new HashMap<String, StorageAdaptor>();
|
||||
|
||||
private StorageAdaptor getStorageAdaptor(StoragePoolType type) {
|
||||
// type can be null: LibVirtComputingResource:3238
|
||||
if (type == null) {
|
||||
return _storageMapper.get("libvirt");
|
||||
}
|
||||
// type can be null: LibVirtComputingResource:3238
|
||||
if (type == null) {
|
||||
return _storageMapper.get("libvirt");
|
||||
}
|
||||
StorageAdaptor adaptor = _storageMapper.get(type.toString());
|
||||
if (adaptor == null) {
|
||||
// LibvirtStorageAdaptor is selected by default
|
||||
|
||||
@ -200,56 +200,58 @@ public class Script implements Callable<String> {
|
||||
s_executors.execute(task);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
if (_process.waitFor() == 0) {
|
||||
_logger.debug("Execution is successful.");
|
||||
if (interpreter != null) {
|
||||
return interpreter.drain() ? task.getResult() : interpreter.interpret(ir);
|
||||
}
|
||||
else {
|
||||
// null return is ok apparently
|
||||
return (_process.exitValue() == 0) ? "Ok" : "Failed, exit code " + _process.exitValue();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
if (!_isTimeOut) {
|
||||
/* This is not timeout, we are interrupted by others, continue */
|
||||
_logger.debug("We are interrupted but it's not a timeout, just continue");
|
||||
continue;
|
||||
}
|
||||
|
||||
TimedOutLogger log = new TimedOutLogger(_process);
|
||||
Task timedoutTask = new Task(log, ir);
|
||||
while (true) {
|
||||
try {
|
||||
if (_process.waitFor() == 0) {
|
||||
_logger.debug("Execution is successful.");
|
||||
if (interpreter != null) {
|
||||
return interpreter.drain() ? task.getResult() : interpreter.interpret(ir);
|
||||
} else {
|
||||
// null return is ok apparently
|
||||
return (_process.exitValue() == 0) ? "Ok" : "Failed, exit code " + _process.exitValue();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
if (!_isTimeOut) {
|
||||
/*
|
||||
* This is not timeout, we are interrupted by others,
|
||||
* continue
|
||||
*/
|
||||
_logger.debug("We are interrupted but it's not a timeout, just continue");
|
||||
continue;
|
||||
}
|
||||
|
||||
timedoutTask.run();
|
||||
if (!_passwordCommand) {
|
||||
_logger.warn("Timed out: " + buildCommandLine(command) + ". Output is: " + timedoutTask.getResult());
|
||||
} else {
|
||||
_logger.warn("Timed out: " + buildCommandLine(command));
|
||||
}
|
||||
TimedOutLogger log = new TimedOutLogger(_process);
|
||||
Task timedoutTask = new Task(log, ir);
|
||||
|
||||
return ERR_TIMEOUT;
|
||||
} finally {
|
||||
if (future != null) {
|
||||
future.cancel(false);
|
||||
}
|
||||
Thread.interrupted();
|
||||
}
|
||||
}
|
||||
timedoutTask.run();
|
||||
if (!_passwordCommand) {
|
||||
_logger.warn("Timed out: " + buildCommandLine(command) + ". Output is: " + timedoutTask.getResult());
|
||||
} else {
|
||||
_logger.warn("Timed out: " + buildCommandLine(command));
|
||||
}
|
||||
|
||||
_logger.debug("Exit value is " + _process.exitValue());
|
||||
return ERR_TIMEOUT;
|
||||
} finally {
|
||||
if (future != null) {
|
||||
future.cancel(false);
|
||||
}
|
||||
Thread.interrupted();
|
||||
}
|
||||
}
|
||||
|
||||
_logger.debug("Exit value is " + _process.exitValue());
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(_process.getInputStream()), 128);
|
||||
|
||||
String error;
|
||||
if (interpreter != null) {
|
||||
error = interpreter.processError(reader);
|
||||
error = interpreter.processError(reader);
|
||||
}
|
||||
else {
|
||||
error = "Non zero exit code : " + _process.exitValue();
|
||||
error = "Non zero exit code : " + _process.exitValue();
|
||||
}
|
||||
|
||||
if (_logger.isDebugEnabled()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user