2 Replies Latest reply on Apr 2, 2015 12:07 AM by mitradebopam

    Retrieve Hardware information about VM in VappTemplate

    red9472 Lurker

      How do you obtain the Virtual Hardware configuration for a VM that is in a VappTemplate, using the java API?

      Here is what I have so far, but cannot find anywhere the information about the number of CPUs, memory etc for a VM in a VappTemplate.

       

      CatalogItem catItem = CatalogItem.getCatalogItemByReference(vcloudClient, catItemRef);

      ReferenceType vappTemplateRef = catItem.getEntityReference();

      VappTemplate vappTemplate = VappTemplate.getVappTemplateByReference(vcloudClient, vappTemplateRef);

      for (VappTemplate child : vappTemplate.getChildren()) { ... }

       

      The 'child' object (illogically, it is a VappTemplateType type) contains most of the information about the VM such as name, and it even contains the NetworkConfig section etc, Now am I simply missing something, or is the CPU, Memory and Disk information not there?

        • 1. Re: Retrieve Hardware information about VM in VappTemplate
          test_c Novice

          The VappTemplate VM's are also of the same type as the VappTemplate object. The getChildren() method returns a list of VappTemplates which are actually the VM objects inside.There is no straight forward way to get the virtual hardware section of the VappTemplate VM's. This feature is available in vCD 5.6.

          //Code snippet to retrieve this using vCD 5.6

           

           

          VappTemplate template = VappTemplate.getVappTemplateByReference(vcloudClient, vappTemplRef);

                List<VappTemplate> temp = template.getChildren();

          for (VappTemplate vappTemplate : temp)

                {

                      System.out.println(vappTemplate.getCpu());

                }

           

           

           

           

           

           

           

           

          As a work around you can try to use the root VappTemplate's getOvf method and then parse through the EnvelopeType object and get the required CPU, Memory, Disks etc.

           

           

          //Code snippet to retrieve h/w info using vCD 5.5

           

           

          // START

          VappTemplate vAppTemplate = null;

          // Retrieving all the vAppReferences

          for (ReferenceType vAppTemplateRef : Vdc.getVdcByReference(vcloudClient, vdcRef).getVappTemplateRefs()) {

          // Retrieve the vppTemplate using Reference

          vAppTemplate = VappTemplate.getVappTemplateByReference(vcloudClient, vAppTemplateRef);

          EnvelopeType envelope = vAppTemplate.getOvf();

          // Retrieve the VirtualSystemCollection

          VirtualSystemCollectionType virtualSystemCollection = (VirtualSystemCollectionType) envelope.getContent().getValue();

          Iterator<JAXBElement<? extends ContentType>> iterator = virtualSystemCollection.getContent().iterator();

          VirtualSystemType virtualSystem = null;

          while (iterator.hasNext()) {

          virtualSystem = (VirtualSystemType) iterator.next().getValue();

          List<JAXBElement<? extends SectionType>> sections = virtualSystem.getSection();

          Iterator<JAXBElement<? extends SectionType>> it = sections.iterator();

          VirtualHardwareSectionType virtualHardwareSection = null;

          while (it.hasNext()) {

          JAXBElement<? extends SectionType> sec = it.next();

          if (sec.getValue() instanceof VirtualHardwareSectionType) {

            virtualHardwareSection = ((VirtualHardwareSectionType) sec.getValue());

            if (virtualHardwareSection != null) {

              List<RASDType> items = virtualHardwareSection.getItem();

          if (items != null) {

             for (RASDType item : items) {

               String itemResourceType = item.getResourceType().getValue();

            if (itemResourceType.equals("3"))//CPU

              System.out.println("vm:"+ virtualSystem.getId()+ "  Number of CPU:"+ item.getVirtualQuantity().getValue());

            if (itemResourceType.equals("4"))//Memory

                     System.out.println("vm:"+ virtualSystem.getId()+ "  Memory: "+ item.getVirtualQuantity().getValue());

            if (itemResourceType.equals("17"))//DISK

                     System.out.println("vm:"+ virtualSystem.getId()+ "  Disk Name: "+ item.getElementName().getValue());

          }

          }

          }

          }

          }

          }

          }

          // END

          • 2. Re: Retrieve Hardware information about VM in VappTemplate
            mitradebopam Lurker


            Thanks. This really helped me getting the details. 


            But I am struggling to get the Hard Disk space. Can you please help?


            I am using the version 5.1.