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

Cannot initialize a rest client against the govcsim #352

Closed
laidbackware opened this issue Dec 20, 2022 · 2 comments
Closed

Cannot initialize a rest client against the govcsim #352

laidbackware opened this issue Dec 20, 2022 · 2 comments
Labels

Comments

@laidbackware
Copy link

laidbackware commented Dec 20, 2022

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 <module>
    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
Copy link

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
Copy link

Per my previous comment.

@mtsvetanov mtsvetanov closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants