8 # This wrapper implements the Geni Registry and Slice Interfaces on PLC.
9 # Depending on command line options, it starts some combination of a
10 # Registry, an Aggregate Manager, and a Slice Manager.
12 # There are several items that need to be done before starting the wrapper
15 # NOTE: Many configuration settings, including the PLC maintenance account
16 # credentials, URI of the PLCAPI, and PLC DB URI and admin credentials are initialized
17 # from your MyPLC configuration (/etc/planetlab/plc_config*). Please make sure this information
18 # is up to date and accurate.
20 # 1) Import the existing planetlab database, creating the
21 # appropriate geni records. This is done by running the "sfa-import-plc.py" tool.
23 # 2) Create a "trusted_roots" directory and place the certificate of the root
24 # authority in that directory. Given the defaults in sfa-import-plc.py, this
25 # certificate would be named "planetlab.gid". For example,
27 # mkdir trusted_roots; cp authorities/planetlab.gid trusted_roots/
29 # TODO: Can all three servers use the same "registry" certificate?
32 # TCP ports for the three servers
38 from optparse import OptionParser
40 from sfa.trust.trustedroot import TrustedRootList
41 from sfa.trust.certificate import Keypair, Certificate
43 from sfa.server.registry import Registry
44 from sfa.server.aggregate import Aggregate
45 from sfa.server.slicemgr import SliceMgr
47 from sfa.trust.hierarchy import Hierarchy
49 # after http://www.erlenstar.demon.co.uk/unix/faq_2.html
51 """Daemonize the current process."""
52 if os.fork() != 0: os._exit(0)
54 if os.fork() != 0: os._exit(0)
56 devnull = os.open(os.devnull, os.O_RDWR)
58 # xxx fixme - this is just to make sure that nothing gets stupidly lost - should use devnull
59 crashlog = os.open('/var/log/sfa.daemon', os.O_RDWR | os.O_APPEND | os.O_CREAT, 0644)
64 # xxx get rid of globals - name consistently CamelCase or under_score
71 # Generate command line parser
72 parser = OptionParser(usage="plc [options]")
73 parser.add_option("-r", "--registry", dest="registry", action="store_true",
74 help="run registry server", default=False)
75 parser.add_option("-s", "--slicemgr", dest="sm", action="store_true",
76 help="run slice manager", default=False)
77 parser.add_option("-a", "--aggregate", dest="am", action="store_true",
78 help="run aggregate manager", default=False)
79 parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
80 help="verbose mode", default=False)
81 parser.add_option("-d", "--daemon", dest="daemon", action="store_true",
82 help="Run as daemon.", default=False)
83 (options, args) = parser.parse_args()
85 hierarchy = Hierarchy()
86 path = hierarchy.basedir
87 key_file = os.path.join(path, "server.key")
88 cert_file = os.path.join(path, "server.cert")
90 if (options.daemon): daemon()
92 if (os.path.exists(key_file)) and (not os.path.exists(cert_file)):
93 # If private key exists and cert doesnt, recreate cert
94 key = Keypair(filename=key_file)
95 cert = Certificate(subject="registry")
96 cert.set_issuer(key=key, subject="registry")
99 cert.save_to_file(cert_file)
101 elif (not os.path.exists(key_file)) or (not os.path.exists(cert_file)):
102 # if no key is specified, then make one up
103 key = Keypair(create=True)
104 key.save_to_file(key_file)
105 cert = Certificate(subject="registry")
106 cert.set_issuer(key=key, subject="registry")
109 cert.save_to_file(cert_file)
111 AuthHierarchy = Hierarchy()
113 TrustedRoots = TrustedRootList()
115 # start registry server
116 if (options.registry):
117 r = Registry("", registry_port, key_file, cert_file)
118 #r.trusted_cert_list = TrustedRoots.get_list()
119 #r.hierarchy = AuthHierarchy
122 # start aggregate manager
124 a = Aggregate("", aggregate_port, key_file, cert_file)
125 #a.trusted_cert_list = TrustedRoots.get_list()
128 # start slice manager
130 s = SliceMgr("", slicemgr_port, key_file, cert_file)
131 #s.trusted_cert_list = TrustedRoots.get_list()
134 if __name__ == "__main__":