Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- service_instance = None
- vcenter_host = "XYZ"
- vcenter_port = X
- vcenter_username = "XYZ"
- vcenter_password = "XYZ"
- vmName = "VM NAME";
- try:
- #For trying to connect to VM
- service_instance = connect.SmartConnect(host=vcenter_host, user=vcenter_username, pwd=vcenter_password, port=vcenter_port, sslContext=context)
- atexit.register(connect.Disconnect, service_instance)
- content = service_instance.RetrieveContent()
- container = content.rootFolder # starting point to look into
- viewType = [vim.VirtualMachine] # object types to look for
- recursive = True # whether we should look into it recursively
- containerView = content.viewManager.CreateContainerView(
- container, viewType, recursive)
- #getting all the VM's from the connection
- children = containerView.view
- #going 1 by 1 to every VM
- for child in children:
- vm = child.summary.config.name
- #check for the VM
- if(vm == vmName):
- vmSummary = child.summary
- #get the diskInfo of the selected VM
- info = vmSummary.vm.guest.disk
- #check for the freeSpace property of each disk
- for each in info:
- #To get the freeSPace in GB's
- diskFreeSpace = each.freeSpace/1024/1024/1024
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement