]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Change port/net create calls to take an additional kwargs param
authorBrad Hall <brad@nicira.com>
Fri, 30 Sep 2011 05:47:10 +0000 (22:47 -0700)
committerBrad Hall <brad@nicira.com>
Sun, 2 Oct 2011 22:46:29 +0000 (15:46 -0700)
This is to allow data extensions to flow through the middleware to the actual
plugin.

Change-Id: Ief95b806504e10dd05ce7e941437628ac11a215b

quantum/api/api_common.py
quantum/api/networks.py
quantum/api/ports.py
quantum/plugins/SamplePlugin.py
quantum/quantum_plugin_base.py

index 0fb68696e8beb6b531cd26a852c3cfffc6e4eb42..8201f38b31c9d19bcc882331211d5adb22bfbb3b 100644 (file)
@@ -61,6 +61,12 @@ class QuantumController(wsgi.Controller):
                 raise exc.HTTPBadRequest(msg)
             results[param_name] = param_value or param.get('default-value')
 
+        # There may be other parameters (data extensions), so we
+        # should include those in the results dict as well.
+        for key in data.keys():
+            if key not in params:
+                results[key] = data[key]
+
         return results
 
     def _build_response(self, req, res_data, status_code=200):
index 5ba603a2a149632112b634d0ecc9de744b3696a6..9e53f5f3806d1f16336f5ccd932e3fe223c40240 100644 (file)
@@ -95,16 +95,22 @@ class Controller(common.QuantumController):
 
     def create(self, request, tenant_id):
         """ Creates a new network for a given tenant """
-        #look for network name in request
         try:
             request_params = \
                 self._parse_request_params(request,
                                            self._network_ops_param_list)
         except exc.HTTPError as e:
             return faults.Fault(e)
+        # NOTE(bgh): We're currently passing both request_params['name'] and
+        # the entire request_params dict because their may be pieces of
+        # information (data extensions) inside the request params that the
+        # actual plugin will want to parse.  We could just pass only
+        # request_params but that would mean all the plugins would need to
+        # change.
         network = self._plugin.\
                    create_network(tenant_id,
-                                  request_params['name'])
+                                  request_params['name'],
+                                  **request_params)
         builder = networks_view.get_view_builder(request)
         result = builder.build(network)['network']
         # Wsgi middleware allows us to build the response
index 9256cabe64a061f41c6b05ab1e2b3c8e3ae0018d..ef8b4207af6ff0dc04c2f37bb79f467e7a4bbf77 100644 (file)
@@ -104,7 +104,6 @@ class Controller(common.QuantumController):
 
     def create(self, request, tenant_id, network_id):
         """ Creates a new port for a given network """
-        #look for port state in request
         try:
             request_params = \
                 self._parse_request_params(request, self._port_ops_param_list)
@@ -113,7 +112,8 @@ class Controller(common.QuantumController):
         try:
             port = self._plugin.create_port(tenant_id,
                                             network_id,
-                                            request_params['state'])
+                                            request_params['state'],
+                                            **request_params)
             builder = ports_view.get_view_builder(request)
             result = builder.build(port)['port']
             # Wsgi middleware allows us to build the response
@@ -128,7 +128,6 @@ class Controller(common.QuantumController):
 
     def update(self, request, tenant_id, network_id, id):
         """ Updates the state of a port for a given network """
-        #look for port state in request
         try:
             request_params = \
                 self._parse_request_params(request, self._port_ops_param_list)
index af75083daa000775b53b0f91706a9f91a7be795a..151e139048d9dd4b829deeca07ce46727ffb3c86 100644 (file)
@@ -42,7 +42,7 @@ class QuantumEchoPlugin(object):
         """
         print("get_all_networks() called\n")
 
-    def create_network(self, tenant_id, net_name):
+    def create_network(self, tenant_id, net_name, **kwargs):
         """
         Creates a new Virtual Network, and assigns it
         a symbolic name.
@@ -77,7 +77,7 @@ class QuantumEchoPlugin(object):
         """
         print("get_all_ports() called\n")
 
-    def create_port(self, tenant_id, net_id):
+    def create_port(self, tenant_id, net_id, **kwargs):
         """
         Creates a port on the specified Virtual Network.
         """
@@ -195,7 +195,7 @@ class FakePlugin(object):
                 'net-name': net.name,
                 'net-ports': ports}
 
-    def create_network(self, tenant_id, net_name):
+    def create_network(self, tenant_id, net_name, **kwargs):
         """
         Creates a new Virtual Network, and assigns it
         a symbolic name.
@@ -256,7 +256,7 @@ class FakePlugin(object):
                 'attachment': port.interface_id,
                 'port-state': port.state}
 
-    def create_port(self, tenant_id, net_id, port_state=None):
+    def create_port(self, tenant_id, net_id, port_state=None, **kwargs):
         """
         Creates a port on the specified Virtual Network.
         """
index 3228f868c772c7d323a6b60f11d49cb4556c4d2f..07281a020c574c5773d5fac71b82ffd9077f94af 100644 (file)
@@ -54,7 +54,7 @@ class QuantumPluginBase(object):
         pass
 
     @abstractmethod
-    def create_network(self, tenant_id, net_name):
+    def create_network(self, tenant_id, net_name, **kwargs):
         """
         Creates a new Virtual Network, and assigns it
         a symbolic name.
@@ -139,7 +139,7 @@ class QuantumPluginBase(object):
         pass
 
     @abstractmethod
-    def create_port(self, tenant_id, net_id, port_state=None):
+    def create_port(self, tenant_id, net_id, port_state=None, **kwargs):
         """
         Creates a port on the specified Virtual Network.