Change in vdsm[master]: bridge_options: Add custom network hook for applying bridge_...
asegurap at redhat.com
asegurap at redhat.com
Thu Apr 10 12:05:34 UTC 2014
Antoni Segura Puimedon has uploaded a new change for review.
Change subject: bridge_options: Add custom network hook for applying bridge_options
......................................................................
bridge_options: Add custom network hook for applying bridge_options
This patch introduces a hook called bridge_options that takes as
input a custom network property with name 'bridge_opts' with the
format:
'key=value [key=value]*'
and applies each option to the network bridge.
Change-Id: I28424cf036b18afc2c1767d6184cb76f25026d8b
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M configure.ac
M debian/Makefile.am
M debian/control
A debian/vdsm-hook-bridge-options.docs
A debian/vdsm-hook-bridge-options.install
M vdsm.spec.in
M vdsm_hooks/Makefile.am
A vdsm_hooks/bridge_options/Makefile.am
A vdsm_hooks/bridge_options/README
A vdsm_hooks/bridge_options/bridge_options.py
10 files changed, 163 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/70/26670/1
diff --git a/configure.ac b/configure.ac
index a6382c4..7a9b187 100644
--- a/configure.ac
+++ b/configure.ac
@@ -280,6 +280,7 @@
vdsm/virt/Makefile
vdsm_api/Makefile
vdsm_hooks/Makefile
+ vdsm_hooks/bridge_options/Makefile
vdsm_hooks/checkimages/Makefile
vdsm_hooks/directlun/Makefile
vdsm_hooks/extnet/Makefile
diff --git a/debian/Makefile.am b/debian/Makefile.am
index d6678ff..a65a5d6 100644
--- a/debian/Makefile.am
+++ b/debian/Makefile.am
@@ -35,6 +35,8 @@
vdsm.docs \
vdsm-gluster.docs \
vdsm-gluster.install \
+ vdsm-hook-bridge-options.docs \
+ vdsm-hook-bridge-options.install \
vdsm-hook-checkimages.docs \
vdsm-hook-checkimages.install \
vdsm-hook-directlun.docs \
diff --git a/debian/control b/debian/control
index 45c2b1c..cdc380a 100644
--- a/debian/control
+++ b/debian/control
@@ -148,6 +148,12 @@
Description: Unit and functional tests for vdsm
A test suite for verifying the functionality of a running vdsm instance
+Package: vdsm-hook-bridge-options
+Architecture: all
+Depends: ${shlibs:Depends}, ${misc:Depends}, python (>=2.7.3), vdsm (>= ${source:Version})
+Description: VDSM hook used for applying custom network properties that define
+ bridge options for vdsm network bridges
+
Package: vdsm-hook-checkimages
Architecture: all
Depends: ${shlibs:Depends}, ${misc:Depends}, python (>=2.7.3), vdsm (>= ${source:Version})
diff --git a/debian/vdsm-hook-bridge-options.docs b/debian/vdsm-hook-bridge-options.docs
new file mode 100644
index 0000000..5ecd9c6
--- /dev/null
+++ b/debian/vdsm-hook-bridge-options.docs
@@ -0,0 +1 @@
+COPYING
diff --git a/debian/vdsm-hook-bridge-options.install b/debian/vdsm-hook-bridge-options.install
new file mode 100644
index 0000000..6ceec3b
--- /dev/null
+++ b/debian/vdsm-hook-bridge-options.install
@@ -0,0 +1 @@
+usr/libexec/vdsm/hooks/after_network_setup/20_bridge_options
diff --git a/vdsm.spec.in b/vdsm.spec.in
index e1d6d40..bffce1b 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -384,6 +384,15 @@
VDSM hook used to perform consistency check on a qcow2 format disk image
using the QEMU disk image utility.
+%package hook-bridge-options
+Summary: Allow setting custom bridge options for vdsm network bridges
+BuildArch: noarch
+Requires: %{name} = %{version}-%{release}
+
+%description hook-bridge-options
+VDSM hook used for applying custom network properties that define bridge
+options for vdsm network bridges
+
%if 0%{?with_vhostmd}
%package hook-vhostmd
Summary: VDSM hook set for interaction with vhostmd
@@ -1235,6 +1244,10 @@
%doc COPYING
%{_libexecdir}/%{vdsm_name}/hooks/before_vm_start/50_qemucmdline
+%files hook-bridge-options
+%defattr(-, root, root, -)
+%{_libexecdir}/%{vdsm_name}/hooks/after_network_setup/20_bridge_options
+
%if 0%{?with_hooks}
%files hook-checkimages
%defattr(-, root, root, -)
diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am
index ce4aa46..f046eaf 100644
--- a/vdsm_hooks/Makefile.am
+++ b/vdsm_hooks/Makefile.am
@@ -18,7 +18,7 @@
# Refer to the README and COPYING files for full details of the license
#
-SUBDIRS = faqemu vhostmd qemucmdline openstacknet
+SUBDIRS = bridge_options faqemu vhostmd qemucmdline openstacknet
include $(top_srcdir)/build-aux/Makefile.subs
diff --git a/vdsm_hooks/bridge_options/Makefile.am b/vdsm_hooks/bridge_options/Makefile.am
new file mode 100644
index 0000000..cfe5efc
--- /dev/null
+++ b/vdsm_hooks/bridge_options/Makefile.am
@@ -0,0 +1,30 @@
+#
+# Copyright 2013 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+EXTRA_DIST = \
+ bridge_options.py
+
+install-data-local:
+ $(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/after_network_setup
+ $(INSTALL_SCRIPT) $(srcdir)/bridge_options.py \
+ $(DESTDIR)$(vdsmhooksdir)/after_network_setup/20_bridge_options
+
+uninstall-local:
+ $(RM) $(DESTDIR)$(vdsmhooksdir)/after_network_setup/20_bridge_options
diff --git a/vdsm_hooks/bridge_options/README b/vdsm_hooks/bridge_options/README
new file mode 100644
index 0000000..241bc15
--- /dev/null
+++ b/vdsm_hooks/bridge_options/README
@@ -0,0 +1,11 @@
+bridge_options vdsm hook
+=================================
+This hook allows the user to set bridge options for VM networks.
+
+Requirements:
+* oVirt-3.5
+
+Usage:
+In the oVirt UI edit custom network properties and, for the key 'bridge_opts'
+set space separated 'key=value' elements. E.g.:
+ 'forward_delay=1600 max_age=2010'
diff --git a/vdsm_hooks/bridge_options/bridge_options.py b/vdsm_hooks/bridge_options/bridge_options.py
new file mode 100644
index 0000000..034642e
--- /dev/null
+++ b/vdsm_hooks/bridge_options/bridge_options.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+from vdsm.netinfo import DUMMY_BRIDGE
+from vdsm.utils import CommandPath
+import json
+import os
+import sys
+import hooking
+import traceback
+
+BRIDGING_OPT_PATH = '/sys/class/net/%s/bridge/%s'
+EXT_TEE = CommandPath('tee', '/usr/bin/tee')
+
+
+def test():
+ def dummy_fwd_delay():
+ with open(BRIDGING_OPT_PATH % (DUMMY_BRIDGE, 'forward_delay')) as f:
+ return int(f.read().strip())
+
+ net_attrs = {'nic': 'em1', 'custom': {'bridge_opts': 'forward_delay=150'},
+ 'bootproto': 'dhcp', 'STP': 'no', 'bridged': 'true'}
+
+ if os.path.exists(BRIDGING_OPT_PATH % (DUMMY_BRIDGE, '')):
+ old_fwd_delay = dummy_fwd_delay()
+
+ new_fwd_delay = old_fwd_delay + 100
+ net_attrs['custom']['bridge_opts'] = 'forward_delay=%s' % new_fwd_delay
+
+ try:
+ _process_network(DUMMY_BRIDGE, net_attrs)
+ print 'Found: %s. Expected %s' % (dummy_fwd_delay(), new_fwd_delay)
+ finally:
+ _set_bridge_opts(DUMMY_BRIDGE,
+ ('forward_delay=%s' % old_fwd_delay,))
+
+
+def main():
+ """Read bridge_options from the network 'custom' properties and apply them
+ to the network's bridge."""
+ with open(os.environ['_hook_json']) as data_file:
+ setup_nets_config = json.load(data_file)
+
+ for network, attrs in setup_nets_config['request']['networks'].items():
+ if 'remove' in attrs:
+ continue
+ elif 'custom' in attrs and attrs.get('bridged') is not False:
+ _process_network(network, attrs)
+
+
+def _process_network(network, attrs):
+ """Applies bridge_options to the network if necessary"""
+ options = attrs['custom'].get('bridge_opts')
+ if options is not None:
+ _set_bridge_opts(network, options.split(' '))
+
+
+def _set_bridge_opts(bridge_name, options):
+ """Takes an iterable of strings of the form 'key=value' that describe
+ bridge options and applied them to the bridge"""
+ for option in options:
+ key, value = option.split('=')
+ rc, _, err = hooking.execCmd(
+ [EXT_TEE.cmd, BRIDGING_OPT_PATH % (bridge_name, key)], sudo=True,
+ data=value)
+ if rc != 0:
+ raise RuntimeError('Failed to set bridge option %=% for bridge %s'
+ 'because of: %s' % (key, value, bridge_name,
+ err))
+ # TODO: Reload radvd (router advertisement daemon) service for IPv6
+
+
+if __name__ == '__main__':
+ try:
+ if '--test' in sys.argv:
+ test()
+ else:
+ main()
+ except:
+ hooking.exit_hook('bridge_options hook: [unexpected error]: %s\n' %
+ traceback.format_exc())
--
To view, visit http://gerrit.ovirt.org/26670
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I28424cf036b18afc2c1767d6184cb76f25026d8b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>
More information about the vdsm-patches
mailing list