Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #Idea here is to use vmkfstool to fix all the disk images when we have a crash
- import getpass
- import pexpect
- import time
- import re
- DIRECTORY='/vmfs/volumes/datastore1/Images'
- USER='root'
- ESXI='10.0.0.6'
- def matchme(strg, pattern):
- search=re.compile(pattern).search
- return bool(search(strg))
- print "Enter user %s " % USER
- password = getpass.getpass('password: ')
- SSHTOESXI='ssh %s@%s' % (USER,ESXI)
- print "Logging into ESXI server: %s" % ESXI
- telconn = pexpect.spawn(SSHTOESXI)
- time.sleep(3)
- telconn.expect("Password:")
- telconn.sendline(password)
- telconn.expect("root@esxi:")
- telconn.sendline("cd %s" % DIRECTORY)
- telconn.expect("Images]")
- print "Getting list of VMDK files..."
- telconn.sendline("ls *.vmdk | awk {'print $1'}")
- telconn.expect("Images]")
- filelist=[]
- for line in telconn.before.splitlines():
- linecheck=matchme(line, "vmdk")
- #matchme is boolean. If true, we have a legitimate line to append
- if linecheck:
- filelist.append(line)
- print "Running vmkfstools on each vmdk file..."
- for x in filelist:
- print "Running vmfstools repair on %s" % str(x)
- telconn.sendline("vmkfstools -x repair %s" % str(x))
- telconn.expect("Images]")
- #Close our connection
- telconn.sendline("exit")
- print "Complete!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement