4 # This wrapper implements the Geni Registry and Slice Interfaces on PLC.
5 # Depending on command line options, it starts some combination of a
6 # Registry, an Aggregate Manager, and a Slice Manager.
8 # There are several items that need to be done before starting the wrapper
11 # NOTE: Many configuration settings, including the PLC maintenance account
12 # credentials, URI of the PLCAPI, and PLC DB URI and admin credentials are initialized
13 # from your MyPLC configuration (/etc/planetlab/plc_config*). Please make sure this information
14 # is up to date and accurate.
16 # 1) Import the existing planetlab database, creating the
17 # appropriate geni records. This is done by running the "import.py" tool.
19 # 2) Create a "trusted_roots" directory and place the certificate of the root
20 # authority in that directory. Given the defaults in import.py, this
21 # certificate would be named "planetlab.gid". For example,
23 # mkdir trusted_roots; cp authorities/planetlab.gid trusted_roots/
25 # TODO: Can all three servers use the same "registry" certificate?
28 # TCP ports for the three servers
34 from optparse import OptionParser
36 from geni.util.hierarchy import Hierarchy
37 from geni.util.trustedroot import TrustedRootList
38 from geni.util.cert import Keypair, Certificate
39 from geni.registry import Registry
40 from geni.aggregate import Aggregate
41 from geni.slicemgr import SliceMgr
50 # Generate command line parser
51 parser = OptionParser(usage="plc [options]")
52 parser.add_option("-r", "--registry", dest="registry", action="store_true",
53 help="run registry server", default=False)
54 parser.add_option("-s", "--slicemgr", dest="sm", action="store_true",
55 help="run slice manager", default=False)
56 parser.add_option("-a", "--aggregate", dest="am", action="store_true",
57 help="run aggregate manager", default=False)
58 parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
59 help="verbose mode", default=False)
60 (options, args) = parser.parse_args()
62 key_file = "server.key"
63 cert_file = "server.cert"
65 if (os.path.exists(key_file)) and (not os.path.exists(cert_file)):
66 # If private key exists and cert doesnt, recreate cert
67 key = Keypair(filename=key_file)
68 cert = Certificate(subject="registry")
69 cert.set_issuer(key=key, subject="registry")
72 cert.save_to_file(cert_file)
74 elif (not os.path.exists(key_file)) or (not os.path.exists(cert_file)):
75 # if no key is specified, then make one up
76 key = Keypair(create=True)
77 key.save_to_file(key_file)
78 cert = Certificate(subject="registry")
79 cert.set_issuer(key=key, subject="registry")
82 cert.save_to_file(cert_file)
84 AuthHierarchy = Hierarchy()
86 TrustedRoots = TrustedRootList()
88 # start registry server
89 if (options.registry):
90 r = Registry("", registry_port, key_file, cert_file)
91 r.trusted_cert_list = TrustedRoots.get_list()
92 r.hierarchy = AuthHierarchy
95 # start aggregate manager
97 a = Aggregate("", aggregate_port, key_file, cert_file)
98 a.trusted_cert_list = TrustedRoots.get_list()
101 # start slice manager
103 s = SliceMgr("", slicemgr_port, key_file, cert_file)
104 s.trusted_cert_list = TrustedRoots.get_list()
107 if __name__ == "__main__":