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['reset_network'] = 'POST'
#server_members['inject_network_info'] = 'POST'
mapper.resource("network", "networks", controller=networks.Controller(),
collection={'detail': 'GET'})
print mapper
mapper.resource("/tenants/{tenant_id}/network", "/tenants/{tenant_id}/networks", controller=networks.Controller())
print "AFTER MAPPING"
print mapper
for route in mapper.matchlist:
print "Found route:%s %s" %(route.defaults,route.conditions)
#mapper.resource("port", "ports", controller=ports.Controller(),
# collection=dict(public='GET', private='GET'),
# 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 """
#TODO: this should be for a given tenant!!!
print "PIPPO"
LOG.debug("HERE - index")
return self._items(req, is_detail=False)
LOG.debug("HERE - Controller.index")
return self._items(req, tenant_id, is_detail=False)
def _items(self, req, is_detail):
def _items(self, req, tenant_id, is_detail):
""" Returns a list of networks. """
#TODO: we should return networks for a given tenant only
#TODO: network controller should be retrieved here!!!
test = { 'ciao':'bello','porco':'mondo' }
test = self.network_manager.get_all_networks(tenant_id)
#builder = self._get_view_builder(req)
#servers = [builder.build(inst, is_detail)['server']
# for inst in limited_list]
#return dict(servers=servers)
return test
def show(self, req, id):
def show(self, req, tenant_id, id):
""" Returns network details by network id """
try:
return "TEST NETWORK DETAILS"
return "SHOW NETWORK %s FOR TENANT %s" %(id,tenant_id)
except exception.NotFound:
return faults.Fault(exc.HTTPNotFound())

View File

@ -29,12 +29,13 @@ import socket
import sys
import ConfigParser
from quantum.common import exceptions
from quantum.common import exceptions as exception
from quantum.common import flags
from exceptions import ProcessExecutionError
TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
FLAGS = flags.FLAGS
def int_from_bool_as_string(subject):
"""
@ -70,10 +71,16 @@ def bool_from_string(subject):
def import_class(import_str):
"""Returns a class from a string including module and class"""
mod_str, _sep, class_str = import_str.rpartition('.')
print "MOD_STR:%s SEP:%s CLASS_STR:%s" %(mod_str, _sep, class_str)
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)
print "IO SONO QUI"
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)
@ -186,8 +193,9 @@ def parse_isotime(timestr):
return datetime.datetime.strptime(timestr, TIME_FORMAT)
def getPluginFromConfig(file="config.ini"):
print "FILE:%s" %os.path.join(FLAGS.state_path, file)
Config = ConfigParser.ConfigParser()
Config.read(file)
Config.read(os.path.join(FLAGS.state_path, file))
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.
If no match, return a 404.
"""
LOG.debug("HERE - wsgi.Router.__call__")
return self._router
@staticmethod
@ -328,10 +329,16 @@ class Controller(object):
@webob.dec.wsgify(RequestClass=Request)
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]
action = arg_dict['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))
del arg_dict['controller']
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 quantum_plugin_base import QuantumPluginBase
CONFIG_FILE = "plugins.ini"
CONFIG_FILE = "quantum/plugins.ini"
class QuantumManager(object):
def __init__(self,config=CONFIG_FILE):
self.configuration_file = CONFIG_FILE
plugin_location = utils.getPluginFromConfig(CONFIG_FILE)
print "PLUGIN LOCATION:%s" %plugin_location
plugin_klass = utils.import_class(plugin_location)
if not issubclass(plugin_klass, QuantumPluginBase):
raise Exception("Configured Quantum plug-in didn't pass compatibility test")