xenserver: Add support for disabling in-band management via XAPI.
authorAndrew Evans <aevans@nicira.com>
Tue, 1 Mar 2011 02:26:04 +0000 (18:26 -0800)
committerAndrew Evans <aevans@nicira.com>
Tue, 1 Mar 2011 02:26:48 +0000 (18:26 -0800)
Allow users or applications to enable or disable in-band management of
individual bridges by setting the 'vswitch-disable-in-band' key in the
'other_config' attribute of the corresponding network to 'true' or
'false'.

Bug #4749.

tests/interface-reconfigure.at
xenserver/etc_xapi.d_plugins_openvswitch-cfg-update
xenserver/opt_xensource_libexec_InterfaceReconfigure.py
xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py
xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync

index ad70263..1470967 100644 (file)
@@ -584,7 +584,11 @@ EOF
                <bridge>
                        xenbr0
                </bridge>
-               <other_config/>
+               <other_config>
+                       <vswitch-disable-in-band>
+                               true
+                       </vswitch-disable-in-band>
+               </other_config>
                <uuid>
                        c9eecb03-560d-61de-b6a8-56dfc766f67e
                </uuid>
@@ -671,6 +675,7 @@ Applying changes to /etc/sysconfig/network-scripts/ifcfg-xenbr2 configuration
     --may-exist add-port xenbr2 eth2
     set Bridge xenbr2 other-config:hwaddr="00:15:17:a0:29:80"
     set Bridge xenbr2 fail_mode=standalone
+    remove Bridge xenbr2 other_config disable-in-band
     br-set-external-id xenbr2 xs-network-uuids d08c8749-0c8f-9e8d-ce25-fd364661ee99
 /sbin/ifup xenbr2
 /sbin/update-issue
@@ -736,6 +741,7 @@ Applying changes to /etc/sysconfig/network-scripts/ifcfg-xapi3 configuration
     --may-exist add-port xenbr3 eth3
     set Bridge xenbr3 other-config:hwaddr="00:15:17:a0:29:81"
     set Bridge xenbr3 fail_mode=standalone
+    remove Bridge xenbr3 other_config disable-in-band
     br-set-external-id xenbr3 xs-network-uuids 2902ae1b-8013-897a-b697-0b200ea3aaa5;db7bdc03-074d-42ae-fc73-9b06de1d57f6
     --may-exist add-br xapi3 xenbr3 123
     br-set-external-id xapi3 xs-network-uuids 2902ae1b-8013-897a-b697-0b200ea3aaa5;db7bdc03-074d-42ae-fc73-9b06de1d57f6
@@ -823,6 +829,7 @@ Applying changes to /etc/sysconfig/network-scripts/ifcfg-xapi1 configuration
     set Port bond0 MAC="00:22:19:22:4b:af" other-config:bond-miimon-interval=100 bond_downdelay=200 bond_updelay=31000 other-config:bond-detect-mode=carrier lacp=off bond_mode=balance-slb
     set Bridge xapi1 other-config:hwaddr="00:22:19:22:4b:af"
     set Bridge xapi1 fail_mode=standalone
+    remove Bridge xapi1 other_config disable-in-band
     br-set-external-id xapi1 xs-network-uuids 45cbbb43-113d-a712-3231-c6463f253cef;99be2da4-6c33-6f8e-49ea-3bc592fe3c85
 /sbin/ifup xapi1
 action_up: bring up bond0
@@ -907,6 +914,7 @@ Applying changes to /etc/sysconfig/network-scripts/ifcfg-xapi2 configuration
     set Port bond0 MAC="00:22:19:22:4b:af" other-config:bond-miimon-interval=100 bond_downdelay=200 bond_updelay=31000 other-config:bond-detect-mode=carrier lacp=off bond_mode=balance-slb
     set Bridge xapi1 other-config:hwaddr="00:22:19:22:4b:af"
     set Bridge xapi1 fail_mode=standalone
+    remove Bridge xapi1 other_config disable-in-band
     br-set-external-id xapi1 xs-network-uuids 45cbbb43-113d-a712-3231-c6463f253cef;99be2da4-6c33-6f8e-49ea-3bc592fe3c85
     --may-exist add-br xapi2 xapi1 4
     br-set-external-id xapi2 xs-network-uuids 45cbbb43-113d-a712-3231-c6463f253cef;99be2da4-6c33-6f8e-49ea-3bc592fe3c85
index 721fe64..e2dc939 100755 (executable)
@@ -97,9 +97,38 @@ def update(session, args):
         except KeyError:
             pass
 
+    dib_changed = False
     fail_mode_changed = False
     for bridge in vswitchCfgQuery(['list-br']).split():
+        network = bton[bridge]
         bridge = vswitchCfgQuery(['br-to-parent', bridge])
+
+        xapi_dib = network['other_config'].get('vswitch-disable-in-band')
+        if not xapi_dib:
+            xapi_dib = ''
+
+        ovs_dib = vswitchCfgQuery(['get', 'Bridge', bridge,
+                                   'other_config:disable-in-band']).strip('"')
+
+        # Do nothing if setting is invalid, and warn the user.
+        if xapi_dib not in ['true', 'false', '']:
+            ret_str += '"' + xapi_dib + '"' + \
+                ' is an invalid value for vswitch-disable-in-band on ' + \
+                bridge + '  '
+
+        # Change bridge disable-in-band option if XAPI and OVS states differ.
+        elif xapi_dib != ovs_dib:
+            # 'true' or 'false'
+            if xapi_dib:
+                vswitchCfgMod(['--', 'set', 'Bridge', bridge,
+                               'other_config:disable-in-band=' + xapi_dib])
+            # '' or None
+            else:
+                vswitchCfgMod(['--', 'remove', 'Bridge', bridge,
+                               'other_config', 'disable-in-band'])
+            dib_changed = True
+
+        # Change bridge fail_mode if XAPI state differs from OVS state.
         bridge_fail_mode = vswitchCfgQuery(["get", "Bridge",
             bridge, "fail_mode"]).strip('[]"')
 
@@ -119,6 +148,8 @@ def update(session, args):
                 "fail_mode=%s" % fail_mode])
             fail_mode_changed = True
 
+    if dib_changed:
+        ret_str += "Updated in-band management.  "
     if fail_mode_changed:
         ret_str += "Updated fail_mode.  "
 
index a9bbf07..0fd79e6 100644 (file)
@@ -332,7 +332,11 @@ _BOND_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml),
                           lambda n: _strlist_from_xml(n, 'slaves', 'slave')),
               }
 
-_NETWORK_OTHERCONFIG_ATTRS = [ 'mtu', 'static-routes', 'vswitch-controller-fail-mode' ] + _ETHTOOL_OTHERCONFIG_ATTRS
+_NETWORK_OTHERCONFIG_ATTRS = [ 'mtu',
+                               'static-routes',
+                               'vswitch-controller-fail-mode',
+                               'vswitch-disable-in-band' ] \
+                               + _ETHTOOL_OTHERCONFIG_ATTRS
 
 _NETWORK_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml),
                    'bridge': (_str_to_xml,_str_from_xml),
index 6a1d4ed..661199b 100644 (file)
@@ -351,6 +351,7 @@ def configure_datapath(pif):
 
     pool = db().get_pool_record()
     network = db().get_network_by_bridge(bridge)
+    network_rec = None
     fail_mode = None
     valid_fail_modes = ['standalone', 'secure']
 
@@ -366,6 +367,15 @@ def configure_datapath(pif):
 
     vsctl_argv += ['--', 'set', 'Bridge', bridge, 'fail_mode=%s' % fail_mode]
 
+    if network_rec:
+        dib = network_rec['other_config'].get('vswitch-disable-in-band')
+        if not dib:
+            vsctl_argv += ['--', 'remove', 'Bridge', bridge, 'other_config', 'disable-in-band']
+        elif dib in ['true', 'false']:
+            vsctl_argv += ['--', 'set', 'Bridge', bridge, 'other_config:disable-in-band=' + dib]
+        else:
+            log('"' + dib + '"' "isn't a valid setting for other_config:disable-in-band on " + bridge)
+
     vsctl_argv += set_br_external_ids(pif)
     vsctl_argv += ['## done configuring datapath %s' % bridge]
 
index 4d030fd..4d82b99 100755 (executable)
@@ -148,6 +148,24 @@ def update_fail_mode(name):
 
     call_vsctl(["set", "bridge", name, "fail_mode=" + fail_mode])
 
+def update_in_band_mgmt(name):
+    rec = get_network_by_bridge(name)
+
+    if not rec:
+        return
+
+    dib = rec['other_config'].get('vswitch-disable-in-band')
+    if not dib:
+        call_vsctl(['remove', 'bridge', name, 'other_config',
+                    'disable-in-band'])
+    elif dib in ['true', 'false']:
+        call_vsctl(['set', 'bridge', name,
+                    'other_config:disable-in-band=' + dib])
+    else:
+        s_log.warning('"' + dib + '"'
+                      "isn't a valid setting for other_config:disable-in-band on " +
+                      bridge)
+
 def update_bridge_id(name, ids):
     id = get_bridge_id(name, ids.get("xs-network-uuids"))
 
@@ -279,6 +297,7 @@ def main(argv):
             for name,ids in new_bridges.items():
                 if name not in bridges:
                     update_fail_mode(name)
+                    update_in_band_mgmt(name)
 
                 if (name not in bridges) or (bridges[name] != ids):
                     update_bridge_id(name, ids)