source: trunk/packages/sipb-xen-database/client/usr/sbin/sipb-xen-lvcreate @ 330

Last change on this file since 330 was 142, checked in by tabbott, 17 years ago

throw error when disk creation fails

  • Property svn:executable set to *
File size: 813 bytes
Line 
1#!/usr/bin/env python
2
3from sipb_xen_database import *
4import sys
5import os.path
6from subprocess import call
7import re
8
9connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
10
11def check(b):
12    if not b:
13        exit(1)
14
15vg = "xenvg"
16for d in Disk.select():
17    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
18    machine = Machine.get(d.machine_id)
19    check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
20    lvname = machine.name + "_" + d.guest_device_name
21    if not os.path.exists("/dev/%s/%s" % (vg, lvname)):
22        # LV doesn't exist
23        print >>sys.stderr, "Creating LV %s..." % (lvname,)
24        rv = call(["lvcreate", "-L", str(d.size) + "M", "-n", lvname, vg])
25        if rv != 0:
26            print >>sys.stderr, "Error creating LV %s\n" %(lvname,)
27            sys.exit(1)
Note: See TracBrowser for help on using the repository browser.