4 Replies Latest reply on Nov 12, 2012 11:19 AM by coldwater1

    UID to ManagedObjectReference in vsphere web client

    coldwater1 Novice

      Hello ,

       

      I'm currently implementing an Plugin using vsphere web client. I'm currently implementing my own custom service layer , however to give the application the notion of context and initiate a web service call , I need to know which

       

      1. ServiceGuid,

      2. Type of object being deal with

      3. object reference

       

      After some investigation I found that _contextObject (which is of type IResourceReference) has UID in the form of ServiceUID:Type:ObjectReference

      For example: XXXXXXXXXXXXXXXXXXXX:HostSystem:host-9

       

      How can I extract the Service UID , ObjectReference Type and Object Reference  using vmware API with out any custom parsing in my Java Service layer ( so that in case the current schema changes it would effect my application.)?

       

      If I'm using Data Access Manager API such as Property Provider Adapater , I can extract objects passed into GetProperties which are of type PropertyRequestSpec propertyRequest and iterating through PropertyRequestSpec.objects I can use

       

      Clean API  of

      VimObjectReferenceService .getResourceObjectType, getValue ,getServerGuid  which would provide me all the information I need .

       

      The reason of the ability to use VimObjectReferenceService in DAM API is internally UID is being converted into this form:

      ManagedObjectReference: type = HostSystem, value = host-9, serverGuid = XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX

       

      I want to eliminate any custom parsing would be really helpful if VMware provided an API which would convert UID or IResourceReference (object) and extract the relavant information such the above 3 that I provided.

       

      Thanks!

        • 1. Re: UID to ManagedObjectReference in vsphere web client
          laurentsd Master
          VMware Employees

          I don't understand your question... you mention the  VimObjectReferenceService API which is precisely what you need to use to get what your want :-)

          I assume you already looked at the vsphereviews/vsphere-wssdk-provider SDK sample where it is used.

          • 2. Re: UID to ManagedObjectReference in vsphere web client
            coldwater1 Novice

            Glad you mentioned vsphere-wssdk-provider ,Let me elaborate my question drawing analogy from that example.

             

            In the vsphere-wssdk-provider:

            The program flow is as follows

            UI -Layer:

            Frinje Framework loads the setContextObject-> requestData() is issued ->

            RequestData -> creates an instance of PropertyRequest with the current _contextObject(IResourceReference type) and custom data(samples:vmData) .

            After which dispatchEvent is issued....

             

            Code Snippet below

             

            var myhostInfoRequest:PropertyRequest =
            PropertyRequest.newInstance(_contextObject, "websvc:hostinfo");
            dispatchEvent(myhostInfoRequest);
            Service Layer we override the getProperties and extract objects from PropertyRequestSpec

             

            Code Snippet:

            public ResultSet getProperties(PropertyRequestSpec propertyRequest) {.......

            for(Object hostRef:propertyRequest.objects)

            {

               getHostProps(hostRef);

            }

            On hostRef Object I'm able construct a managedObject Reference by doing something like this :

            ManagedObjectReference hostMor = new ManagedObjectReference();

            hostMor.setType(_vimObjectReferenceService.getResourceObjectType(hostRef));

            hostMor.setValue(_vimObjectReferenceService.getValue(hostRef));

            String serverGuid = _vimObjectReferenceService.getServerGuid(hostRef);

             

            When I printed out hostRef structure, this is what I got (_logger.debug("\n In hostRef -  " + hostRef.toString()); )

            ManagedObjectReference: type = HostSystem, value = host-9, serverGuid = 15A5FDE1-F882-434A-B3FC-61B866021812

             

            It seems to me that because the hostRef structure was in the above format I was able to use VimObjectReferenceService API, : _vimObjectReferenceService.getResourceObjectType(hostRef), _vimObjectReferenceService.getValue(hostRef)

             

            Looks like  hostRef Structure is being constructed internally by  PropertyRequestProvider API passed in the UI layer and set down which is compatible to be used by VimObjectReferenceService API .

             

            However If I have my own custom build Service Layer and passdown a UID or forthat matter passdown an instance of IResourceReference type I can't use the VimObjectReferenceService API . I don't want to do any custom parsing or constructing data in a specific format, lest the structure might change in future releases. So Is there any API or mechanism to extract the same information for my custom service layer methods.

             

            _proxy.getSettings(_contextObject.uid ,onGetSettingsResult);

            Currently the UID is of the format 15A5FDE1-F882-434A-B3FC-61B866021812:HostSystem:host-9

             

            Thanks!

            • 3. Re: UID to ManagedObjectReference in vsphere web client
              laurentsd Master
              VMware Employees

              OK, I understand the question now.

               

              > It seems to me that because the hostRef structure was in the above format I was able to use VimObjectReferenceService API, :_vimObjectReferenceService.getResourceObjectType(hostRef), _vimObjectReferenceService.getValue(hostRef)

               

              You can use VimObjectReferenceService precisely for all Vim objects, i.e. ManagedObjectReferences - the internal type of vSphere objects.

               

               

              > However If I have my own custom build Service Layer and passdown a UID or for that matter pass down an instance of IResourceReference type I can't use the VimObjectReferenceService API . I don't want to do any custom parsing or constructing data in a specific format, lest the structure might change in future releases. So Is there any API or mechanism to extract the same information for my custom service layer methods.

               

              Custom objects represented as IResourceReference in the UI can be resolved in the Java layer with a ResouceTypeResolver.

              See how we do it in the chassis-app sample (either chassisRack-service or chassisRackVSphere-service)

              1 person found this helpful
              • 4. Re: UID to ManagedObjectReference in vsphere web client
                coldwater1 Novice

                Great! I'll definetly try out ResouceTypeResolver. Thanks!.