Beispiel #1
0
import webob
import webob.dec
import webob.exc

from mock import ec2
from mock import log as logging
from mock import wsgi

LOG = logging.getLogger('mock.api.service')


class Mock(wsgi.Application):

    def __init__(self, config):
        wsgi.Application.__init__(self, config)
        self.ec2_mock = ec2.Ec2Mock(config)

    @webob.dec.wsgify(RequestClass=webob.Request)
    def __call__(self, req):
        resp = self.ec2_mock(req)
        LOG.debug("Created mock response %s", resp)
        return resp
Beispiel #2
0
import json
import sys
import os

import eventlet
import eventlet.wsgi
import routes
import routes.middleware
import webob
import webob.dec
import webob.exc

from mock import log as logging
from mock import config as cfg

LOG = logging.getLogger('mock.wsgi')


class WritableLogger(object):
    """A thin wrapper that responds to `write` and logs."""

    def __init__(self, logger, level=logging.DEBUG):
        self.logger = logger
        self.level = level

    def write(self, msg):
        self.logger.log(self.level, msg)


class Server(object):
    """Server class to manage multiple WSGI sockets and applications."""
Beispiel #3
0
 def _run(self, application, socket):
     """Start a WSGI server in a new green thread."""
     logger = logging.getLogger('mock.wsgi.server')
     # See: http://eventlet.net/doc/modules/wsgi.html
     eventlet.wsgi.server(socket, application, custom_pool=self.pool,
                          log=WritableLogger(logger))
Beispiel #4
0
import sqlite3
import time
import urllib2

import webob
import webob.dec
import webob.exc

import xml.sax.saxutils as xmlutils

from mock import log as logging
from mock import wsgi
from mock import utils

INSTANCE_FORMAT = 'instance-%08x'
LOG = logging.getLogger('mock.ec2')


class Ec2Mock(object):

    STATES = {
        '0': 'pending',
        '16': 'running',
        '32': 'shutting-down',
        '48': 'terminated',
        '64': 'stopping',
        '80': 'stopped'
    }

    ERROR_TEMPLATE = u'''
<?xml version="1.0" encoding="UTF-8"?>