From c07686a4b073aa2092a0653a3fa92bb78688e090 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Tue, 27 Oct 2009 18:38:33 -0700 Subject: [PATCH] xenserver: Set network-uuid for internal bridges The "citrix" branch contains a script called dump-vif-details that would write detailed information about the vifs into ovs-vswitchd.conf. Additionally, it would add the network-uuid information for internal bridges, since the interface-reconfigure script that normally takes care of this is not called on internal bridges. The Midnight Ride release no longer needs to call dump-vif-details, but the functionality to write the network-uuid for internal bridges was not put elsewhere. This commit addresses that. It introduces the vif-on-internal-bridge script, which is a hack until a more appropriate method, such XAPI writing out the information to xenstore, becomes available. Bug #2208 --- xenserver/automake.mk | 1 + xenserver/etc_xensource_scripts_vif | 22 ++++++++ ...are_vswitch_scripts_vif-on-internal-bridge | 56 +++++++++++++++++++ xenserver/vswitch-xen.spec | 3 + 4 files changed, 82 insertions(+) create mode 100755 xenserver/usr_share_vswitch_scripts_vif-on-internal-bridge diff --git a/xenserver/automake.mk b/xenserver/automake.mk index 691d379ce..be0530e3a 100644 --- a/xenserver/automake.mk +++ b/xenserver/automake.mk @@ -19,4 +19,5 @@ EXTRA_DIST += \ xenserver/usr_sbin_brctl \ xenserver/usr_sbin_xen-bugtool \ xenserver/usr_share_vswitch_scripts_sysconfig.template \ + xenserver/usr_share_vswitch_scripts_vif-on-internal-bridge \ xenserver/vswitch-xen.spec diff --git a/xenserver/etc_xensource_scripts_vif b/xenserver/etc_xensource_scripts_vif index 033e001cb..fdfc3205d 100755 --- a/xenserver/etc_xensource_scripts_vif +++ b/xenserver/etc_xensource_scripts_vif @@ -16,6 +16,7 @@ vsctl="/usr/bin/ovs-vsctl" dump_vif_details="/usr/share/vswitch/scripts/dump-vif-details" service="/sbin/service" IP="/sbin/ip" +vif_on_internal_bridge="/usr/share/vswitch/scripts/vif-on-internal-bridge" handle_promiscuous() { @@ -74,6 +75,27 @@ handle_vif_details() if [ -n "${vm_uuid}" ] ; then vif_details="$vif_details --add=port.${dev}.vm-uuid=${vm_uuid}" fi + + # vNetManager needs to know the network UUID(s) associated with + # each datapath. Normally interface-reconfigure adds them, but + # interface-reconfigure never gets called for internal networks + # (xapi does the addbr ioctl internally), so we have to do it + # here instead for internal networks. This is only acceptable + # because xapi is lazy about creating internal networks: it + # only creates one just before it adds the first vif to it. + # There may still be a brief delay between the initial + # ovs-vswitchd connection to vNetManager and setting this + # configuration variable, but vNetManager can tolerate that. + local internal=$(${vif_on_internal_bridge} ${DOMID} ${DEVID}) + if [ "$internal" = "true" ]; then + local bridge=$(xenstore-read "${PRIVATE}/bridge" 2>/dev/null) + local net_uuid=$(xenstore-read "${PRIVATE}/network-uuid" 2>/dev/null) + local key="bridge.${bridge}.xs-network-uuids" + + vif_details="$vif_details --del-match=${key}=*" + vif_details="$vif_details --add=${key}=${net_uuid}" + fi + echo ${vif_details} } diff --git a/xenserver/usr_share_vswitch_scripts_vif-on-internal-bridge b/xenserver/usr_share_vswitch_scripts_vif-on-internal-bridge new file mode 100755 index 000000000..dd1ee6a3c --- /dev/null +++ b/xenserver/usr_share_vswitch_scripts_vif-on-internal-bridge @@ -0,0 +1,56 @@ +#!/usr/bin/python +# +# Script to determine whether a vif is on an internal bridge + +# Copyright (C) 2009 Nicira Networks, Inc. +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without warranty of any kind. + +import sys +import XenAPI +import xen.lowlevel.xs + +# Query XenStore for the opaque reference of this vif +def get_vif_ref(domid, devid): + xenstore = xen.lowlevel.xs.xs() + t = xenstore.transaction_start() + vif_ref = xenstore.read(t, '/xapi/%s/private/vif/%s/ref' % (domid, devid)) + xenstore.transaction_end(t) + return vif_ref + +# Query XAPI for the information we need using the vif's opaque reference +def dump_vif_info(domid, devid, vif_ref): + try: + session = XenAPI.xapi_local() + session.xenapi.login_with_password("root", "") + vif_rec = session.xenapi.VIF.get_record(vif_ref) + net_rec = session.xenapi.network.get_record(vif_rec["network"]) + + if len(net_rec['PIFs']) == 0: + sys.stdout.write("true\n") + else: + sys.stdout.write("false\n") + + finally: + session.xenapi.session.logout() + +if __name__ == '__main__': + if (len(sys.argv) != 3): + sys.stderr.write("ERROR: %s \n" % sys.argv[0]) + sys.exit(1) + + domid = sys.argv[1] + devid = sys.argv[2] + + vif_ref = get_vif_ref(domid, devid) + if not vif_ref: + sys.stderr.write("ERROR: Could not find interface vif%s.%s\n" + % (domid, devid)) + sys.exit(1) + + dump_vif_info(domid, devid, vif_ref) + sys.exit(0) + diff --git a/xenserver/vswitch-xen.spec b/xenserver/vswitch-xen.spec index 63996d155..94920116b 100644 --- a/xenserver/vswitch-xen.spec +++ b/xenserver/vswitch-xen.spec @@ -71,6 +71,8 @@ install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \ $RPM_BUILD_ROOT/usr/share/vswitch/scripts/interface-reconfigure install -m 755 xenserver/etc_xensource_scripts_vif \ $RPM_BUILD_ROOT/usr/share/vswitch/scripts/vif +install -m 755 xenserver/usr_share_vswitch_scripts_vif-on-internal-bridge \ + $RPM_BUILD_ROOT/usr/share/vswitch/scripts/vif-on-internal-bridge install -m 755 xenserver/usr_sbin_xen-bugtool \ $RPM_BUILD_ROOT/usr/share/vswitch/scripts/xen-bugtool install -m 755 xenserver/usr_sbin_brctl \ @@ -313,6 +315,7 @@ fi /usr/share/vswitch/scripts/XSFeatureVSwitch.py /usr/share/vswitch/scripts/brctl /usr/share/vswitch/scripts/sysconfig.template +/usr/share/vswitch/scripts/vif-on-internal-bridge /usr/share/vswitch/scripts/xen-backend.rules # Following two files are generated automatically by rpm. We don't # really need them and they won't be used on the XenServer, but there -- 2.45.2