Guest User

Untitled

a guest
Nov 9th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import atexit
  2. import argparse
  3. import getpass
  4.  
  5. from pyVim import connect
  6.  
  7.  
  8. def get_args():
  9. parser = argparse.ArgumentParser()
  10.  
  11. parser.add_argument('-s', '--host',
  12. required=True,
  13. action='store',
  14. help='Remote host to connect to')
  15.  
  16. parser.add_argument('-o', '--port',
  17. required=False,
  18. action='store',
  19. help="port to use, default 443", default=443)
  20.  
  21. parser.add_argument('-u', '--user',
  22. required=True,
  23. action='store',
  24. help='User name to use when connecting to host')
  25.  
  26. parser.add_argument('-p', '--password',
  27. required=False,
  28. action='store',
  29. help='Password to use when connecting to host')
  30.  
  31. parser.add_argument('-d', '--uuid',
  32. required=True,
  33. action='store',
  34. help='Instance UUID of the VM to look for.')
  35.  
  36. args = parser.parse_args()
  37. if args.password is None:
  38. args.password = getpass.getpass(
  39. prompt='Enter password for host %s and user %s: ' %
  40. (args.host, args.user))
  41.  
  42. args = parser.parse_args()
  43.  
  44. return args
  45.  
  46. args = get_args()
  47.  
  48. # form a connection...
  49. si = connect.SmartConnect(host=args.host, user=args.user, pwd=args.password,
  50. port=args.port)
  51.  
  52.  
  53. atexit.register(connect.Disconnect, si)
  54.  
  55.  
  56. search_index = si.content.searchIndex
  57. vm = search_index.FindByUuid(None, args.uuid, True, True)
  58.  
  59. if vm is None:
  60. print("Could not find virtual machine '{0}'".format(args.uuid))
  61. exit(1)
  62.  
  63.  
  64. print("Found Virtual Machine")
  65. details = {'name': vm.summary.config.name,
  66. 'instance UUID': vm.summary.config.instanceUuid,
  67. 'bios UUID': vm.summary.config.uuid,
  68. 'path to VM': vm.summary.config.vmPathName,
  69. 'guest OS id': vm.summary.config.guestId,
  70. 'guest OS name': vm.summary.config.guestFullName,
  71. 'host name': vm.runtime.host.name,
  72. 'last booted timestamp': vm.runtime.bootTime,
  73. }
  74.  
  75. for name, value in details.items():
  76. print("{0:{width}{base}}: {1}".format(name, value, width=25, base='s'))
Add Comment
Please, Sign In to add comment