Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * Contains DrupalvmwareapiControllerVMwareController.
- */
- namespace DrupalvmwareapiController;
- use DrupalCoreControllerControllerBase;
- #require_once("../../nusoap/nusoap.php");
- /**
- * NuSoap is required, and included here.
- */
- /**
- * Controller routines for book routes.
- */
- class VMwareController extends ControllerBase {
- private static $instance = NULL;
- private $session_result, $myconnection, $namespace;
- private $debug = 0;
- private $servicestatus = false;
- private $logedin = false;
- private $appliances = array();
- /* process() retries, on error 503, $max_retries times
- * every $recursion_timeout seconds
- */
- private $max_retries = 15;
- private $recursion_timeout = 1;
- private $logfile = '';
- //public function VMwareAPI ($ip) {
- public function __construct ($ip, $user, $password) { //echo $password;exit();
- #echo $ip.$user.$password;exit();
- require_once './' . drupal_get_path('module', 'vmwareapi') . '/nusoap/nusoap.php';
- $this->myconnection = new nusoap_client("https://" . $ip ."/sdk/");
- $this->myconnection->timeout = 10;
- $this->myconnection->useHTTPPersistentConnection();
- $this->myconnection->soap_defencoding = "UTF-8";
- $this->namespace = "urn:vim25";
- $status = $this->_Login($user, $password);
- if (!$status) {
- drupal_set_message(
- t(
- 'Unable to connect to vCenter "@ip", check connection!',
- array('@ip' => $ip)
- ),
- 'error'
- );
- }
- }
- public function __destruct () {
- $this->_Logout();
- unset($this->myconnection);
- }
- public static function getinstance($ip = NULL, $user, $password)
- {
- if (!isset(self::$instance)) {
- $className = __CLASS__;
- self::$instance = new $className($ip, $user, $password);
- }
- return self::$instance;
- }
- }
- <?php
- namespace DrupalvmwareapiController;
- /**
- *
- * nusoap_base
- *
- * @author Dietrich Ayala <dietrich@ganx4.com>
- * @author Scott Nichol <snichol@users.sourceforge.net>
- * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
- * @access public
- */
- class nusoap_base {
- /**
- * Identification for HTTP headers.
- *
- * @var string
- * @access private
- */
- var $title = 'NuSOAP';
- /**
- * Version for HTTP headers.
- *
- * @var string
- * @access private
- */
- var $version = '0.9.5';
- /**
- * CVS revision for HTTP headers.
- *
- * @var string
- * @access private
- */
- var $revision = '$Revision: 1.123 $';
- /**
- * Current error string (manipulated by getError/setError)
- *
- * @var string
- * @access private
- */
- var $error_str = '';
- /**
- * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
- *
- * @var string
- * @access private
- */
- var $debug_str = '';
- /**
- * toggles automatic encoding of special characters as entities
- * (should always be true, I think)
- *
- * @var boolean
- * @access private
- */
- var $charencoding = true;
- /**
- * the debug level for this instance
- *
- * @var integer
- * @access private
- */
- var $debugLevel;
- /**
- * set schema version
- *
- * @var string
- * @access public
- */
- var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
- /**
- * charset encoding for outgoing messages
- *
- * @var string
- * @access public
- */
- var $soap_defencoding = 'ISO-8859-1';
- //var $soap_defencoding = 'UTF-8';
- /**
- * namespaces in an array of prefix => uri
- *
- * this is "seeded" by a set of constants, but it may be altered by code
- *
- * @var array
- * @access public
- */
- var $namespaces = array(
- 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
- 'xsd' => 'http://www.w3.org/2001/XMLSchema',
- 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
- 'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
- );
- /**
- * namespaces used in the current context, e.g. during serialization
- *
- * @var array
- * @access private
- */
- var $usedNamespaces = array();
- /**
- * XML Schema types in an array of uri => (array of xml type => php type)
- * is this legacy yet?
- * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
- * @var array
- * @access public
- */
- var $typemap = array(
- 'http://www.w3.org/2001/XMLSchema' => array(
- 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
- 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
- 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
- // abstract "any" types
- 'anyType'=>'string','anySimpleType'=>'string',
- // derived datatypes
- 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
- 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
- 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
- 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
- 'http://www.w3.org/2000/10/XMLSchema' => array(
- 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
- 'float'=>'double','dateTime'=>'string',
- 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
- 'http://www.w3.org/1999/XMLSchema' => array(
- 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
- 'float'=>'double','dateTime'=>'string',
- 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
- 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
- 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
- 'http://xml.apache.org/xml-soap' => array('Map')
- );
- /**
- * XML entities to convert
- *
- * @var array
- * @access public
- * @deprecated
- * @see expandEntities
- */
- var $xmlEntities = array('quot' => '"','amp' => '&',
- 'lt' => '<','gt' => '>','apos' => "'");
- /**
- * constructor
- *
- * @access public
- */
- function nusoap_base() {
- $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
- }
- ...................
- * @author Dietrich Ayala <dietrich@ganx4.com>
- * @author Scott Nichol <snichol@users.sourceforge.net>
- * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
- * @access public
- */
- class nusoap_client extends nusoap_base {
- var $username = ''; // Username for HTTP authentication
- var $password = ''; // Password for HTTP authentication
- var $authtype = ''; // Type of HTTP authentication
- var $certRequest = array(); // Certificate for HTTP SSL authentication
- var $requestHeaders = false; // SOAP headers in request (text)
- var $responseHeaders = ''; // SOAP headers from response (incomplete namespace resolution) (text)
- var $responseHeader = NULL; // SOAP Header from response (parsed)
- var $document = ''; // SOAP body response portion (incomplete namespace resolution) (text)
- var $endpoint;
- var $forceEndpoint = ''; // overrides WSDL endpoint
- var $proxyhost = '';
- var $proxyport = '';
- var $proxyusername = '';
- var $proxypassword = '';
- var $portName = ''; // port name to use in WSDL
- var $xml_encoding = ''; // character set encoding of incoming (response) messages
- var $http_encoding = false;
- var $timeout = 0; // HTTP connection timeout
- var $response_timeout = 30; // HTTP response timeout
- var $endpointType = ''; // soap|wsdl, empty for WSDL initialization error
- var $persistentConnection = false;
- var $defaultRpcParams = false; // This is no longer used
- var $request = ''; // HTTP request
- var $response = ''; // HTTP response
- var $responseData = ''; // SOAP payload of response
- var $cookies = array(); // Cookies from response or for request
- var $decode_utf8 = true; // toggles whether the parser decodes element content w/ utf8_decode()
- var $operations = array(); // WSDL operations, empty for WSDL initialization error
- var $curl_options = array(); // User-specified cURL options
- var $bindingType = ''; // WSDL operation binding type
- var $use_curl = false; // whether to always try to use cURL
- public function __construct () {
- #echo 'soap constructor';exit();
- #nusoap_client($endpoint,$wsdl = false,$proxyhost = false,$proxyport = false,$proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $portName = '');
- }
- /*
- * fault related variables
- */
- /**
- * @var fault
- * @access public
- */
- var $fault;
- /**
- * @var faultcode
- * @access public
- */
- var $faultcode;
- /**
- * @var faultstring
- * @access public
- */
- var $faultstring;
- /**
- * @var faultdetail
- * @access public
- */
- var $faultdetail;
- /**
- * constructor
- *
- * @param mixed $endpoint SOAP server or WSDL URL (string), or wsdl instance (object)
- * @param mixed $wsdl optional, set to 'wsdl' or true if using WSDL
- * @param string $host optional
- * @param string $port optional
- * @param string $username optional
- * @param string $password optional
- * @param integer $timeout set the connection timeout
- * @param integer $response_timeout set the response timeout
- * @param string $portName optional portName in WSDL document
- * @access public
- */
- function nusoap_client($endpoint,$wsdl = false,$host = false,$port = false,$username = false, $password = false, $timeout = 0, $response_timeout = 30, $portName = ''){
- parent::nusoap_base();
- $this->endpoint = $endpoint;
- $this->host = $host;
- $this->port = $port;
- $this->username = $username;
- $this->password = $password;
- $this->timeout = $timeout;
- $this->response_timeout = $response_timeout;
- $this->portName = $portName;
- $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
- $this->appendDebug('endpoint=' . $this->varDump($endpoint));
- // make values
- if($wsdl){
- if (is_object($endpoint) && (get_class($endpoint) == 'wsdl')) {
- $this->wsdl = $endpoint;
- $this->endpoint = $this->wsdl->wsdl;
- $this->wsdlFile = $this->endpoint;
- $this->debug('existing wsdl instance created from ' . $this->endpoint);
- $this->checkWSDL();
- } else {
- $this->wsdlFile = $this->endpoint;
- $this->wsdl = null;
- $this->debug('will use lazy evaluation of wsdl from ' . $this->endpoint);
- }
- $this->endpointType = 'wsdl';
- } else {
- $this->debug("instantiate SOAP with endpoint at $endpoint");
- $this->endpointType = 'soap';
- }
- }
- $instance = VMwareController::getinstance($host, $user, $pass);
Add Comment
Please, Sign In to add comment