def _run(self, application, socket): """Start a WSGI server in a new green thread.""" logger = logging.getLogger('eventlet.wsgi') eventlet.wsgi.server(socket, application, custom_pool=self.tg.pool, log=logging.WritableLogger(logger))
from oslo.config import cfg import muranoapi.context from muranoapi.openstack.common.gettextutils import _ # noqa import muranoapi.openstack.common.log as logging from muranoapi.openstack.common import wsgi context_opts = [ cfg.StrOpt('admin_role', default='admin', help=_('Role used to identify an authenticated user as ' 'administrator.'))] CONF = cfg.CONF CONF.register_opts(context_opts) LOG = logging.getLogger(__name__) CONF = cfg.CONF class ContextMiddleware(wsgi.Middleware): def process_request(self, req): """Convert authentication information into a request context Generate a muranoapi.context.RequestContext object from the available authentication headers and store on the 'context' attribute of the req object. :param req: wsgi request object that will be given the context object """ kwargs = {
# 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 time from muranoapi.api import v1 from muranoapi.db.services import stats from muranoapi.openstack.common import log as logging from muranoapi.openstack.common import wsgi LOG = logging.getLogger(__name__) class RequestStatisticsCollection(object): request_count = 0 error_count = 0 average_time = 0.0 requests_per_tenant = {} errors_per_tenant = {} def add_api_request(self, tenant, ex_time): self.average_time = (self.average_time * self.request_count + ex_time) / (self.request_count + 1) if tenant: tenant_count = self.requests_per_tenant.get(tenant, 0)