CLOUDSTACK-435: Vmware network labels are ignored when creating a Zone using 
basic networking
Due to incorrect logic the private network traffic label specified was not 
getting used, instead some default was getting used (vSwitch0 or 
privateEthernetPortProfile). The fix passes the correct label in the format 
vSwitchX or vSwitchX,<vlan_id> and based on that the correct switch is used.


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

Branch: refs/heads/vim51_win8
Commit: ca56e7667c4bd6998c13ee36d6cd43c639be4dd4
Parents: a2e89c4
Author: Koushik Das <[email protected]>
Authored: Thu Nov 1 23:40:34 2012 +0530
Committer: Koushik Das <[email protected]>
Committed: Mon Feb 4 19:23:30 2013 +0530

----------------------------------------------------------------------
 .../vmware/manager/VmwareManagerImpl.java          |  103 +++++----------
 1 files changed, 31 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ca56e766/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
 
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 7939620..88e03f5 100755
--- 
a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ 
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -344,6 +344,34 @@ public class VmwareManagerImpl extends ManagerBase 
implements VmwareManager, Vmw
         return _netMgr.getDefaultGuestTrafficLabel(dcId, hypervisorType);
     }
 
+    private void prepareHost(HostMO hostMo, String privateTrafficLabel) throws 
Exception {
+        // For ESX host, we need to enable host firewall to allow VNC access
+        HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
+        if(firewallMo != null) {
+            if(hostMo.getHostType() == VmwareHostType.ESX) {
+                firewallMo.enableRuleset("vncServer");
+                firewallMo.refreshFirewall();
+            }
+        }
+
+        // prepare at least one network on the vswitch to enable OVF importing
+        String vSwitchName = privateTrafficLabel;
+        String vlanId = null;
+        String[] tokens = privateTrafficLabel.split(",");
+        if(tokens.length == 2) {
+            vSwitchName = tokens[0].trim();
+            vlanId = tokens[1].trim();
+        }
+
+        s_logger.info("Preparing network on host " + 
hostMo.getContext().toString() + " for " + privateTrafficLabel);
+        if(!_nexusVSwitchActive) {
+            HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.private", 
hostMo, vlanId, null, null, 180000, false);
+        }
+        else {
+            HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.private", 
hostMo, vlanId, null, null, 180000);
+        }
+    }
+    
     @Override
     public List<ManagedObjectReference> addHostToPodCluster(VmwareContext 
serviceContext, long dcId, Long podId, Long clusterId,
             String hostInventoryPath) throws Exception {
@@ -365,30 +393,7 @@ public class VmwareManagerImpl extends ManagerBase 
implements VmwareManager, Vmw
 
                 // For ESX host, we need to enable host firewall to allow VNC 
access
                 HostMO hostMo = new HostMO(serviceContext, hosts[0]);
-                HostFirewallSystemMO firewallMo = 
hostMo.getHostFirewallSystemMO();
-                if(firewallMo != null) {
-                    if(hostMo.getHostType() == VmwareHostType.ESX) {
-
-                        firewallMo.enableRuleset("vncServer");
-                        firewallMo.refreshFirewall();
-                    }
-                }
-
-                // prepare at least one network on the vswitch to enable OVF 
importing
-                String vlanId = null;
-                if(privateTrafficLabel != null) {
-                    String[] tokens = privateTrafficLabel.split(",");
-                    if(tokens.length == 2)
-                        vlanId = tokens[1];
-                }
-
-                if(!_nexusVSwitchActive) {
-                    
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, 
"cloud.private", hostMo, vlanId, null, null, 180000, false);
-                }
-                else {
-                    s_logger.info("Preparing Network on " + 
privateTrafficLabel);
-                    HypervisorHostHelper.prepareNetwork(privateTrafficLabel, 
"cloud.private", hostMo, vlanId, null, null, 180000);
-                }
+                prepareHost(hostMo, privateTrafficLabel);
                 returnedHostList.add(hosts[0]);
                 return returnedHostList;
             } else if(mor.getType().equals("ClusterComputeResource")) {
@@ -404,60 +409,14 @@ public class VmwareManagerImpl extends ManagerBase 
implements VmwareManager, Vmw
                 for(ManagedObjectReference morHost: hosts) {
                     // For ESX host, we need to enable host firewall to allow 
VNC access
                     HostMO hostMo = new HostMO(serviceContext, morHost);
-                    HostFirewallSystemMO firewallMo = 
hostMo.getHostFirewallSystemMO();
-                    if(firewallMo != null) {
-                        if(hostMo.getHostType() == VmwareHostType.ESX) {
-                            firewallMo.enableRuleset("vncServer");
-                            firewallMo.refreshFirewall();
-                        }
-                    }
-
-                    String vlanId = null;
-                    if(privateTrafficLabel != null) {
-                        String[] tokens = privateTrafficLabel.split(",");
-                        if(tokens.length == 2)
-                            vlanId = tokens[1];
-                    }
-
-
-                    s_logger.info("Calling prepareNetwork : " + 
hostMo.getContext().toString());
-                    // prepare at least one network on the vswitch to enable 
OVF importing
-                    if(!_nexusVSwitchActive) {
-                        
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, 
"cloud.private", hostMo, vlanId, null, null, 180000, false);
-                    }
-                    else {
-                        s_logger.info("Preparing Network on " + 
privateTrafficLabel);
-                        
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", 
hostMo, vlanId, null, null, 180000);
-                    }
+                    prepareHost(hostMo, privateTrafficLabel);
                     returnedHostList.add(morHost);
                 }
                 return returnedHostList;
             } else if(mor.getType().equals("HostSystem")) {
                 // For ESX host, we need to enable host firewall to allow VNC 
access
                 HostMO hostMo = new HostMO(serviceContext, mor);
-                HostFirewallSystemMO firewallMo = 
hostMo.getHostFirewallSystemMO();
-                if(firewallMo != null) {
-                    if(hostMo.getHostType() == VmwareHostType.ESX) {
-                        firewallMo.enableRuleset("vncServer");
-                        firewallMo.refreshFirewall();
-                    }
-                }
-
-                String vlanId = null;
-                if(privateTrafficLabel != null) {
-                    String[] tokens = privateTrafficLabel.split(",");
-                    if(tokens.length == 2)
-                        vlanId = tokens[1];
-                }
-
-                // prepare at least one network on the vswitch to enable OVF 
importing
-                if(!_nexusVSwitchActive) {
-                    
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, 
"cloud.private", hostMo, vlanId, null, null, 180000, false);
-                }
-                else {
-                    s_logger.info("Preparing Network on " + 
privateTrafficLabel);
-                    HypervisorHostHelper.prepareNetwork(privateTrafficLabel, 
"cloud.private", hostMo, vlanId, null, null, 180000);
-                }
+                prepareHost(hostMo, privateTrafficLabel);
                 returnedHostList.add(mor);
                 return returnedHostList;
             } else {

Reply via email to