VMware {code} Community
abhishekdubey
Enthusiast
Enthusiast

Extending a vSphere Object List View for chassisRackVSphere

I am trying to add a new column to existing VM list view by referring below code snippet from

https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wcsdk.pg.doc%2FListExtensions_Chapt...

Below is the sample code given in chassisRackVSphere-ui  sample for the same.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<!-- Example of a VM list extension (not related to chassis and racks)

   Using the extension point vsphere.core.vm.list.columns we add a 'hostname'

   column to VM Objects tab.

    -->

   <extension id="com.vmware.samples.vm.columns">

      <extendedPoint>vsphere.core.vm.list.columns</extendedPoint>

      <object>

         <!-- XML representation of com.vmware.ui.lists.ColumnSetContainer -->

         <items>

            <com.vmware.ui.lists.ColumnContainer>

               <uid>com.vmware.samples.vm.column.hostname</uid>

               <dataInfo>

                  <com.vmware.ui.lists.ColumnDataSourceInfo>

                      <headerText>#{vmList.hostNameColumn}</headerText>

                      <!-- Object property whose text value will be displayed (array of 1 elt) -->

                      <requestedProperties>

                        <String>hostName</String>

                     </requestedProperties>

                     <sortProperty>hostName</sortProperty>

                     <exportProperty>hostName</exportProperty>

                  </com.vmware.ui.lists.ColumnDataSourceInfo>

               </dataInfo>

            </com.vmware.ui.lists.ColumnContainer>

         </items>

       </object>

   </extension>

--------------------------------------------------------------------------------------------------------------------------

MY Query :-

I am trying to add a column to existing VM list view to display related Chassis Name (Custom) Object.

However when i tried to do that using <String>chassisName</String> i  am not getting proper query at java layer .

Can you please suggest a code snippet for plugin.xml which defines this querySpec.

As i want to display property/value in VMList view from my Chassis plugin.

Thanks,

Abhishek

Tags (2)
0 Kudos
7 Replies
laurentsd
VMware Employee
VMware Employee

The code snippet is the same where you replace hostName by chassisName.

The reason you are not seeing the query for chassisName is because chassisName is not an intrinsic property of the VM object, the way hostName is. You need to set up a data provider for the type VirtualMachine which will handle queries for chassisName (and will ignore any other type of queries) 

0 Kudos
abhishekdubey
Enthusiast
Enthusiast

I tried with the data adapter however when request comes to my adapter(getData method) it is not having the VM object reference in the querySpec .

?

How can i get the VM object reference in the query which i received in a requestSpec for VM list view 

0 Kudos
abhishekdubey
Enthusiast
Enthusiast

ExtendList_MutipleRows issue.png

Hi lauretsd,

Some how i am able to get the query for this usecase in my dataAdapter and i have parsed processPropertyConstraint for the query and returned the ResultItem for custom property.

I am able to successfully returned the result  as displayed in attached screenshot.

Interestingly i can see a duplicate row for that VM object which must be displaying by vmware webclient framework for the same property as blank.

Can you please let me know how can avoid this duplicate row issue and able to override my data on the single row for my custom column.

?????@

0 Kudos
abhishekdubey
Enthusiast
Enthusiast

laurentsd

Please suggest is this will be the behavior for this usecase ..?

0 Kudos
laurentsd
VMware Employee
VMware Employee

I think you are seeing a duplicate row because your Data Adapter for the VirtualMachine type is doing more than handling the PropertyConstraint for your custom property.

Please share your code so I can have a look.

0 Kudos
abhishekdubey
Enthusiast
Enthusiast

My Data Adapter Follows Code is as follows

1)  configured my adapter to handle Queries for type VirtualMachine

2) Validate the query for  my plugins property only before proceeding in processProertyConstrain(..

3) Then Write a querySpect to get VM list as Managed Object references

4) iterate with each VM

4) Add additional property pair in and append VM in iteration to result set with new properties and resourceObject reference of that VM

          pv.propertyName = "VM_MYPLUGIN_DATA";

          pv.value = "VM_MYPLUGIN_DATA";

5) Return ResultSet

Please have a look at below code and please let me know if i am doing any mistake here or is there any other way to return a new custom column value for VM list view.

---------------------------------------------------------------------

private List<ResultItem> processPropertyConstraint(PropertyConstraint pc,

          PropertySpec[] propertySpecs) {

       assert (pc.comparator == Comparator.TEXTUALLY_MATCHES);

       String comparableValue = pc.comparableValue.toString().toLowerCase();

       List<ResultItem> items = new ArrayList<ResultItem>();

       Boolean myPlugin_Query = validateVMWareViewQueries(propertySpecs);

       if(pc.targetType.equals(Constants.VMWARE_VIRTUALMACHINE) && myPlugin_Query){

      

       items=getVirtualMachinesFromVCAndAppendMyCustomPropertyinResultSet(propertySpecs);

       return items;

       }

  }

  //Method to validate whether it is valid query for custom column property for my plugin

  private Boolean validateVMWareViewQueries(PropertySpec[] propertySpecs) {

  Boolean myPlugin_Query=false;

       if(propertySpecs.length>0){

       List<String> propNameinPropSpec=Arrays.asList(propertySpecs[0].propertyNames);

       if(!propNameinPropSpec.isEmpty() && propNameinPropSpec.contains("VM_MYPLUGIN_DATA")){

      

       myPlugin_Query=true;

      

       }

       else{

       myPlugin_Query=false;

       }

       }

  return myPlugin_Query;

  }

  

  //Method to retun list of Virtual machine as ResultItem with additional property-value pair

  private List<ResultItem> getVirtualMachinesFromVCAndAppendMyCustomPropertyinResultSet(PropertySpec[] propertySpecs) {

       // create QuerySpec

   List<ResultItem> reultItem = new ArrayList<ResultItem>();

       QuerySpec qs = new QuerySpec();

       qs.resourceSpec = new ResourceSpec();

       qs.resourceSpec.constraint = new Constraint();

       // HostSystem is the targetType

       qs.resourceSpec.constraint.targetType = "VirtualMachine";

       // request the name property

       PropertySpec pSpec = new PropertySpec();

       pSpec.propertyNames = new String[]{"name"};

       qs.resourceSpec.propertySpecs = propertySpecs;

       qs.resultSpec = new ResultSpec();

      // qs.resultSpec.maxResultCount = new Integer(maxResultCount);

       // use default ordering

       qs.resultSpec.order = new OrderingCriteria();

       qs.resultSpec.order.orderingProperties = new OrderingPropertySpec[0];

       // get data from DataService

       RequestSpec requestSpec = new RequestSpec();

       requestSpec.querySpec = new QuerySpec[]{qs};

       //Here Fetching the ALL VM Objects from webclient service

       Response response = _dataService.getData(requestSpec);

       ResultItem[] items = response.resultSet[0].items;

       if (items!= null) {

       for(ResultItem vmObjResultItems:items)

       {

      

      

      //Here we processed each VM and return specific property for each VM(Based on My plugin logic)  add it as

      // pv.propertyName = "VM_MYPLUGIN_DATA";

  //pv.value = "VM_MYPLUGIN_DATA";

      vmObjResultItems.resourceObject = toURI(vmObjResultItems.resourceObject);

      ArrayList<PropertyValue> propValArr = new ArrayList<PropertyValue>(1);

      PropertyValue pv = new PropertyValue();

      pv.resourceObject = (vmObjResultItems.resourceObject);

      pv.propertyName = "VM_MYPLUGIN_DATA";

      pv.value = "VM_MYPLUGIN_DATA";

      propValArr.add(pv);

    

      vmObjResultItems.properties = propValArr.toArray(new PropertyValue[0]);

      reultItem.add(vmObjResultItems);

       }

       }

    

       return reultItem;

    }

---------------------------------------------------------------------------------------------------------------------

Please let me know if i am doing any mistake here or is there any other way to return a new custom column value for VM list view.

0 Kudos
abhishekdubey
Enthusiast
Enthusiast

Any updates will be helpful!!!

0 Kudos