Advertisement
Guest User

Untitled

a guest
Nov 8th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. class soapclientd extends soapclient
  2. {
  3. public $action = false;
  4.  
  5. public function __construct($wsdl, $options = array())
  6. {
  7. parent::__construct($wsdl, $options);
  8. }
  9.  
  10. public function __doRequest($request, $location, $action, $version, $one_way = 0)
  11. {
  12. // echo '<pre>' . htmlspecialchars(str_replace(array ('<ns', '></'), array (PHP_EOL . '<ns', '>'.PHP_EOL.'</'), $request)) . '</pre>';
  13. $resp = parent::__doRequest($request, $location, $action, $version, $one_way);
  14. return $resp;
  15. }
  16.  
  17. }
  18.  
  19.  
  20. $client = new SoapClient("https://172.16.3.3/sdk/vimService.wsdl", array("trace" => 1, "location"=>"https://172.16.3.3/sdk/"));
  21. try
  22. {
  23. $request = new stdClass();
  24. $request->_this = array ('_' => 'ServiceInstance', 'type' => 'ServiceInstance');
  25. $response = $client->__soapCall('RetrieveServiceContent', array((array)$request));
  26. } catch (Exception $e)
  27. {
  28. echo $e->getMessage();
  29. exit;
  30. }
  31. $ret = $response->returnval;
  32.  
  33. try
  34. {
  35. $request = new stdClass();
  36. $request->_this = $ret->sessionManager;
  37. $request->userName = 'root';
  38. $request->password = 'xxxx';
  39. $response = $client->__soapCall('Login', array((array)$request));
  40. } catch (Exception $e)
  41. {
  42. echo $e->getMessage();
  43. exit;
  44. }
  45.  
  46. $ss1 = new soapvar(array ('name' => 'FolderTraversalSpec'), SOAP_ENC_OBJECT, null, null, 'selectSet', null);
  47. $ss2 = new soapvar(array ('name' => 'DataCenterVMTraversalSpec'), SOAP_ENC_OBJECT, null, null, 'selectSet', null);
  48. $a = array ('name' => 'FolderTraversalSpec', 'type' => 'Folder', 'path' => 'childEntity', 'skip' => false, $ss1, $ss2);
  49.  
  50. $ss = new soapvar(array ('name' => 'FolderTraversalSpec'), SOAP_ENC_OBJECT, null, null, 'selectSet', null);
  51. $b = array ('name' => 'DataCenterVMTraversalSpec', 'type' => 'Datacenter', 'path' => 'vmFolder', 'skip' => false, $ss);
  52.  
  53. $res = null;
  54. try
  55. {
  56. $request = new stdClass();
  57. $request->_this = $ret->propertyCollector;
  58. $request->specSet = array (
  59. 'propSet' => array (
  60. array ('type' => 'VirtualMachine', 'all' => 0, 'pathSet' => array ('name', 'guest.ipAddress', 'guest.guestState', 'runtime.powerState', 'config.hardware.numCPU', 'config.hardware.memoryMB')),
  61. ),
  62. 'objectSet' => array (
  63. 'obj' => $ret->rootFolder,
  64. 'skip' => false,
  65. 'selectSet' => array (
  66. new soapvar($a, SOAP_ENC_OBJECT, 'TraversalSpec'),
  67. new soapvar($b, SOAP_ENC_OBJECT, 'TraversalSpec'),
  68. ),
  69. )
  70. );
  71. $res = $client->__soapCall('RetrieveProperties', array((array)$request));
  72. } catch (Exception $e)
  73. {
  74. echo $e->getMessage();
  75. }
  76.  
  77. print_r($res);
  78.  
  79. [28] => stdClass Object
  80. (
  81. [obj] => stdClass Object
  82. (
  83. [_] => 97
  84. [type] => VirtualMachine
  85. )
  86.  
  87. [propSet] => Array
  88. (
  89. [0] => stdClass Object
  90. (
  91. [name] => config.hardware.memoryMB
  92. [val] => 15996
  93. )
  94.  
  95. [1] => stdClass Object
  96. (
  97. [name] => config.hardware.numCPU
  98. [val] => 4
  99. )
  100.  
  101. [2] => stdClass Object
  102. (
  103. [name] => guest.guestState
  104. [val] => notRunning
  105. )
  106.  
  107. [3] => stdClass Object
  108. (
  109. [name] => name
  110. [val] => 8796-january-Core-3.181
  111. )
  112.  
  113. [4] => stdClass Object
  114. (
  115. [name] => runtime.powerState
  116. [val] => poweredOff
  117. )
  118.  
  119. )
  120.  
  121. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement