X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=xenserver%2Fusr_share_openvswitch_scripts_ovs-xapi-sync;h=649ddbe536521d870b247e6e953be4b3606391c1;hb=825da1c6d1c7b9bc5128d7588b8bad6efaae650e;hp=5083bbd160f71eef2c8046844be0d81c85a4a316;hpb=53cf9963ccc60b443d738b31fbb446bc79170693;p=sliver-openvswitch.git diff --git a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync index 5083bbd16..649ddbe53 100755 --- a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync +++ b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync @@ -41,6 +41,7 @@ vlog = ovs.vlog.Vlog("ovs-xapi-sync") session = None flush_cache = False exiting = False +xapi_down = False def unixctl_exit(conn, unused_argv, unused_aux): @@ -82,13 +83,44 @@ 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 +# There are possibilities when multiple xs-network-uuids are set for a bridge. +# 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): + global xapi_down + 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: + try: + recs = session.xenapi.network.get_all_records_where(\ + 'field "uuid"="%s"' % bridge_id) + if recs: + pifs = recs.values()[0]['PIFs'] + for pif in pifs: + try: + rec = session.xenapi.PIF.get_record(pif) + if rec['VLAN'] == '-1': + return bridge_id + except XenAPI.Failure: + vlog.warn("Could not find XAPI entry for PIF %s" % pif) + continue + + except XenAPI.Failure: + vlog.warn("Could not find XAPI entry for bridge_id %s" % bridge_id) + continue + + vlog.warn("Failed to get a single bridge id from Xapi.") + xapi_down = True + return default # By default, the "bridge-id" external id in the Bridge table is the # same as "xs-network-uuids". This may be overridden by defining a @@ -210,7 +242,7 @@ def update_in_band_mgmt(row): def main(): - global flush_cache + global flush_cache, xapi_down parser = argparse.ArgumentParser() parser.add_argument("database", metavar="DATABASE", @@ -257,13 +289,18 @@ def main(): break; idl.run() - if not flush_cache and seqno == idl.change_seqno: + if not xapi_down and not flush_cache and seqno == idl.change_seqno: poller = ovs.poller.Poller() unixctl_server.wait(poller) idl.wait(poller) poller.block() continue + if xapi_down: + vlog.warn("Xapi is probably down. Retry again after a second.") + time.sleep(1) + xapi_down = False + if flush_cache: vlog.info("Flushing cache as the result of unixctl.") bridges = {} @@ -287,6 +324,9 @@ def main(): bridge_id = nbd if bridge_id is None: bridge_id = row.external_ids.get("xs-network-uuids") + if bridge_id and len(bridge_id.split(";")) > 1: + bridge_ids = bridge_id.split(";") + bridge_id = get_single_bridge_id(bridge_ids, "") if bridge_id is not None: set_external_id(row, "bridge-id", bridge_id.split(";")[0])