Whamcloud - gitweb
e691423d6c9667dacf986a2cd9ae3c5dcbbdbba1
[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 import Lustre
35
36 lactive_options = [
37     ('ldapurl',"LDAP server URL", Lustre.Options.PARAM,
38      "ldap://localhost"),
39     ('config', "Cluster config name used for LDAP query", Lustre.Options.PARAM),
40     ('group', "The group of devices to update", Lustre.Options.PARAM),
41     ('active', "The active node name", Lustre.Options.PARAM),
42     ]
43
44 def fatal(*args):
45     msg = string.join(map(str,args))
46     print "! " + msg
47     sys.exit(1)
48
49
50 cl = Lustre.Options("lactive","", lactive_options)
51 config, args = cl.parse(sys.argv[1:])
52
53 if not (config.group or config.active):
54     fatal("Must specify both  group and active node.")
55
56 if not config.config:
57     fatal("Missing config")
58     
59 base = "config=%s,fs=lustre" % (config.config,)
60 db = Lustre.LustreDB_LDAP('', {}, base=base, pw = "secret",
61                           url = config.ldapurl)
62
63 active_node = db.lookup_name(config.active)
64 if not active_node:
65     fatal(config.active, "node not found in database.")
66
67 devices =  db.get_group(config.group)
68 if len(devices) < 0:
69     fatal("no devices found for group", config.group)
70
71 # for all devices in group
72   # lookup device in active node
73   # update the active device 
74 for tgtuuid in devices:
75     active_uuid = db.get_active_dev(tgtuuid)
76     new_active_uuid = active_node.get_tgt_dev(tgtuuid)
77     if active_uuid != new_active_uuid:
78         print ("%s: changing active %s to %s:%s"
79                % (tgtuuid, active_uuid,
80                   config.active, new_active_uuid))
81         db.update_active(tgtuuid, new_active_uuid)
82
83
84
85
86