Advertisement
Guest User

Untitled

a guest
May 9th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #Idea here is to use vmkfstool to fix all the disk images when we have a crash
  4.  
  5. import getpass
  6. import pexpect
  7. import time
  8. import re
  9.  
  10. DIRECTORY='/vmfs/volumes/datastore1/Images'
  11. USER='root'
  12. ESXI='10.0.0.6'
  13.  
  14.  
  15. def matchme(strg, pattern):
  16. search=re.compile(pattern).search
  17. return bool(search(strg))
  18.  
  19.  
  20. print "Enter user %s " % USER
  21. password = getpass.getpass('password: ')
  22.  
  23. SSHTOESXI='ssh %s@%s' % (USER,ESXI)
  24.  
  25. print "Logging into ESXI server: %s" % ESXI
  26.  
  27. telconn = pexpect.spawn(SSHTOESXI)
  28. time.sleep(3)
  29. telconn.expect("Password:")
  30. telconn.sendline(password)
  31. telconn.expect("root@esxi:")
  32. telconn.sendline("cd %s" % DIRECTORY)
  33. telconn.expect("Images]")
  34. print "Getting list of VMDK files..."
  35. telconn.sendline("ls *.vmdk | awk {'print $1'}")
  36. telconn.expect("Images]")
  37. filelist=[]
  38. for line in telconn.before.splitlines():
  39. linecheck=matchme(line, "vmdk")
  40. #matchme is boolean. If true, we have a legitimate line to append
  41. if linecheck:
  42. filelist.append(line)
  43. print "Running vmkfstools on each vmdk file..."
  44. for x in filelist:
  45. print "Running vmfstools repair on %s" % str(x)
  46. telconn.sendline("vmkfstools -x repair %s" % str(x))
  47. telconn.expect("Images]")
  48. #Close our connection
  49. telconn.sendline("exit")
  50. print "Complete!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement