Ejemplo n.º 1
0
from pysphere import VIServer, VITask, VIProperty
from pysphere.resources import VimService_services as VI

from pprint import pprint

HOST = "my esxi server"
USER = "******"
PASSWORD = "******"
DATASTORE = "datastore1"  #WHERE THE DISK WILL BE CREATED AT
VM_NAME = "vm-test-name"

folder = "vm-test-name"

server = VIServer()
server.connect(HOST, USER, PASSWORD)
#th = server.get_task_history_collector(entity='all', recursion='all')

vm = server.get_vm_by_name(VM_NAME)
th = server.get_task_history_collector(entity=vm._mor, recursion='all')

#get the most recent tasks
tasks = th.get_latest_tasks()
for t in tasks:
    try:
        print t.get_info().name, t.get_state()
    except:
        #some tasks may be old enough to be removed
        #so you won't be able to get its info
        pass