57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
# Copyright (c) 2013 Rackspace, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import abc
|
|
import falcon
|
|
import six
|
|
|
|
from cdn import transport
|
|
from cdn.transport import DriverBase
|
|
from wsgiref import simple_server
|
|
|
|
from hosts import HostsResource
|
|
from v1 import V1Resource
|
|
|
|
|
|
@six.add_metaclass(abc.ABCMeta)
|
|
class Driver(transport.DriverBase):
|
|
|
|
def __init__(self, conf):
|
|
super(DriverBase, self).__init__()
|
|
|
|
self.app = None
|
|
self._init_routes()
|
|
|
|
def _init_routes(self):
|
|
"""Initialize hooks and URI routes to resources."""
|
|
self.app = falcon.API()
|
|
version_path = "/v1"
|
|
|
|
self.app.add_route(version_path + '/', V1Resource)
|
|
self.app.add_route(version_path + '/hosts', HostsResource)
|
|
|
|
def listen(self):
|
|
"""Self-host using 'bind' and 'port' from the WSGI config group."""
|
|
bind = '127.0.0.1'
|
|
port = '8080'
|
|
msgtmpl = (u'Serving on host %(bind)s:%(port)s')
|
|
|
|
print(msgtmpl)
|
|
|
|
httpd = simple_server.make_server(bind=bind,
|
|
port=port,
|
|
app=self.app)
|
|
httpd.serve_forever()
|