waldirio / rvtools_python

Application to be executed on Linux and collect all information from vCenter
10 stars 10 forks source link

Keep getting "IndexError: list index out of range" in vinfo.py #35

Open davehouser1 opened 3 years ago

davehouser1 commented 3 years ago

Full error:

  File "/home/bob/.local/lib/python3.6/site-packages/rvtools/vinfo/vinfo.py", line 8, in get_obj
    obj = container.view[0].name
IndexError: list index out of range

Here is the function where it is failing:

def get_obj(content, vimtype):
    obj = None
    container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
    obj = container.view[0].name
    # for c in container.view:
    #     if name:
    #         if c.name == name:
    #             obj = c
    #             break
    #     else:
    #         obj = c
    #         break
    return obj

Trouble shooting:

def get_obj(content, vimtype):
    obj = None
    container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
    print("!!!!!!!!!!!!!!1")
    print(container.view[0].name)
    print("!!!!!!!!!!!!!!2")
    obj = container.view[0].name
    # for c in container.view:
    #     if name:
    #         if c.name == name:
    #             obj = c
    #             break
    #     else:
    #         obj = c
    #         break
    return obj

Here is the output I get now:

bob@Ubuntu-vm:~$ rvtools -s 10.10.10.10 -u administrator@vsphere.local -p admin123 -d ./vmware/
Using flags
vcenter: 10.10.10.10
user: administrator@vsphere.local

## Processing vInfo module
Machine Name: vm01
Powerstate: poweredOn
Template: False
Config status: green
DNS Name: localhost
Connection state: connected
Guest state: running
Heartbeat: green
Consolidation needed: False
Suspend time:
Change version: 2020-11-11T18:44:52.989107Z
CPUs: 2
Latency sensitivy: normal
Memory: 16384
Nics: 1
Disks: 1
Network #1: VM Network
Network #2:
Network #3:
Network #4:
Num monitors: 1
Video ram KB: 4096
FT state: notConfigured
Boot delay: 0
Boot retry delay: 10000
Boot retry enabled: False
Firmware: bios
Path: [datadisk-01] vm01/vm01.vmx
!!!!!!!!!!!!!!1
MyDataCenter
!!!!!!!!!!!!!!2
Datacenter: MyDataCenter
!!!!!!!!!!!!!!1
Traceback (most recent call last):
  File "/home/bob/.local/bin/rvtools", line 8, in <module>
    rvtools.main()
  File "/home/bob/.local/lib/python3.6/site-packages/rvtools/rvtools.py", line 92, in main
    vinfo_collect(service_instance, directory)
  File "/home/bob/.local/lib/python3.6/site-packages/rvtools/vinfo/vinfo.py", line 364, in vinfo_collect
    cluster = get_obj(content, [vim.ClusterComputeResource])
  File "/home/bob/.local/lib/python3.6/site-packages/rvtools/vinfo/vinfo.py", line 9, in get_obj
    print(container.view[0].name)
IndexError: list index out of range

Workaround

I am not a python guru, so any feedback you could provide would be helpful. It looks like the function is trying to pull the datacenter name out of the object, and it looks like it succeeds based on the sytnax container.view[0].name, but for whatever reason the get_obj function fails.

Rajeshunix13 commented 3 years ago

Hi, Anyone has a solution for this issue on centos8/python3.

waldirio commented 2 years ago

Hello @davehouser1 and @Rajeshunix13

Sorry for the long time to answer. I'll check this out ASAP.

Thanks for the heads up

bugcy013 commented 2 years ago

@waldirio Getting the same error. can you please help with this?

I am using rvtools-python==0.0.1

Datacenter: ha-datacenter
Traceback (most recent call last):
  File "/home/ansible/test/bin/rvtools", line 8, in <module>
    rvtools.main()
  File "/home/ansible/test/lib/python3.8/site-packages/rvtools/rvtools.py", line 92, in main
    vinfo_collect(service_instance, directory)
  File "/home/ansible/test/lib/python3.8/site-packages/rvtools/vinfo/vinfo.py", line 361, in vinfo_collect
    cluster = get_obj(content, [vim.ClusterComputeResource])
  File "/home/ansible/test/lib/python3.8/site-packages/rvtools/vinfo/vinfo.py", line 8, in get_obj
    obj = container.view[0].name
IndexError: list index out of range
waldirio commented 2 years ago

Hey @bugcy013

Are you using the binary version available here ?

Thank you! Waldirio

eyryve commented 1 year ago

Hello. This error appends when there is no cluster defined. Here: cluster = get_obj(content, [vim.ClusterComputeResource]) print("Cluster: {}".format(cluster)) vinfo_data['cluster'] = str(cluster)

lastest version do not fix this issue.

Bye.

waldirio commented 6 months ago

Hello @bugcy013 @Rajeshunix13 @davehouser1 and @eyryve

I pushed one new version via pip, with that said, you can update the package and try once again.

Please, let me know if you are still facing issues, then I'll move on.

Thank you for your help and sorry for my delay. Waldirio