VMware {code} Community
elviran
Contributor
Contributor

Retrieve relevant server data in linked vc mode

Hi,

We are developing a plugin for the vsphere web client, and until now, in order to retrieve data from the vc we are connected to we used UserSessionManager.instance.userSession.serversInfo[0].

But now whenever we use a linked vc configuration serversInfo contains the list of all linked VCs and we cannot determine which one is the vc on which the web client is invoked.

Is there a way the plugin can identify which of this servers is the relevant one?

Thanks!

Ella

Reply
0 Kudos
5 Replies
laurentsd
VMware Employee
VMware Employee

hi Ella,

The fact that userSession.serversInfo contains the list of all connected VCs is not new, whether they are linked or not.  In order to find the relevant server in your plugin code you need to find a way pass the serverGuid and then use a simple utility like this one to iterate over the serversInfo array:

   private ServerInfo getServerInfoObject(String serverGuid) {

      UserSession userSession = _userSessionService.getUserSession();

      for (ServerInfo sinfo : userSession.serversInfo) {

         if (sinfo.serviceGuid.equalsIgnoreCase(serverGuid)) {

            return sinfo;

         }

      }

      return null;

   }

You can get the relevant serverGuid in different ways:

1) If your java code is handling a vSphere object reference passed by the client (in a property or data adapter for instance) you extract serverGuid from that reference using the vimObjectRerenceService as shown in this SDK sample: samples/vsphereviews/vsphere-wssdk-provider/src/main/java/com/vmware/samples/wssdkprovider/VmDataProviderImpl.java

String serverGuid = _vimObjectReferenceService.getServerGuid(vmRef);

2) If your code is handling a java service call from the UI it is up to the UI code to pass the correct object reference to the Java service or pass directly the serverGuid value.  For instance, if you have a UI containing a vCenter selector to let the user decide which vCenter is relevant you get serverGuid from that selector.


3) If you are dealing with custom objects you need to find a way to map those objects to the relevant vCenter assuming that it makes sense in your plugin.

Reply
0 Kudos
elviran
Contributor
Contributor

Thanks for your quick reply.

Unfortunately in our case none of these options are helpful for us. 

Our plugin needs this information before any user interaction (like selecting a vm reference or a vc from a list). Our plugin contains a global view extension, and as soon as the user navigates to this view the plugin needs to figure out which vc it is running on and get some required information from it.

We thought about getting the url from the browser but we are hoping there's a more elegant way.

Is there any way for the plugin to do so?

Reply
0 Kudos
laurentsd
VMware Employee
VMware Employee

> Our plugin contains a global view extension, as soon as the user navigates to this view the plugin needs to figure out which vc it is running on and get some required information from it.

By definition a global view is not attached to any particular context object, so it is not related to any particular VC.  I don't know what your view contains but this must be applicable to all connected VCs, otherwise it is not global. And in that case you need to let the user select which VC is relevant, or have something in your code which does the same thing.

Reply
0 Kudos
kakumanuh
Contributor
Contributor

did u get any solution for this problem to do it from the plugin itself?

Reply
0 Kudos
_vladi_
VMware Employee
VMware Employee

The only way you could potentially do this within a plugin is checking the host of the Web Client instance against the host of each serverInfo. Unfortunately, the Web Client SDK does not provide capabilities to fetch such information.

The reason is that global views are designed to have no context and no relation to any vCenter. Even in the case of a single vCenter, the Web Client instance might be running locally on you machine and not on the vCenter itself - this additionally limits what you can do in such a global view (without context or user selection).

Reply
0 Kudos