5 # This wrapper implements the Geni Registry and Slice Interfaces on PLC.
6 # Depending on command line options, it starts some combination of a
7 # Registry, an Aggregate Manager, and a Slice Manager.
9 # There are several items that need to be done before starting the wrapper
12 # NOTE: Many configuration settings, including the PLC maintenance account
13 # credentials, URI of the PLCAPI, and PLC DB URI and admin credentials are initialized
14 # from your MyPLC configuration (/etc/planetlab/plc_config*). Please make sure this information
15 # is up to date and accurate.
17 # 1) Import the existing planetlab database, creating the
18 # appropriate geni records. This is done by running the "gimport.py" tool.
20 # 2) Create a "trusted_roots" directory and place the certificate of the root
21 # authority in that directory. Given the defaults in gimport.py, this
22 # certificate would be named "planetlab.gid". For example,
24 # mkdir trusted_roots; cp authorities/planetlab.gid trusted_roots/
26 # TODO: Can all three servers use the same "registry" certificate?
29 # TCP ports for the three servers
35 from optparse import OptionParser
37 from geni.util.hierarchy import Hierarchy
38 from geni.util.trustedroot import TrustedRootList
39 from geni.util.cert import Keypair, Certificate
40 from geni.util.config import Config
41 from geni.registry import Registry
42 from geni.aggregate import Aggregate
43 from geni.slicemgr import SliceMgr
45 # after http://www.erlenstar.demon.co.uk/unix/faq_2.html
47 """Daemonize the current process."""
48 if os.fork() != 0: os._exit(0)
50 if os.fork() != 0: os._exit(0)
52 devnull = os.open(os.devnull, os.O_RDWR)
54 # xxx fixme - this is just to make sure that nothing gets stupidly lost - should use devnull
55 crashlog = os.open('/var/log/geni.daemon', os.O_RDWR | os.O_APPEND | os.O_CREAT, 0644)
66 # Generate command line parser
67 parser = OptionParser(usage="plc [options]")
68 parser.add_option("-r", "--registry", dest="registry", action="store_true",
69 help="run registry server", default=False)
70 parser.add_option("-s", "--slicemgr", dest="sm", action="store_true",
71 help="run slice manager", default=False)
72 parser.add_option("-a", "--aggregate", dest="am", action="store_true",
73 help="run aggregate manager", default=False)
74 parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
75 help="verbose mode", default=False)
76 parser.add_option("-d", "--daemon", dest="daemon", action="store_true",
77 help="Run as daemon.", default=False)
78 (options, args) = parser.parse_args()
81 path = config.basepath
82 key_file = path + os.sep + "server.key"
83 cert_file = path + os.sep + "server.cert"
85 if (options.daemon): daemon()
87 if (os.path.exists(key_file)) and (not os.path.exists(cert_file)):
88 # If private key exists and cert doesnt, recreate cert
89 key = Keypair(filename=key_file)
90 cert = Certificate(subject="registry")
91 cert.set_issuer(key=key, subject="registry")
94 cert.save_to_file(cert_file)
96 elif (not os.path.exists(key_file)) or (not os.path.exists(cert_file)):
97 # if no key is specified, then make one up
98 key = Keypair(create=True)
99 key.save_to_file(key_file)
100 cert = Certificate(subject="registry")
101 cert.set_issuer(key=key, subject="registry")
104 cert.save_to_file(cert_file)
106 AuthHierarchy = Hierarchy()
108 TrustedRoots = TrustedRootList()
110 # start registry server
111 if (options.registry):
112 r = Registry("", registry_port, key_file, cert_file)
113 #r.trusted_cert_list = TrustedRoots.get_list()
114 #r.hierarchy = AuthHierarchy
117 # start aggregate manager
119 a = Aggregate("", aggregate_port, key_file, cert_file)
120 #a.trusted_cert_list = TrustedRoots.get_list()
123 # start slice manager
125 s = SliceMgr("", slicemgr_port, key_file, cert_file)
126 #s.trusted_cert_list = TrustedRoots.get_list()
129 if __name__ == "__main__":