Change in vdsm[master]: hooks: Add fcoe hook

pzhukov at redhat.com pzhukov at redhat.com
Tue Mar 22 08:17:41 UTC 2016


Pavel Zhukov has uploaded a new change for review.

Change subject: hooks: Add fcoe hook
......................................................................

hooks: Add fcoe hook

This hook is used to enable fcoe on one or several network interfaces

Change-Id: Iad2faed7205ca08801132df072b469dbe781318c
Bug-Url: https://bugzilla.redhat.com/1239122
Signed-off-by: Pavel Zhukov <pzhukov at redhat.com>
---
M vdsm.spec.in
A vdsm_hooks/fcoe/Makefile.am
A vdsm_hooks/fcoe/README
A vdsm_hooks/fcoe/fcoe_before_network_setup.py
4 files changed, 150 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/29/55029/4

diff --git a/vdsm.spec.in b/vdsm.spec.in
index f348028..14bc74b 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -622,6 +622,15 @@
 VDSM hook used for applying IPv6 configuration through custom network
 properties
 
+%package hook-fcoe
+Summary:        Hook for enable fcoe support
+BuildArch:      noarch
+Requires:       %{name} = %{version}-%{release}
+Requires:       fcoe-utils
+
+%description hook-fcoe
+%{summary}
+
 %if 0%{?with_gluster_mgmt}
 %package gluster
 Summary:        Gluster Plugin for VDSM
@@ -1474,6 +1483,10 @@
 %{_libexecdir}/%{vdsm_name}/hooks/before_vm_start/50_vmfex
 %endif
 
+%files hook-ovs
+%defattr(-, root, root, -)
+%{_libexecdir}/%{vdsm_name}/hooks/before_network_setup/50_fcoe
+
 %files cli
 %defattr(-, root, root, -)
 %license COPYING
diff --git a/vdsm_hooks/fcoe/Makefile.am b/vdsm_hooks/fcoe/Makefile.am
new file mode 100644
index 0000000..12de02b
--- /dev/null
+++ b/vdsm_hooks/fcoe/Makefile.am
@@ -0,0 +1,30 @@
+#
+# Copyright 2011 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 = \
+	fcoe_before_network_setup.py
+
+install-data-local:
+	$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_network_setup
+	$(INSTALL_SCRIPT) $(srcdir)/fcoe_before_network_setup.py \
+		$(DESTDIR)$(vdsmhooksdir)/before_network_setup/50_fcoe
+
+uninstall-local:
+	$(RM) $(DESTDIR)$(vdsmhooksdir)/before_network_setup/50_fcoe
diff --git a/vdsm_hooks/fcoe/README b/vdsm_hooks/fcoe/README
new file mode 100644
index 0000000..d8d2bbd
--- /dev/null
+++ b/vdsm_hooks/fcoe/README
@@ -0,0 +1,18 @@
+fcoe vdsm hook
+=================================
+This hook allow to configure one or more NIC as FCoE interface(s)
+
+Intallation:
+* Use engine-config to append the appropriate custom property:
+  sudo engine-config -s UserDefinedNetworkCustomProperties='fcoe=^(true|false)$' --cver=3.6
+
+* Verify that custom property was added:
+  engine-config  -g UserDefinedNetworkCustomProperties                                
+
+Usage:
+* Define virtual network for FCoE
+* Under "setup host networks" attach (drag) it to interface.
+* Click small "Edit" button and add fcoe property with value "true"
+
+
+
diff --git a/vdsm_hooks/fcoe/fcoe_before_network_setup.py b/vdsm_hooks/fcoe/fcoe_before_network_setup.py
new file mode 100755
index 0000000..82e5b02
--- /dev/null
+++ b/vdsm_hooks/fcoe/fcoe_before_network_setup.py
@@ -0,0 +1,89 @@
+#!/bin/env python
+
+import hooking
+import os
+import traceback
+import subprocess
+from shutil import copyfile
+from vdsm import utils
+from vdsm.netconfpersistence import RunningConfig
+
+FCOE_CONFIG_DIR = "/etc/fcoe/"
+FCOE_DEFAULT_CONFIG = "cfg-ethx"
+
+try:
+    # 3.0 compat
+    import libvirtconnection
+    libvirtconnection
+except ImportError:
+    # 3.1 compat
+    from vdsm import libvirtconnection
+
+
+def _configured_fcoe_interfaces():
+    files = os.listdir(FCOE_CONFIG_DIR)
+    return [file[4:] for file in files
+            if file != FCOE_DEFAULT_CONFIG and file.startswith("cfg-")]
+
+
+def _configure(interface):
+    # IOError can be raised here is FCOE_DEFAULT_CONFIG doesn't exist
+    # or we're not able to copy file
+    # Don't catch exceptions here. Propagate them to main
+    # and show traceback in supervdsm log
+    filename = os.path.join(FCOE_CONFIG_DIR, "cfg-%s" % interface)
+    if not os.path.exists(filename):
+        copyfile(os.path.join(FCOE_CONFIG_DIR, FCOE_DEFAULT_CONFIG),
+                 filename)
+        utils.persist(filename)
+
+
+def _unconfigure(interface):
+    filename = os.path.join(FCOE_CONFIG_DIR, "cfg-%s" % (interface))
+    if os.path.exists(filename):
+        utils.rmFile(filename)
+        utils.unpersist(filename)
+
+
+def main():
+    config = RunningConfig()
+    configured_fcoe = [[net, config.networks[net]["nic"]] for net in config.networks
+                       if config.networks[net].get("custom")
+                       and config.networks[net]["custom"].get("fcoe") == "true"]
+
+    setup_nets_config = hooking.read_json()
+    changed_networks = setup_nets_config["request"]["networks"]
+    changed_fcoe = [[net, changed_networks[net]["nic"]] for net in changed_networks
+                    if changed_networks[net].get("custom")
+                    and changed_networks[net].get("custom").get("fcoe") == "true"]
+    changed_non_fcoe = [[net, changed_networks[net]["nic"]] for net in changed_networks
+                        if not changed_networks[net].get("remove") == "true"
+                        and {net: changed_networks[net]["nic"]} not in changed_fcoe]
+
+    removed_networks = [[net, config.networks[net]["nic"]] for net in changed_networks
+                         if changed_networks[net].get("remove") == "true"]
+
+
+    for net in removed_networks:
+        if net in configured_fcoe:
+            _unconfigure(config.networks[net[0]]["nic"])
+
+    for changed in changed_non_fcoe:
+        if changed in configured_fcoe:
+            _unconfigure(changed[1])
+
+    # FIXME! BUG! if  fcoe network changed interface old interface must be unconfigured
+    for changed in changed_fcoe:
+        if changed not in configured_fcoe:
+            _configure(changed[1])
+
+    # TODO Remove file in _fail hook if services are not able to start ??
+    subprocess.call(['/sbin/service', 'lldpad', 'restart'])
+    subprocess.call(['/sbin/service', 'fcoe', 'restart'])
+
+
+if __name__ == "__main__":
+    try:
+        main()
+    except:
+        hooking.exit_hook(traceback.format_exc())


-- 
To view, visit https://gerrit.ovirt.org/55029
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iad2faed7205ca08801132df072b469dbe781318c
Gerrit-PatchSet: 4
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Pavel Zhukov <pzhukov at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Edward Haas <edwardh at redhat.com>
Gerrit-Reviewer: Pavel Zhukov <pzhukov at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>


More information about the vdsm-patches mailing list