Advertisement
Guest User

Untitled

a guest
Aug 10th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. service_instance = None
  2. vcenter_host = "XYZ"
  3. vcenter_port = X
  4. vcenter_username = "XYZ"
  5. vcenter_password = "XYZ"
  6. vmName = "VM NAME";
  7. try:
  8. #For trying to connect to VM
  9. service_instance = connect.SmartConnect(host=vcenter_host, user=vcenter_username, pwd=vcenter_password, port=vcenter_port, sslContext=context)
  10.  
  11. atexit.register(connect.Disconnect, service_instance)
  12.  
  13. content = service_instance.RetrieveContent()
  14.  
  15. container = content.rootFolder # starting point to look into
  16. viewType = [vim.VirtualMachine] # object types to look for
  17. recursive = True # whether we should look into it recursively
  18. containerView = content.viewManager.CreateContainerView(
  19. container, viewType, recursive)
  20. #getting all the VM's from the connection
  21. children = containerView.view
  22. #going 1 by 1 to every VM
  23. for child in children:
  24. vm = child.summary.config.name
  25. #check for the VM
  26. if(vm == vmName):
  27. vmSummary = child.summary
  28. #get the diskInfo of the selected VM
  29. info = vmSummary.vm.guest.disk
  30. #check for the freeSpace property of each disk
  31. for each in info:
  32. #To get the freeSPace in GB's
  33. diskFreeSpace = each.freeSpace/1024/1024/1024
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement