Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up the connection to vhost #20

Open
geoff-maddock opened this issue Sep 11, 2015 · 2 comments
Open

Setting up the connection to vhost #20

geoff-maddock opened this issue Sep 11, 2015 · 2 comments

Comments

@geoff-maddock
Copy link

This looks like something that could be very useful to me.
However, I’m having trouble connecting to my host.

Using a simple, existing SOAP client request, i can connect to my vhost using:
https://top.mydomain.net/sdk’

When trying to connect using this library, I tried:

$vhost = new \Vmwarephp\Vhost(‘https://top.mydomain.net/sdk’, ‘username’, ‘password’);
$virtualMachines = $vhost->findAllManagedObjects(‘VirtualMachine’, array(‘configStatus’));

But when I try to connect, I get errors:

PHP Notice: Undefined property: SoapFault::$detail in /var/www/smc/lib/vendor/vmwarephp/library/Vmwarephp/Exception/Soap.php on line 27
PHP Warning: Invalid argument supplied for foreach() in /var/www/smc/lib/vendor/vmwarephp/library/Vmwarephp/Exception/Soap.php on line 27
PHP Fatal error: Uncaught exception ‘Vmwarephp\Exception\Soap’ with message ‘HTTP: Could not connect to host. ‘ in /var/www/smc/lib/vendor/vmwarephp/library/Vmwarephp/Service.php:74
Stack trace:

I tried to use (removing the https:// and the sdk)
‘top.mydomain.net:443’

And I get a similar, but slightly less verbose error message:

PHP Fatal error: Uncaught exception ‘Vmwarephp\Exception\Soap’ with message ‘ServerFaultCode: type. InvalidRequest: InvalidRequest Object
(
)
‘ in /var/www/smc/lib/vendor/vmwarephp/library/Vmwarephp/Service.php:74

Added a bit of debugging to Service.php, but i'm not sure what to do with the response:

error is – RetrieveServiceContentArray
(
[_this] => SoapVar Object
(
[enc_type] => 101
[enc_value] => ServiceInstance
[enc_stype] => ServiceInstance
)

)
PHP Fatal error: Uncaught exception ‘Vmwarephp\Exception\Soap’ with message ‘ServerFaultCode: type. InvalidRequest: InvalidRequest Object

Any suggestions? I’m connecting to a vCenter server running 5.5

@jvdminne
Copy link

Maybe late, but maybe usefull for others facing this issue.

I had this problem in vCenter 6 with an untrusted certificate (test setup).

I changed the Factory\SoapClient.php file, the method make() to be as follows, essentially disabling the certificate validation.

Please note that for a production environment I highly recommend against making this change.

function make(\Vmwarephp\Vhost $vhost, $useExceptions = 1, $trace = 1) {
        $context = stream_context_create(array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        ));

        $options = array(
            'trace' => $trace,
            'location' => $this->makeRequestsLocation($vhost),
            'exceptions' => $useExceptions,
            'connection_timeout' => 120,
            'classmap' => $this->wsdlClassMapper->getClassMap(),
            'features' => SOAP_SINGLE_ELEMENT_ARRAYS + SOAP_USE_XSI_ARRAY_TYPE,
            'stream_context' => $context
        );
        $soapClient = $this->makeDefaultSoapClient($this->wsdlFilePath, $options);
        if (!$soapClient) throw new Ex\CannotCreateSoapClient();
        return $soapClient;
    }

@domin8r
Copy link

domin8r commented May 12, 2016

Cheers @jvdminne I was running into the same problem testing it locally with some tunneling (and therefore invalidating the certificate). Your fix is great for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants