xen-drbd

diff xen-drbd-install.py @ 37:e80bdf496aa2

1. --network (-n) option; topology name is not hardcoded since present
2. fix for incorrect processing of the paramater spicified in form like drbd8=sda1 in xen-drbd-install
author igor@manas.xt.vpn
date Mon Sep 15 10:03:24 2008 +0300 (2008-09-15)
parents 44efea4507ac
children 30671fe7fd79
line diff
     1.1 --- a/xen-drbd-install.py	Sat Aug 30 11:14:50 2008 +0300
     1.2 +++ b/xen-drbd-install.py	Mon Sep 15 10:03:24 2008 +0300
     1.3 @@ -1,13 +1,13 @@
     1.4  #!/usr/bin/python
     1.5  
     1.6 -import sys,re
     1.7 +import sys,re,getopt
     1.8  sys.path.append('/etc/xen')
     1.9  
    1.10  def show_usage():
    1.11      print """
    1.12  Usage:
    1.13 -    xen-drbd-install <network> <command>            (to view)
    1.14 -    xen-drbd-install <network> <command> | sh -s    (to run)
    1.15 +    xen-drbd-install [options] <command>            (to view)
    1.16 +    xen-drbd-install [options] <command> | sh -s    (to run)
    1.17  
    1.18      <network> is the name of the file, which contains network description
    1.19  
    1.20 @@ -16,20 +16,43 @@
    1.21      make-domains
    1.22      make-bridges
    1.23      make-links
    1.24 +
    1.25 +Options:
    1.26 +    --help         (-h)   -- show usage information
    1.27 +    --network=name (-n)   -- the network descriptions is in the file name.py (default: network.py)
    1.28  """
    1.29  
    1.30 -if len(sys.argv) != 3:
    1.31 +
    1.32 +
    1.33 +network='network'
    1.34 +try:
    1.35 +    opts, args = getopt.getopt(sys.argv[1:], "hn:", ["help", "network="])
    1.36 +except getopt.GetoptError, err:
    1.37 +    # print help information and exit:
    1.38 +    print str(err) # will print something like "option -a not recognized"
    1.39 +    usage()
    1.40 +    sys.exit(2)
    1.41 +
    1.42 +for o, a in opts:
    1.43 +    if o in ("-h", "--help"):
    1.44 +        show_usage()
    1.45 +        sys.exit()
    1.46 +    elif o in ("-n", "--network"):
    1.47 +        network = a
    1.48 +    else:
    1.49 +        assert False, "unhandled option"
    1.50 +
    1.51 +if len(args) != 1:
    1.52      show_usage()
    1.53      sys.exit(1)
    1.54  
    1.55 -
    1.56 -network=sys.argv[1]
    1.57  try:
    1.58      exec 'from %s import * ' % (network)
    1.59  except ImportError:
    1.60 -    print "Can't find or interpret module %s with topology description" %(network)
    1.61 +    print "Can't find or interpret module <%s> with topology description" %(network)
    1.62      sys.exit(1)
    1.63  
    1.64 +
    1.65  drbd_base_port=7790
    1.66  meta_disk='/dev/%s/meta'%lvm_vg_name
    1.67  drbd_device={}
    1.68 @@ -83,7 +106,7 @@
    1.69  
    1.70      for dom in domains:
    1.71          for disk in disk_table[dom]:
    1.72 -            drbd_number=int(re.compile('drbd').sub('',disk.split(':')[0]))
    1.73 +            drbd_number=int(re.compile('drbd').sub('',(disk.split(':')[0]).split('=')[0] ))
    1.74              resource=disk.split(':')[1]
    1.75              disk="/dev/%s/%s" % (lvm_vg_name,resource)
    1.76  
    1.77 @@ -345,8 +368,8 @@
    1.78  
    1.79  #make_all_system()
    1.80  
    1.81 -if len(sys.argv) > 1:
    1.82 -    command = sys.argv[2]
    1.83 +if len(args) > 0:
    1.84 +    command = args[0]
    1.85      if command == 'make-drbd':
    1.86          make_drbd()
    1.87      elif command == 'make-domains':