10
10
// limitations under the License.
11
11
//
12
12
// Automatically generated by addcopyright.py at 04/03/2012
13
-
14
13
package com .cloud .hypervisor .vmware ;
15
-
14
+
16
15
import java .net .URI ;
17
16
import java .net .URLDecoder ;
18
17
import java .util .HashMap ;
@@ -73,14 +72,12 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer
73
72
@ Inject ClusterDao _clusterDao ;
74
73
@ Inject VmwareManager _vmwareMgr ;
75
74
@ Inject AlertManager _alertMgr ;
76
- @ Inject VMTemplateDao _tmpltDao ;
75
+ @ Inject VMTemplateDao _tmpltDao ;
77
76
@ Inject ClusterDetailsDao _clusterDetailsDao ;
78
77
@ Inject HostDao _hostDao ;
79
78
@ Inject
80
79
DataCenterDao _dcDao ;
81
-
82
80
@ Inject ResourceManager _resourceMgr ;
83
-
84
81
@ Inject CiscoNexusVSMDeviceDao _nexusDao ;
85
82
@ Inject
86
83
NetworkManager _netmgr ;
@@ -102,7 +99,7 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
102
99
if (cluster == null || cluster .getHypervisorType () != HypervisorType .VMware ) {
103
100
if (s_logger .isInfoEnabled ())
104
101
s_logger .info ("invalid cluster id or cluster is not for VMware hypervisors" );
105
- return null ;
102
+ return null ;
106
103
}
107
104
108
105
List <HostVO > hosts = _resourceMgr .listAllHostsInCluster (clusterId );
@@ -116,15 +113,13 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
116
113
String publicTrafficLabel = null ;
117
114
String guestTrafficLabel = null ;
118
115
Map <String , String > vsmCredentials = null ;
116
+
117
+ privateTrafficLabel = _netmgr .getDefaultManagementTrafficLabel (dcId , HypervisorType .VMware );
118
+ if (privateTrafficLabel != null ) {
119
+ s_logger .info ("Detected private network label : " + privateTrafficLabel );
120
+ }
121
+
119
122
if (_vmwareMgr .getNexusVSwitchGlobalParameter ()) {
120
- if (_vmwareMgr .getPrivateVSwitchTypeGlobalParameter () != null && _vmwareMgr .getPrivateVSwitchTypeGlobalParameter ().equalsIgnoreCase ("nexus" )) {
121
- // Get physical network label
122
- privateTrafficLabel = _netmgr .getDefaultManagementTrafficLabel (dcId , HypervisorType .VMware );
123
- if (privateTrafficLabel != null ) {
124
- s_logger .info ("Detected private network label : " + privateTrafficLabel );
125
- }
126
- }
127
-
128
123
DataCenterVO zone = _dcDao .findById (dcId );
129
124
NetworkType zoneType = zone .getNetworkType ();
130
125
if (zoneType != NetworkType .Basic ) {
@@ -144,11 +139,10 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
144
139
VmwareContext context = null ;
145
140
try {
146
141
context = VmwareContextFactory .create (url .getHost (), username , password );
142
+ if (privateTrafficLabel != null )
143
+ context .registerStockObject ("privateTrafficLabel" , privateTrafficLabel );
144
+
147
145
if (_vmwareMgr .getNexusVSwitchGlobalParameter ()) {
148
- if (_vmwareMgr .getPrivateVSwitchTypeGlobalParameter ().equalsIgnoreCase ("nexus" )) {
149
- if (privateTrafficLabel != null )
150
- context .registerStockObject ("privateTrafficLabel" , privateTrafficLabel );
151
- }
152
146
if (vsmCredentials != null ) {
153
147
s_logger .info ("Stocking credentials of Nexus VSM" );
154
148
context .registerStockObject ("vsmcredentials" , vsmCredentials );
@@ -238,95 +232,95 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
238
232
cluster .setGuid (UUID .nameUUIDFromBytes (String .valueOf (clusterId ).getBytes ()).toString ());
239
233
_clusterDao .update (clusterId , cluster );
240
234
241
- return resources ;
235
+ return resources ;
242
236
} catch (DiscoveredWithErrorException e ) {
243
237
throw e ;
244
- } catch (Exception e ) {
245
- s_logger .warn ("Unable to connect to Vmware vSphere server. service address: " + url .getHost ());
246
- return null ;
247
- } finally {
248
- if (context != null )
249
- context .close ();
250
- }
251
- }
252
-
253
- private boolean validateDiscoveredHosts (VmwareContext context , ManagedObjectReference morCluster , List <ManagedObjectReference > morHosts ) throws Exception {
254
- if (morCluster == null ) {
255
- for (ManagedObjectReference morHost : morHosts ) {
256
- ManagedObjectReference morParent = (ManagedObjectReference )context .getServiceUtil ().getDynamicProperty (morHost , "parent" );
257
- if (morParent .getType ().equalsIgnoreCase ("ClusterComputeResource" ))
258
- return false ;
259
- }
260
- } else {
261
- for (ManagedObjectReference morHost : morHosts ) {
262
- ManagedObjectReference morParent = (ManagedObjectReference )context .getServiceUtil ().getDynamicProperty (morHost , "parent" );
263
- if (!morParent .getType ().equalsIgnoreCase ("ClusterComputeResource" ))
264
- return false ;
265
-
266
- if (!morParent .get_value ().equals (morCluster .get_value ()))
267
- return false ;
268
- }
269
- }
270
-
271
- return true ;
272
- }
273
-
274
- @ Override
275
- public void postDiscovery (List <HostVO > hosts , long msId ) {
276
- // do nothing
277
- }
278
-
279
- @ Override
280
- public boolean matchHypervisor (String hypervisor ) {
281
- if (hypervisor == null )
282
- return true ;
283
-
284
- return Hypervisor .HypervisorType .VMware .toString ().equalsIgnoreCase (hypervisor );
285
- }
286
-
287
- @ Override
288
- public Hypervisor .HypervisorType getHypervisorType () {
289
- return Hypervisor .HypervisorType .VMware ;
290
- }
291
-
292
- @ Override
293
- public boolean configure (String name , Map <String , Object > params ) throws ConfigurationException {
294
- if (s_logger .isInfoEnabled ())
295
- s_logger .info ("Configure VmwareServerDiscoverer, discover name: " + name );
296
-
297
- super .configure (name , params );
298
-
299
- ComponentLocator locator = ComponentLocator .getCurrentLocator ();
300
- ConfigurationDao configDao = locator .getDao (ConfigurationDao .class );
301
- if (configDao == null ) {
302
- throw new ConfigurationException ("Unable to get the configuration dao." );
303
- }
304
-
305
- createVmwareToolsIso ();
306
-
307
- if (s_logger .isInfoEnabled ()) {
238
+ } catch (Exception e ) {
239
+ s_logger .warn ("Unable to connect to Vmware vSphere server. service address: " + url .getHost ());
240
+ return null ;
241
+ } finally {
242
+ if (context != null )
243
+ context .close ();
244
+ }
245
+ }
246
+
247
+ private boolean validateDiscoveredHosts (VmwareContext context , ManagedObjectReference morCluster , List <ManagedObjectReference > morHosts ) throws Exception {
248
+ if (morCluster == null ) {
249
+ for (ManagedObjectReference morHost : morHosts ) {
250
+ ManagedObjectReference morParent = (ManagedObjectReference )context .getServiceUtil ().getDynamicProperty (morHost , "parent" );
251
+ if (morParent .getType ().equalsIgnoreCase ("ClusterComputeResource" ))
252
+ return false ;
253
+ }
254
+ } else {
255
+ for (ManagedObjectReference morHost : morHosts ) {
256
+ ManagedObjectReference morParent = (ManagedObjectReference )context .getServiceUtil ().getDynamicProperty (morHost , "parent" );
257
+ if (!morParent .getType ().equalsIgnoreCase ("ClusterComputeResource" ))
258
+ return false ;
259
+
260
+ if (!morParent .get_value ().equals (morCluster .get_value ()))
261
+ return false ;
262
+ }
263
+ }
264
+
265
+ return true ;
266
+ }
267
+
268
+ @ Override
269
+ public void postDiscovery (List <HostVO > hosts , long msId ) {
270
+ // do nothing
271
+ }
272
+
273
+ @ Override
274
+ public boolean matchHypervisor (String hypervisor ) {
275
+ if (hypervisor == null )
276
+ return true ;
277
+
278
+ return Hypervisor .HypervisorType .VMware .toString ().equalsIgnoreCase (hypervisor );
279
+ }
280
+
281
+ @ Override
282
+ public Hypervisor .HypervisorType getHypervisorType () {
283
+ return Hypervisor .HypervisorType .VMware ;
284
+ }
285
+
286
+ @ Override
287
+ public boolean configure (String name , Map <String , Object > params ) throws ConfigurationException {
288
+ if (s_logger .isInfoEnabled ())
289
+ s_logger .info ("Configure VmwareServerDiscoverer, discover name: " + name );
290
+
291
+ super .configure (name , params );
292
+
293
+ ComponentLocator locator = ComponentLocator .getCurrentLocator ();
294
+ ConfigurationDao configDao = locator .getDao (ConfigurationDao .class );
295
+ if (configDao == null ) {
296
+ throw new ConfigurationException ("Unable to get the configuration dao." );
297
+ }
298
+
299
+ createVmwareToolsIso ();
300
+
301
+ if (s_logger .isInfoEnabled ()) {
308
302
s_logger .info ("VmwareServerDiscoverer has been successfully configured" );
309
303
}
310
- _resourceMgr .registerResourceStateAdapter (this .getClass ().getSimpleName (), this );
311
- return true ;
312
- }
313
-
314
- private void createVmwareToolsIso () {
315
- String isoName = "vmware-tools.iso" ;
316
- VMTemplateVO tmplt = _tmpltDao .findByTemplateName (isoName );
317
- Long id ;
318
- if (tmplt == null ) {
319
- id = _tmpltDao .getNextInSequence (Long .class , "id" );
320
- VMTemplateVO template = new VMTemplateVO (id , isoName , isoName , ImageFormat .ISO , true , true ,
321
- TemplateType .PERHOST , null , null , true , 64 ,
322
- Account .ACCOUNT_ID_SYSTEM , null , "VMware Tools Installer ISO" , false , 1 , false , HypervisorType .VMware );
323
- _tmpltDao .persist (template );
324
- } else {
325
- id = tmplt .getId ();
326
- tmplt .setTemplateType (TemplateType .PERHOST );
327
- tmplt .setUrl (null );
328
- _tmpltDao .update (id , tmplt );
329
- }
304
+ _resourceMgr .registerResourceStateAdapter (this .getClass ().getSimpleName (), this );
305
+ return true ;
306
+ }
307
+
308
+ private void createVmwareToolsIso () {
309
+ String isoName = "vmware-tools.iso" ;
310
+ VMTemplateVO tmplt = _tmpltDao .findByTemplateName (isoName );
311
+ Long id ;
312
+ if (tmplt == null ) {
313
+ id = _tmpltDao .getNextInSequence (Long .class , "id" );
314
+ VMTemplateVO template = new VMTemplateVO (id , isoName , isoName , ImageFormat .ISO , true , true ,
315
+ TemplateType .PERHOST , null , null , true , 64 ,
316
+ Account .ACCOUNT_ID_SYSTEM , null , "VMware Tools Installer ISO" , false , 1 , false , HypervisorType .VMware );
317
+ _tmpltDao .persist (template );
318
+ } else {
319
+ id = tmplt .getId ();
320
+ tmplt .setTemplateType (TemplateType .PERHOST );
321
+ tmplt .setUrl (null );
322
+ _tmpltDao .update (id , tmplt );
323
+ }
330
324
}
331
325
332
326
@ Override
@@ -365,6 +359,6 @@ public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForc
365
359
public boolean stop () {
366
360
_resourceMgr .unregisterResourceStateAdapter (this .getClass ().getSimpleName ());
367
361
return super .stop ();
368
- }
369
- }
370
-
362
+ }
363
+ }
364
+
0 commit comments