Pyvmomi get folders name
Question: I'm new to Python and Django and I need to list all my VMs. I used pyvmomi and
Django but I can't get the folders name from VSphere, it shows a strange line.

> VMware list
>
> 'vim.Folder:group-v207'
>
> 'vim.Folder:group-v3177'
>
> 'vim.Folder:group-v188'

I have 3 folders on vSphere so I think my connection it's good but that's
absolutely not their names.

Here is my code :

views.py

    
    
    from __future__ import print_function
    from django.shortcuts import render
    from pyVim.connect import SmartConnect, Disconnect
    import ssl
    
    def home(request):
        s = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        s.verify_mode = ssl.CERT_NONE
        try:
            connect = SmartConnect(...)
        except:
            connect = SmartConnect(...)
        datacenter = connect.content.rootFolder.childEntity[0]
        vmsFolders = datacenter.vmFolder.childEntity
        Disconnect(connect)
        return render(request, 'vmware/home.html', {'vmsFolders':vmsFolders})
    

home.html

    
    
    <h1>VMware list</h1>
    {% for vmFolder in vmsFolders %}
    <div>
        <h3>{{ vmFolder }}</h3>
    </div>
    {% endfor %}
    

Can anybody help me to get the real names of my folders?


Answer: You need to specifically state you want the name, like this:

    
    
    vmFolders = datacenter.vmFolder.childEntity
    for folder in vmFolders:
        print(folder.name)
    

