3 # Test script for obtaining a node session key. Usually, the Boot
4 # Manager obtains it, then writes it to /etc/planetlab/session.
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2006 The Trustees of Princeton University
15 from config import Config
16 from plcapi import PLCAPI
26 print "Usage: %s [OPTION]..." % sys.argv[0]
28 print " -f, --config=FILE PLC configuration file (default: /etc/planetlab/plc_config)"
29 print " -n, --node-id=FILE Node ID (or file)"
30 print " -k, --key=FILE Node key (or file)"
31 print " --help This message"
36 (opts, argv) = getopt.getopt(sys.argv[1:], "f:n:k:h",
37 ["config=", "cfg=", "file=",
38 "node=", "nodeid=", "node-id", "node_id",
41 except getopt.GetoptError, err:
42 print "Error: " + err.msg
45 for (opt, optval) in opts:
46 if opt == "-f" or opt == "--config" or opt == "--cfg" or opt == "--file":
47 config = Config(optval)
48 elif opt == "-n" or opt == "--node" or opt == "--nodeid" or opt == "--node-id" or opt == "--node_id":
49 if os.path.exists(optval):
50 node_id = file(optval).read().strip()
53 elif opt == "-k" or opt == "--key":
54 if os.path.exists(optval):
55 key = file(optval).read().strip()
64 if node_id is None or \
68 # Authenticate as the Boot Manager would and get a session key
69 plc = PLCAPI(config.plc_api_uri, config.cacert, (node_id, key))
70 session = plc.BootGetNodeDetails()['session']
72 plc = PLCAPI(config.plc_api_uri, config.cacert, session)
73 assert session == plc.GetSession()
77 if __name__ == '__main__':