plabdiscover.in 2.37 KB
Newer Older
Kirk Webb's avatar
Kirk Webb committed
1
#!/usr/local/bin/python
Kirk Webb's avatar
Kirk Webb committed
2 3
# -*- python -*-
#
4
# Copyright (c) 2000-2003, 2008 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Kirk Webb's avatar
Kirk Webb committed
24
#
Kirk Webb's avatar
Kirk Webb committed
25 26 27 28 29 30 31

import sys
sys.path.append("@prefix@/lib")
import libplab
from libtestbed import *

def usage(me):
32
    print "Usage: %s [ -vd ] [ -n ] [ -g ] [<plc>] ... [<plc>]" % me
33
    print "    (where <plc> is the name or id of a plc in the db)"
Kirk Webb's avatar
Kirk Webb committed
34 35 36 37 38
    sys.exit(1)


def main(args):
    me = args[0]
Kirk Webb's avatar
Kirk Webb committed
39
    parser = TBParser()
40 41 42 43 44 45

    parser.add_option("-n", "--nodes",dest="nodes",default=False,
                      action="store_true",help="Only synch node entries.")
    parser.add_option("-g", "--nodegroups",dest="nodegroups",default=False,
                      action="store_true",help="Only synch node group entries.")
    
46
    (options,cargs) = parser.parse_args()
Kirk Webb's avatar
Kirk Webb committed
47

David Johnson's avatar
David Johnson committed
48 49 50
    libplab.debug = options.debug
    libplab.verbose = options.verbose

51 52 53 54 55 56
    both = True
    if options.nodes and options.nodegroups:
        both = True
    elif options.nodes or options.nodegroups:
        both = False

Kirk Webb's avatar
Kirk Webb committed
57
    plab = libplab.Plab()
58 59

    plcids = []    
60
    if len(cargs) > 0:
61 62
        # Only do the args...
        plcids = cargs
63 64 65 66
    else:
        # Grab all the PLCs we know about and do for all...
        plcs = plab.getPLCs()
        for (name,idx) in plcs:
67
            plcids.append(name)
68 69
            pass
        pass
70 71 72 73 74 75 76 77 78

    for plc in plcids:
        if options.nodes or both:
            print "Updating node entries at %s." % plc
            plab.updateNodeEntries(plc)
        if options.nodegroups or both:
            print "Updating node group entries at %s." % plc
            plab.updateNodeGroupEntries(plc)
        pass
Kirk Webb's avatar
Kirk Webb committed
79 80 81 82
    return

if __name__ == "__main__":
    main(sys.argv)