Adding support for 'detail' action on networks objects
GET /tenants/{tenant-id}/networks/detail returns details about all networks (id,name,number of logical ports) GET /tenants/{tenant-id}/networks/{network-id}/detail return complete details about a specific network, including ports and attachments
This commit is contained in:
parent
15a625ba16
commit
cc07877e10
|
@ -50,6 +50,8 @@ class APIRouterV01(wsgi.Router):
|
|||
uri_prefix = '/tenants/{tenant_id}/'
|
||||
mapper.resource('network', 'networks',
|
||||
controller=networks.Controller(),
|
||||
collection={'detail': 'GET'},
|
||||
member={'detail': 'GET'},
|
||||
path_prefix=uri_prefix)
|
||||
mapper.resource('port', 'ports',
|
||||
controller=ports.Controller(),
|
||||
|
@ -75,3 +77,5 @@ class APIRouterV01(wsgi.Router):
|
|||
controller=ports.Controller(),
|
||||
action="detach_resource",
|
||||
conditions=dict(method=['DELETE']))
|
||||
print "MAPPED ROUTES"
|
||||
print mapper
|
||||
|
|
|
@ -36,6 +36,7 @@ class Controller(common.QuantumController):
|
|||
"application/xml": {
|
||||
"attributes": {
|
||||
"network": ["id", "name"],
|
||||
"port": ["id", "state"],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -47,25 +48,43 @@ class Controller(common.QuantumController):
|
|||
def index(self, req, tenant_id):
|
||||
""" Returns a list of network ids """
|
||||
#TODO: this should be for a given tenant!!!
|
||||
return self._items(req, tenant_id, is_detail=False)
|
||||
return self._items(req, tenant_id, net_detail=False)
|
||||
|
||||
def _items(self, req, tenant_id, is_detail):
|
||||
def _item(self, req, tenant_id, network_id,
|
||||
net_details, port_details):
|
||||
network = self.network_manager.get_network_details(
|
||||
tenant_id, network_id)
|
||||
builder = networks_view.get_view_builder(req)
|
||||
result = builder.build(network, net_details, port_details)
|
||||
return dict(networks=result)
|
||||
|
||||
def _items(self, req, tenant_id, net_details, port_details):
|
||||
""" Returns a list of networks. """
|
||||
networks = self.network_manager.get_all_networks(tenant_id)
|
||||
builder = networks_view.get_view_builder(req)
|
||||
result = [builder.build(network, is_detail)['network']
|
||||
result = [builder.build(network, net_details, port_details)['network']
|
||||
for network in networks]
|
||||
return dict(networks=result)
|
||||
|
||||
def show(self, req, tenant_id, id):
|
||||
""" Returns network details for the given network id """
|
||||
try:
|
||||
network = self.network_manager.get_network_details(
|
||||
tenant_id, id)
|
||||
builder = networks_view.get_view_builder(req)
|
||||
#build response with details
|
||||
result = builder.build(network, True)
|
||||
return dict(networks=result)
|
||||
return self._item(req, tenant_id, id,
|
||||
net_details=True, port_details=False)
|
||||
except exception.NetworkNotFound as e:
|
||||
return faults.Fault(faults.NetworkNotFound(e))
|
||||
|
||||
def detail(self, req, **kwargs):
|
||||
tenant_id = kwargs.get('tenant_id')
|
||||
network_id = kwargs.get('id')
|
||||
try:
|
||||
if network_id:
|
||||
return self._item(req, tenant_id, network_id,
|
||||
net_details=True, port_details=True)
|
||||
else:
|
||||
#do like show but with detaik
|
||||
return self._items(req, tenant_id,
|
||||
net_details=True, port_details=False)
|
||||
except exception.NetworkNotFound as e:
|
||||
return faults.Fault(faults.NetworkNotFound(e))
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
from quantum.api.views import ports as ports_view
|
||||
|
||||
|
||||
def get_view_builder(req):
|
||||
|
@ -31,19 +31,32 @@ class ViewBuilder(object):
|
|||
"""
|
||||
self.base_url = base_url
|
||||
|
||||
def build(self, network_data, is_detail=False):
|
||||
def build(self, network_data, net_detail=False, port_detail=False):
|
||||
"""Generic method used to generate a network entity."""
|
||||
if is_detail:
|
||||
if net_detail:
|
||||
network = self._build_detail(network_data)
|
||||
else:
|
||||
network = self._build_simple(network_data)
|
||||
if port_detail:
|
||||
builder = ports_view.ViewBuilder(self.base_url)
|
||||
ports = [builder.build(port_data, port_detail)['port']
|
||||
for port_data in network_data['net-ports'].values()]
|
||||
network['ports'] = ports
|
||||
return network
|
||||
|
||||
def _build_simple(self, network_data):
|
||||
"""Return a simple model of a server."""
|
||||
"""Return a simple model of a network."""
|
||||
return dict(network=dict(id=network_data['net-id']))
|
||||
|
||||
def _build_detail(self, network_data):
|
||||
"""Return a simple model of a server."""
|
||||
"""Return a detailed model of a network."""
|
||||
return dict(network=dict(id=network_data['net-id'],
|
||||
name=network_data['net-name']))
|
||||
name=network_data['net-name'],
|
||||
PortCount=len(network_data['net-ports'].
|
||||
keys())))
|
||||
|
||||
def _build_port(self, port_data):
|
||||
"""Return details about a specific logical port."""
|
||||
return dict(port=dict(id=port_data['port-id'],
|
||||
state=port_data['port-state'],
|
||||
attachment=port_data['attachment']))
|
||||
|
|
|
@ -44,4 +44,5 @@ class ViewBuilder(object):
|
|||
def _build_detail(self, port_data):
|
||||
"""Return a simple model of a server."""
|
||||
return dict(port=dict(id=port_data['port-id'],
|
||||
state=port_data['port-state']))
|
||||
state=port_data['port-state'],
|
||||
attachment=port_data['attachment']))
|
||||
|
|
Loading…
Reference in New Issue