Exemple #1
0
  /**
   * Retrieves the MOREF of the host.
   *
   * @param hostName :
   * @return
   */
  private static ManagedObjectReference getHostByHostName(String hostName) {
    ManagedObjectReference retVal = null;
    ManagedObjectReference rootFolder = serviceContent.getRootFolder();
    try {
      TraversalSpec tSpec = getHostSystemTraversalSpec();
      // Create Property Spec
      PropertySpec propertySpec = new PropertySpec();
      propertySpec.setAll(Boolean.FALSE);
      propertySpec.getPathSet().add("name");
      propertySpec.setType("HostSystem");

      // Now create Object Spec
      ObjectSpec objectSpec = new ObjectSpec();
      objectSpec.setObj(rootFolder);
      objectSpec.setSkip(Boolean.TRUE);
      objectSpec.getSelectSet().add(tSpec);

      // Create PropertyFilterSpec using the PropertySpec and ObjectPec
      // created above.
      PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
      propertyFilterSpec.getPropSet().add(propertySpec);
      propertyFilterSpec.getObjectSet().add(objectSpec);
      List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
      listpfs.add(propertyFilterSpec);
      List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs);

      if (listobjcont != null) {
        for (ObjectContent oc : listobjcont) {
          ManagedObjectReference mr = oc.getObj();
          String hostnm = null;
          List<DynamicProperty> listDynamicProps = oc.getPropSet();
          DynamicProperty[] dps =
              listDynamicProps.toArray(new DynamicProperty[listDynamicProps.size()]);
          if (dps != null) {
            for (DynamicProperty dp : dps) {
              hostnm = (String) dp.getVal();
            }
          }
          if (hostnm != null && hostnm.equals(hostName)) {
            retVal = mr;
            break;
          }
        }
      } else {
        System.out.println("The Object Content is Null");
      }
    } catch (SOAPFaultException sfe) {
      printSoapFaultException(sfe);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return retVal;
  }
Exemple #2
0
  /** Prints the Host names. */
  private static void printHostProductDetails() {
    try {
      setHostSystemAttributesList();
      TraversalSpec tSpec = getHostSystemTraversalSpec();
      // Create Property Spec
      PropertySpec propertySpec = new PropertySpec();
      propertySpec.setAll(Boolean.FALSE);
      propertySpec.getPathSet().addAll(hostSystemAttributesArr);
      propertySpec.setType("HostSystem");

      // Now create Object Spec
      ObjectSpec objectSpec = new ObjectSpec();
      objectSpec.setObj(rootRef);
      objectSpec.setSkip(Boolean.TRUE);
      objectSpec.getSelectSet().add(tSpec);

      // Create PropertyFilterSpec using the PropertySpec and ObjectPec
      // created above.
      PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
      propertyFilterSpec.getPropSet().add(propertySpec);
      propertyFilterSpec.getObjectSet().add(objectSpec);
      List<PropertyFilterSpec> pfSpecList = new ArrayList<PropertyFilterSpec>(1);
      pfSpecList.add(propertyFilterSpec);

      List<ObjectContent> listobjcont = retrievePropertiesAllObjects(pfSpecList);

      if (listobjcont != null) {
        for (ObjectContent oc : listobjcont) {
          List<DynamicProperty> dpList = oc.getPropSet();
          if (dpList != null) {
            for (DynamicProperty dp : dpList) {
              System.out.println(dp.getName() + " : " + dp.getVal());
            }
          }
          System.out.println("\n\n***************************************************************");
        }
      }
    } catch (SOAPFaultException sfe) {
      printSoapFaultException(sfe);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #3
0
 /**
  * Retrieve contents for a single object based on the property collector registered with the
  * service.
  *
  * @param collector Property collector registered with service
  * @param mobj Managed Object Reference to get contents for
  * @param properties names of properties of object to retrieve
  * @return retrieved object contents
  */
 private static ObjectContent[] getObjectProperties(
     ManagedObjectReference mobj, String[] properties) throws Exception {
   if (mobj == null) {
     return null;
   }
   PropertyFilterSpec spec = new PropertyFilterSpec();
   spec.getPropSet().add(new PropertySpec());
   if ((properties == null || properties.length == 0)) {
     spec.getPropSet().get(0).setAll(Boolean.TRUE);
   } else {
     spec.getPropSet().get(0).setAll(Boolean.FALSE);
   }
   spec.getPropSet().get(0).setType(mobj.getType());
   spec.getPropSet().get(0).getPathSet().addAll(Arrays.asList(properties));
   spec.getObjectSet().add(new ObjectSpec());
   spec.getObjectSet().get(0).setObj(mobj);
   spec.getObjectSet().get(0).setSkip(Boolean.FALSE);
   List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
   listpfs.add(spec);
   List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs);
   return listobjcont.toArray(new ObjectContent[listobjcont.size()]);
 }