dnaeon / py-vpoller

Distributed vSphere API Proxy
Other
83 stars 31 forks source link

Cannot serialize result: Circular reference detected #274

Closed k05054 closed 4 years ago

k05054 commented 4 years ago

Hi, i'm trying to get all VMs in a resource pool vmware_test. The command i'm using is: vpoller-client --method resource.pool.get --vsphere-host x.x.x.x --name vmware_test --properties vm But all i get is {"msg": "Cannot serialize result: Circular reference detected", "success": 1} What am i doing wrong ?

dnaeon commented 4 years ago

@k05054 Do other vPoller method work?

Are you seeing this issue only when requesting a given resource pool, or this happens for all resource pools?

k05054 commented 4 years ago

Hi ! Other vPoller methods are working fine. I'm getting this message when i'm using resource.pool.get method with properties: vm, summary, config, childConfiguration and owner for all resource pools. Only --properties runtime are working fine.

dnaeon commented 4 years ago

Generally you should be requesting individual property names, and not composite ones like vm for a ResourcePool, as this may indeed run into a circular resolving, because some of the VM properties point back to the originating resource pool.

For VM properties you should be using the vm.get properties instead.

k05054 commented 4 years ago

I see, thanks. Is it even possible to get a list of vm's associated with specific resource pool ?

dnaeon commented 4 years ago

That can probably be implemented as part of a separate vpoller method. I'll leave this issue open for now, hopefully I will have some spare time to implement that new method.

k05054 commented 4 years ago

Thanks. Looking forward to that.

dnaeon commented 4 years ago

@k05054 what properties would you want to have as part of the new method for getting VMs from a specific resource pool?

k05054 commented 4 years ago

Hi ! I wanted to make an alternative VM discovery based on resource pool. That should give us more flexible monitoring of the VM's by assigning different templates based on resource pool VM's associated with, or not discovering them at all. So i think there should be a discovery method without specific properties. If we can get a VM name and UUID that would be enough.

dnaeon commented 4 years ago

Can you test out the code from the feat/resource-pool-vm-get branch?

https://github.com/dnaeon/py-vpoller/commit/2363366d3491fcee9e52a98093cf72e377b096e3

Let me know how it goes, and if things are looking good I will merge this into the main branch.

Use the resource.pool.vm.get method and pass in --properties the properties you want to collect from VMs, e.g. name, runtime.powerState, etc.

k05054 commented 4 years ago

Thanks ! I'll test it after the holidays. I don't have access to my work computers right now.

k05054 commented 4 years ago

I tried to use the new method and there's the results: Console command works perfect. It gives all the information needed to make a discovery. Then i updated the zabbix.py helper file by adding 'resource.pool.vm.get': self.zabbix_lld_data, and tried to make a discovery from zabbix. Unfortunately i didn't managed to make this method work in zabbix. All that i keep getting for now is "Unknown or missing agent name" What am i doing wrong again ?

dnaeon commented 4 years ago

Can you run from the command line using the zabbix helper and show the results. You should use the --helper flag.

k05054 commented 4 years ago

[root@mon-test helpers]# vpoller-client --method resource.pool.vm.get --vsphere-host 192.168.0.21 --name testRP --properties name --helper zabbix {"msg": "Successfully discovered objects", "result": [{"name": "test1"}, {"name": "test2"}, {"name": "test3"}], "success": 0} As i understand helper is not working. right ?

dnaeon commented 4 years ago

Please get the lates code from the feat/resource-pool-vm-get branch.

You haven't specified the correct helper name. This is how it should look like.

$ vpoller-client -m resource.pool.vm.get --name TestPool -V vc01--helper vpoller.helpers.zabbix

Which returns this result in my lab environment.

{"data": [{"{#VSPHERE.RESOURCE.POOL.VM.NAME}": "k8s-node01"}]}

Let me know how it goes.

k05054 commented 4 years ago

Thank you for pointing out my mistake. I've updated the code you mentioned and corrected the request. Now i'm getting correct values. [root@mon-test helpers]# vpoller-client --method resource.pool.vm.get --vsphere-host 192.168.0.21 --name testRP --properties name --helper vpoller.helpers.zabbix {"data": [{"{#VSPHERE.RESOURCE.POOL.VM.NAME}": "Test1"}, {"{#VSPHERE.RESOURCE.POOL.VM.NAME}": "Test2"}, {"{#VSPHERE.RESOURCE.POOL.VM.NAME}": "Test3"}]} I tried to make a discovery from zabbix and it worked too. It all works just great now. Thanks so much for your help !

dnaeon commented 4 years ago

Welcome! I've also merged the code in the main branch.