VMware {code} Community
vaibhav87
Enthusiast
Enthusiast

Unable to get serverGuid in vsphere-ui plugin 6.7

I have plugin deployed on vsphere 6.7 on both Flex and HTML version.

Plugin is developed using html-client sdk . Now post-deployment vsphere-client[Flex] web-platform.js gives proper serverGuid but same fails on html client i.e vsphere-ui.

Flex client return proper serverGuid = xxxx xxx xxx xxx

whereas in html client we are getting serverGuid as null.

/ Get the info provided in a global view using a vCenter selector

      WEB_PLATFORM.getVcSelectorInfo = function() {

         var info = {serviceGuid: getURLParameter("serviceGuid"),

                     sessionId: getURLParameter("sessionId"),

                     serviceUrl: getURLParameter("serviceUrl")};

         return info;

      };

Thanks

Tags (2)
Reply
0 Kudos
8 Replies
Denis_Chorbadzh
VMware Employee
VMware Employee

Hi,

The vCenter selector has been deprecated since 6.5U1.

We have provided an example in the globalview sample in 6.5U1 SDK, where you can use WEB_PLATFORM.getUserSession() to retrieve the server infos. You can then get the serviceGuid.

Have in mind that the getUserSession() API (part of the old bridge APIs) is also deprecated and the recommended approach is to get the user session in your java code and pass it to the UI.

Best Regards,

Denis

Reply
0 Kudos
vaibhav87
Enthusiast
Enthusiast

Hi Denis thanks for the response.

  WEB-PLATFROM.getUserSession() will return all the available sever info but not the selected one and as we have used serverSelector using extension we need   

   selected server details.   

    While debugging we found that location.href injected by vmware parent on page in FLEX + 6.5 HTML and vSphere 6.7 html is different

    In Flex client all version + HTML 6.5 client it provides all the details in location.href where as in 6.7 html these details are missing.

    Attaching screenshot for the same.

    1. Do we need to modify anyting to make it compatible with vSphere 6.7 HTML Client ?

    2. Are there any other options available to fetch selected serverInfo using JAVA or JAVASCRIPT API ?

 

Thanks

Reply
0 Kudos
Denis_Chorbadzh
VMware Employee
VMware Employee

Hi,

 

The serviceGuid and other parameters are removed from the URL because of security issues.

Currently, you have two options to get the serverGuid:

1. Using the deprecated WEB_PLATFORM.getUserSession() -> please look at the "globalview sample" from 6.5U1 SDK

2. Using getUserSession() JAVA API in your backend code -> look at the service part of "html sample" from 6.7 SDK 

 

Regards,

Denis

Reply
0 Kudos
sagarsavairam
Contributor
Contributor

Hi Denis, Thanks for the response,

we are using WEB-PLATFROM.getUserSession() in 6.7 SDK, It returns all the available sever info where we find the parameters like (serviceGuid,sessionId,serviceUrl,locale) but we are unable to get(objectId, actionUid, targets)which are not in userSession.

As you specify in previous comment, we saw at the "globalview sample" from 6.5U1 SDK but unabe to understand how to get(objectId, actionUid, targets) these parameters.

Is there any way to get(objectId, actionUid, targets) these parameters specifically with 6.7 SDK?

Please see the code snipplet in web-platform.js for reference. where we are able to get (serviceGuid,sessionId,serviceUrl,locale) with WEB-PLATFROM.getUserSession() but unable to proceed for (objectId, actionUid, targets)

// Get a parameter value from the current document URL

function getURLParameter(name) {
return (new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [,""])[1].replace(/\+/g, '%20') || null;
}

// Get the current context object id or return null if none is defined
WEB_PLATFORM.getObjectId = function() {
return getURLParameter("objectId");
};

// Get the current action Uid or return null if none is defined
WEB_PLATFORM.getActionUid = function() {
return getURLParameter("actionUid");
};

// Get the comma-separated list of object ids for an action, or null for a global action
WEB_PLATFORM.getActionTargets = function() {
return getURLParameter("targets");
};

// Get the current locale
WEB_PLATFORM.getLocale = function() {
return WEB_PLATFORM.getUserSession().locale;
};

// Get the info provided in a global view using a vCenter selector

WEB_PLATFORM.getVcSelectorInfo = function() {
var server = WEB_PLATFORM.getUserSession().serversInfo;
var info = { serviceGuid: server[0].serviceGuid;,
              sessionId: server[0].serviceGuid;,
              serviceUrl: server[0].serviceGuid;};
return info;
};

Reply
0 Kudos
Denis_Chorbadzh
VMware Employee
VMware Employee

Hi,

 

 

 

Yes, you can use the new JS APIs to get the objectId and targets.

 

The API is called getContextObjects() and it returns a list of objects related to the current context. If you are in an action dialog, the API will return the action targets. If you are in a monitor view (for example), the API will return the context object.

 

 

 

Regards,

 

Denis

Reply
0 Kudos
kumargandhi16
Contributor
Contributor

Hi @Denis_Chorbadzh 

I checked the Java code for getUserSession()...In general what it does is read the values defined in the Configuration class, like, there are few constants defined in the class, and Java backend just sets and gets these values?, looks like they are hardcoded or reading from env fields? (Not entirely sure, I am not a Java dev)

But, the getUserSession() API from the Html bridge JavaScript actually gives the serversInfo and linkedServersInfo dynamically. PFB screenshot.

WEB_PLATFORM_getUserSession.png

It's sad that htmlClientSdk (JavaScript APIs) doesn't have such API!!.

We have a linked vCenters setup and we are having trouble fetching the right api-endpoint that we need to set in the headers for our API calls.

PFB screenshot of out current setup. We have two plugin instances, each with its own vCenter.

Linked_vCenters_New.png

Now the problem is getting the right api-endpoint for the selected plugin instance.

PFB code for the three headers we set in the remote-vcp UI code.

 

// Below are the headers we set for UI API calls.
getHttpClientHeaders(): any {
      return {
         "vcenter-guid": this.getGUID(),
         "vmware-api-ui-endpoint-url": this.getUIApiEndpointUrl(),
         "vmware-api-session-id": this.getVMwareAPISessionId()
      };
   }

// Below fetching the API end point, but what about for linked setup!!
getUIApiEndpointUrl() {
   return this.gs.getClientSdk().app.getApiEndpoints().uiApiEndpoint.fullUrl;
}

 

Can you please provide some feedback? Thanks.

Reply
0 Kudos
stoevm
VMware Employee
VMware Employee

Hi kumargandhi

With the new forwarding feature implemented in the SDK you do not even need the correct API endpoint in the UI.
All you need is the target VC for which the call is intended.

The clone-ticket can be send to any VC in the linked environment, and it will be forwarded to the VC from which vSphere Client the plugin is used. (this feature works for VCs >= 7.0u2 version)
More information on this can be found in the vsphere client docs: 
https://vdc-download.vmware.com/vmwb-repository/dcr-public/009a36e4-2f17-46fc-ac27-ea9f8bf8c923/9988...
Section: How to Delegate Session Authority to the Plug-in Server

If your plugin is to work after 7.0u2 you can take advantage of this new feature. Otherwise before 7.0u2 the plugin needs to trust all vCenters in the linked environment and use the getApiEndpoint.

The getApiEndpoint is not dependent on the linked environment, basically the guid is the one which determines for which VC the vsphere client will clone the session. This means that the api-endpoint is the same no matter for which VC you need a cloned ticket.

Again it is best to use the new functionality which eliminates the need for the getApiEndpoint API call. 

kumargandhi16
Contributor
Contributor

Hi @stoevm 

Thanks for checking this issue and replying

I will go through shared docs and come back.

**We are giving support for remote-vcp from vCenter version 8.

Reply
0 Kudos