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