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