[openstack-dev] [Neutron] need help in translating sql query to sqlalchemy query

Venkata Anil vkommadi at redhat.com
Tue Dec 1 15:41:15 UTC 2015



On 12/01/2015 09:06 PM, Sean M. Collins wrote:
> On Tue, Dec 01, 2015 at 10:22:41AM EST, Venkata Anil wrote:
>> Thanks Sean. I will check that.
>>
>> Meanwhile I tried this and it is working
>>
>>          port1 = orm.aliased(models_v2.Port, name="port1")
>>          port2 = orm.aliased(models_v2.Port, name="port2")
>>          router_intf_qry =
>> context.session.query(RouterPort.router_id).join((port1,
>> port1.id==RouterPort.port_id), (port2,
>> port2.device_id==RouterPort.router_id)).filter(port1.network_id==int_net_id,
>> port2.network_id==ext_net_id).distinct()
>>
>>         for router in router_intf_qry:
>>              router_id =router.router_id
>>
> That looks pretty close. My only suggestion would be to try and see if
> you can just alias it once, instead of twice. Basically see if it is
> possible to replace all the port1 references with "models_v2.Port"
>
Thanks Sean. Sure, I will try that suggestion.





More information about the OpenStack-dev mailing list