Also fix some minor style issues and add this script to the list of things checked in the pep8 tox environment.
Signed-off-by: Russell Bryant <russ...@ovn.org> --- python/tox.ini | 2 +- .../usr_share_openvswitch_scripts_ovs-xapi-sync | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/python/tox.ini b/python/tox.ini index a63dd86..73dd2e9 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -14,7 +14,7 @@ deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt [testenv:pep8] -commands = flake8 --exclude="*testsuite.dir*" ovs/ ovstest/ {toxinidir}/../tests/ {toxinidir}/../debian/ovs-monitor-ipsec {toxinidir}/../utilities/ovs-pcap.in {toxinidir}/../vtep/ovs-vtep {toxinidir}/../ofproto/ipfix-gen-entities +commands = flake8 --exclude="*testsuite.dir*" ovs/ ovstest/ {toxinidir}/../tests/ {toxinidir}/../debian/ovs-monitor-ipsec {toxinidir}/../utilities/ovs-pcap.in {toxinidir}/../vtep/ovs-vtep {toxinidir}/../ofproto/ipfix-gen-entities {toxinidir}/../xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync [flake8] ignore=E111,E113,E126,E127,E128,E129,E131 diff --git a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync index f5c38be..098e4bf 100755 --- a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync +++ b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync @@ -30,12 +30,11 @@ import time import XenAPI import ovs.dirs -from ovs.db import error -from ovs.db import types import ovs.daemon import ovs.db.idl import ovs.unixctl import ovs.unixctl.server +import six vlog = ovs.vlog.Vlog("ovs-xapi-sync") session = None @@ -69,7 +68,7 @@ def init_session(): try: session = XenAPI.xapi_local() session.xenapi.login_with_password("", "") - except XenAPI.Failure, e: + except XenAPI.Failure as e: session = None vlog.warn("Couldn't login to XAPI (%s)" % e) return False @@ -83,12 +82,14 @@ def get_network_by_bridge(br_name): " XAPI session could not be initialized" % br_name) return None - recs = session.xenapi.network.get_all_records_where('field "bridge"="%s"' % br_name) + recs = session.xenapi.network.get_all_records_where('field "bridge"="%s"' + % br_name) if len(recs) > 0: - return recs.values()[0] + return list(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 associated with the bridge # name. @@ -103,6 +104,7 @@ def get_single_bridge_id(bridge_ids, br_name, default=None): 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 # "nicira-bridge-id" key in the "other_config" field of the network @@ -267,7 +269,7 @@ def main(): while True: unixctl_server.run() if exiting: - break; + break idl.run() if not xapi_down and not flush_cache and seqno == idl.change_seqno: @@ -293,7 +295,7 @@ def main(): txn = ovs.db.idl.Transaction(idl) new_bridges = {} - for row in idl.tables["Bridge"].rows.itervalues(): + for row in six.itervalues(idl.tables["Bridge"].rows): bridge_id = bridges.get(row.name) if bridge_id is None: # Configure the new bridge. @@ -318,12 +320,12 @@ def main(): bridges = new_bridges iface_by_name = {} - for row in idl.tables["Interface"].rows.itervalues(): + for row in six.itervalues(idl.tables["Interface"].rows): iface_by_name[row.name] = row new_iface_ids = {} new_vm_ids = {} - for row in idl.tables["Interface"].rows.itervalues(): + for row in six.itervalues(idl.tables["Interface"].rows): # Match up paired vif and tap devices. if row.name.startswith("vif"): vif = row -- 2.5.0 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev