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
748 stars 311 forks source link

Error when trying to list all the vm's running. #209

Closed jhamukesh998 closed 4 years ago

jhamukesh998 commented 4 years ago

Environment

Steps or code snippet to reproduce

import requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client
session = requests.session()

session.verify = False

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

vsphere_client = create_vsphere_client(server='aa.bbb.yyy.xxx', username='name@organisation.org', password=pwd, session=session)

print(vsphere_client.vcenter.VM.list())

Actual behavior:

Traceback (most recent call last):
  File "hosts.py", line 13, in <module>
    print(vsphere_client.vcenter.VM.list())
  File "/usr/local/lib/python3.7/site-packages/com/vmware/vcenter_client.py", line 5153, in list
    'filter': filter,
  File "/usr/local/lib/python3.7/site-packages/vmware/vapi/bindings/stub.py", line 345, in _invoke
    return self._api_interface.native_invoke(ctx, _method_name, kwargs)
  File "/usr/local/lib/python3.7/site-packages/vmware/vapi/bindings/stub.py", line 298, in native_invoke
    self._rest_converter_mode)
com.vmware.vapi.std.errors_client.InternalServerError: {messages : [LocalizableMessage(id='vapi.bindings.method.impl.unexpected', default_message='Provider method implementation threw unexpected exception: null', args=['null'], params=None, localized=None)], data : None, error_type : None}

Expected behavior:

All the Vm's should be listed up

However when I do this I get the bunch of VM's which are up. I don't know are they both doing same thing ?

from __future__ import print_function
from vconnector.core import VConnector
from config import *

client = VConnector(
     user='name@organisation.org',
     pwd=pwd,
     host='aa.bbb.yyy.xxx')
client.connect()
vms = client.get_vm_view()
print(vms.view)

client.disconnect()

Moreover in Vsphere - api explorer the code for fetching requests are also not given as well as no way to generate token.

anusha94 commented 4 years ago

I don't get the error with your code snippet.

Have you followed the installation steps correctly? https://github.com/vmware/vsphere-automation-sdk-python#installing-required-python-packages

jhamukesh998 commented 4 years ago

Yep, I have configured things correctly. The issue seems to be in last line VM.list(). Because if I comment it, then no error comes prior to that line. I tried https://github.com/vmware/pyvmomi/blob/master/sample/getallvms.py this url and things worked. But not via current repo. Are both using same code base ?

anusha94 commented 4 years ago

Try this? https://github.com/vmware/vsphere-automation-sdk-python/blob/master/samples/vsphere/vcenter/vm/list_vms.py

pyvmomi uses SOAP APIs whereas Automation SDK uses REST endpoints

jhamukesh998 commented 4 years ago

Ya I had used this as well https://github.com/vmware/vsphere-automation-sdk-python/blob/master/samples/vsphere/vcenter/vm/list_vms.py list_of_vms = self.client.vcenter.VM.list() code was breaking on this function.

anusha94 commented 4 years ago

Can you try it in a new virtual environment? Not that what you have done is incorrect, just to make sure there are no conflicting versions.

jhamukesh998 commented 4 years ago

Yes, I will do and update it. Most probably I can do this tomorrow.

jhamukesh998 commented 4 years ago

Same error even when tried again in new venv

  File "file.py", line 18, in <module>
    print(vsphere_client.vcenter.VM.list())
  File "/Users/mukesh/Desktop/vcenter/sdk/sdk/lib/python3.7/site-packages/com/vmware/vcenter_client.py", line 5153, in list
    'filter': filter,
  File "/Users/mukesh/Desktop/vcenter/sdk/sdk/lib/python3.7/site-packages/vmware/vapi/bindings/stub.py", line 345, in _invoke
    return self._api_interface.native_invoke(ctx, _method_name, kwargs)
  File "/Users/mukesh/Desktop/vcenter/sdk/sdk/lib/python3.7/site-packages/vmware/vapi/bindings/stub.py", line 298, in native_invoke
    self._rest_converter_mode)
com.vmware.vapi.std.errors_client.InternalServerError: {messages : [LocalizableMessage(id='vapi.bindings.method.impl.unexpected', default_message='Provider method implementation threw unexpected exception: null', args=['null'], params=None, localized=None)], data : None, error_type : None}
anusha94 commented 4 years ago

what is your vsphere version?

Note that list_vms works only for 6.5+ https://github.com/vmware/vsphere-automation-sdk-python/blob/861b66e7d79b815aea02227e4ea0f250e49f1032/samples/vsphere/vcenter/vm/list_vms.py#L18

jhamukesh998 commented 4 years ago

6.7

anusha94 commented 4 years ago

@ngp-star can you check if you can reproduce this issue?

anusha94 commented 4 years ago

@iamjhamukesh Do you have any other VC setup that you can try on? Have you by any chance modified any permissions?

jhamukesh998 commented 4 years ago

No, I don't have access to other VC setups and I haven't modified any permissions. But pyVim and pyVmomi is working perfectly for me. Only vmware.vapi.vsphere.client isn't working for me . I am even able to write an output to the server inside the cluster using pyVmomi and pyVim

ngp-star commented 4 years ago

Hi @iamjhamukesh

we tried with vc setup 67u1 version sample , its working, able to list all vms.

jhamukesh998 commented 4 years ago

I am facing the same issue yet: vSphere Client version 6.7.0.40000

Traceback (most recent call last):
  File "sample.py", line 12, in <module>
    print(vsphere_client.vcenter.VM.list())
  File "/usr/local/lib/python3.7/site-packages/com/vmware/vcenter_client.py", line 5153, in list
    'filter': filter,
  File "/usr/local/lib/python3.7/site-packages/vmware/vapi/bindings/stub.py", line 345, in _invoke
    return self._api_interface.native_invoke(ctx, _method_name, kwargs)
  File "/usr/local/lib/python3.7/site-packages/vmware/vapi/bindings/stub.py", line 298, in native_invoke
    self._rest_converter_mode)
com.vmware.vapi.std.errors_client.InternalServerError: {messages : [LocalizableMessage(id='vapi.bindings.method.impl.unexpected', default_message='Provider method implementation threw unexpected exception: null', args=['null'], params=None, localized=None)], data : None, error_type : None}
imokyoureok commented 4 years ago

I get the same error when trying to list VMs that are not assigned to a network and are therefore inaccessible. If I exclude the problematic VMs, then the API call works.

anusha94 commented 4 years ago

@iamjhamukesh,

Is @imokyoureok 's scenario possible cause of error in your case?

anusha94 commented 4 years ago

@iamjhamukesh Any update?

anusha94 commented 4 years ago

closing this issue as there are no updates.

ewan-derivco commented 4 years ago

wait!! we get the same issue, it errors when there are orphaned vms in the result set

ewan-derivco commented 4 years ago

we are using the rest interface directly via c# though so maybe not the python sdk at fault

dungla2011 commented 4 years ago

I test with vcenter 6.7.0.42000 with API https:///rest/vcenter/vm

I have the same problem: Provider method implementation threw unexpected exception: null

But it work well (list ok vm) when push some string in filter: https:///rest/vcenter/vm?filter.hosts.1= OR: https:///rest/vcenter/vm?filter.power_states.1=POWERED_ON

(With API document: https://vdc-repo.vmware.com/vmwb-repository/dcr-public/1cd28284-3b72-4885-9e31-d1c6d9e26686/71ef7304-a6c9-43b3-a3cd-868b2c236c81/doc/operations/com/vmware/vcenter/vm.list-operation.html )

dungla2011 commented 4 years ago

More information: In my case, there is one esxi included an Inaccessable VM, it will cause return Empty list of vm. I remove Inaccessable VM, it return well full list VMs

image

inshal96 commented 4 years ago

Hi,

So when i apply the powered on filter, it lists all vms. When I remove that filter, it produces the following exception:

image

dungla2011 commented 4 years ago

Hi,

So when i apply the powered on filter, it lists all vms. When I remove that filter, it produces the following exception:

image

If it has any unaccessable, obsolete vm on vcenter?

inshal96 commented 4 years ago

Hi, So when i apply the powered on filter, it lists all vms. When I remove that filter, it produces the following exception: image

If it has any unaccessable, obsolete vm on vcenter?

Yes, it did have an obsolete vm.

yanglijian201 commented 3 years ago

Almost a year, issue still there....Quite easy to reproduce, what are you doing VMware, my lover?

shwetapurohit commented 2 years ago

@jhamukesh998

Could you please share the vc bundle, i'm not able to reproduce the issue