当前位置: 代码迷 >> Web前端 >> 经过VMWare的Webservice API连接ESX|ESXi主机的JAVA源码
  详细解决方案

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

热度:496   发布时间:2012-08-01 17:53:41.0
通过VMWare的Webservice API连接ESX|ESXi主机的JAVA源码

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

版本: ESX|ESXi 4.0

JAVA代码如下:

view plain copy to clipboard print ?
  1. import ?java.net.URL;??
  2. ??
  3. import ?com.vmware.vim25.ManagedObjectReference;??
  4. import ?com.vmware.vim25.ServiceContent;??
  5. import ?com.vmware.vim25.VimPortType;??
  6. import ?com.vmware.vim25.VimServiceLocator;??
  7. ??
  8. /** ?
  9. ?*??获取到VMWare?ESX?or?ESXi的连接 ?
  10. ?*?ESX?|?ESXi版本:4.0 ?
  11. ?*?@author?forandever ?
  12. ?*?@date?2009-12-29 ?
  13. ?*? ?
  14. ?*/ ??
  15. public ? class ?ServerConn?{??
  16. ??
  17. ????private ?ManagedObjectReference?_svcRef;??
  18. ????private ?VimServiceLocator?_locator;??
  19. ????private ?VimPortType?_service;??
  20. ????private ?ServiceContent?_sic;??
  21. ??????
  22. ????private ? void ?createServiceRef()? throws ?Exception?{??
  23. ????????_svcRef?=?new ?ManagedObjectReference();??
  24. ????????_svcRef.setType("ServiceInstance" );??
  25. ????????_svcRef.set_value("ServiceInstance" );??
  26. ????}??
  27. ??????
  28. ????public ? void ?prepare(String?hostName,?String?userName,?String?password)? throws ?Exception?{??
  29. ????????System.setProperty("axis.socketSecureFactory" ,? "org.apache.axis.components.net.SunFakeTrustSocketFactory" );??
  30. ????????String?url?=?"https://" ?+?hostName?+? "/sdk/vimService" ;??
  31. ????????createServiceRef();??
  32. ????????_locator?=?new ?VimServiceLocator();??
  33. ????????_locator.setMaintainSession(true );??
  34. ????????_service?=?_locator.getVimPort(new ?URL(url));??
  35. ????????_sic?=?_service.retrieveServiceContent(_svcRef);??
  36. ????????if ?(_sic.getSessionManager()?!=? null )?{??
  37. ????????????_service.login(_sic.getSessionManager(),?userName,?password,?null );??
  38. ????????}??
  39. ????????System.out.println(_sic.getAbout().getFullName());??
  40. ????????System.out.println("API?type?is?" ?+?_sic.getAbout().getApiType());??
  41. ????????System.out.println("API?version?is?" ?+?_sic.getAbout().getApiVersion());??
  42. ????}??
  43. ??????
  44. ??????
  45. ????public ?ManagedObjectReference?get_svcRef()?{??
  46. ????????return ?_svcRef;??
  47. ????}??
  48. ??
  49. ????public ? void ?set_svcRef(ManagedObjectReference?ref)?{??
  50. ????????_svcRef?=?ref;??
  51. ????}??
  52. ??
  53. ????public ?VimServiceLocator?get_locator()?{??
  54. ????????return ?_locator;??
  55. ????}??
  56. ??
  57. ????public ? void ?set_locator(VimServiceLocator?_locator)?{??
  58. ????????this ._locator?=?_locator;??
  59. ????}??
  60. ??
  61. ????public ?VimPortType?get_service()?{??
  62. ????????return ?_service;??
  63. ????}??
  64. ??
  65. ????public ? void ?set_service(VimPortType?_service)?{??
  66. ????????this ._service?=?_service;??
  67. ????}??
  68. ??
  69. ????public ?ServiceContent?get_sic()?{??
  70. ????????return ?_sic;??
  71. ????}??
  72. ??
  73. ????public ? void ?set_sic(ServiceContent?_sic)?{??
  74. ????????this ._sic?=?_sic;??
  75. ????}??
  76. ??
  77. ????/** ?
  78. ?????*?@param?args ?
  79. ?????*/ ??
  80. ????public ? static ? void ?main(String[]?args)?{??
  81. ????????//?TODO?Auto-generated?method?stub ??
  82. ??
  83. ????}??
  84. ??
  85. }?
  相关解决方案