]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Implementing interface with plugin
authorSalvatore Orlando <salvatore.orlando@eu.citrix.com>
Thu, 26 May 2011 17:53:48 +0000 (18:53 +0100)
committerSalvatore Orlando <salvatore.orlando@eu.citrix.com>
Thu, 26 May 2011 17:53:48 +0000 (18:53 +0100)
quantum/api/__init__.py
quantum/api/networks.py
quantum/common/utils.py
quantum/common/wsgi.py
quantum/manager.py

index 9e7d5549758c586dea415f6169d8b1d27e8b883f..1ea601c14e7977470de2b979939fd95019aa7e0b 100644 (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',
index 48cd89619aa5930102d34d942bfca75a2ab00c5b..5700a199625e5682a6309b4074f45e2277188035 100644 (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())
 
index c56a53ac135009d680256432e67a4eeb30ed0993..4acea98523cf49cf0dfad7bbf5226f3bf49d314d 100644 (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")
 
 
index d2d7badb04415d1dc54bd4de0100f948246e85fd..277b482d6eb23d25768dff1c73fc48e5fbeb495f 100644 (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']
index a36e9b28f4c0ca1dda8a4ca952e62ad3502eac3a..ed09f365c95508318b29017f340382b65089fd45 100644 (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")