Hi-<div><br></div><div>While developing the new extension, I was struck at the SQLalchemy ORM query,</div><div><br></div><div>To achieve, the query below in ORM,</div><div><br></div><div><div><font face="courier new, monospace">select distinct(inst.hostname) as server_name, </font></div>
<div><font face="courier new, monospace"> fip.address as fixed_ip_address,</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span> vif.address as fixed_ip_mac_address</font></div>
<div><font face="courier new, monospace">from instances inst, instance_metadata mtd, virtual_interfaces vif, fixed_ips fip</font></div><div><font face="courier new, monospace">where <a href="http://inst.id">inst.id</a> = mtd.instance_id<span class="Apple-tab-span" style="white-space:pre"> </span> and</font></div>
<div><font face="courier new, monospace"> mtd.instance_id = vif.instance_id and</font></div><div><font face="courier new, monospace"> vif.instance_id = fip.instance_id and</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span> inst.project_id = 'e216fcb54dc944a8ab16e4e325299643' and</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span> mtd.key = 'Server Group' and</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre"> </span> mtd.value = 'DOM1'</font></div>
<div><font face="courier new, monospace">group by mtd.key,mtd.value;</font></div><div><br></div><div><font face="courier new, monospace">SQL></font></div><div><font face="courier new, monospace">+-------------+------------------+----------------------+</font></div>
<div><font face="courier new, monospace">| server_name | fixed_ip_address | fixed_ip_mac_address |</font></div><div><font face="courier new, monospace">+-------------+------------------+----------------------+</font></div>
<div><font face="courier new, monospace">| serverpoc | 172.15.1.2 | fa:16:3e:56:47:71 |</font></div><div><font face="courier new, monospace">| serverpoc2 | 172.15.1.3 | fa:16:3e:4f:3c:9b |</font></div>
<div><font face="courier new, monospace">+-------------+------------------+----------------------+</font></div><div><br></div><div><br></div><div>I have written the ORM query as</div><div><br></div><div><div><font face="courier new, monospace">result = session.query(models.Instance.hostname.distinct(),models.FixedIp.address,models.VirtualInterface.address).\</font></div>
<div><font face="courier new, monospace"> join((models.InstanceMetadata,</font></div><div><font face="courier new, monospace"> models.InstanceMetadata.instance_id == <a href="http://models.Instance.id">models.Instance.id</a>)).\</font></div>
<div><font face="courier new, monospace"> join ((models.FixedIp,</font></div><div><font face="courier new, monospace"> models.FixedIp.instance_id == models.InstanceMetadata.instance_id)).\</font></div>
<div><font face="courier new, monospace"> join ((models.VirtualInterface,</font></div><div><font face="courier new, monospace"> models.VirtualInterface.instance_id == models.FixedIp.instance_id)).\</font></div>
<div><font face="courier new, monospace"> filter(and_(models.Instance.project_id == search_opts['project_id'])).\</font></div><div><font face="courier new, monospace"> filter(and_(models.InstanceMetadata.key == str(search_opts['key']) )).\</font></div>
<div><font face="courier new, monospace"> filter(and_(models.InstanceMetadata.value == str(search_opts['value']))).\</font></div><div><font face="courier new, monospace"> all()</font></div>
</div><div><br></div><div>I'm new to sqlalchemy and with the help from existing queries in nova api, I have come upto this level. </div><div><br></div><div>Can any one guide me why the above ORM query is not returning rows? Is the ORM query reflecting correctly the SQL query above.</div>
<div><br></div><div>Please guide me troubleshoot the same. I was unable to plot the mistake in the ORM. Am i correct with respect to the ORM query preparation?</div><div><br></div><div><br></div><div>Thanks a lot in advance.</div>
<div><br></div>-- <br>Regards,<br>----------------------------------------------<br>Trinath Somanchi,<div>+91 9866 235 130</div><br>
</div>