X-Git-Url: http://git.onelab.eu/?p=nodemanager.git;a=blobdiff_plain;f=bootauth.py;h=19353f45d5c3064f211a3846732af099c11416f5;hp=a946db3432d5ff51bef5102eed3ae8a74af4e1e0;hb=HEAD;hpb=2e4fb420d60d9433082950338c97af61917b145d diff --git a/bootauth.py b/bootauth.py index a946db3..19353f4 100755 --- a/bootauth.py +++ b/bootauth.py @@ -1,16 +1,11 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -# Test script for obtaining a node session key. Usually, the Boot -# Manager obtains it, then writes it to /etc/planetlab/session. To -# generate a node key for a node, execute: -# -# AdmGenerateNodeConfFile(node_id) +# Obtaining a node session key. Usually, the Boot +# Manager obtains it, then writes it to /etc/planetlab/session. # # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id$ -# import os, sys import getopt @@ -26,35 +21,38 @@ def main(): # Help def usage(): - print "Usage: %s [OPTION]..." % sys.argv[0] - print "Options:" - print " -f, --config=FILE PLC configuration file (default: /etc/planetlab/plc_config)" - print " -n, --node-id=FILE Node ID (or file)" - print " -k, --key=FILE Node key (or file)" - print " --help This message" + print("Usage: %s [OPTION]..." % sys.argv[0]) + print("Options:") + print(" -f, --config=FILE PLC configuration file (default: /etc/planetlab/plc_config)") + print(" -n, --node-id=FILE Node ID (or file)") + print(" -k, --key=FILE Node key (or file)") + print(" --help This message") sys.exit(1) # Get options try: - (opts, argv) = getopt.getopt(sys.argv[1:], "n:k:h", - ["node=", "nodeid=", "node-id", "node_id", + (opts, argv) = getopt.getopt(sys.argv[1:], "f:n:k:h", + ["config=", "cfg=", "file=", + "node=", "nodeid=", "node-id", "node_id", "key=", "help"]) - except getopt.GetoptError, err: - print "Error: " + err.msg + except getopt.GetoptError as err: + print("Error: " + err.msg) usage() for (opt, optval) in opts: if opt == "-f" or opt == "--config" or opt == "--cfg" or opt == "--file": - config = optval + config = Config(optval) elif opt == "-n" or opt == "--node" or opt == "--nodeid" or opt == "--node-id" or opt == "--node_id": if os.path.exists(optval): - node_id = file(optval).read().strip() + with open(optval) as optfile: + node_id = optfile.read().strip() else: node_id = int(optval) elif opt == "-k" or opt == "--key": if os.path.exists(optval): - key = file(optval).read().strip() + with open(optval) as optfile: + key = optfile.read().strip() else: key = optval else: @@ -68,13 +66,13 @@ def main(): usage() # Authenticate as the Boot Manager would and get a session key - plc = PLCAPI(config.plc_api_uri, (node_id, key)) + plc = PLCAPI(config.plc_api_uri, config.cacert, (node_id, key)) session = plc.BootGetNodeDetails()['session'] - plc = PLCAPI(config.plc_api_uri, session) + plc = PLCAPI(config.plc_api_uri, config.cacert, session) assert session == plc.GetSession() - print session + print(session) if __name__ == '__main__': main()