VMware {code} Community
myelaman
Enthusiast
Enthusiast

retrieve datacenter name in vsphere SDK 6.0

we were using 5.5 SDK and retrieving datacenter name .Now,with 6.0 SDK,the dc name code throws null pointer exception.Please suggest

 

 

serverConnection sc = si.getServerConnection();
         
         String dcName = null;
         _logger.info(" Server connection url :  " + sc.getUrl());
         Object dvsObject = MorUtil.createExactManagedEntity(sc, dvsMor);
        
        
        if(dvsObject != null && dvsObject instanceof DistributedVirtualSwitch){
            DistributedVirtualSwitch dvsObj = (DistributedVirtualSwitch)dvsObject;
            
            ManagedEntity me = dvsObj.getParent();
                
            ManagedObjectReference networkMor = me.getMOR();

 

The above line throws null pointer.Please suggest an example to retrieve the dc name from dvs object.

Is there any change in amanged object entity hierarchy and folder hierarchy in 6.0?

Marianne

0 Kudos
3 Replies
stumpr
Virtuoso
Virtuoso

Which part throws a null pointer?

There's nothing that changed (unless there is a bug in the dotNET version of the SDK) that would impact looking at the first level parent.  However, you may have nested folders (not sure if getParent is recursive).  Still, I'd expect parent to be the first parent, regardless of type based on what you shown below.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
myelaman
Enthusiast
Enthusiast

 ManagedObjectReference networkMor = me.getMOR();

 

The above line throws null pointer which was not the case with 5.5 SDK.Please suggest a way to retrieve datacenter name in 6.0 sdk when we have the dvs object

 

Thanks,

Marianne

0 Kudos
myelaman
Enthusiast
Enthusiast

dvsobj.getParent() is null  and it in  turn throws null pointer in the next line.

Please let me know if vijava jar that was working with 5.5 has some problems when run with vsphere 6.0 sdk?

0 Kudos