Skip to content

Commit b6687fa

Browse files
Sateesh ChodapuneediVijayendra Bhamidipati
authored andcommitted
CS-9919 Support for Nexus Swiches (Cisco Vswitches)
Description: Retreving physical network configuration from database. Passing configuration down to resource. Cleanup. Conflicts: core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java server/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
1 parent 8d1b9c2 commit b6687fa

4 files changed

Lines changed: 165 additions & 107 deletions

File tree

core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.util.List;
1717
import java.util.Map;
1818

19-
//import com.cloud.cluster.CheckPointManager;
2019
import com.cloud.hypervisor.vmware.mo.HostMO;
2120
import com.cloud.hypervisor.vmware.util.VmwareContext;
2221
import com.cloud.utils.Pair;
@@ -62,4 +61,8 @@ List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, l
6261
void endExclusiveOperation();
6362

6463
Map<String, String> getNexusVSMCredentials(String hostGuid);
64+
65+
boolean getNexusVSwitchGlobalParameter();
66+
67+
Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId);
6568
}

server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@
6161
import com.cloud.hypervisor.vmware.mo.DiskControllerType;
6262
import com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO;
6363
import com.cloud.hypervisor.vmware.mo.HostMO;
64-
import com.cloud.hypervisor.vmware.mo.HostVirtualNicType;
6564
import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
6665
import com.cloud.hypervisor.vmware.mo.TaskMO;
6766
import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
6867
import com.cloud.hypervisor.vmware.mo.VmwareHostType;
6968
import com.cloud.hypervisor.vmware.resource.SshHelper;
7069
import com.cloud.hypervisor.vmware.util.VmwareContext;
7170
import com.cloud.network.CiscoNexusVSMDeviceVO;
71+
import com.cloud.network.NetworkManager;
7272
import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
7373
import com.cloud.network.router.VirtualNetworkApplianceManager;
7474
import com.cloud.org.Cluster.ClusterType;
@@ -91,7 +91,6 @@
9191
import com.cloud.vm.DomainRouterVO;
9292
import com.google.gson.Gson;
9393
import com.vmware.apputils.vim25.ServiceUtil;
94-
import com.vmware.vim25.AboutInfo;
9594
import com.vmware.vim25.HostConnectSpec;
9695
import com.vmware.vim25.HostPortGroupSpec;
9796
import com.vmware.vim25.ManagedObjectReference;
@@ -110,6 +109,8 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
110109
private String _instance;
111110

112111
@Inject AgentManager _agentMgr;
112+
@Inject
113+
protected NetworkManager _netMgr;
113114
@Inject HostDao _hostDao;
114115
@Inject ClusterDao _clusterDao;
115116
@Inject ClusterDetailsDao _clusterDetailsDao;
@@ -132,7 +133,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
132133
String _privateNetworkVSwitchType;
133134
String _publicNetworkVSwitchType;
134135
String _guestNetworkVSwitchType;
135-
Boolean _nexusVSwitchActive;
136+
boolean _nexusVSwitchActive;
136137
String _serviceConsoleName;
137138
String _managemetPortGroupName;
138139
String _defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString();
@@ -358,6 +359,10 @@ public String getName() {
358359
return _name;
359360
}
360361

362+
public boolean getNexusVSwitchGlobalParameter() {
363+
return _nexusVSwitchActive;
364+
}
365+
361366
@Override
362367
public String composeWorkerName() {
363368
return UUID.randomUUID().toString().replace("-", "");
@@ -367,6 +372,13 @@ public String composeWorkerName() {
367372
public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId,
368373
String hostInventoryPath) throws Exception {
369374
ManagedObjectReference mor = serviceContext.getHostMorByPath(hostInventoryPath);
375+
String privateTrafficLabel = null;
376+
if (_nexusVSwitchActive) {
377+
privateTrafficLabel = serviceContext.getStockObject("privateTrafficLabel");
378+
if (privateTrafficLabel == null) {
379+
privateTrafficLabel = _privateNetworkVSwitchName;
380+
}
381+
}
370382
if(mor != null) {
371383
List<ManagedObjectReference> returnedHostList = new ArrayList<ManagedObjectReference>();
372384

@@ -392,12 +404,12 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
392404
if(spec.getVlanId() != 0) {
393405
vlanId = String.valueOf(spec.getVlanId());
394406
}
395-
407+
396408
if(!_nexusVSwitchActive) {
397409
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
398410
}
399411
else {
400-
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000);
412+
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
401413
}
402414
returnedHostList.add(hosts[0]);
403415
return returnedHostList;
@@ -435,7 +447,7 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
435447
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
436448
}
437449
else {
438-
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000);
450+
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
439451
}
440452
returnedHostList.add(morHost);
441453
}
@@ -464,7 +476,7 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
464476
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
465477
}
466478
else {
467-
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000);
479+
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
468480
}
469481
returnedHostList.add(mor);
470482
return returnedHostList;
@@ -962,4 +974,17 @@ public int getMaxHostsPerCluster() {
962974
public int getRouterExtraPublicNics() {
963975
return this._routerExtraPublicNics;
964976
}
977+
978+
@Override
979+
public Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId) {
980+
ClusterVSMMapVO vsmMapVO = _vsmMapDao.findByClusterId(clusterId);
981+
CiscoNexusVSMDeviceVO nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId());
982+
if (nexusVSM == null)
983+
return null;
984+
Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
985+
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
986+
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
987+
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
988+
return nexusVSMCredentials;
989+
}
965990
}

server/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java

Lines changed: 123 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
// limitations under the License.
1111
//
1212
// Automatically generated by addcopyright.py at 04/03/2012
13-
package com.cloud.hypervisor.vmware;
13+
14+
package com.cloud.hypervisor.vmware;
1415

1516
import java.net.URI;
1617
import java.net.URLDecoder;
@@ -35,22 +36,22 @@
3536
import com.cloud.exception.DiscoveryException;
3637
import com.cloud.host.HostVO;
3738
import com.cloud.host.dao.HostDao;
38-
import com.cloud.hypervisor.Hypervisor;
39-
import com.cloud.hypervisor.Hypervisor.HypervisorType;
40-
import com.cloud.hypervisor.vmware.manager.VmwareManager;
41-
import com.cloud.hypervisor.vmware.mo.ClusterMO;
42-
import com.cloud.hypervisor.vmware.mo.HostMO;
43-
import com.cloud.hypervisor.vmware.resource.VmwareContextFactory;
44-
import com.cloud.hypervisor.vmware.resource.VmwareResource;
45-
import com.cloud.hypervisor.vmware.util.VmwareContext;
39+
import com.cloud.hypervisor.Hypervisor;
40+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
41+
import com.cloud.hypervisor.vmware.manager.VmwareManager;
42+
import com.cloud.hypervisor.vmware.mo.ClusterMO;
43+
import com.cloud.hypervisor.vmware.mo.HostMO;
44+
import com.cloud.hypervisor.vmware.resource.VmwareContextFactory;
45+
import com.cloud.hypervisor.vmware.resource.VmwareResource;
46+
import com.cloud.hypervisor.vmware.util.VmwareContext;
47+
import com.cloud.network.NetworkManager;
4648
import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
47-
import com.cloud.resource.Discoverer;
49+
import com.cloud.resource.Discoverer;
4850
import com.cloud.resource.DiscovererBase;
4951
import com.cloud.resource.ResourceManager;
5052
import com.cloud.resource.ResourceStateAdapter;
5153
import com.cloud.resource.ServerResource;
5254
import com.cloud.resource.UnableDeleteHostException;
53-
import com.cloud.resource.ResourceStateAdapter.DeleteHostAnswer;
5455
import com.cloud.storage.Storage.ImageFormat;
5556
import com.cloud.storage.Storage.TemplateType;
5657
import com.cloud.storage.VMTemplateVO;
@@ -61,20 +62,22 @@
6162
import com.cloud.utils.component.Inject;
6263
import com.vmware.vim25.ClusterDasConfigInfo;
6364
import com.vmware.vim25.ManagedObjectReference;
64-
65-
@Local(value=Discoverer.class)
66-
public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter {
67-
private static final Logger s_logger = Logger.getLogger(VmwareServerDiscoverer.class);
68-
69-
@Inject ClusterDao _clusterDao;
70-
@Inject VmwareManager _vmwareMgr;
71-
@Inject AlertManager _alertMgr;
65+
66+
@Local(value=Discoverer.class)
67+
public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter {
68+
private static final Logger s_logger = Logger.getLogger(VmwareServerDiscoverer.class);
69+
70+
@Inject ClusterDao _clusterDao;
71+
@Inject VmwareManager _vmwareMgr;
72+
@Inject AlertManager _alertMgr;
7273
@Inject VMTemplateDao _tmpltDao;
7374
@Inject ClusterDetailsDao _clusterDetailsDao;
7475
@Inject HostDao _hostDao;
7576
@Inject ResourceManager _resourceMgr;
7677

7778
@Inject CiscoNexusVSMDeviceDao _nexusDao;
79+
@Inject
80+
NetworkManager _netmgr;
7881

7982
@Override
8083
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url,
@@ -102,80 +105,110 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
102105
s_logger.error(msg);
103106
throw new DiscoveredWithErrorException(msg);
104107
}
105-
106-
VmwareContext context = null;
107-
try {
108+
109+
String privateTrafficLabel = null;
110+
Map<String, String> vsmCredentials = null;
111+
if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
112+
// Get physical network label
113+
privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware);
114+
if (privateTrafficLabel != null) {
115+
s_logger.info("Detected private network label : " + privateTrafficLabel);
116+
}
117+
// Get credentials
118+
vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
119+
}
120+
121+
VmwareContext context = null;
122+
try {
108123
context = VmwareContextFactory.create(url.getHost(), username, password);
109-
List<ManagedObjectReference> morHosts = _vmwareMgr.addHostToPodCluster(context, dcId, podId, clusterId,
124+
if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
125+
// Get physical network label
126+
privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware);
127+
if (privateTrafficLabel != null) {
128+
context.registerStockObject("privateTrafficLabel", privateTrafficLabel);
129+
s_logger.info("Detected private network label : " + privateTrafficLabel);
130+
}
131+
// Get credentials
132+
vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
133+
if (vsmCredentials != null)
134+
context.registerStockObject("vsmCredentials", vsmCredentials);
135+
}
136+
List<ManagedObjectReference> morHosts = _vmwareMgr.addHostToPodCluster(context, dcId, podId, clusterId,
110137
URLDecoder.decode(url.getPath()));
111-
if(morHosts == null) {
112-
s_logger.error("Unable to find host or cluster based on url: " + URLDecoder.decode(url.getPath()));
113-
return null;
114-
}
115-
116-
ManagedObjectReference morCluster = null;
117-
Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
118-
if(clusterDetails.get("url") != null) {
119-
URI uriFromCluster = new URI(UriUtils.encodeURIComponent(clusterDetails.get("url")));
120-
morCluster = context.getHostMorByPath(URLDecoder.decode(uriFromCluster.getPath()));
121-
122-
if(morCluster == null || !morCluster.getType().equalsIgnoreCase("ClusterComputeResource")) {
123-
s_logger.warn("Cluster url does not point to a valid vSphere cluster, url: " + clusterDetails.get("url"));
124-
return null;
125-
} else {
126-
ClusterMO clusterMo = new ClusterMO(context, morCluster);
127-
ClusterDasConfigInfo dasConfig = clusterMo.getDasConfig();
128-
if(dasConfig != null && dasConfig.getEnabled() != null && dasConfig.getEnabled().booleanValue()) {
129-
clusterDetails.put("NativeHA", "true");
130-
_clusterDetailsDao.persist(clusterId, clusterDetails);
131-
}
132-
}
133-
}
134-
135-
if(!validateDiscoveredHosts(context, morCluster, morHosts)) {
136-
if(morCluster == null)
137-
s_logger.warn("The discovered host is not standalone host, can not be added to a standalone cluster");
138-
else
139-
s_logger.warn("The discovered host does not belong to the cluster");
140-
return null;
141-
}
142-
143-
Map<VmwareResource, Map<String, String>> resources = new HashMap<VmwareResource, Map<String, String>>();
144-
for(ManagedObjectReference morHost : morHosts) {
145-
Map<String, String> details = new HashMap<String, String>();
146-
Map<String, Object> params = new HashMap<String, Object>();
147-
148-
HostMO hostMo = new HostMO(context, morHost);
149-
details.put("url", hostMo.getHostName());
150-
details.put("username", username);
151-
details.put("password", password);
152-
String guid = morHost.getType() + ":" + morHost.get_value() + "@"+ url.getHost();
153-
details.put("guid", guid);
154-
155-
params.put("url", hostMo.getHostName());
156-
params.put("username", username);
157-
params.put("password", password);
158-
params.put("zone", Long.toString(dcId));
159-
params.put("pod", Long.toString(podId));
160-
params.put("cluster", Long.toString(clusterId));
138+
if (privateTrafficLabel != null)
139+
context.uregisterStockObject("privateTrafficLabel");
140+
141+
if(morHosts == null) {
142+
s_logger.error("Unable to find host or cluster based on url: " + URLDecoder.decode(url.getPath()));
143+
return null;
144+
}
145+
146+
ManagedObjectReference morCluster = null;
147+
Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
148+
if(clusterDetails.get("url") != null) {
149+
URI uriFromCluster = new URI(UriUtils.encodeURIComponent(clusterDetails.get("url")));
150+
morCluster = context.getHostMorByPath(URLDecoder.decode(uriFromCluster.getPath()));
151+
152+
if(morCluster == null || !morCluster.getType().equalsIgnoreCase("ClusterComputeResource")) {
153+
s_logger.warn("Cluster url does not point to a valid vSphere cluster, url: " + clusterDetails.get("url"));
154+
return null;
155+
} else {
156+
ClusterMO clusterMo = new ClusterMO(context, morCluster);
157+
ClusterDasConfigInfo dasConfig = clusterMo.getDasConfig();
158+
if(dasConfig != null && dasConfig.getEnabled() != null && dasConfig.getEnabled().booleanValue()) {
159+
clusterDetails.put("NativeHA", "true");
160+
_clusterDetailsDao.persist(clusterId, clusterDetails);
161+
}
162+
}
163+
}
164+
165+
if(!validateDiscoveredHosts(context, morCluster, morHosts)) {
166+
if(morCluster == null)
167+
s_logger.warn("The discovered host is not standalone host, can not be added to a standalone cluster");
168+
else
169+
s_logger.warn("The discovered host does not belong to the cluster");
170+
return null;
171+
}
172+
173+
Map<VmwareResource, Map<String, String>> resources = new HashMap<VmwareResource, Map<String, String>>();
174+
for(ManagedObjectReference morHost : morHosts) {
175+
Map<String, String> details = new HashMap<String, String>();
176+
Map<String, Object> params = new HashMap<String, Object>();
177+
178+
HostMO hostMo = new HostMO(context, morHost);
179+
details.put("url", hostMo.getHostName());
180+
details.put("username", username);
181+
details.put("password", password);
182+
String guid = morHost.getType() + ":" + morHost.get_value() + "@"+ url.getHost();
183+
details.put("guid", guid);
184+
185+
params.put("url", hostMo.getHostName());
186+
params.put("username", username);
187+
params.put("password", password);
188+
params.put("zone", Long.toString(dcId));
189+
params.put("pod", Long.toString(podId));
190+
params.put("cluster", Long.toString(clusterId));
161191
params.put("guid", guid);
162-
163-
VmwareResource resource = new VmwareResource();
164-
try {
165-
resource.configure("VMware", params);
166-
} catch (ConfigurationException e) {
167-
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + url.getHost(), "Error is " + e.getMessage());
168-
s_logger.warn("Unable to instantiate " + url.getHost(), e);
169-
}
170-
resource.start();
171-
172-
resources.put(resource, details);
173-
}
174-
175-
// place a place holder guid derived from cluster ID
176-
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString());
177-
_clusterDao.update(clusterId, cluster);
178-
192+
if (privateTrafficLabel != null) {
193+
params.put("private.network.vswitch.name", privateTrafficLabel);
194+
}
195+
196+
VmwareResource resource = new VmwareResource();
197+
try {
198+
resource.configure("VMware", params);
199+
} catch (ConfigurationException e) {
200+
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + url.getHost(), "Error is " + e.getMessage());
201+
s_logger.warn("Unable to instantiate " + url.getHost(), e);
202+
}
203+
resource.start();
204+
205+
resources.put(resource, details);
206+
}
207+
208+
// place a place holder guid derived from cluster ID
209+
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString());
210+
_clusterDao.update(clusterId, cluster);
211+
179212
return resources;
180213
} catch (DiscoveredWithErrorException e) {
181214
throw e;

0 commit comments

Comments
 (0)