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.
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.
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.
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.
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.
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.
28 # XXX add error checking
29 # XXX make this code less ugly
31 import sys, getopt, types
34 PYMOD_DIR = "/usr/lib/lustre/python"
36 def development_mode():
37 base = os.path.dirname(sys.argv[0])
38 if os.access(base+"/Makefile.am", os.R_OK):
42 if not development_mode():
43 sys.path.append(PYMOD_DIR)
48 ('ldapurl',"LDAP server URL", Lustre.Options.PARAM,
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),
56 msg = string.join(map(str,args))
61 cl = Lustre.Options("lactive","", lactive_options)
62 config, args = cl.parse(sys.argv[1:])
64 if not (config.group or config.active):
65 fatal("Must specify both group and active node.")
68 fatal("Missing config")
70 base = "config=%s,fs=lustre" % (config.config,)
71 db = Lustre.LustreDB_LDAP('', {}, base=base, pw = "secret",
74 active_node = db.lookup_name(config.active)
76 fatal(config.active, "node not found in database.")
78 devices = db.get_group(config.group)
80 fatal("no devices found for group", config.group)
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)