From aab44f36151ca732e2040f8a6066b99c80c2a04a Mon Sep 17 00:00:00 2001 From: Brad Hall Date: Thu, 29 Sep 2011 22:47:10 -0700 Subject: [PATCH] Change port/net create calls to take an additional kwargs param This is to allow data extensions to flow through the middleware to the actual plugin. Change-Id: Ief95b806504e10dd05ce7e941437628ac11a215b --- quantum/api/api_common.py | 6 ++++++ quantum/api/networks.py | 10 ++++++++-- quantum/api/ports.py | 5 ++--- quantum/plugins/SamplePlugin.py | 8 ++++---- quantum/quantum_plugin_base.py | 4 ++-- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/quantum/api/api_common.py b/quantum/api/api_common.py index 0fb68696e..8201f38b3 100644 --- a/quantum/api/api_common.py +++ b/quantum/api/api_common.py @@ -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): diff --git a/quantum/api/networks.py b/quantum/api/networks.py index 5ba603a2a..9e53f5f38 100644 --- a/quantum/api/networks.py +++ b/quantum/api/networks.py @@ -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 diff --git a/quantum/api/ports.py b/quantum/api/ports.py index 9256cabe6..ef8b4207a 100644 --- a/quantum/api/ports.py +++ b/quantum/api/ports.py @@ -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) diff --git a/quantum/plugins/SamplePlugin.py b/quantum/plugins/SamplePlugin.py index af75083da..151e13904 100644 --- a/quantum/plugins/SamplePlugin.py +++ b/quantum/plugins/SamplePlugin.py @@ -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. """ diff --git a/quantum/quantum_plugin_base.py b/quantum/quantum_plugin_base.py index 3228f868c..07281a020 100644 --- a/quantum/quantum_plugin_base.py +++ b/quantum/quantum_plugin_base.py @@ -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. -- 2.45.2