Implementing interface with plugin

This commit is contained in:
Salvatore Orlando 2011-05-26 18:53:48 +01:00
parent 64ed5da205
commit 5022c07f6b
5 changed files with 41 additions and 20 deletions

View File

@ -70,10 +70,11 @@ class APIRouterV01(wsgi.Router):
#server_members['unrescue'] = 'POST' #server_members['unrescue'] = 'POST'
#server_members['reset_network'] = 'POST' #server_members['reset_network'] = 'POST'
#server_members['inject_network_info'] = 'POST' #server_members['inject_network_info'] = 'POST'
mapper.resource("/tenants/{tenant_id}/network", "/tenants/{tenant_id}/networks", controller=networks.Controller())
mapper.resource("network", "networks", controller=networks.Controller(), print "AFTER MAPPING"
collection={'detail': 'GET'}) print mapper
print mapper for route in mapper.matchlist:
print "Found route:%s %s" %(route.defaults,route.conditions)
#mapper.resource("port", "ports", controller=ports.Controller(), #mapper.resource("port", "ports", controller=ports.Controller(),
# collection=dict(public='GET', private='GET'), # collection=dict(public='GET', private='GET'),
# parent_resource=dict(member_name='network', # parent_resource=dict(member_name='network',

View File

@ -56,28 +56,32 @@ class Controller(wsgi.Controller):
}, },
} }
def index(self, req): def __init__(self):
self._setup_network_manager()
super(Controller, self).__init__()
def _setup_network_manager(self):
self.network_manager=manager.QuantumManager().get_manager()
def index(self, req, tenant_id):
""" Returns a list of network names and ids """ """ Returns a list of network names and ids """
#TODO: this should be for a given tenant!!! #TODO: this should be for a given tenant!!!
print "PIPPO" LOG.debug("HERE - Controller.index")
LOG.debug("HERE - index") return self._items(req, tenant_id, is_detail=False)
return self._items(req, is_detail=False)
def _items(self, req, is_detail): def _items(self, req, tenant_id, is_detail):
""" Returns a list of networks. """ """ Returns a list of networks. """
#TODO: we should return networks for a given tenant only test = self.network_manager.get_all_networks(tenant_id)
#TODO: network controller should be retrieved here!!!
test = { 'ciao':'bello','porco':'mondo' }
#builder = self._get_view_builder(req) #builder = self._get_view_builder(req)
#servers = [builder.build(inst, is_detail)['server'] #servers = [builder.build(inst, is_detail)['server']
# for inst in limited_list] # for inst in limited_list]
#return dict(servers=servers) #return dict(servers=servers)
return test return test
def show(self, req, id): def show(self, req, tenant_id, id):
""" Returns network details by network id """ """ Returns network details by network id """
try: try:
return "TEST NETWORK DETAILS" return "SHOW NETWORK %s FOR TENANT %s" %(id,tenant_id)
except exception.NotFound: except exception.NotFound:
return faults.Fault(exc.HTTPNotFound()) return faults.Fault(exc.HTTPNotFound())

View File

@ -29,12 +29,13 @@ import socket
import sys import sys
import ConfigParser import ConfigParser
from quantum.common import exceptions from quantum.common import exceptions as exception
from quantum.common import flags
from exceptions import ProcessExecutionError from exceptions import ProcessExecutionError
TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
FLAGS = flags.FLAGS
def int_from_bool_as_string(subject): def int_from_bool_as_string(subject):
""" """
@ -70,10 +71,16 @@ def bool_from_string(subject):
def import_class(import_str): def import_class(import_str):
"""Returns a class from a string including module and class""" """Returns a class from a string including module and class"""
mod_str, _sep, class_str = import_str.rpartition('.') mod_str, _sep, class_str = import_str.rpartition('.')
print "MOD_STR:%s SEP:%s CLASS_STR:%s" %(mod_str, _sep, class_str)
try: try:
#mod_str = os.path.join(FLAGS.state_path, mod_str)
print "MODULE PATH:%s" %mod_str
print "CUR DIR:%s" %os.getcwd()
__import__(mod_str) __import__(mod_str)
print "IO SONO QUI"
return getattr(sys.modules[mod_str], class_str) return getattr(sys.modules[mod_str], class_str)
except (ImportError, ValueError, AttributeError): except (ImportError, ValueError, AttributeError) as e:
print e
raise exception.NotFound('Class %s cannot be found' % class_str) raise exception.NotFound('Class %s cannot be found' % class_str)
@ -186,8 +193,9 @@ def parse_isotime(timestr):
return datetime.datetime.strptime(timestr, TIME_FORMAT) return datetime.datetime.strptime(timestr, TIME_FORMAT)
def getPluginFromConfig(file="config.ini"): def getPluginFromConfig(file="config.ini"):
print "FILE:%s" %os.path.join(FLAGS.state_path, file)
Config = ConfigParser.ConfigParser() Config = ConfigParser.ConfigParser()
Config.read(file) Config.read(os.path.join(FLAGS.state_path, file))
return Config.get("PLUGIN", "provider") return Config.get("PLUGIN", "provider")

View File

@ -298,6 +298,7 @@ class Router(object):
Route the incoming request to a controller based on self.map. Route the incoming request to a controller based on self.map.
If no match, return a 404. If no match, return a 404.
""" """
LOG.debug("HERE - wsgi.Router.__call__")
return self._router return self._router
@staticmethod @staticmethod
@ -328,10 +329,16 @@ class Controller(object):
@webob.dec.wsgify(RequestClass=Request) @webob.dec.wsgify(RequestClass=Request)
def __call__(self, req): def __call__(self, req):
"""Call the method specified in req.environ by RoutesMiddleware.""" """
Call the method specified in req.environ by RoutesMiddleware.
"""
LOG.debug("HERE - wsgi.Controller.__call__")
arg_dict = req.environ['wsgiorg.routing_args'][1] arg_dict = req.environ['wsgiorg.routing_args'][1]
action = arg_dict['action'] action = arg_dict['action']
method = getattr(self, action) method = getattr(self, action)
LOG.debug("ARG_DICT:%s",arg_dict)
LOG.debug("Action:%s",action)
LOG.debug("Method:%s",method)
LOG.debug("%s %s" % (req.method, req.url)) LOG.debug("%s %s" % (req.method, req.url))
del arg_dict['controller'] del arg_dict['controller']
del arg_dict['action'] del arg_dict['action']

View File

@ -27,13 +27,14 @@ The caller should make sure that QuantumManager is a singleton.
from common import utils from common import utils
from quantum_plugin_base import QuantumPluginBase from quantum_plugin_base import QuantumPluginBase
CONFIG_FILE = "plugins.ini" CONFIG_FILE = "quantum/plugins.ini"
class QuantumManager(object): class QuantumManager(object):
def __init__(self,config=CONFIG_FILE): def __init__(self,config=CONFIG_FILE):
self.configuration_file = CONFIG_FILE self.configuration_file = CONFIG_FILE
plugin_location = utils.getPluginFromConfig(CONFIG_FILE) plugin_location = utils.getPluginFromConfig(CONFIG_FILE)
print "PLUGIN LOCATION:%s" %plugin_location
plugin_klass = utils.import_class(plugin_location) plugin_klass = utils.import_class(plugin_location)
if not issubclass(plugin_klass, QuantumPluginBase): if not issubclass(plugin_klass, QuantumPluginBase):
raise Exception("Configured Quantum plug-in didn't pass compatibility test") raise Exception("Configured Quantum plug-in didn't pass compatibility test")