通过VMWare的Webservice API连接ESX|ESXi主机的JAVA源码
参考VMWare的Webservice API的文档,连接到ESX|ESXi主机。
版本: ESX|ESXi 4.0
JAVA代码如下:
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 } }
相关推荐
80981934 2020-02-05
goawalk 2012-09-06
89520991 2011-04-28
BearWow 2014-09-16
EricaYue 2014-03-06
viplinux 2012-11-06
sprintwind 2012-07-03
wangkeIDC 2017-11-08
尚 2017-05-16
Congpanpan 2017-03-28
第N帝国 2016-01-11
万里之书 2015-06-11
LuxVeritas 2012-03-19
qiaoqiangv 2012-09-09
鹏鹏之家 2012-04-03
OccamsRazor 2018-05-27
优雅地逆袭 2017-12-19