5 from subprocess import call
14 subcommand = sys.argv[1]
17 lvname = prefix + machine + "_" + disk
18 lvpath = "/dev/" + vg + "/" + lvname
20 def ensureoff(machine):
21 # Make sure the machine is off, but we don't care about errors if it is already off.
22 rv = call(["/usr/sbin/xm", "destroy", prefix + machine]
24 if subcommand == "lvremove":
25 rv = call(["/sbin/lvremove", "--force", lvpath])
28 print >>sys.stderr, "Error removing LV %s\n" %(lvname,)
30 else if subcommand == "lvresize":
33 rv = call(["/sbin/lvresize", "-L", size + "M", lvpath])
35 print >>sys.stderr, "Error resizing LV %s\n" %(lvname,)
37 else if subcommand == "lvrename":
38 newmachine = sys.argv[4]
39 newlvname = prefix + newmachine + "_" + disk
42 rv = call(["/sbin/lvrename", vg, lvname, newlvname])
44 print >>sys.stderr, "Error renaming LV %s\n" %(lvname,)
46 else if subcommand == "lvcreate":
48 rv = call(["/sbin/lvcreate", "-L", size + "M", "-n", lvname, vg])
50 print >>sys.stderr, "Error creating LV %s\n" %(lvname,)
53 else if subcommand == "lvcreate-all":
54 from sipb_xen_database import *
56 connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
57 for d in Disk.select():
58 check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
59 machine = Machine.get(d.machine_id)
60 check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
61 lvname = machine.name + "_" + d.guest_device_name
62 if not os.path.exists("/dev/%s/%s" % (vg, lvname)):
64 print >>sys.stderr, "Creating LV %s..." % (lvname,)
65 rv = call(["/sbin/lvcreate", "-L", str(d.size) + "M", "-n", lvname, vg])
67 print >>sys.stderr, "Error creating LV %s\n" %(lvname,)