5 from subprocess import call, PIPE
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.
18 rv = call(["/usr/sbin/xm", "destroy", prefix + machine], stderr=PIPE)
20 if subcommand == "lvcreate-all":
21 from sipb_xen_database import *
23 connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
24 for d in Disk.select():
25 check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
26 machine = Machine.get(d.machine_id)
27 check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
28 lvname = prefix + machine.name + "_" + d.guest_device_name
29 if not os.path.exists("/dev/%s/%s" % (vg, lvname)):
31 print >>sys.stderr, "Creating LV %s..." % (lvname,)
32 rv = call(["/sbin/lvcreate", "-L", str(d.size) + "M", "-n", lvname, vg])
34 print >>sys.stderr, "Error creating LV %s\n" %(lvname,)
39 lvname = prefix + machine + "_" + disk
40 lvpath = "/dev/" + vg + "/" + lvname
41 if subcommand == "lvremove":
42 rv = call(["/sbin/lvremove", "--force", lvpath])
45 print >>sys.stderr, "Error removing LV %s\n" %(lvname,)
47 elif subcommand == "lvresize":
50 rv = call(["/sbin/lvresize", "-L", size + "M", lvpath])
52 print >>sys.stderr, "Error resizing LV %s\n" %(lvname,)
54 elif subcommand == "lvrename":
55 newmachine = sys.argv[4]
56 newlvname = prefix + newmachine + "_" + disk
59 rv = call(["/sbin/lvrename", vg, lvname, newlvname])
61 print >>sys.stderr, "Error renaming LV %s\n" %(lvname,)
63 elif subcommand == "lvcreate":
65 rv = call(["/sbin/lvcreate", "-L", size + "M", "-n", lvname, vg])
67 print >>sys.stderr, "Error creating LV %s\n" %(lvname,)