You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2013/01/23 08:15:57 UTC

[19/45] git commit: Summary: Begone pesky tabs

Summary: Begone pesky tabs

Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/2d69a185
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/2d69a185
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/2d69a185

Branch: refs/heads/master
Commit: 2d69a1855de5110c57010e248f83d88607c668fe
Parents: f09d453
Author: Hugo Trippaers <tr...@gmail.com>
Authored: Tue Jan 15 10:00:58 2013 +0100
Committer: Hugo Trippaers <tr...@gmail.com>
Committed: Tue Jan 15 10:00:58 2013 +0100

----------------------------------------------------------------------
 .../hypervisor/kvm/resource/BridgeVifDriver.java   |    2 +-
 .../kvm/resource/LibvirtComputingResource.java     |   97 +++++++--------
 .../hypervisor/kvm/resource/LibvirtVMDef.java      |   34 +++---
 .../hypervisor/kvm/resource/OvsVifDriver.java      |   46 ++++----
 .../kvm/storage/KVMStoragePoolManager.java         |    8 +-
 utils/src/com/cloud/utils/script/Script.java       |   88 +++++++-------
 6 files changed, 137 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2d69a185/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
index 031721e..3883c62 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
@@ -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) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2d69a185/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 1474d11..03c5367 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -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();
-
-			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());
-		}
+        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());
+        }
 
         /* 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);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2d69a185/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
index df27778..c02d8fc 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
@@ -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();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2d69a185/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
index 0ff05a9..04c29a8 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
@@ -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) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2d69a185/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
index 1af2ed2..c2bfad9 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
@@ -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

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2d69a185/utils/src/com/cloud/utils/script/Script.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java
index d82d1d0..1e5aab4 100755
--- a/utils/src/com/cloud/utils/script/Script.java
+++ b/utils/src/com/cloud/utils/script/Script.java
@@ -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);
-
-					timedoutTask.run();
-					if (!_passwordCommand) {
-						_logger.warn("Timed out: " + buildCommandLine(command) + ".  Output is: " + timedoutTask.getResult());
-					} else {
-						_logger.warn("Timed out: " + buildCommandLine(command));
-					}
-
-					return ERR_TIMEOUT;
-				} finally {
-					if (future != null) {
-						future.cancel(false);
-					}
-					Thread.interrupted();
-				}
-			}
-
-			_logger.debug("Exit value is " + _process.exitValue());
+            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);
+
+                    timedoutTask.run();
+                    if (!_passwordCommand) {
+                        _logger.warn("Timed out: " + buildCommandLine(command) + ".  Output is: " + timedoutTask.getResult());
+                    } else {
+                        _logger.warn("Timed out: " + buildCommandLine(command));
+                    }
+
+                    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()) {