3 # 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
13 from config import Config
14 from plcapi import PLCAPI
24 print "Usage: %s [OPTION]..." % sys.argv[0]
26 print " -f, --config=FILE PLC configuration file (default: /etc/planetlab/plc_config)"
27 print " -n, --node-id=FILE Node ID (or file)"
28 print " -k, --key=FILE Node key (or file)"
29 print " --help This message"
34 (opts, argv) = getopt.getopt(sys.argv[1:], "f:n:k:h",
35 ["config=", "cfg=", "file=",
36 "node=", "nodeid=", "node-id", "node_id",
39 except getopt.GetoptError, err:
40 print "Error: " + err.msg
43 for (opt, optval) in opts:
44 if opt == "-f" or opt == "--config" or opt == "--cfg" or opt == "--file":
45 config = Config(optval)
46 elif opt == "-n" or opt == "--node" or opt == "--nodeid" or opt == "--node-id" or opt == "--node_id":
47 if os.path.exists(optval):
48 node_id = file(optval).read().strip()
51 elif opt == "-k" or opt == "--key":
52 if os.path.exists(optval):
53 key = file(optval).read().strip()
62 if node_id is None or \
66 # Authenticate as the Boot Manager would and get a session key
67 plc = PLCAPI(config.plc_api_uri, config.cacert, (node_id, key))
68 session = plc.BootGetNodeDetails()['session']
70 plc = PLCAPI(config.plc_api_uri, config.cacert, session)
71 assert session == plc.GetSession()
75 if __name__ == '__main__':