четвъртък, 24 април 2014 г.

indexing vms on separate vmware ESXi servers

When there is no Enterprise license for ESXi there is usually more than one separate servers and if no proper documentation is kept you can easily forget where is your vm (on which hypervisor).

Here is a handy little python script that will show all vms on a list of hosts.
It uses pysphere for esx communication and yaml for config file. Also some commented parts that give more info if you uncomment.

getvms.py
#!/usr/bin/python

import yaml
from pysphere import *

def listvms(server,hv):
    vmlist = server.get_registered_vms()
    for i in vmlist:
        vm1 = server.get_vm_by_path(i)
        print ("%s -") % hv ,
        print vm1.get_properties()['name']



f = open('config.yaml')
config = yaml.load(f)
f.close()
hvlist = ['host1', 'host2', 'host3']
for hvserver in hvlist:
    server = VIServer()
    server.connect(hvserver, config["user"], config["pass"])
    #print "Connection established to host %s" % hvserver,
    #print server.get_server_type(), server.get_api_version()




    #vm1 = server.get_vm_by_path("[datastore1] cvs/cvs.vmx")
    """
    for i in vm1.get_properties():
        print i,
        print vm1.get_property(i)
    """

    listvms(server,hvserver)

    server.disconnect()


config.yaml
user: root
pass: passwordforuser

Няма коментари:

Публикуване на коментар