Beispiel #1
0
  /**
   * Establishes session with the virtual center server.
   *
   * @throws Exception the exception
   */
  private static void connect() throws Exception {

    HostnameVerifier hv =
        new HostnameVerifier() {
          public boolean verify(String urlHostName, SSLSession session) {
            return true;
          }
        };
    trustAllHttpsCertificates();
    HttpsURLConnection.setDefaultHostnameVerifier(hv);

    SVC_INST_REF.setType(SVC_INST_NAME);
    SVC_INST_REF.setValue(SVC_INST_NAME);

    vimService = new VimService();
    vimPort = vimService.getVimPort();
    Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();

    ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
    ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);

    serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF);
    vimPort.login(serviceContent.getSessionManager(), userName, password, null);
    isConnected = true;

    propCollectorRef = serviceContent.getPropertyCollector();
    rootRef = serviceContent.getRootFolder();
    perfManager = serviceContent.getPerfManager();
  }
Beispiel #2
0
 private static void refreshStats() {
   try {
     PerfCompositeMetric metric = vimPort.queryPerfComposite(perfManager, querySpec);
     XMLGregorianCalendar latestTs = displayStats(querySpec.getMetricId(), metric);
     if (latestTs != null) {
       querySpec.setStartTime(latestTs);
     }
   } catch (SOAPFaultException sfe) {
     printSoapFaultException(sfe);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Beispiel #3
0
  /**
   * Uses the new RetrievePropertiesEx method to emulate the now deprecated RetrieveProperties
   * method.
   *
   * @param listpfs
   * @return list of object content
   * @throws Exception
   */
  private static List<ObjectContent> retrievePropertiesAllObjects(List<PropertyFilterSpec> listpfs)
      throws Exception {

    RetrieveOptions propObjectRetrieveOpts = new RetrieveOptions();

    List<ObjectContent> listobjcontent = new ArrayList<ObjectContent>();

    try {
      RetrieveResult rslts =
          vimPort.retrievePropertiesEx(propCollectorRef, listpfs, propObjectRetrieveOpts);
      if (rslts != null && rslts.getObjects() != null && !rslts.getObjects().isEmpty()) {
        listobjcontent.addAll(rslts.getObjects());
      }
      String token = null;
      if (rslts != null && rslts.getToken() != null) {
        token = rslts.getToken();
      }
      while (token != null && !token.isEmpty()) {
        rslts = vimPort.continueRetrievePropertiesEx(propCollectorRef, token);
        token = null;
        if (rslts != null) {
          token = rslts.getToken();
          if (rslts.getObjects() != null && !rslts.getObjects().isEmpty()) {
            listobjcontent.addAll(rslts.getObjects());
          }
        }
      }
    } catch (SOAPFaultException sfe) {
      printSoapFaultException(sfe);
    } catch (Exception e) {
      System.out.println(" : Failed Getting Contents");
      e.printStackTrace();
    }

    return listobjcontent;
  }
Beispiel #4
0
 /**
  * Disconnects the user session.
  *
  * @throws Exception
  */
 private static void disconnect() throws Exception {
   if (isConnected) {
     vimPort.logout(serviceContent.getSessionManager());
   }
   isConnected = false;
 }