5 from subprocess import call, PIPE, Popen
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],
21 if subcommand == "lvcreate-all":
22 from sipb_xen_database import *
24 connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
25 for d in Disk.select():
26 check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
27 machine = Machine.get(d.machine_id)
28 check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
29 lvname = prefix + machine.name + "_" + d.guest_device_name
30 if not os.path.exists("/dev/%s/%s" % (vg, lvname)):
32 print >>sys.stderr, "Creating LV %s..." % (lvname,)
33 rv = call(["/sbin/lvcreate", "-L", str(d.size) + "M", "-n", lvname, vg])
35 print >>sys.stderr, "Error creating LV %s\n" %(lvname,)
40 lvname = prefix + machine + "_" + disk
41 lvpath = "/dev/" + vg + "/" + lvname
42 if subcommand == "lvremove":
43 rv = call(["/sbin/lvremove", "--force", lvpath])
46 print >>sys.stderr, "Error removing LV %s\n" %(lvname,)
48 elif subcommand == "lvresize":
51 p = Popen(["/sbin/lvresize", "-L", size + "M", lvpath],
52 stdin=PIPE, stderr=PIPE)
55 if p.wait() != 0 and 'matches existing size' not in err:
56 print >> sys.stderr, "Error resizing LV %s:\n" %(lvname,)
57 print >> sys.stderr, err
59 print >> sys.stderr, err
60 elif subcommand == "lvrename":
61 newmachine = sys.argv[4]
62 newlvname = prefix + newmachine + "_" + disk
65 rv = call(["/sbin/lvrename", vg, lvname, newlvname])
67 print >>sys.stderr, "Error renaming LV %s\n" %(lvname,)
69 elif subcommand == "lvcreate":
71 rv = call(["/sbin/lvcreate", "-L", size + "M", "-n", lvname, vg])
73 print >>sys.stderr, "Error creating LV %s\n" %(lvname,)