Whamcloud - gitweb
merge b_devel into HEAD (20030703)
[fs/lustre-release.git] / lustre / utils / lactive
1 #!/usr/bin/env python
2 #
3 #  Copyright (C) 2002 Cluster File Systems, Inc.
4 #   Author: Robert Read <rread@clusterfs.com>
5 #   This file is part of Lustre, http://www.lustre.org.
6 #
7 #   Lustre is free software; you can redistribute it and/or
8 #   modify it under the terms of version 2 of the GNU General Public
9 #   License as published by the Free Software Foundation.
10 #
11 #   Lustre is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with Lustre; if not, write to the Free Software
18 #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #
20
21 # For all the OST/MDSs that are primary on the --primary node, set
22 # them to be active on --active if that OST is available on --active.
23 #
24 # Make the active node the active node for all devices it shares with the
25 # old. The bulk of this code is for figuring out which devices to
26 # change, and what to change them to.
27
28 # XXX add error checking
29 # XXX make this code less ugly
30
31 import sys, getopt, types
32 import string, os
33 import ldap
34 PYMOD_DIR = "/usr/lib/lustre/python"
35
36 def development_mode():
37     base = os.path.dirname(sys.argv[0])
38     if os.access(base+"/Makefile.am", os.R_OK):
39         return 1
40     return 0
41
42 if not development_mode():
43     sys.path.append(PYMOD_DIR)
44
45 import Lustre
46
47 lactive_options = [
48     ('ldapurl',"LDAP server URL", Lustre.Options.PARAM,
49      "ldap://localhost"),
50     ('config', "Cluster config name used for LDAP query", Lustre.Options.PARAM),
51     ('group', "The group of devices to update", Lustre.Options.PARAM),
52     ('active', "The active node name", Lustre.Options.PARAM),
53     ]
54
55 def fatal(*args):
56     msg = string.join(map(str,args))
57     print "! " + msg
58     sys.exit(1)
59
60
61 cl = Lustre.Options("lactive","", lactive_options)
62 config, args = cl.parse(sys.argv[1:])
63
64 if not (config.group or config.active):
65     fatal("Must specify both  group and active node.")
66
67 if not config.config:
68     fatal("Missing config")
69     
70 base = "config=%s,fs=lustre" % (config.config,)
71 db = Lustre.LustreDB_LDAP('', {}, base=base, pw = "secret",
72                           url = config.ldapurl)
73
74 active_node = db.lookup_name(config.active)
75 if not active_node:
76     fatal(config.active, "node not found in database.")
77
78 devices =  db.get_group(config.group)
79 if len(devices) < 0:
80     fatal("no devices found for group", config.group)
81
82 # for all devices in group
83   # lookup device in active node
84   # update the active device 
85 for tgtuuid in devices:
86     active_uuid = db.get_active_dev(tgtuuid)
87     new_active_uuid = active_node.get_tgt_dev(tgtuuid)
88     if active_uuid != new_active_uuid:
89         print ("%s: changing active %s to %s:%s"
90                % (tgtuuid, active_uuid,
91                   config.active, new_active_uuid))
92         db.update_active(tgtuuid, new_active_uuid)
93
94
95
96
97