-
Notifications
You must be signed in to change notification settings - Fork 33
/
rest_server_v6.py
executable file
·94 lines (73 loc) · 3.04 KB
/
rest_server_v6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/env python2.7
"""
* Copyright (c) 2014 by Cisco Systems, Inc.
* All rights reserved.
Rest command server
-- used for various tasks
-- here for running the Pathman REST API
Maintainer: Niklas Montin (niklas@cisco.com)
20140710 - v1 basic command support, based on work by vrpolak@cisco.com
20140716 - v2 SSL support and other http extras
20140728 - v3 Adopted to Pathman
20140824 - v4 Commandhandler2
20141120 - v5 Removed need for Launcher - main section added
20160413 - v6 Split out the actual handler to work with pathman and pathman_sr at the same time
"""
__author__ = 'niklas'
# Import standard Python library modules.
import json
import copy
import re
import time
import logging
# Import third party library modules.
import tornado.ioloop
import tornado.web
import tornado.httpserver
from pathman_ini import *
from server_sr import CommandHandlerSR, LOGGING, build_odl_topology
#from server_pathman import CommandHandler2
Response_Flag = True
response_list = []
# for certs
data_dir = ''
class Commands(object):
""" ioloop to pick up REST commands. """
def __init__(self, port=None, uri=None, debug=False):
"""Create http server, register callbacks and start immediatelly."""
#nprint(uri, debug=debug)
re_uri = re.compile('/' + uri )
txt_uri = re_uri.pattern
re_uri_sr = re.compile('/pathman_sr' )
txt_uri_sr = re_uri_sr.pattern
build_odl_topology(debug=debug)
logging.info('patterned to ' + repr(txt_uri))
##tuple_register2 = (txt_uri, CommandHandler2, dict(debug=debug))
tuple_register_sr = (txt_uri_sr, CommandHandlerSR, dict(debug=debug))
application = tornado.web.Application([ tuple_register_sr, # For Pathman_sr backend
#tuple_register2, # For regular Pathman backend
(r'/cisco-ctao/apps/(.*)', tornado.web.StaticFileHandler, {"path": "client"}), # For UI
#(r'/pathman/topology', dataHandler), # For BGP APP
], dict(debug=debug))
"""
http_server = tornado.httpserver.HTTPServer(application, ssl_options={
"certfile": os.path.join(data_dir, "server.crt"),
"keyfile": os.path.join(data_dir, "server.key"),
})
"""
#http_server.listen(int(port))
application.listen(int(port))
ioloop = tornado.ioloop.IOLoop.instance()
#nprint('Pathman REST API Launched on port %s' % port, debug=debug)
logging.info('Pathman REST API Launched on port %s' % port)
ioloop.start()
if __name__ == "__main__":
kwargs = {}
kwargs['port'] = 8020
kwargs['uri'] = 'pathman'
kwargs['debug'] = True
logging.config.dictConfig(LOGGING)
#logging.config.fileConfig("pathman_logging.conf")
logging.info('This is initializing the log')
Commands(**kwargs)
# Bye bye.