首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

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

2012-08-01 
通过VMWare的Webservice API连接ESX|ESXi主机的JAVA源码参考VMWare的Webservice API的文档,连接到ESX|ESXi

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

参考VMWare的Webservice API的文档,连接到ESX|ESXi主机。

版本: ESX|ESXi 4.0

JAVA代码如下:

view plaincopy to clipboardprint?
  1. import?java.net.URL;????
  2. import?com.vmware.vim25.ManagedObjectReference;??import?com.vmware.vim25.ServiceContent;??
  3. import?com.vmware.vim25.VimPortType;??import?com.vmware.vim25.VimServiceLocator;??
  4. ??/**?
  5. ?*??获取到VMWare?ESX?or?ESXi的连接??*?ESX?|?ESXi版本:4.0?
  6. ?*?@author?forandever??*?@date?2009-12-29?
  7. ?*???*/??
  8. public?class?ServerConn?{????
  9. ????private?ManagedObjectReference?_svcRef;??????private?VimServiceLocator?_locator;??
  10. ????private?VimPortType?_service;??????private?ServiceContent?_sic;??
  11. ??????????private?void?createServiceRef()?throws?Exception?{??
  12. ????????_svcRef?=?new?ManagedObjectReference();??????????_svcRef.setType("ServiceInstance");??
  13. ????????_svcRef.set_value("ServiceInstance");??????}??
  14. ??????????public?void?prepare(String?hostName,?String?userName,?String?password)?throws?Exception?{??
  15. ????????System.setProperty("axis.socketSecureFactory",?"org.apache.axis.components.net.SunFakeTrustSocketFactory");??????????String?url?=?"https://"?+?hostName?+?"/sdk/vimService";??
  16. ????????createServiceRef();??????????_locator?=?new?VimServiceLocator();??
  17. ????????_locator.setMaintainSession(true);??????????_service?=?_locator.getVimPort(new?URL(url));??
  18. ????????_sic?=?_service.retrieveServiceContent(_svcRef);??????????if?(_sic.getSessionManager()?!=?null)?{??
  19. ????????????_service.login(_sic.getSessionManager(),?userName,?password,?null);??????????}??
  20. ????????System.out.println(_sic.getAbout().getFullName());??????????System.out.println("API?type?is?"?+?_sic.getAbout().getApiType());??
  21. ????????System.out.println("API?version?is?"?+?_sic.getAbout().getApiVersion());??????}??
  22. ????????????
  23. ????public?ManagedObjectReference?get_svcRef()?{??????????return?_svcRef;??
  24. ????}????
  25. ????public?void?set_svcRef(ManagedObjectReference?ref)?{??????????_svcRef?=?ref;??
  26. ????}????
  27. ????public?VimServiceLocator?get_locator()?{??????????return?_locator;??
  28. ????}????
  29. ????public?void?set_locator(VimServiceLocator?_locator)?{??????????this._locator?=?_locator;??
  30. ????}????
  31. ????public?VimPortType?get_service()?{??????????return?_service;??
  32. ????}????
  33. ????public?void?set_service(VimPortType?_service)?{??????????this._service?=?_service;??
  34. ????}????
  35. ????public?ServiceContent?get_sic()?{??????????return?_sic;??
  36. ????}????
  37. ????public?void?set_sic(ServiceContent?_sic)?{??????????this._sic?=?_sic;??
  38. ????}????
  39. ????/**??????*?@param?args?
  40. ?????*/??????public?static?void?main(String[]?args)?{??
  41. ????????//?TODO?Auto-generated?method?stub????
  42. ????}????
  43. }?

热点排行