Last active
August 29, 2015 14:04
-
-
Save krazybean/19d1ebacc8a42238f55c to your computer and use it in GitHub Desktop.
Useful for finding attached blocks for openvz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import commands | |
command_list = "sudo vzlist -aH | awk '{print $1}'" | |
vzid = commands.getoutput(command_list) | |
for vz in vzid.split('\n'): | |
print "VZID: {0}".format(vz) | |
command_ext_storage = """sudo cat /etc/vz/conf/{vz}.ext_storage""".format(vz=vz) | |
config_output = commands.getoutput(command_ext_storage) | |
config = config_output.split(' ')[13].strip('"').rstrip('",') | |
command_mount = "sudo ls -la /dev/disk/by-path | grep {0}".format(config) | |
mountpoint = commands.getoutput(command_mount) | |
mount = mountpoint.split('/')[len(mountpoint.split('/')) -1:][0] | |
if len(mount) > 1: | |
command_blockstart = "sudo ls -la /dev/{0}".format(mount) | |
block = commands.getoutput(command_blockstart) | |
command_actualblock = "sudo cat /etc/vz/conf/{0}.conf | grep DEVICES".format(vz) | |
ablock = commands.getoutput(command_actualblock) | |
print "Mapped Blocks: {0} {1}".format(ablock.split(':')[1], ablock.split(':')[2]) | |
print "Expected Blocks: {0} {1}".format(block.split(' ')[4].strip(','), block.split(' ')[5]) | |
a1, a2, b1, b2 = ablock.split(':')[1], ablock.split(':')[2], block.split(' ')[4].strip(','), block.split(' ')[5] | |
if a1 not in b1 or a2 not in b2: | |
print "**Error: No match found" | |
try: | |
if sys.argv[1] == '--print-fix': | |
print """---- How to fix it ----""" | |
print """rm /var/lib/vz/private/{0}/dev/vdb""".format(vz) | |
print """mknod /var/lib/vz/private/{0}/dev/vdb b {1} {2}""".format(vz, b1, b2) | |
print """vzctl set {0} --save --devices b:{1}:{2}:rw""".format(vz, b1, b2) | |
except: | |
pass | |
print "--- end ---" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment