6 # Test script for obtaining a node session key. Usually, the Boot
7 # Manager obtains it, then writes it to /etc/planetlab/session.
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:], "f:n:k:h",
40 ["config=", "cfg=", "file=",
41 "node=", "nodeid=", "node-id", "node_id",
44 except getopt.GetoptError, err:
45 print "Error: " + err.msg
48 for (opt, optval) in opts:
49 if opt == "-f" or opt == "--config" or opt == "--cfg" or opt == "--file":
50 config = Config(optval)
51 elif opt == "-n" or opt == "--node" or opt == "--nodeid" or opt == "--node-id" or opt == "--node_id":
52 if os.path.exists(optval):
53 node_id = file(optval).read().strip()
56 elif opt == "-k" or opt == "--key":
57 if os.path.exists(optval):
58 key = file(optval).read().strip()
67 if node_id is None or \
71 # Authenticate as the Boot Manager would and get a session key
72 plc = PLCAPI(config.plc_api_uri, config.cacert, (node_id, key))
73 session = plc.BootGetNodeDetails()['session']
75 plc = PLCAPI(config.plc_api_uri, config.cacert, session)
76 assert session == plc.GetSession()
80 if __name__ == '__main__':