xenserver: Improve efficiency of code by using get_all_records_where()
authorRob Hoes <rob.hoes@citrix.com>
Wed, 27 Jun 2012 15:14:21 +0000 (16:14 +0100)
committerBen Pfaff <blp@nicira.com>
Wed, 27 Jun 2012 16:33:55 +0000 (09:33 -0700)
Replace the get_record() for network references which caused as many
slave-to-master calls as there are Network records plus one.
The get_all_records_where() call gets exactly what is needed with a single
call.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
Acked-by: Dominic Curran <dominic.curran@citrix.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync

index 5083bbd..cb35e7a 100755 (executable)
@@ -82,10 +82,9 @@ def get_network_by_bridge(br_name):
                 " XAPI session could not be initialized" % br_name)
         return None
 
-    for n in session.xenapi.network.get_all():
-        rec = session.xenapi.network.get_record(n)
-        if rec['bridge'] == br_name:
-            return rec
+    recs = session.xenapi.network.get_all_records_where('field "bridge"="%s"' % br_name)
+    if len(recs) > 0:
+        return recs.values()[0]
 
     return None