allow filters to use 'like' operation of sqlalchemy

Registered by yong sheng gong

currently, the get_xxxs use the in_ to query the resources in filters parameter. It cannot deal with the requirement like ' to list all of the ports which have the ip address like this '10.0.%', or to list all of the network the name of which is like 'test_network%'.
This BP will add an way to deal with it.
for top field:
quantum net-list --name test_network% x_query=like
query = query.filter(Network.name.like('test_network%'))
for sub field:
quantum port-list --fixed-ips ip_address~=10.0.%
query = query.filter(IPAllocation.ip_address.like('10.0.%'))

for API compatible:
we will use the current filters parameter:
quantum net-list --name test_network% x_query=like
filters = {'name': [test_network%],
              'name_x_query': ['like']}
quantum port-list --fixed-ips ip_address~=10.0.%
filters = {'fixed-ips': {'ip_address': ['10.0.%']},
              'fixed-ips_ip_address_x_query': ['like']}

Blueprint information

Status:
Complete
Approver:
Salvatore Orlando
Priority:
Undefined
Drafter:
None
Direction:
Approved
Assignee:
yong sheng gong
Definition:
Obsolete
Series goal:
None
Implementation:
Needs Code Review
Milestone target:
milestone icon next
Started by
yong sheng gong
Completed by
Armando Migliaccio

Related branches

Sprints

Whiteboard

Dec-07-2015(armax): If someone is interested in pursuing it, this must be re-submitted according to guidelines defined in [1].

[1] http://docs.openstack.org/developer/neutron/policies/blueprints.html

-----------

4-Sep: Moving to next for possible inclusion into Icehouse.

Jordan P : I am not sure about this one. I find the x_query=like, the % and ~= notations not elegant. I would rather try to detect if the submitted IPs are complete (4 bytes) and if not make use the LIKE SQL operator (more precisely : use the SQL Alchemy helper). For the network name, it seems reasonable to always use a "like" query.

One should also note that currently the filter is done with an IN operator which allow several values to be passed.

Update 2013-05-24:
- Set Salvatore Orlando as approver, waiting for specification
- Regardless of implementation/style details, compliance with other Openstack APIs should be the first factor to take into account. My (Salvatore) opinion is that it does not matter whether Quantum has a nicer mechanism than nova. If users are forced to learn two distinct methods for doing regex-based queries on Quantum and Nova, that wouldn't be good.

(yong sheng gong said on 2013-05-25): nova help list:
  --ip <ip-regexp> Search with regular expression match by IP address
                        (Admin only).
  --ip6 <ip6-regexp> Search with regular expression match by IPv6 address
                        (Admin only).
  --name <name-regexp> Search with regular expression match by name
  --instance-name <name-regexp>
                        Search with regular expression match by instance name

and I want our API have a generic way to deal with 'filters' using regex besides the current 'in_'. so that we can deal with 'quantum xxx-list --anyattr regext-value'.

(yong sheng gong said on 2013-07-25):
to keep compliance with in_, we have to make a difference, for example we have to add action=regex into neutron client command.
neutron net-list --name action=regex n[x]]x

Gerrit topic: https://review.openstack.org/#q,topic:bug/1182883,n,z

Addressed by: https://review.openstack.org/38600
    allow regex in List operation of API

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.