Merge "Remove 'verbose' API capability"

This commit is contained in:
Jenkins 2012-08-25 04:13:02 +00:00 committed by Gerrit Code Review
commit e1bb5603c1
16 changed files with 101 additions and 276 deletions

View File

@ -21,7 +21,6 @@ import webob.exc
from quantum.api.v2 import attributes from quantum.api.v2 import attributes
from quantum.api.v2 import resource as wsgi_resource from quantum.api.v2 import resource as wsgi_resource
from quantum.common import exceptions from quantum.common import exceptions
from quantum.common import utils
from quantum.openstack.common import cfg from quantum.openstack.common import cfg
from quantum.openstack.common.notifier import api as notifier_api from quantum.openstack.common.notifier import api as notifier_api
from quantum import policy from quantum import policy
@ -70,7 +69,7 @@ def _filters(request, attr_info):
Returns a dict of lists for the filters: Returns a dict of lists for the filters:
check=a&check=b&name=Bob&verbose=True&verbose=other check=a&check=b&name=Bob&
becomes becomes
@ -78,7 +77,7 @@ def _filters(request, attr_info):
""" """
res = {} res = {}
for key in set(request.GET): for key in set(request.GET):
if key in ('verbose', 'fields'): if key == 'fields':
continue continue
values = [v for v in request.GET.getall(key) if v] values = [v for v in request.GET.getall(key) if v]
if not attr_info.get(key) and values: if not attr_info.get(key) and values:
@ -100,38 +99,6 @@ def _filters(request, attr_info):
return res return res
def _verbose(request):
"""
Determines the verbose fields for a request
Returns a list of items that are requested to be verbose:
check=a&check=b&name=Bob&verbose=True&verbose=other
returns
[True]
and
check=a&check=b&name=Bob&verbose=other
returns
['other']
"""
verbose = [utils.boolize(v) for v in request.GET.getall('verbose') if v]
# NOTE(jkoelker) verbose=<bool> trumps all other verbose settings
if True in verbose:
return True
elif False in verbose:
return False
return verbose
class Controller(object): class Controller(object):
def __init__(self, plugin, collection, resource, attr_info, def __init__(self, plugin, collection, resource, attr_info,
@ -191,7 +158,6 @@ class Controller(object):
# plugin before returning. # plugin before returning.
original_fields, fields_to_add = self._do_field_list(_fields(request)) original_fields, fields_to_add = self._do_field_list(_fields(request))
kwargs = {'filters': _filters(request, self._attr_info), kwargs = {'filters': _filters(request, self._attr_info),
'verbose': _verbose(request),
'fields': original_fields} 'fields': original_fields}
obj_getter = getattr(self._plugin, "get_%s" % self._collection) obj_getter = getattr(self._plugin, "get_%s" % self._collection)
obj_list = obj_getter(request.context, **kwargs) obj_list = obj_getter(request.context, **kwargs)
@ -205,15 +171,13 @@ class Controller(object):
"get_%s" % self._resource, "get_%s" % self._resource,
obj, obj,
plugin=self._plugin)] plugin=self._plugin)]
return {self._collection: [self._view(obj, return {self._collection: [self._view(obj,
fields_to_strip=fields_to_add) fields_to_strip=fields_to_add)
for obj in obj_list]} for obj in obj_list]}
def _item(self, request, id, do_authz=False, field_list=None): def _item(self, request, id, do_authz=False, field_list=None):
"""Retrieves and formats a single element of the requested entity""" """Retrieves and formats a single element of the requested entity"""
kwargs = {'verbose': _verbose(request), kwargs = {'fields': field_list}
'fields': field_list}
action = "get_%s" % self._resource action = "get_%s" % self._resource
obj_getter = getattr(self._plugin, action) obj_getter = getattr(self._plugin, action)
obj = obj_getter(request.context, id, **kwargs) obj = obj_getter(request.context, id, **kwargs)

View File

@ -82,21 +82,13 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
query = query.filter(model.tenant_id == context.tenant_id) query = query.filter(model.tenant_id == context.tenant_id)
return query return query
def _get_by_id(self, context, model, id, joins=(), verbose=None): def _get_by_id(self, context, model, id):
query = self._model_query(context, model) query = self._model_query(context, model)
if verbose:
if verbose and isinstance(verbose, list):
options = [orm.joinedload(join) for join in joins
if join in verbose]
else:
options = [orm.joinedload(join) for join in joins]
query = query.options(*options)
return query.filter_by(id=id).one() return query.filter_by(id=id).one()
def _get_network(self, context, id, verbose=None): def _get_network(self, context, id):
try: try:
network = self._get_by_id(context, models_v2.Network, id, network = self._get_by_id(context, models_v2.Network, id)
joins=('subnets',), verbose=verbose)
except exc.NoResultFound: except exc.NoResultFound:
raise q_exc.NetworkNotFound(net_id=id) raise q_exc.NetworkNotFound(net_id=id)
except exc.MultipleResultsFound: except exc.MultipleResultsFound:
@ -104,10 +96,9 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
raise q_exc.NetworkNotFound(net_id=id) raise q_exc.NetworkNotFound(net_id=id)
return network return network
def _get_subnet(self, context, id, verbose=None): def _get_subnet(self, context, id):
try: try:
subnet = self._get_by_id(context, models_v2.Subnet, id, subnet = self._get_by_id(context, models_v2.Subnet, id)
verbose=verbose)
except exc.NoResultFound: except exc.NoResultFound:
raise q_exc.SubnetNotFound(subnet_id=id) raise q_exc.SubnetNotFound(subnet_id=id)
except exc.MultipleResultsFound: except exc.MultipleResultsFound:
@ -115,10 +106,9 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
raise q_exc.SubnetNotFound(subnet_id=id) raise q_exc.SubnetNotFound(subnet_id=id)
return subnet return subnet
def _get_port(self, context, id, verbose=None): def _get_port(self, context, id):
try: try:
port = self._get_by_id(context, models_v2.Port, id, port = self._get_by_id(context, models_v2.Port, id)
verbose=verbose)
except exc.NoResultFound: except exc.NoResultFound:
# NOTE(jkoelker) The PortNotFound exceptions requires net_id # NOTE(jkoelker) The PortNotFound exceptions requires net_id
# kwarg in order to set the message correctly # kwarg in order to set the message correctly
@ -156,7 +146,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
return resource return resource
def _get_collection(self, context, model, dict_func, filters=None, def _get_collection(self, context, model, dict_func, filters=None,
fields=None, verbose=None): fields=None):
collection = self._model_query(context, model) collection = self._model_query(context, model)
if filters: if filters:
for key, value in filters.iteritems(): for key, value in filters.iteritems():
@ -796,15 +786,14 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
subnets_qry.filter_by(network_id=id).delete() subnets_qry.filter_by(network_id=id).delete()
context.session.delete(network) context.session.delete(network)
def get_network(self, context, id, fields=None, verbose=None): def get_network(self, context, id, fields=None):
network = self._get_network(context, id, verbose=verbose) network = self._get_network(context, id)
return self._make_network_dict(network, fields) return self._make_network_dict(network, fields)
def get_networks(self, context, filters=None, fields=None, verbose=None): def get_networks(self, context, filters=None, fields=None):
return self._get_collection(context, models_v2.Network, return self._get_collection(context, models_v2.Network,
self._make_network_dict, self._make_network_dict,
filters=filters, fields=fields, filters=filters, fields=fields)
verbose=verbose)
def create_subnet_bulk(self, context, subnets): def create_subnet_bulk(self, context, subnets):
return self._create_bulk('subnet', context, subnets) return self._create_bulk('subnet', context, subnets)
@ -955,15 +944,14 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
context.session.delete(subnet) context.session.delete(subnet)
def get_subnet(self, context, id, fields=None, verbose=None): def get_subnet(self, context, id, fields=None):
subnet = self._get_subnet(context, id, verbose=verbose) subnet = self._get_subnet(context, id)
return self._make_subnet_dict(subnet, fields) return self._make_subnet_dict(subnet, fields)
def get_subnets(self, context, filters=None, fields=None, verbose=None): def get_subnets(self, context, filters=None, fields=None):
return self._get_collection(context, models_v2.Subnet, return self._get_collection(context, models_v2.Subnet,
self._make_subnet_dict, self._make_subnet_dict,
filters=filters, fields=fields, filters=filters, fields=fields)
verbose=verbose)
def create_port_bulk(self, context, ports): def create_port_bulk(self, context, ports):
return self._create_bulk('port', context, ports) return self._create_bulk('port', context, ports)
@ -1077,16 +1065,15 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
port_id=id) port_id=id)
context.session.delete(port) context.session.delete(port)
def get_port(self, context, id, fields=None, verbose=None): def get_port(self, context, id, fields=None):
port = self._get_port(context, id, verbose=verbose) port = self._get_port(context, id)
return self._make_port_dict(port, fields) return self._make_port_dict(port, fields)
def get_ports(self, context, filters=None, fields=None, verbose=None): def get_ports(self, context, filters=None, fields=None):
fixed_ips = filters.pop('fixed_ips', []) if filters else [] fixed_ips = filters.pop('fixed_ips', []) if filters else []
ports = self._get_collection(context, models_v2.Port, ports = self._get_collection(context, models_v2.Port,
self._make_port_dict, self._make_port_dict,
filters=filters, fields=fields, filters=filters, fields=fields)
verbose=verbose)
if ports and fixed_ips: if ports and fixed_ips:
filtered_ports = [] filtered_ports = []

View File

@ -77,9 +77,9 @@ class FloatingIP(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
class L3_NAT_db_mixin(l3.RouterPluginBase): class L3_NAT_db_mixin(l3.RouterPluginBase):
"""Mixin class to add L3/NAT router methods to db_plugin_base_v2""" """Mixin class to add L3/NAT router methods to db_plugin_base_v2"""
def _get_router(self, context, id, verbose=None): def _get_router(self, context, id):
try: try:
router = self._get_by_id(context, Router, id, verbose=verbose) router = self._get_by_id(context, Router, id)
except exc.NoResultFound: except exc.NoResultFound:
raise l3.RouterNotFound(router_id=id) raise l3.RouterNotFound(router_id=id)
except exc.MultipleResultsFound: except exc.MultipleResultsFound:
@ -191,15 +191,14 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
# thanks to cascading on the ORM relationship # thanks to cascading on the ORM relationship
context.session.delete(router) context.session.delete(router)
def get_router(self, context, id, fields=None, verbose=None): def get_router(self, context, id, fields=None):
router = self._get_router(context, id, verbose=verbose) router = self._get_router(context, id)
return self._make_router_dict(router, fields) return self._make_router_dict(router, fields)
def get_routers(self, context, filters=None, fields=None, verbose=None): def get_routers(self, context, filters=None, fields=None):
return self._get_collection(context, Router, return self._get_collection(context, Router,
self._make_router_dict, self._make_router_dict,
filters=filters, fields=fields, filters=filters, fields=fields)
verbose=verbose)
def _check_for_dup_router_subnet(self, context, router_id, def _check_for_dup_router_subnet(self, context, router_id,
network_id, subnet_id): network_id, subnet_id):
@ -315,10 +314,9 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
"interface on subnet %(subnet_id)s" "interface on subnet %(subnet_id)s"
% locals()) % locals())
def _get_floatingip(self, context, id, verbose=None): def _get_floatingip(self, context, id):
try: try:
floatingip = self._get_by_id(context, FloatingIP, id, floatingip = self._get_by_id(context, FloatingIP, id)
verbose=verbose)
except exc.NoResultFound: except exc.NoResultFound:
raise l3.FloatingIPNotFound(floatingip_id=id) raise l3.FloatingIPNotFound(floatingip_id=id)
except exc.MultipleResultsFound: except exc.MultipleResultsFound:
@ -508,16 +506,14 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
context.session.delete(floatingip) context.session.delete(floatingip)
self.delete_port(context, floatingip['floating_port_id']) self.delete_port(context, floatingip['floating_port_id'])
def get_floatingip(self, context, id, fields=None, verbose=None): def get_floatingip(self, context, id, fields=None):
floatingip = self._get_floatingip(context, id, verbose=verbose) floatingip = self._get_floatingip(context, id)
return self._make_floatingip_dict(floatingip, fields) return self._make_floatingip_dict(floatingip, fields)
def get_floatingips(self, context, filters=None, fields=None, def get_floatingips(self, context, filters=None, fields=None):
verbose=None):
return self._get_collection(context, FloatingIP, return self._get_collection(context, FloatingIP,
self._make_floatingip_dict, self._make_floatingip_dict,
filters=filters, fields=fields, filters=filters, fields=fields)
verbose=verbose)
def disassociate_floatingips(self, context, port_id): def disassociate_floatingips(self, context, port_id):
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):

View File

@ -169,7 +169,7 @@ class RouterPluginBase(object):
pass pass
@abstractmethod @abstractmethod
def get_router(self, context, id, fields=None, verbose=None): def get_router(self, context, id, fields=None):
pass pass
@abstractmethod @abstractmethod
@ -177,7 +177,7 @@ class RouterPluginBase(object):
pass pass
@abstractmethod @abstractmethod
def get_routers(self, context, filters=None, fields=None, verbose=None): def get_routers(self, context, filters=None, fields=None):
pass pass
@abstractmethod @abstractmethod
@ -197,7 +197,7 @@ class RouterPluginBase(object):
pass pass
@abstractmethod @abstractmethod
def get_floatingip(self, context, id, fields=None, verbose=None): def get_floatingip(self, context, id, fields=None):
pass pass
@abstractmethod @abstractmethod
@ -205,6 +205,5 @@ class RouterPluginBase(object):
pass pass
@abstractmethod @abstractmethod
def get_floatingips(self, context, filters=None, fields=None, def get_floatingips(self, context, filters=None, fields=None):
verbose=None):
pass pass

View File

@ -148,11 +148,11 @@ class NetworkMultiBladeV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
# TODO (Sumit): Check if we need to perform any rollback here # TODO (Sumit): Check if we need to perform any rollback here
raise raise
def get_network(self, context, id, fields=None, verbose=None): def get_network(self, context, id, fields=None):
"""Currently there is no processing required for the device plugins""" """Currently there is no processing required for the device plugins"""
pass pass
def get_networks(self, context, filters=None, fields=None, verbose=None): def get_networks(self, context, filters=None, fields=None):
"""Currently there is no processing required for the device plugins""" """Currently there is no processing required for the device plugins"""
pass pass
@ -210,11 +210,11 @@ class NetworkMultiBladeV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
# TODO (Sumit): Check if we need to perform any rollback here # TODO (Sumit): Check if we need to perform any rollback here
raise raise
def get_port(self, context, id, fields=None, verbose=None): def get_port(self, context, id, fields=None):
"""Currently there is no processing required for the device plugins""" """Currently there is no processing required for the device plugins"""
pass pass
def get_ports(self, context, filters=None, fields=None, verbose=None): def get_ports(self, context, filters=None, fields=None):
"""Currently there is no processing required for the device plugins""" """Currently there is no processing required for the device plugins"""
pass pass
@ -244,7 +244,7 @@ class NetworkMultiBladeV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""Currently there is no processing required for the device plugins""" """Currently there is no processing required for the device plugins"""
pass pass
def get_subnet(self, context, id, fields=None, verbose=None): def get_subnet(self, context, id, fields=None):
"""Currently there is no processing required for the device plugins""" """Currently there is no processing required for the device plugins"""
pass pass
@ -252,7 +252,7 @@ class NetworkMultiBladeV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""Currently there is no processing required for the device plugins""" """Currently there is no processing required for the device plugins"""
pass pass
def get_subnets(self, context, filters=None, fields=None, verbose=None): def get_subnets(self, context, filters=None, fields=None):
"""Currently there is no processing required for the device plugins""" """Currently there is no processing required for the device plugins"""
pass pass

View File

@ -251,11 +251,11 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
except: except:
raise raise
def get_network(self, context, id, fields=None, verbose=None): def get_network(self, context, id, fields=None):
"""For this model this method will be delegated to vswitch plugin""" """For this model this method will be delegated to vswitch plugin"""
pass pass
def get_networks(self, context, filters=None, fields=None, verbose=None): def get_networks(self, context, filters=None, fields=None):
"""For this model this method will be delegated to vswitch plugin""" """For this model this method will be delegated to vswitch plugin"""
pass pass
@ -263,11 +263,11 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""For this model this method will be delegated to vswitch plugin""" """For this model this method will be delegated to vswitch plugin"""
pass pass
def get_port(self, context, id, fields=None, verbose=None): def get_port(self, context, id, fields=None):
"""For this model this method will be delegated to vswitch plugin""" """For this model this method will be delegated to vswitch plugin"""
pass pass
def get_ports(self, context, filters=None, fields=None, verbose=None): def get_ports(self, context, filters=None, fields=None):
"""For this model this method will be delegated to vswitch plugin""" """For this model this method will be delegated to vswitch plugin"""
pass pass
@ -287,7 +287,7 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""For this model this method will be delegated to vswitch plugin""" """For this model this method will be delegated to vswitch plugin"""
pass pass
def get_subnet(self, context, id, fields=None, verbose=None): def get_subnet(self, context, id, fields=None):
"""For this model this method will be delegated to vswitch plugin""" """For this model this method will be delegated to vswitch plugin"""
pass pass
@ -295,6 +295,6 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""For this model this method will be delegated to vswitch plugin""" """For this model this method will be delegated to vswitch plugin"""
pass pass
def get_subnets(self, context, filters=None, fields=None, verbose=None): def get_subnets(self, context, filters=None, fields=None):
"""For this model this method will be delegated to vswitch plugin""" """For this model this method will be delegated to vswitch plugin"""
pass pass

View File

@ -150,21 +150,19 @@ class PluginV2(db_base_plugin_v2.QuantumDbPluginV2):
except: except:
raise raise
def get_network(self, context, id, fields=None, verbose=None): def get_network(self, context, id, fields=None):
""" """
Gets a particular network Gets a particular network
""" """
LOG.debug("get_network() called\n") LOG.debug("get_network() called\n")
return super(PluginV2, self).get_network(context, id, return super(PluginV2, self).get_network(context, id, fields)
fields, verbose)
def get_networks(self, context, filters=None, fields=None, verbose=None): def get_networks(self, context, filters=None, fields=None):
""" """
Gets all networks Gets all networks
""" """
LOG.debug("get_networks() called\n") LOG.debug("get_networks() called\n")
return super(PluginV2, self).get_networks(context, filters, return super(PluginV2, self).get_networks(context, filters, fields)
fields, verbose)
def create_port(self, context, port): def create_port(self, context, port):
""" """

View File

@ -330,15 +330,14 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
if self.agent_rpc: if self.agent_rpc:
self.notifier.network_delete(self.rpc_context, id) self.notifier.network_delete(self.rpc_context, id)
def get_network(self, context, id, fields=None, verbose=None): def get_network(self, context, id, fields=None):
net = super(LinuxBridgePluginV2, self).get_network(context, id, net = super(LinuxBridgePluginV2, self).get_network(context, id, None)
None, verbose)
self._extend_network_dict(context, net) self._extend_network_dict(context, net)
return self._fields(net, fields) return self._fields(net, fields)
def get_networks(self, context, filters=None, fields=None, verbose=None): def get_networks(self, context, filters=None, fields=None):
nets = super(LinuxBridgePluginV2, self).get_networks(context, filters, nets = super(LinuxBridgePluginV2, self).get_networks(context, filters,
None, verbose) None)
for net in nets: for net in nets:
self._extend_network_dict(context, net) self._extend_network_dict(context, net)
# TODO(rkukura): Filter on extended attributes. # TODO(rkukura): Filter on extended attributes.

View File

@ -144,16 +144,16 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
plugin = self._get_plugin(flavor) plugin = self._get_plugin(flavor)
return plugin.delete_network(context, id) return plugin.delete_network(context, id)
def get_network(self, context, id, fields=None, verbose=None): def get_network(self, context, id, fields=None):
flavor = meta_db_v2.get_flavor_by_network(id) flavor = meta_db_v2.get_flavor_by_network(id)
plugin = self._get_plugin(flavor) plugin = self._get_plugin(flavor)
net = plugin.get_network(context, id, fields, verbose) net = plugin.get_network(context, id, fields)
if not fields or 'flavor:id' in fields: if not fields or 'flavor:id' in fields:
self._extend_network_dict(context, net) self._extend_network_dict(context, net)
return net return net
def get_networks_with_flavor(self, context, filters=None, def get_networks_with_flavor(self, context, filters=None,
fields=None, verbose=None): fields=None):
collection = self._model_query(context, models_v2.Network) collection = self._model_query(context, models_v2.Network)
collection = collection.join(Flavor, collection = collection.join(Flavor,
models_v2.Network.id == Flavor.network_id) models_v2.Network.id == Flavor.network_id)
@ -167,11 +167,9 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
collection = collection.filter(column.in_(value)) collection = collection.filter(column.in_(value))
return [self._make_network_dict(c, fields) for c in collection.all()] return [self._make_network_dict(c, fields) for c in collection.all()]
def get_networks(self, context, filters=None, fields=None, verbose=None): def get_networks(self, context, filters=None, fields=None):
nets = self.get_networks_with_flavor(context, filters, nets = self.get_networks_with_flavor(context, filters, None)
None, verbose) return [self.get_network(context, net['id'], fields)
return [self.get_network(context, net['id'],
fields, verbose)
for net in nets] for net in nets]
def _get_flavor_by_network_id(self, network_id): def _get_flavor_by_network_id(self, network_id):

View File

@ -52,10 +52,9 @@ class NECPluginV2Base(db_base_plugin_v2.QuantumDbPluginV2):
'status': packet_filter['status']} 'status': packet_filter['status']}
return self._fields(res, fields) return self._fields(res, fields)
def _get_packet_filter(self, context, id, verbose=None): def _get_packet_filter(self, context, id):
try: try:
packet_filter = self._get_by_id(context, nmodels.PacketFilter, id, packet_filter = self._get_by_id(context, nmodels.PacketFilter, id)
verbose=verbose)
except exc.NoResultFound: except exc.NoResultFound:
raise q_exc.PacketFilterNotFound(id=id) raise q_exc.PacketFilterNotFound(id=id)
except exc.MultipleResultsFound: except exc.MultipleResultsFound:
@ -63,18 +62,16 @@ class NECPluginV2Base(db_base_plugin_v2.QuantumDbPluginV2):
raise q_exc.PacketFilterNotFound(id=id) raise q_exc.PacketFilterNotFound(id=id)
return packet_filter return packet_filter
def get_packet_filter(self, context, id, fields=None, verbose=None): def get_packet_filter(self, context, id, fields=None):
packet_filter = self._get_packet_filter(context, id, verbose=verbose) packet_filter = self._get_packet_filter(context, id)
return self._make_packet_filter_dict(packet_filter, fields) return self._make_packet_filter_dict(packet_filter, fields)
def get_packet_filters(self, context, filters=None, fields=None, def get_packet_filters(self, context, filters=None, fields=None):
verbose=None):
return self._get_collection(context, return self._get_collection(context,
nmodels.PacketFilter, nmodels.PacketFilter,
self._make_packet_filter_dict, self._make_packet_filter_dict,
filters=filters, filters=filters,
fields=fields, fields=fields)
verbose=verbose)
def create_packet_filter(self, context, packet_filter): def create_packet_filter(self, context, packet_filter):
pf = packet_filter['packet_filter'] pf = packet_filter['packet_filter']

View File

@ -358,7 +358,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
LOG.debug("Returning pairs for network: %s" % (pairs)) LOG.debug("Returning pairs for network: %s" % (pairs))
return pairs return pairs
def get_network(self, context, id, fields=None, verbose=None): def get_network(self, context, id, fields=None):
""" """
Retrieves all attributes of the network, NOT including Retrieves all attributes of the network, NOT including
the ports of that network. the ports of that network.
@ -387,7 +387,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
# the context, as with shared networks context.tenant_id and # the context, as with shared networks context.tenant_id and
# network['tenant_id'] might differ on GETs # network['tenant_id'] might differ on GETs
# goto to the plugin DB and fecth the network # goto to the plugin DB and fecth the network
network = self._get_network(context, id, verbose) network = self._get_network(context, id)
# TODO(salvatore-orlando): verify whether the query on os_tid is # TODO(salvatore-orlando): verify whether the query on os_tid is
# redundant or not. # redundant or not.
if context.is_admin is False: if context.is_admin is False:
@ -429,7 +429,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
context.tenant_id, d)) context.tenant_id, d))
return d return d
def get_networks(self, context, filters=None, fields=None, verbose=None): def get_networks(self, context, filters=None, fields=None):
""" """
Retrieves all attributes of the network, NOT including Retrieves all attributes of the network, NOT including
the ports of that network. the ports of that network.
@ -567,7 +567,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
context.tenant_id) context.tenant_id)
return super(NvpPluginV2, self).update_network(context, id, network) return super(NvpPluginV2, self).update_network(context, id, network)
def get_ports(self, context, filters=None, fields=None, verbose=None): def get_ports(self, context, filters=None, fields=None):
""" """
Returns all ports from given tenant Returns all ports from given tenant
@ -806,7 +806,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
LOG.debug("delete_port() completed for tenant: %s" % context.tenant_id) LOG.debug("delete_port() completed for tenant: %s" % context.tenant_id)
return super(NvpPluginV2, self).delete_port(context, id) return super(NvpPluginV2, self).delete_port(context, id)
def get_port(self, context, id, fields=None, verbose=None): def get_port(self, context, id, fields=None):
""" """
This method allows the user to retrieve a remote interface This method allows the user to retrieve a remote interface
that is attached to this particular port. that is attached to this particular port.
@ -823,8 +823,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
:raises: exception.NetworkNotFound :raises: exception.NetworkNotFound
""" """
quantum_db = super(NvpPluginV2, self).get_port(context, id, fields, quantum_db = super(NvpPluginV2, self).get_port(context, id, fields)
verbose)
port, cluster = ( port, cluster = (
nvplib.get_port_by_quantum_tag(self.clusters, nvplib.get_port_by_quantum_tag(self.clusters,

View File

@ -338,15 +338,14 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
self.notifier.network_delete(self.context, id) self.notifier.network_delete(self.context, id)
return result return result
def get_network(self, context, id, fields=None, verbose=None): def get_network(self, context, id, fields=None):
net = super(OVSQuantumPluginV2, self).get_network(context, id, net = super(OVSQuantumPluginV2, self).get_network(context, id, None)
None, verbose)
self._extend_network_dict(context, net) self._extend_network_dict(context, net)
return self._fields(net, fields) return self._fields(net, fields)
def get_networks(self, context, filters=None, fields=None, verbose=None): def get_networks(self, context, filters=None, fields=None):
nets = super(OVSQuantumPluginV2, self).get_networks(context, filters, nets = super(OVSQuantumPluginV2, self).get_networks(context, filters,
None, verbose) None)
for net in nets: for net in nets:
self._extend_network_dict(context, net) self._extend_network_dict(context, net)
# TODO(rkukura): Filter on extended attributes. # TODO(rkukura): Filter on extended attributes.

View File

@ -66,7 +66,7 @@ class QuantumPluginBaseV2(object):
pass pass
@abstractmethod @abstractmethod
def get_subnet(self, context, id, fields=None, verbose=None): def get_subnet(self, context, id, fields=None):
pass pass
@abstractmethod @abstractmethod
@ -74,7 +74,7 @@ class QuantumPluginBaseV2(object):
pass pass
@abstractmethod @abstractmethod
def get_subnets(self, context, filters=None, fields=None, verbose=None): def get_subnets(self, context, filters=None, fields=None):
pass pass
@abstractmethod @abstractmethod
@ -105,11 +105,11 @@ class QuantumPluginBaseV2(object):
pass pass
@abstractmethod @abstractmethod
def get_network(self, context, id, fields=None, verbose=None): def get_network(self, context, id, fields=None):
pass pass
@abstractmethod @abstractmethod
def get_networks(self, context, filters=None, fields=None, verbose=None): def get_networks(self, context, filters=None, fields=None):
pass pass
@abstractmethod @abstractmethod
@ -188,9 +188,9 @@ class QuantumPluginBaseV2(object):
pass pass
@abstractmethod @abstractmethod
def get_port(self, context, id, fields=None, verbose=None): def get_port(self, context, id, fields=None):
pass pass
@abstractmethod @abstractmethod
def get_ports(self, context, filters=None, fields=None, verbose=None): def get_ports(self, context, filters=None, fields=None):
pass pass

View File

@ -165,77 +165,6 @@ class APIv2TestCase(APIv2TestBase):
# raises without being caught. Using unittest2 # raises without being caught. Using unittest2
# or dropping 2.6 support so we can use addCleanup # or dropping 2.6 support so we can use addCleanup
# will get around this. # will get around this.
def test_verbose_attr(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': 'foo'})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=['foo'])
def test_multiple_verbose_attr(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': ['foo', 'bar']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=['foo',
'bar'])
def test_verbose_false_str(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': 'false'})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=False)
def test_verbose_true_str(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': 'true'})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=True)
def test_verbose_true_trump_attr(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': ['true', 'foo']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=True)
def test_verbose_false_trump_attr(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': ['false', 'foo']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=False)
def test_verbose_true_trump_false(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'verbose': ['true', 'false']})
instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY,
fields=mock.ANY,
verbose=True)
def _do_field_list(self, resource, base_fields): def _do_field_list(self, resource, base_fields):
attr_info = attributes.RESOURCE_ATTRIBUTE_MAP[resource] attr_info = attributes.RESOURCE_ATTRIBUTE_MAP[resource]
policy_attrs = [name for (name, info) in attr_info.items() policy_attrs = [name for (name, info) in attr_info.items()
@ -252,8 +181,7 @@ class APIv2TestCase(APIv2TestBase):
fields = self._do_field_list('networks', ['foo']) fields = self._do_field_list('networks', ['foo'])
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY, filters=mock.ANY,
fields=fields, fields=fields)
verbose=mock.ANY)
def test_fields_multiple(self): def test_fields_multiple(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -263,8 +191,7 @@ class APIv2TestCase(APIv2TestBase):
self.api.get(_get_path('networks'), {'fields': ['foo', 'bar']}) self.api.get(_get_path('networks'), {'fields': ['foo', 'bar']})
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY, filters=mock.ANY,
fields=fields, fields=fields)
verbose=mock.ANY)
def test_fields_multiple_with_empty(self): def test_fields_multiple_with_empty(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -274,8 +201,7 @@ class APIv2TestCase(APIv2TestBase):
self.api.get(_get_path('networks'), {'fields': ['foo', '']}) self.api.get(_get_path('networks'), {'fields': ['foo', '']})
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY, filters=mock.ANY,
fields=fields, fields=fields)
verbose=mock.ANY)
def test_fields_empty(self): def test_fields_empty(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -284,8 +210,7 @@ class APIv2TestCase(APIv2TestBase):
self.api.get(_get_path('networks'), {'fields': ''}) self.api.get(_get_path('networks'), {'fields': ''})
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY, filters=mock.ANY,
fields=[], fields=[])
verbose=mock.ANY)
def test_fields_multiple_empty(self): def test_fields_multiple_empty(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -294,8 +219,7 @@ class APIv2TestCase(APIv2TestBase):
self.api.get(_get_path('networks'), {'fields': ['', '']}) self.api.get(_get_path('networks'), {'fields': ['', '']})
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=mock.ANY, filters=mock.ANY,
fields=[], fields=[])
verbose=mock.ANY)
def test_filters(self): def test_filters(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -305,8 +229,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {'foo': ['bar']} filters = {'foo': ['bar']}
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters, filters=filters,
fields=mock.ANY, fields=mock.ANY)
verbose=mock.ANY)
def test_filters_empty(self): def test_filters_empty(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -316,8 +239,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {} filters = {}
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters, filters=filters,
fields=mock.ANY, fields=mock.ANY)
verbose=mock.ANY)
def test_filters_multiple_empty(self): def test_filters_multiple_empty(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -327,8 +249,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {} filters = {}
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters, filters=filters,
fields=mock.ANY, fields=mock.ANY)
verbose=mock.ANY)
def test_filters_multiple_with_empty(self): def test_filters_multiple_with_empty(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -338,8 +259,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {'foo': ['bar']} filters = {'foo': ['bar']}
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters, filters=filters,
fields=mock.ANY, fields=mock.ANY)
verbose=mock.ANY)
def test_filters_multiple_values(self): def test_filters_multiple_values(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -349,8 +269,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {'foo': ['bar', 'bar2']} filters = {'foo': ['bar', 'bar2']}
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters, filters=filters,
fields=mock.ANY, fields=mock.ANY)
verbose=mock.ANY)
def test_filters_multiple(self): def test_filters_multiple(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -361,8 +280,7 @@ class APIv2TestCase(APIv2TestBase):
filters = {'foo': ['bar'], 'foo2': ['bar2']} filters = {'foo': ['bar'], 'foo2': ['bar2']}
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters, filters=filters,
fields=mock.ANY, fields=mock.ANY)
verbose=mock.ANY)
def test_filters_with_fields(self): def test_filters_with_fields(self):
instance = self.plugin.return_value instance = self.plugin.return_value
@ -373,34 +291,7 @@ class APIv2TestCase(APIv2TestBase):
fields = self._do_field_list('networks', ['foo']) fields = self._do_field_list('networks', ['foo'])
instance.get_networks.assert_called_once_with(mock.ANY, instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters, filters=filters,
fields=fields, fields=fields)
verbose=mock.ANY)
def test_filters_with_verbose(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'foo': 'bar',
'verbose': 'true'})
filters = {'foo': ['bar']}
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=mock.ANY,
verbose=True)
def test_filters_with_fields_and_verbose(self):
instance = self.plugin.return_value
instance.get_networks.return_value = []
self.api.get(_get_path('networks'), {'foo': 'bar',
'fields': 'foo',
'verbose': 'true'})
filters = {'foo': ['bar']}
fields = self._do_field_list('networks', ['foo'])
instance.get_networks.assert_called_once_with(mock.ANY,
filters=filters,
fields=fields,
verbose=True)
# Note: since all resources use the same controller and validation # Note: since all resources use the same controller and validation

View File

@ -136,7 +136,6 @@ class L3NatExtensionTestCase(unittest.TestCase):
res = self.api.get(_get_path('routers')) res = self.api.get(_get_path('routers'))
instance.get_routers.assert_called_with(mock.ANY, fields=mock.ANY, instance.get_routers.assert_called_with(mock.ANY, fields=mock.ANY,
verbose=mock.ANY,
filters=mock.ANY) filters=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code) self.assertEqual(res.status_int, exc.HTTPOk.code)
@ -174,8 +173,7 @@ class L3NatExtensionTestCase(unittest.TestCase):
res = self.api.get(_get_path('routers', id=router_id)) res = self.api.get(_get_path('routers', id=router_id))
instance.get_router.assert_called_with(mock.ANY, router_id, instance.get_router.assert_called_with(mock.ANY, router_id,
fields=mock.ANY, fields=mock.ANY)
verbose=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code) self.assertEqual(res.status_int, exc.HTTPOk.code)
self.assertTrue('router' in res.json) self.assertTrue('router' in res.json)
router = res.json['router'] router = res.json['router']

View File

@ -250,7 +250,7 @@ class QuantumPolicyTestCase(unittest.TestCase):
def tearDown(self): def tearDown(self):
self.patcher.stop() self.patcher.stop()
quantum.policy.reset() policy.reset()
def test_nonadmin_write_on_private_returns_403(self): def test_nonadmin_write_on_private_returns_403(self):
action = "update_network" action = "update_network"