vmware / vsphere-automation-sdk-python

Python samples, language bindings, and API reference documentation for vSphere, VMC, and NSX-T using the VMware REST API
MIT License
746 stars 313 forks source link

Cannot initialize a rest client against the govcsim #352

Closed laidbackware closed 1 year ago

laidbackware commented 1 year ago

Describe the bug

The govcsim is capable simulating Rest API requests, but the creation of he client fails with a HTTP 404 error. The PyVmomi implementation in the client works without issue, but the rest API client generates an exception with the a 404 error.

When querying the govcsim using govc I am able to work with rest only objects such as tags, meaning that the govcsim fully implements authentication using the rest API.

I'm building a collection of vSphere with Tanzu Ansible modules that will be published via vmware-tanzu-labs, but will not be able to do any Github Actions integration tests without the ability to use govcsim - without significant infrastructure automation and resources.

Reproduction steps

  1. Run the sim with docker run -p 9090:9090 --name vcsim --rm --detach vmware/vcsim -l :9090
  2. Run the following code:
    
    import requests
    from vmware.vapi.vsphere.client import create_vsphere_client

session = requests.Session() session.verify = False client = create_vsphere_client( server="localhost:9090", username="user", password="pass", session=session )


### Expected behavior

Expect the client to return without error

### Additional context

Full traceback

Traceback (most recent call last): File "/home/matt/workspace/projects/ansible-for-vsphere-with-tanzu/tst.py", line 6, in client = create_vsphere_client( File "/home/matt/.local/lib/python3.10/site-packages/vmware/vapi/vsphere/client.py", line 173, in create_vsphere_client return VsphereClient(session=session, server=server, username=username, File "/home/matt/.local/lib/python3.10/site-packages/vmware/vapi/vsphere/client.py", line 116, in init session_id = session_svc.create() File "/home/matt/.local/lib/python3.10/site-packages/com/vmware/cis_client.py", line 201, in create return self._invoke('create', None) File "/home/matt/.local/lib/python3.10/site-packages/vmware/vapi/bindings/stub.py", line 345, in _invoke return self._api_interface.native_invoke(ctx, _method_name, kwargs) File "/home/matt/.local/lib/python3.10/site-packages/vmware/vapi/bindings/stub.py", line 266, in native_invoke method_result = self.invoke(ctx, method_id, data_val) File "/home/matt/.local/lib/python3.10/site-packages/vmware/vapi/bindings/stub.py", line 199, in invoke return self._api_provider.invoke(self._iface_id.get_name(), File "/home/matt/.local/lib/python3.10/site-packages/vmware/vapi/security/client/security_context_filter.py", line 101, in invoke method_result = ApiProviderFilter.invoke( File "/home/matt/.local/lib/python3.10/site-packages/vmware/vapi/provider/filter.py", line 75, in invoke method_result = self.next_provider.invoke( File "/home/matt/.local/lib/python3.10/site-packages/vmware/vapi/protocol/client/msg/json_connector.py", line 79, in invoke response = self._do_request(VAPI_INVOKE, ctx, params) File "/home/matt/.local/lib/python3.10/site-packages/vmware/vapi/protocol/client/msg/json_connector.py", line 127, in _do_request http_response.data.raise_for_status() File "/home/matt/.local/lib/python3.10/site-packages/requests/models.py", line 960, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://localhost:9090/api/

mtsvetanov commented 1 year ago

This doesn't work because the vsphere-automation-sdk-python uses JSON-RPC internal protocol to invoke the vCenter APIs (which also have REST rendering), while the govmomi vcsim only supports vCenter SOAP and REST APIs (but not the JSON-RPC protocol).

353 already tracks a reasonable feature request to switch the SDK to use REST. This issue is not a bug

mtsvetanov commented 1 year ago

Per my previous comment.