Now loading plugin before setting up routes.
Passing same plugin instance to API controllers. Also renamed 'network_manager' to 'plugin' in API controllers.
This commit is contained in:
parent
5d23ba2598
commit
dbd0fa5193
@ -24,6 +24,7 @@ import routes
|
||||
import webob.dec
|
||||
import webob.exc
|
||||
|
||||
from quantum import manager
|
||||
from quantum.api import faults
|
||||
from quantum.api import networks
|
||||
from quantum.api import ports
|
||||
@ -46,32 +47,32 @@ class APIRouterV01(wsgi.Router):
|
||||
super(APIRouterV01, self).__init__(mapper)
|
||||
|
||||
def _setup_routes(self, mapper):
|
||||
|
||||
# Loads the quantum plugin
|
||||
plugin = manager.QuantumManager().get_plugin()
|
||||
uri_prefix = '/tenants/{tenant_id}/'
|
||||
mapper.resource('network', 'networks',
|
||||
controller=networks.Controller(),
|
||||
controller=networks.Controller(plugin),
|
||||
path_prefix=uri_prefix)
|
||||
mapper.resource('port', 'ports',
|
||||
controller=ports.Controller(),
|
||||
controller=ports.Controller(plugin),
|
||||
parent_resource=dict(member_name='network',
|
||||
collection_name=uri_prefix +\
|
||||
'networks'))
|
||||
|
||||
mapper.connect("get_resource",
|
||||
uri_prefix + 'networks/{network_id}/' \
|
||||
'ports/{id}/attachment{.format}',
|
||||
controller=ports.Controller(),
|
||||
controller=ports.Controller(plugin),
|
||||
action="get_resource",
|
||||
conditions=dict(method=['GET']))
|
||||
mapper.connect("attach_resource",
|
||||
uri_prefix + 'networks/{network_id}/' \
|
||||
'ports/{id}/attachment{.format}',
|
||||
controller=ports.Controller(),
|
||||
controller=ports.Controller(plugin),
|
||||
action="attach_resource",
|
||||
conditions=dict(method=['PUT']))
|
||||
mapper.connect("detach_resource",
|
||||
uri_prefix + 'networks/{network_id}/' \
|
||||
'ports/{id}/attachment{.format}',
|
||||
controller=ports.Controller(),
|
||||
controller=ports.Controller(plugin),
|
||||
action="detach_resource",
|
||||
conditions=dict(method=['DELETE']))
|
||||
|
@ -19,7 +19,6 @@ import logging
|
||||
|
||||
from webob import exc
|
||||
|
||||
from quantum import manager
|
||||
from quantum.common import wsgi
|
||||
|
||||
XML_NS_V01 = 'http://netstack.org/quantum/api/v0.1'
|
||||
@ -30,8 +29,8 @@ LOG = logging.getLogger('quantum.api.api_common')
|
||||
class QuantumController(wsgi.Controller):
|
||||
""" Base controller class for Quantum API """
|
||||
|
||||
def __init__(self, plugin_conf_file=None):
|
||||
self._setup_network_manager()
|
||||
def __init__(self, plugin):
|
||||
self._plugin = plugin
|
||||
super(QuantumController, self).__init__()
|
||||
|
||||
def _parse_request_params(self, req, params):
|
||||
@ -65,6 +64,3 @@ class QuantumController(wsgi.Controller):
|
||||
raise exc.HTTPBadRequest(msg)
|
||||
results[param_name] = param_value or param.get('default-value')
|
||||
return results
|
||||
|
||||
def _setup_network_manager(self):
|
||||
self.network_manager = manager.QuantumManager().get_manager()
|
||||
|
@ -40,9 +40,9 @@ class Controller(common.QuantumController):
|
||||
},
|
||||
}
|
||||
|
||||
def __init__(self, plugin_conf_file=None):
|
||||
def __init__(self, plugin):
|
||||
self._resource_name = 'network'
|
||||
super(Controller, self).__init__()
|
||||
super(Controller, self).__init__(plugin)
|
||||
|
||||
def index(self, request, tenant_id):
|
||||
""" Returns a list of network ids """
|
||||
@ -51,7 +51,7 @@ class Controller(common.QuantumController):
|
||||
|
||||
def _items(self, request, tenant_id, is_detail):
|
||||
""" Returns a list of networks. """
|
||||
networks = self.network_manager.get_all_networks(tenant_id)
|
||||
networks = self._plugin.get_all_networks(tenant_id)
|
||||
builder = networks_view.get_view_builder(request)
|
||||
result = [builder.build(network, is_detail)['network']
|
||||
for network in networks]
|
||||
@ -60,7 +60,7 @@ class Controller(common.QuantumController):
|
||||
def show(self, request, tenant_id, id):
|
||||
""" Returns network details for the given network id """
|
||||
try:
|
||||
network = self.network_manager.get_network_details(
|
||||
network = self._plugin.get_network_details(
|
||||
tenant_id, id)
|
||||
builder = networks_view.get_view_builder(request)
|
||||
#build response with details
|
||||
@ -78,7 +78,7 @@ class Controller(common.QuantumController):
|
||||
self._network_ops_param_list)
|
||||
except exc.HTTPError as e:
|
||||
return faults.Fault(e)
|
||||
network = self.network_manager.\
|
||||
network = self._plugin.\
|
||||
create_network(tenant_id,
|
||||
request_params['network-name'])
|
||||
builder = networks_view.get_view_builder(request)
|
||||
@ -94,7 +94,7 @@ class Controller(common.QuantumController):
|
||||
except exc.HTTPError as e:
|
||||
return faults.Fault(e)
|
||||
try:
|
||||
network = self.network_manager.rename_network(tenant_id,
|
||||
network = self._plugin.rename_network(tenant_id,
|
||||
id, request_params['network-name'])
|
||||
|
||||
builder = networks_view.get_view_builder(request)
|
||||
@ -106,7 +106,7 @@ class Controller(common.QuantumController):
|
||||
def delete(self, request, tenant_id, id):
|
||||
""" Destroys the network with the given id """
|
||||
try:
|
||||
self.network_manager.delete_network(tenant_id, id)
|
||||
self._plugin.delete_network(tenant_id, id)
|
||||
return exc.HTTPAccepted()
|
||||
except exception.NetworkNotFound as e:
|
||||
return faults.Fault(faults.NetworkNotFound(e))
|
||||
|
@ -42,9 +42,9 @@ class Controller(common.QuantumController):
|
||||
"attributes": {
|
||||
"port": ["id", "state"], }, }, }
|
||||
|
||||
def __init__(self, plugin_conf_file=None):
|
||||
def __init__(self, plugin):
|
||||
self._resource_name = 'port'
|
||||
super(Controller, self).__init__()
|
||||
super(Controller, self).__init__(plugin)
|
||||
|
||||
def index(self, request, tenant_id, network_id):
|
||||
""" Returns a list of port ids for a given network """
|
||||
@ -53,7 +53,7 @@ class Controller(common.QuantumController):
|
||||
def _items(self, request, tenant_id, network_id, is_detail):
|
||||
""" Returns a list of networks. """
|
||||
try:
|
||||
ports = self.network_manager.get_all_ports(tenant_id, network_id)
|
||||
ports = self._plugin.get_all_ports(tenant_id, network_id)
|
||||
builder = ports_view.get_view_builder(request)
|
||||
result = [builder.build(port, is_detail)['port']
|
||||
for port in ports]
|
||||
@ -64,7 +64,7 @@ class Controller(common.QuantumController):
|
||||
def show(self, request, tenant_id, network_id, id):
|
||||
""" Returns port details for given port and network """
|
||||
try:
|
||||
port = self.network_manager.get_port_details(
|
||||
port = self._plugin.get_port_details(
|
||||
tenant_id, network_id, id)
|
||||
builder = ports_view.get_view_builder(request)
|
||||
#build response with details
|
||||
@ -84,7 +84,7 @@ class Controller(common.QuantumController):
|
||||
except exc.HTTPError as e:
|
||||
return faults.Fault(e)
|
||||
try:
|
||||
port = self.network_manager.create_port(tenant_id,
|
||||
port = self._plugin.create_port(tenant_id,
|
||||
network_id,
|
||||
request_params['port-state'])
|
||||
builder = ports_view.get_view_builder(request)
|
||||
@ -104,7 +104,7 @@ class Controller(common.QuantumController):
|
||||
except exc.HTTPError as e:
|
||||
return faults.Fault(e)
|
||||
try:
|
||||
port = self.network_manager.update_port(tenant_id, network_id, id,
|
||||
port = self._plugin.update_port(tenant_id, network_id, id,
|
||||
request_params['port-state'])
|
||||
builder = ports_view.get_view_builder(request)
|
||||
result = builder.build(port, True)
|
||||
@ -120,7 +120,7 @@ class Controller(common.QuantumController):
|
||||
""" Destroys the port with the given id """
|
||||
#look for port state in request
|
||||
try:
|
||||
self.network_manager.delete_port(tenant_id, network_id, id)
|
||||
self._plugin.delete_port(tenant_id, network_id, id)
|
||||
return exc.HTTPAccepted()
|
||||
#TODO(salvatore-orlando): Handle portInUse error
|
||||
except exception.NetworkNotFound as e:
|
||||
@ -132,7 +132,7 @@ class Controller(common.QuantumController):
|
||||
|
||||
def get_resource(self, request, tenant_id, network_id, id):
|
||||
try:
|
||||
result = self.network_manager.get_interface_details(
|
||||
result = self._plugin.get_interface_details(
|
||||
tenant_id, network_id, id)
|
||||
return dict(attachment=result)
|
||||
except exception.NetworkNotFound as e:
|
||||
@ -151,7 +151,7 @@ class Controller(common.QuantumController):
|
||||
except exc.HTTPError as e:
|
||||
return faults.Fault(e)
|
||||
try:
|
||||
self.network_manager.plug_interface(tenant_id,
|
||||
self._plugin.plug_interface(tenant_id,
|
||||
network_id, id,
|
||||
request_params['attachment-id'])
|
||||
return exc.HTTPAccepted()
|
||||
@ -167,7 +167,7 @@ class Controller(common.QuantumController):
|
||||
#TODO - Complete implementation of these APIs
|
||||
def detach_resource(self, request, tenant_id, network_id, id):
|
||||
try:
|
||||
self.network_manager.unplug_interface(tenant_id,
|
||||
self._plugin.unplug_interface(tenant_id,
|
||||
network_id, id)
|
||||
return exc.HTTPAccepted()
|
||||
except exception.NetworkNotFound as e:
|
||||
|
@ -61,5 +61,5 @@ class QuantumManager(object):
|
||||
"All compatibility tests passed\n")
|
||||
self.plugin = plugin_klass()
|
||||
|
||||
def get_manager(self):
|
||||
def get_plugin(self):
|
||||
return self.plugin
|
||||
|
Loading…
Reference in New Issue
Block a user