Skip to content

Commit cce8083

Browse files
author
Koushik Das
committed
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.
1 parent ed60745 commit cce8083

1 file changed

Lines changed: 31 additions & 72 deletions

File tree

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java‎

Lines changed: 31 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,34 @@ public String getGuestVSwitchName(long dcId, HypervisorType hypervisorType) {
344344
return _netMgr.getDefaultGuestTrafficLabel(dcId, hypervisorType);
345345
}
346346

347+
private void prepareHost(HostMO hostMo, String privateTrafficLabel) throws Exception {
348+
// For ESX host, we need to enable host firewall to allow VNC access
349+
HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
350+
if(firewallMo != null) {
351+
if(hostMo.getHostType() == VmwareHostType.ESX) {
352+
firewallMo.enableRuleset("vncServer");
353+
firewallMo.refreshFirewall();
354+
}
355+
}
356+
357+
// prepare at least one network on the vswitch to enable OVF importing
358+
String vSwitchName = privateTrafficLabel;
359+
String vlanId = null;
360+
String[] tokens = privateTrafficLabel.split(",");
361+
if(tokens.length == 2) {
362+
vSwitchName = tokens[0].trim();
363+
vlanId = tokens[1].trim();
364+
}
365+
366+
s_logger.info("Preparing network on host " + hostMo.getContext().toString() + " for " + privateTrafficLabel);
367+
if(!_nexusVSwitchActive) {
368+
HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
369+
}
370+
else {
371+
HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000);
372+
}
373+
}
374+
347375
@Override
348376
public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId,
349377
String hostInventoryPath) throws Exception {
@@ -365,30 +393,7 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
365393

366394
// For ESX host, we need to enable host firewall to allow VNC access
367395
HostMO hostMo = new HostMO(serviceContext, hosts[0]);
368-
HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
369-
if(firewallMo != null) {
370-
if(hostMo.getHostType() == VmwareHostType.ESX) {
371-
372-
firewallMo.enableRuleset("vncServer");
373-
firewallMo.refreshFirewall();
374-
}
375-
}
376-
377-
// prepare at least one network on the vswitch to enable OVF importing
378-
String vlanId = null;
379-
if(privateTrafficLabel != null) {
380-
String[] tokens = privateTrafficLabel.split(",");
381-
if(tokens.length == 2)
382-
vlanId = tokens[1];
383-
}
384-
385-
if(!_nexusVSwitchActive) {
386-
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
387-
}
388-
else {
389-
s_logger.info("Preparing Network on " + privateTrafficLabel);
390-
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
391-
}
396+
prepareHost(hostMo, privateTrafficLabel);
392397
returnedHostList.add(hosts[0]);
393398
return returnedHostList;
394399
} else if(mor.getType().equals("ClusterComputeResource")) {
@@ -404,60 +409,14 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
404409
for(ManagedObjectReference morHost: hosts) {
405410
// For ESX host, we need to enable host firewall to allow VNC access
406411
HostMO hostMo = new HostMO(serviceContext, morHost);
407-
HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
408-
if(firewallMo != null) {
409-
if(hostMo.getHostType() == VmwareHostType.ESX) {
410-
firewallMo.enableRuleset("vncServer");
411-
firewallMo.refreshFirewall();
412-
}
413-
}
414-
415-
String vlanId = null;
416-
if(privateTrafficLabel != null) {
417-
String[] tokens = privateTrafficLabel.split(",");
418-
if(tokens.length == 2)
419-
vlanId = tokens[1];
420-
}
421-
422-
423-
s_logger.info("Calling prepareNetwork : " + hostMo.getContext().toString());
424-
// prepare at least one network on the vswitch to enable OVF importing
425-
if(!_nexusVSwitchActive) {
426-
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
427-
}
428-
else {
429-
s_logger.info("Preparing Network on " + privateTrafficLabel);
430-
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
431-
}
412+
prepareHost(hostMo, privateTrafficLabel);
432413
returnedHostList.add(morHost);
433414
}
434415
return returnedHostList;
435416
} else if(mor.getType().equals("HostSystem")) {
436417
// For ESX host, we need to enable host firewall to allow VNC access
437418
HostMO hostMo = new HostMO(serviceContext, mor);
438-
HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
439-
if(firewallMo != null) {
440-
if(hostMo.getHostType() == VmwareHostType.ESX) {
441-
firewallMo.enableRuleset("vncServer");
442-
firewallMo.refreshFirewall();
443-
}
444-
}
445-
446-
String vlanId = null;
447-
if(privateTrafficLabel != null) {
448-
String[] tokens = privateTrafficLabel.split(",");
449-
if(tokens.length == 2)
450-
vlanId = tokens[1];
451-
}
452-
453-
// prepare at least one network on the vswitch to enable OVF importing
454-
if(!_nexusVSwitchActive) {
455-
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
456-
}
457-
else {
458-
s_logger.info("Preparing Network on " + privateTrafficLabel);
459-
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
460-
}
419+
prepareHost(hostMo, privateTrafficLabel);
461420
returnedHostList.add(mor);
462421
return returnedHostList;
463422
} else {

0 commit comments

Comments
 (0)