Summary: Begone pesky tabs

This commit is contained in:
Hugo Trippaers 2013-01-15 10:00:58 +01:00
parent f09d453efe
commit 2d69a1855d
6 changed files with 133 additions and 134 deletions

View File

@ -86,7 +86,7 @@ public class BridgeVifDriver extends VifDriverBase {
vlanId = broadcastUri.getHost(); vlanId = broadcastUri.getHost();
} }
else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { 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(); String trafficLabel = nic.getName();
if (nic.getType() == Networks.TrafficType.Guest) { if (nic.getType() == Networks.TrafficType.Guest) {

View File

@ -364,7 +364,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
private int _dom0MinMem; private int _dom0MinMem;
protected enum BridgeType { protected enum BridgeType {
NATIVE, OPENVSWITCH NATIVE, OPENVSWITCH
} }
protected enum defineOps { protected enum defineOps {
@ -483,10 +483,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
String bridgeType = (String) params.get("network.bridge.type"); String bridgeType = (String) params.get("network.bridge.type");
if (bridgeType == null) { if (bridgeType == null) {
_bridgeType = BridgeType.NATIVE; _bridgeType = BridgeType.NATIVE;
} }
else { else {
_bridgeType = BridgeType.valueOf(bridgeType.toUpperCase()); _bridgeType = BridgeType.valueOf(bridgeType.toUpperCase());
} }
params.put("domr.scripts.dir", domrScriptsDir); params.put("domr.scripts.dir", domrScriptsDir);
@ -664,19 +664,18 @@ public class LibvirtComputingResource extends ServerResourceBase implements
LibvirtConnection.initialize(_hypervisorURI); LibvirtConnection.initialize(_hypervisorURI);
Connect conn = null; Connect conn = null;
try { try {
conn = LibvirtConnection.getConnection(); conn = LibvirtConnection.getConnection();
if (_bridgeType == BridgeType.OPENVSWITCH) { if (_bridgeType == BridgeType.OPENVSWITCH) {
if (conn.getLibVirVersion() < (9 * 1000 + 11)) { if (conn.getLibVirVersion() < (9 * 1000 + 11)) {
throw new ConfigurationException( throw new ConfigurationException("LibVirt version 0.9.11 required for openvswitch support, but version "
"LibVirt version 0.9.11 required for openvswitch support, but version " + conn.getLibVirVersion() + " detected");
+ conn.getLibVirVersion() + " detected"); }
} }
} } catch (LibvirtException e) {
} catch (LibvirtException e) { throw new CloudRuntimeException(e.getMessage());
throw new CloudRuntimeException(e.getMessage()); }
}
/* Does node support HVM guest? If not, exit */ /* Does node support HVM guest? If not, exit */
if (!IsHVMEnabled(conn)) { if (!IsHVMEnabled(conn)) {
@ -720,12 +719,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements
} }
switch (_bridgeType) { switch (_bridgeType) {
case NATIVE:
getPifs();
break;
case OPENVSWITCH: case OPENVSWITCH:
getOvsPifs(); getOvsPifs();
break; break;
case NATIVE:
default:
getPifs();
break;
} }
if (_pifs.get("private") == null) { if (_pifs.get("private") == null) {
@ -786,31 +786,29 @@ public class LibvirtComputingResource extends ServerResourceBase implements
// Load the vif driver // Load the vif driver
String vifDriverName = (String) params.get("libvirt.vif.driver"); String vifDriverName = (String) params.get("libvirt.vif.driver");
if (vifDriverName == null) { if (vifDriverName == null) {
if (_bridgeType == BridgeType.OPENVSWITCH) { if (_bridgeType == BridgeType.OPENVSWITCH) {
s_logger.info("No libvirt.vif.driver specififed. Defaults to OvsVifDriver."); s_logger.info("No libvirt.vif.driver specififed. Defaults to OvsVifDriver.");
vifDriverName = "com.cloud.hypervisor.kvm.resource.OvsVifDriver"; vifDriverName = "com.cloud.hypervisor.kvm.resource.OvsVifDriver";
} } else {
else { s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver.");
s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver."); vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver";
vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver"; }
}
} }
params.put("libvirt.computing.resource", (Object) this); params.put("libvirt.computing.resource", (Object) this);
try { try {
Class<?> clazz = Class.forName(vifDriverName); Class<?> clazz = Class.forName(vifDriverName);
_vifDriver = (VifDriver) clazz.newInstance(); _vifDriver = (VifDriver) clazz.newInstance();
_vifDriver.configure(params); _vifDriver.configure(params);
} catch (ClassNotFoundException e) { } 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) { } 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) { } 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; return true;
} }
@ -834,15 +832,16 @@ public class LibvirtComputingResource extends ServerResourceBase implements
} }
private void getOvsPifs() { 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); s_logger.debug("cmdout was " + cmdout);
List<String> bridges = Arrays.asList(cmdout.split("%")); List<String> bridges = Arrays.asList(cmdout.split("%"));
for (String bridge : bridges) { for (String bridge : bridges) {
s_logger.debug("looking for pif for bridge " + bridge); s_logger.debug("looking for pif for bridge " + bridge);
//String pif = getOvsPif(bridge); // String pif = getOvsPif(bridge);
// Not really interested in the pif name at this point for ovs bridges // Not really interested in the pif name at this point for ovs
// bridges
String pif = bridge; String pif = bridge;
if(_publicBridgeName != null && bridge.equals(_publicBridgeName)){ if (_publicBridgeName != null && bridge.equals(_publicBridgeName)) {
_pifs.put("public", pif); _pifs.put("public", pif);
} }
if (_guestBridgeName != null && bridge.equals(_guestBridgeName)) { if (_guestBridgeName != null && bridge.equals(_guestBridgeName)) {
@ -875,10 +874,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
} }
if (_bridgeType == BridgeType.OPENVSWITCH) { if (_bridgeType == BridgeType.OPENVSWITCH) {
return checkOvsNetwork(networkName); return checkOvsNetwork(networkName);
} }
else { else {
return checkBridgeNetwork(networkName); return checkBridgeNetwork(networkName);
} }
} }
@ -897,10 +896,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
} }
private boolean checkOvsNetwork(String networkName) { private boolean checkOvsNetwork(String networkName) {
s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge"); s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge");
if (networkName == null) { if (networkName == null) {
return true; return true;
} }
Script command = new Script("/bin/sh", _timeout); Script command = new Script("/bin/sh", _timeout);
command.add("-c"); command.add("-c");

View File

@ -700,27 +700,27 @@ public class LibvirtVMDef {
} }
public void setVirtualPortType(String virtualPortType) { public void setVirtualPortType(String virtualPortType) {
_virtualPortType = virtualPortType; _virtualPortType = virtualPortType;
} }
public String getVirtualPortType() { public String getVirtualPortType() {
return _virtualPortType; return _virtualPortType;
} }
public void setVirtualPortInterfaceId(String virtualPortInterfaceId) { public void setVirtualPortInterfaceId(String virtualPortInterfaceId) {
_virtualPortInterfaceId = virtualPortInterfaceId; _virtualPortInterfaceId = virtualPortInterfaceId;
} }
public String getVirtualPortInterfaceId() { public String getVirtualPortInterfaceId() {
return _virtualPortInterfaceId; return _virtualPortInterfaceId;
} }
public void setVlanTag(int vlanTag) { public void setVlanTag(int vlanTag) {
_vlanTag = vlanTag; _vlanTag = vlanTag;
} }
public int getVlanTag() { public int getVlanTag() {
return _vlanTag; return _vlanTag;
} }
@Override @Override
@ -742,14 +742,14 @@ public class LibvirtVMDef {
netBuilder.append("<model type='" + _model + "'/>\n"); netBuilder.append("<model type='" + _model + "'/>\n");
} }
if (_virtualPortType != null) { if (_virtualPortType != null) {
netBuilder.append("<virtualport type='" + _virtualPortType + "'>\n"); netBuilder.append("<virtualport type='" + _virtualPortType + "'>\n");
if (_virtualPortInterfaceId != null) { if (_virtualPortInterfaceId != null) {
netBuilder.append("<parameters interfaceid='" + _virtualPortInterfaceId + "'/>\n"); netBuilder.append("<parameters interfaceid='" + _virtualPortInterfaceId + "'/>\n");
} }
netBuilder.append("</virtualport>\n"); netBuilder.append("</virtualport>\n");
} }
if (_vlanTag != -1) { 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"); netBuilder.append("</interface>\n");
return netBuilder.toString(); return netBuilder.toString();

View File

@ -36,16 +36,15 @@ import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script; import com.cloud.utils.script.Script;
public class OvsVifDriver extends VifDriverBase { public class OvsVifDriver extends VifDriverBase {
private static final Logger s_logger = Logger private static final Logger s_logger = Logger.getLogger(OvsVifDriver.class);
.getLogger(OvsVifDriver.class);
private int _timeout; private int _timeout;
private String _modifyVlanPath; private String _modifyVlanPath;
@Override @Override
public void configure(Map<String, Object> params) throws ConfigurationException { public void configure(Map<String, Object> params) throws ConfigurationException {
super.configure(params); super.configure(params);
String networkScriptsDir = (String) params.get("network.scripts.dir"); String networkScriptsDir = (String) params.get("network.scripts.dir");
if (networkScriptsDir == null) { if (networkScriptsDir == null) {
networkScriptsDir = "scripts/vm/network/vnet"; networkScriptsDir = "scripts/vm/network/vnet";
} }
@ -59,11 +58,11 @@ public class OvsVifDriver extends VifDriverBase {
} }
createControlNetwork(_bridges.get("linklocal")); createControlNetwork(_bridges.get("linklocal"));
} }
@Override @Override
public InterfaceDef plug(NicTO nic, String guestOsType) public InterfaceDef plug(NicTO nic, String guestOsType)
throws InternalErrorException, LibvirtException { throws InternalErrorException, LibvirtException {
s_logger.debug("plugging nic=" + nic); s_logger.debug("plugging nic=" + nic);
LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef(); LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef();
@ -76,7 +75,7 @@ public class OvsVifDriver extends VifDriverBase {
vlanId = broadcastUri.getHost(); vlanId = broadcastUri.getHost();
} }
else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
logicalSwitchUuid = nic.getBroadcastUri().getSchemeSpecificPart(); logicalSwitchUuid = nic.getBroadcastUri().getSchemeSpecificPart();
} }
String trafficLabel = nic.getName(); String trafficLabel = nic.getName();
if (nic.getType() == Networks.TrafficType.Guest) { if (nic.getType() == Networks.TrafficType.Guest) {
@ -91,9 +90,9 @@ public class OvsVifDriver extends VifDriverBase {
intf.setVlanTag(Integer.parseInt(vlanId)); intf.setVlanTag(Integer.parseInt(vlanId));
} }
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid); s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid);
intf.setVirtualPortInterfaceId(nic.getUuid()); intf.setVirtualPortInterfaceId(nic.getUuid());
String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private"); String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private");
intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType)); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType));
} }
else { else {
@ -127,10 +126,10 @@ public class OvsVifDriver extends VifDriverBase {
return intf; return intf;
} }
@Override @Override
public void unplug(InterfaceDef iface) { public void unplug(InterfaceDef iface) {
// Libvirt apparently takes care of this, see BridgeVifDriver unplug // Libvirt apparently takes care of this, see BridgeVifDriver unplug
} }
private String setVnetBrName(String pifName, String vnetId) { private String setVnetBrName(String pifName, String vnetId) {
String brName = "br" + pifName + "-"+ vnetId; String brName = "br" + pifName + "-"+ vnetId;
@ -174,7 +173,6 @@ public class OvsVifDriver extends VifDriverBase {
Script.runSimpleBashScript("ovs-vsctl add-br " + privBrName + "; ifconfig " + privBrName + " up; ifconfig " + Script.runSimpleBashScript("ovs-vsctl add-br " + privBrName + "; ifconfig " + privBrName + " up; ifconfig " +
privBrName + " 169.254.0.1", _timeout); privBrName + " 169.254.0.1", _timeout);
} }
} }
private boolean isBridgeExists(String bridgeName) { private boolean isBridgeExists(String bridgeName) {

View File

@ -38,10 +38,10 @@ public class KVMStoragePoolManager {
private final Map<String, StorageAdaptor> _storageMapper = new HashMap<String, StorageAdaptor>(); private final Map<String, StorageAdaptor> _storageMapper = new HashMap<String, StorageAdaptor>();
private StorageAdaptor getStorageAdaptor(StoragePoolType type) { private StorageAdaptor getStorageAdaptor(StoragePoolType type) {
// type can be null: LibVirtComputingResource:3238 // type can be null: LibVirtComputingResource:3238
if (type == null) { if (type == null) {
return _storageMapper.get("libvirt"); return _storageMapper.get("libvirt");
} }
StorageAdaptor adaptor = _storageMapper.get(type.toString()); StorageAdaptor adaptor = _storageMapper.get(type.toString());
if (adaptor == null) { if (adaptor == null) {
// LibvirtStorageAdaptor is selected by default // LibvirtStorageAdaptor is selected by default

View File

@ -200,56 +200,58 @@ public class Script implements Callable<String> {
s_executors.execute(task); s_executors.execute(task);
} }
while (true) { while (true) {
try { try {
if (_process.waitFor() == 0) { if (_process.waitFor() == 0) {
_logger.debug("Execution is successful."); _logger.debug("Execution is successful.");
if (interpreter != null) { if (interpreter != null) {
return interpreter.drain() ? task.getResult() : interpreter.interpret(ir); return interpreter.drain() ? task.getResult() : interpreter.interpret(ir);
} } else {
else { // null return is ok apparently
// null return is ok apparently return (_process.exitValue() == 0) ? "Ok" : "Failed, exit code " + _process.exitValue();
return (_process.exitValue() == 0) ? "Ok" : "Failed, exit code " + _process.exitValue(); }
} } else {
} else { break;
break; }
} } catch (InterruptedException e) {
} catch (InterruptedException e) { if (!_isTimeOut) {
if (!_isTimeOut) { /*
/* This is not timeout, we are interrupted by others, continue */ * This is not timeout, we are interrupted by others,
_logger.debug("We are interrupted but it's not a timeout, just continue"); * continue
continue; */
} _logger.debug("We are interrupted but it's not a timeout, just continue");
continue;
}
TimedOutLogger log = new TimedOutLogger(_process); TimedOutLogger log = new TimedOutLogger(_process);
Task timedoutTask = new Task(log, ir); Task timedoutTask = new Task(log, ir);
timedoutTask.run(); timedoutTask.run();
if (!_passwordCommand) { if (!_passwordCommand) {
_logger.warn("Timed out: " + buildCommandLine(command) + ". Output is: " + timedoutTask.getResult()); _logger.warn("Timed out: " + buildCommandLine(command) + ". Output is: " + timedoutTask.getResult());
} else { } else {
_logger.warn("Timed out: " + buildCommandLine(command)); _logger.warn("Timed out: " + buildCommandLine(command));
} }
return ERR_TIMEOUT; return ERR_TIMEOUT;
} finally { } finally {
if (future != null) { if (future != null) {
future.cancel(false); future.cancel(false);
} }
Thread.interrupted(); Thread.interrupted();
} }
} }
_logger.debug("Exit value is " + _process.exitValue()); _logger.debug("Exit value is " + _process.exitValue());
BufferedReader reader = new BufferedReader(new InputStreamReader(_process.getInputStream()), 128); BufferedReader reader = new BufferedReader(new InputStreamReader(_process.getInputStream()), 128);
String error; String error;
if (interpreter != null) { if (interpreter != null) {
error = interpreter.processError(reader); error = interpreter.processError(reader);
} }
else { else {
error = "Non zero exit code : " + _process.exitValue(); error = "Non zero exit code : " + _process.exitValue();
} }
if (_logger.isDebugEnabled()) { if (_logger.isDebugEnabled()) {