3 # Test script for obtaining a node session key. Usually, the Boot
4 # Manager obtains it, then writes it to /etc/planetlab/session. To
5 # generate a node key for a node, execute:
7 # AdmGenerateNodeConfFile(node_id)
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Copyright (C) 2006 The Trustees of Princeton University
18 from config import Config
19 from plcapi import PLCAPI
29 print "Usage: %s [OPTION]..." % sys.argv[0]
31 print " -f, --config=FILE PLC configuration file (default: /etc/planetlab/plc_config)"
32 print " -n, --node-id=FILE Node ID (or file)"
33 print " -k, --key=FILE Node key (or file)"
34 print " --help This message"
39 (opts, argv) = getopt.getopt(sys.argv[1:], "n:k:h",
40 ["node=", "nodeid=", "node-id", "node_id",
43 except getopt.GetoptError, err:
44 print "Error: " + err.msg
47 for (opt, optval) in opts:
48 if opt == "-f" or opt == "--config" or opt == "--cfg" or opt == "--file":
50 elif opt == "-n" or opt == "--node" or opt == "--nodeid" or opt == "--node-id" or opt == "--node_id":
51 if os.path.exists(optval):
52 node_id = file(optval).read().strip()
55 elif opt == "-k" or opt == "--key":
56 if os.path.exists(optval):
57 key = file(optval).read().strip()
66 if node_id is None or \
70 # Authenticate as the Boot Manager would and get a session key
71 plc = PLCAPI(config.plc_api_uri, (node_id, key))
72 session = plc.BootGetNodeDetails()['session']
74 plc = PLCAPI(config.plc_api_uri, session)
75 assert session == plc.GetSession()
79 if __name__ == '__main__':