X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=xenserver%2Fusr_share_openvswitch_scripts_ovs-xapi-sync;h=1c8ad51a4b18b665a536effb87b8274615308478;hb=1d5aaa61fa8ca68f487e8b578b7aa99a0bbd1f26;hp=ac56d371cd51ae1be7ee2278c83e91949c520081;hpb=ede1aa66eca16c812a4349a5aad4131b291f7293;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 ac56d371c..1c8ad51a4 100755 --- a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync +++ b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync @@ -1,5 +1,5 @@ #!/usr/bin/python -# Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc. +# Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -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): @@ -89,33 +90,17 @@ def get_network_by_bridge(br_name): 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): - 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 +# 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'] + + 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 @@ -238,7 +223,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", @@ -285,13 +270,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 = {} @@ -304,25 +294,27 @@ def main(): new_bridges = {} for row in idl.tables["Bridge"].rows.itervalues(): - if row.name in bridges: - nbd = bridges[row.name] - else: - # New bridge. + bridge_id = bridges.get(row.name) + if bridge_id is None: + # Configure the new bridge. update_fail_mode(row) update_in_band_mgmt(row) - nbd = get_bridge_id(row.name) - 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, bridge_ids[0]) + # Get the correct bridge_id, if we can. + bridge_id = get_bridge_id(row.name) + if bridge_id is None: + xs_network_uuids = row.external_ids.get("xs-network-uuids") + if xs_network_uuids: + bridge_ids = xs_network_uuids.split(";") + if len(bridge_ids) == 1: + bridge_id = bridge_ids[0] + else: + bridge_id = get_single_bridge_id(bridge_ids, + row.name) + set_external_id(row, "bridge-id", bridge_id) if bridge_id is not None: - set_external_id(row, "bridge-id", bridge_id.split(";")[0]) - - new_bridges[row.name] = nbd + new_bridges[row.name] = bridge_id bridges = new_bridges iface_by_name = {}