source: trunk/packages/sipb-xen-remctl-auto/sipb-xen-remctl-auto/files/usr/sbin/sipb-xen-lvm @ 174

Last change on this file since 174 was 174, checked in by ecprice, 17 years ago

Actually suppress the error, without suppressing code errors.

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/usr/bin/env python
2
3import sys
4import os.path
5from subprocess import call, PIPE
6
7def check(b):
8    if not b:
9        exit(1)
10
11vg = "xenvg"
12prefix = "d_"
13
14subcommand = sys.argv[1]
15
16def 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)
19
20if subcommand == "lvcreate-all":
21    from sipb_xen_database import *
22    import re
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)):
30            # LV doesn't exist
31            print >>sys.stderr, "Creating LV %s..." % (lvname,)
32            rv = call(["/sbin/lvcreate", "-L", str(d.size) + "M", "-n", lvname, vg])
33            if rv != 0:
34                print >>sys.stderr, "Error creating LV %s\n" %(lvname,)
35                sys.exit(1)
36else:
37    machine = sys.argv[2]
38    disk = sys.argv[3]
39    lvname = prefix + machine + "_" + disk
40    lvpath = "/dev/" + vg + "/" + lvname
41if subcommand == "lvremove":
42    rv = call(["/sbin/lvremove", "--force", lvpath])
43    ensureoff(machine)
44    if rv != 0:
45        print >>sys.stderr, "Error removing LV %s\n" %(lvname,)
46        sys.exit(1)
47elif subcommand == "lvresize":
48    size = sys.argv[4]
49    ensureoff(machine)
50    rv = call(["/sbin/lvresize", "-L", size + "M", lvpath])
51    if rv != 0:
52        print >>sys.stderr, "Error resizing LV %s\n" %(lvname,)
53        sys.exit(1)
54elif subcommand == "lvrename":
55    newmachine = sys.argv[4]
56    newlvname = prefix + newmachine + "_" + disk
57    ensureoff(machine)
58    ensureoff(newmachine)   
59    rv = call(["/sbin/lvrename", vg, lvname, newlvname])
60    if rv != 0:
61        print >>sys.stderr, "Error renaming LV %s\n" %(lvname,)
62        sys.exit(1)
63elif subcommand == "lvcreate":
64    size = sys.argv[4]
65    rv = call(["/sbin/lvcreate", "-L", size + "M", "-n", lvname, vg])
66    if rv != 0:
67        print >>sys.stderr, "Error creating LV %s\n" %(lvname,)
68        sys.exit(1)
69   
70
Note: See TracBrowser for help on using the repository browser.