-# In cases like that, we should choose the bridge-id whose PIF does not have a
-# VLAN associated with it.
-def get_single_bridge_id(bridge_ids, default=None):
- if not init_session():
- vlog.warn("Failed to get single bridge id from %s because"
- "XAPI session could not be initialized" % bridge_ids)
- return default
-
- for bridge_id in bridge_ids:
- recs = session.xenapi.network.get_all_records_where('field "uuid"="%s"' % bridge_id)
- if recs:
- pifs = recs.values()[0]['PIFs']
- for pif in pifs:
- rec = session.xenapi.PIF.get_record(pif)
- if rec['VLAN'] == '-1':
- return bridge_id
+# In cases like that, we should choose the bridge-id associated with the bridge
+# name.
+def get_single_bridge_id(bridge_ids, br_name, default=None):
+ global xapi_down
+
+ rec = get_network_by_bridge(br_name)
+ if rec and rec['uuid'] in bridge_ids:
+ return rec['uuid']