WEB开发网
开发学院WEB开发Jsp 通过VMWare的Webservice API连接ESX|ESXi主机的JA... 阅读

通过VMWare的Webservice API连接ESX|ESXi主机的JAVA源码

 2009-12-30 21:15:15 来源:WEB开发网   
核心提示:参考VMWare的Webservice API的文档,连接到ESX|ESXi主机,通过VMWare的Webservice API连接ESX|ESXi主机的JAVA源码,版本: ESX|ESXi 4.0java代码如下:view plaincopy to clipboardPRint?import java.net.UR
参考VMWare的Webservice API的文档,连接到ESX|ESXi主机。

版本: ESX|ESXi 4.0

java代码如下:

view plaincopy to clipboardPRint?
import java.net.URL;  
 
import com.vmware.vim25.ManagedObjectReference;  
import com.vmware.vim25.ServiceContent;  
import com.vmware.vim25.VimPortType;  
import com.vmware.vim25.VimServiceLocator;  
 
/** 
* 获取到VMWare ESX or ESXi的连接 
* ESX | ESXi版本:4.0 
* @author forandever 
* @date 2009-12-29 
*  
*/ 
public class ServerConn {  
 
  private ManagedObjectReference _svcRef;  
  private VimServiceLocator _locator;  
  private VimPortType _service;  
  private ServiceContent _sic;  
    
  private void createServiceRef() throws Exception {  
    _svcRef = new ManagedObjectReference();  
    _svcRef.setType("ServiceInstance");  
    _svcRef.set_value("ServiceInstance");  
  }  
    
  public void prepare(String hostName, String userName, String passWord) throws Exception {  
    System.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");  
    String url = "https://" + hostName + "/sdk/vimService";  
    createServiceRef();  
    _locator = new VimServiceLocator();  
    _locator.setMaintainsession(true);  
    _service = _locator.getVimPort(new URL(url));  
    _sic = _service.retrieveServiceContent(_svcRef);  
    if (_sic.getSessionManager() != null) {  
      _service.login(_sic.getSessionManager(), userName, password, null);  
    }  
    System.out.println(_sic.getAbout().getFullName());  
    System.out.println("API type is " + _sic.getAbout().getApiType());  
    System.out.println("API version is " + _sic.getAbout().getApiVersion());  
  }  
    
    
  public ManagedObjectReference get_svcRef() {  
    return _svcRef;  
  }  
 
  public void set_svcRef(ManagedObjectReference ref) {  
    _svcRef = ref;  
  }  
 
  public VimServiceLocator get_locator() {  
    return _locator;  
  }  
 
  public void set_locator(VimServiceLocator _locator) {  
    this._locator = _locator;  
  }  
 
  public VimPortType get_service() {  
    return _service;  
  }  
 
  public void set_service(VimPortType _service) {  
    this._service = _service;  
  }  
 
  public ServiceContent get_sic() {  
    return _sic;  
  }  
 
  public void set_sic(ServiceContent _sic) {  
    this._sic = _sic;  
  }  
 
  /** 
   * @param args 
   */ 
  public static void main(String[] args) {  
    // TODO Auto-generated method stub  
 
  }  
 
} 
import java.net.URL;

import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.ServiceContent;
import com.vmware.vim25.VimPortType;
import com.vmware.vim25.VimServiceLocator;

/**
* 获取到VMWare ESX or ESXi的连接
* ESX | ESXi版本:4.0
* @author forandever
* @date 2009-12-29
*
*/
public class ServerConn {

private ManagedObjectReference _svcRef;
private VimServiceLocator _locator;
private VimPortType _service;
private ServiceContent _sic;

private void createServiceRef() throws Exception {
_svcRef = new ManagedObjectReference();
_svcRef.setType("ServiceInstance");
_svcRef.set_value("ServiceInstance");
}

public void prepare(String hostName, String userName, String password) throws Exception {
System.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");
String url = "https://" + hostName + "/sdk/vimService";
createServiceRef();
_locator = new VimServiceLocator();
_locator.setMaintainSession(true);
_service = _locator.getVimPort(new URL(url));
_sic = _service.retrieveServiceContent(_svcRef);
if (_sic.getSessionManager() != null) {
_service.login(_sic.getSessionManager(), userName, password, null);
}
System.out.println(_sic.getAbout().getFullName());
System.out.println("API type is " + _sic.getAbout().getApiType());
System.out.println("API version is " + _sic.getAbout().getApiVersion());
}


public ManagedObjectReference get_svcRef() {
return _svcRef;
}

public void set_svcRef(ManagedObjectReference ref) {
_svcRef = ref;
}

public VimServiceLocator get_locator() {
return _locator;
}

public void set_locator(VimServiceLocator _locator) {
this._locator = _locator;
}

public VimPortType get_service() {
return _service;
}

public void set_service(VimPortType _service) {
this._service = _service;
}

public ServiceContent get_sic() {
return _sic;
}

public void set_sic(ServiceContent _sic) {
this._sic = _sic;
}

/**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}


@forandever 2009-12-31



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/forandever/archive/2009/12/30/5105459.aspx

Tags:通过 VMWare Webservice

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接