Example #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();
  }
 public Connection disconnect() {
   if (this.isConnected()) {
     try {
       vimPort.logout(serviceContent.getSessionManager());
     } catch (Exception e) {
       Throwable cause = e.getCause();
       throw new BasicConnectionException(
           "failed to disconnect properly: " + e.getMessage() + " : " + cause.getMessage(), cause);
     } finally {
       // A connection is very memory intensive, I'm helping the garbage collector here
       userSession = null;
       serviceContent = null;
       vimPort = null;
       vimService = null;
     }
   }
   return this;
 }
  @SuppressWarnings("rawtypes")
  private void _connect() throws RuntimeFaultFaultMsg, InvalidLocaleFaultMsg, InvalidLoginFaultMsg {
    vimService = new VimService();
    vimPort = vimService.getVimPort();
    Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();

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

    serviceContent = vimPort.retrieveServiceContent(this.getServiceInstanceReference());
    headers =
        (Map)
            ((BindingProvider) vimPort)
                .getResponseContext()
                .get(MessageContext.HTTP_RESPONSE_HEADERS);

    userSession = vimPort.login(serviceContent.getSessionManager(), username, password, null);
  }
Example #4
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);
    boolean isVCApi = checkApiType(serviceContent);
    if (!isVCApi) {
      System.out.println("Virtual Center is not supported");
      System.exit(0);
    }
    headers =
        (Map)
            ((BindingProvider) vimPort)
                .getResponseContext()
                .get(MessageContext.HTTP_RESPONSE_HEADERS);
    vimPort.login(serviceContent.getSessionManager(), userName, password, null);
    isConnected = true;
    rootRef = serviceContent.getRootFolder();
    propCollectorRef = serviceContent.getPropertyCollector();
  }
Example #5
0
 /**
  * Disconnects the user session.
  *
  * @throws Exception
  */
 private static void disconnect() throws Exception {
   if (isConnected) {
     vimPort.logout(serviceContent.getSessionManager());
   }
   isConnected = false;
 }
 /**
  * Disconnects the user session
  *
  * @throws Exception
  */
 private static void disconnect() throws Exception {
   VIM_PORT.logout(SERVICE_CONTENT.getSessionManager());
 }
 /**
  * @param url The URL of the server
  * @param uname The user name for the session
  * @param pword The password for the user
  *     <p>Establishes session with the virtual center / ESX server
  * @throws Exception
  */
 private static void connect(String url, String uname, String pword) throws Exception {
   VIM_PORT.login(SERVICE_CONTENT.getSessionManager(), uname, pword, null);
 }