1 from http.server import BaseHTTPRequestHandler
2 from http.server import HTTPServer
3 import _thread, ssl, time, re
8 class AAISetup(BaseHTTPRequestHandler):
11 if re.search('/set_pnfs', self.path):
13 content_length = int(self.headers['Content-Length'])
14 pnfs = self.rfile.read(content_length)
15 _header_200_and_json(self)
20 if re.search('/reset', self.path):
23 _header_200_and_json(self)
27 class AAIHandler(BaseHTTPRequestHandler):
30 pnfs_name = '/aai/v12/network/pnfs/pnf/' + pnfs.decode()
31 if re.search('wrong_aai_record', self.path):
32 self.send_response(400)
34 elif re.search(pnfs_name, self.path):
35 self.send_response(200)
41 def _header_200_and_json(self):
42 self.send_response(200)
43 self.send_header('Content-Type', 'application/json')
47 def _main_(handler_class=AAIHandler, protocol="HTTP/1.0"):
48 handler_class.protocol_version = protocol
49 _thread.start_new_thread(_init_http_endpoints, (3333, AAIHandler))
50 _thread.start_new_thread(_init_https_endpoints, (3334, AAIHandler))
51 _thread.start_new_thread(_init_http_endpoints, (3335, AAISetup))
56 def _init_http_endpoints(port, handler_class, server_class=HTTPServer):
57 server = server_class(('', port), handler_class)
58 sa = server.socket.getsockname()
59 print("Serving HTTP on", sa[0], "port", sa[1], "for", handler_class, "...")
60 server.serve_forever()
63 def _init_https_endpoints(port, handler_class, server_class=HTTPServer):
64 server = server_class(('', port), handler_class)
65 server.socket = ssl.wrap_socket(server.socket,
66 keyfile="certs/server.key", certfile="certs/server.crt",
67 ca_certs="certs/client.crt", server_side=True)
68 sa = server.socket.getsockname()
69 print("Serving HTTPS on", sa[0], "port", sa[1], "for", handler_class, "...")
70 server.serve_forever()
73 if __name__ == '__main__':