Change in vdsm[master]: hooks: ovs: move libvirt configuration into a separate module

phoracek at redhat.com phoracek at redhat.com
Thu Oct 1 13:57:04 UTC 2015


Petr Horáček has uploaded a new change for review.

Change subject: hooks: ovs: move libvirt configuration into a separate module
......................................................................

hooks: ovs: move libvirt configuration into a separate module

Libvirt configuration has nothing to do with OVS configuration.

The main reason is to move creation of new libvirt networks to a place
where all other configurations are already done, so eventual rollback
don't have to do extra job. This is necessary in following
'improve ovs rollback' patch.

Change-Id: I775edc776c738822ed955ffb0b7885dae450b667
Signed-off-by: Petr Horáček <phoracek at redhat.com>
---
M debian/vdsm-hook-ovs.install
M vdsm.spec.in
M vdsm_hooks/ovs/Makefile.am
M vdsm_hooks/ovs/ovs_before_network_setup.py
A vdsm_hooks/ovs/ovs_before_network_setup_libvirt.py
M vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
6 files changed, 67 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/10/46910/1

diff --git a/debian/vdsm-hook-ovs.install b/debian/vdsm-hook-ovs.install
index 36e1f0f..0154da5 100644
--- a/debian/vdsm-hook-ovs.install
+++ b/debian/vdsm-hook-ovs.install
@@ -5,6 +5,7 @@
 usr/libexec/vdsm/hooks/after_get_stats/ovs_utils.py
 usr/libexec/vdsm/hooks/before_device_create/50_ovs
 usr/libexec/vdsm/hooks/before_device_create/ovs_setup_ip.py
+usr/libexec/vdsm/hooks/before_device_create/ovs_setup_libvirt.py
 usr/libexec/vdsm/hooks/before_device_create/ovs_setup_mtu.py
 usr/libexec/vdsm/hooks/before_device_create/ovs_setup_ovs.py
 usr/libexec/vdsm/hooks/before_device_create/ovs_utils.py
diff --git a/vdsm.spec.in b/vdsm.spec.in
index a8a30f5..2e86a9f 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1176,6 +1176,7 @@
 %{_libexecdir}/%{vdsm_name}/hooks/before_device_create/ovs_utils.py*
 %{_libexecdir}/%{vdsm_name}/hooks/before_network_setup/50_ovs
 %{_libexecdir}/%{vdsm_name}/hooks/before_network_setup/ovs_setup_ip.py*
+%{_libexecdir}/%{vdsm_name}/hooks/before_network_setup/ovs_setup_libvirt.py*
 %{_libexecdir}/%{vdsm_name}/hooks/before_network_setup/ovs_setup_mtu.py*
 %{_libexecdir}/%{vdsm_name}/hooks/before_network_setup/ovs_setup_ovs.py*
 %{_libexecdir}/%{vdsm_name}/hooks/before_network_setup/ovs_utils.py*
diff --git a/vdsm_hooks/ovs/Makefile.am b/vdsm_hooks/ovs/Makefile.am
index 4699ef5..8a1411c 100644
--- a/vdsm_hooks/ovs/Makefile.am
+++ b/vdsm_hooks/ovs/Makefile.am
@@ -36,6 +36,7 @@
 	ovs_before_network_setup_ovs.py \
 	ovs_before_network_setup_ip.py \
 	ovs_before_network_setup_mtu.py \
+	ovs_before_network_setup_libvirt.py \
 	$(utilsfile) \
 	sudoers.in
 
@@ -59,6 +60,8 @@
 		$(DESTDIR)$(vdsmhooksdir)/before_network_setup/ovs_setup_ip.py
 	$(INSTALL_SCRIPT) $(srcdir)/ovs_before_network_setup_mtu.py \
 		$(DESTDIR)$(vdsmhooksdir)/before_network_setup/ovs_setup_mtu.py
+	$(INSTALL_SCRIPT) $(srcdir)/ovs_before_network_setup_mtu.py \
+		$(DESTDIR)$(vdsmhooksdir)/before_network_setup/ovs_setup_libvirt.py
 
 uninstall-local: uninstall-data-utils uninstall-data-sudoers
 	$(RM) $(DESTDIR)$(vdsmhooksdir)/after_get_caps/50_ovs
@@ -68,6 +71,7 @@
 	$(RM) $(DESTDIR)$(vdsmhooksdir)/before_network_setup/ovs_setup_ovs.py
 	$(RM) $(DESTDIR)$(vdsmhooksdir)/before_network_setup/ovs_setup_ip.py
 	$(RM) $(DESTDIR)$(vdsmhooksdir)/before_network_setup/ovs_setup_mtu.py
+	$(RM) $(DESTDIR)$(vdsmhooksdir)/before_network_setup/ovs_setup_libvirt.py
 
 install-data-utils:
 	$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/after_get_caps
diff --git a/vdsm_hooks/ovs/ovs_before_network_setup.py b/vdsm_hooks/ovs/ovs_before_network_setup.py
index 6cef711..ea10c10 100755
--- a/vdsm_hooks/ovs/ovs_before_network_setup.py
+++ b/vdsm_hooks/ovs/ovs_before_network_setup.py
@@ -32,6 +32,8 @@
 from ovs_setup_ovs import configure_ovs, prepare_ovs
 from ovs_setup_ip import configure_ip
 from ovs_setup_mtu import configure_mtu
+from ovs_setup_libvirt import (create_libvirt_nets, remove_libvirt_nets,
+                               prepare_libvirt)
 
 
 def _separate_ovs_nets_bonds(nets, bonds, running_config):
@@ -76,12 +78,14 @@
 def configure(nets, bonds, running_config, in_rollback):
     initial_config = deepcopy(running_config)
 
-    commands, libvirt_create, libvirt_remove = prepare_ovs(
-        nets, bonds, running_config)
+    commands = prepare_ovs(nets, bonds, running_config)
+    libvirt_create, libvirt_remove = prepare_libvirt(nets, running_config)
     with _rollback(running_config, initial_config, in_rollback):
+        remove_libvirt_nets(libvirt_remove)
         configure_ovs(commands, libvirt_create, libvirt_remove, running_config)
         configure_mtu(running_config)
         configure_ip(nets, initial_config.networks)
+        create_libvirt_nets(libvirt_create)
 
     hooking.log('Saving running configuration: %s %s' %
                 (running_config.networks, running_config.bonds))
diff --git a/vdsm_hooks/ovs/ovs_before_network_setup_libvirt.py b/vdsm_hooks/ovs/ovs_before_network_setup_libvirt.py
new file mode 100644
index 0000000..a68d056
--- /dev/null
+++ b/vdsm_hooks/ovs/ovs_before_network_setup_libvirt.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+# Copyright 2015 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
+#
+import sys
+
+from ovs_utils import suppress
+
+# TODO: move required modules into vdsm/lib
+sys.path.append('/usr/share/vdsm')
+from network.configurators import libvirt
+
+
+def prepare_libvirt(nets, running_config):
+    libvirt_create = {}
+    libvirt_remove = set()
+    for net, attrs in nets.iteritems():
+        if 'remove' in attrs:
+            libvirt_remove.add(net)
+    for net, attrs in nets.iteritems():
+        if 'remove' not in attrs:
+            if net in running_config.networks:
+                libvirt_remove.add(net)
+            libvirt_network_xml = libvirt.createNetworkDef(
+                net, True, attrs.get('nic') or attrs.get('bonding'))
+            libvirt_create[net] = libvirt_network_xml
+    return libvirt_create, libvirt_remove
+
+
+def create_libvirt_nets(libvirt_create):
+    for net, net_xml in libvirt_create.items():
+        libvirt.createNetwork(net_xml)
+
+
+def remove_libvirt_nets(libvirt_remove):
+    for net in libvirt_remove:
+        with suppress():
+            libvirt.removeNetwork(net)
diff --git a/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py b/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
index 3f663b6..cb55bf4 100644
--- a/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
+++ b/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
@@ -55,33 +55,6 @@
     return nets_by_nic
 
 
-def _get_libvirt_changes(nets, running_config):
-    libvirt_create = {}
-    libvirt_remove = set()
-    for net, attrs in nets.iteritems():
-        if 'remove' in attrs:
-            libvirt_remove.add(net)
-    for net, attrs in nets.iteritems():
-        if 'remove' not in attrs:
-            if net in running_config.networks:
-                libvirt_remove.add(net)
-            libvirt_network_xml = libvirt.createNetworkDef(
-                net, True, attrs.get('nic') or attrs.get('bonding'))
-            libvirt_create[net] = libvirt_network_xml
-    return libvirt_create, libvirt_remove
-
-
-def _create_libvirt_nets(libvirt_create):
-    for net, net_xml in libvirt_create.items():
-        libvirt.createNetwork(net_xml)
-
-
-def _remove_libvirt_nets(libvirt_remove):
-    for net in libvirt_remove:
-        with suppress():
-            libvirt.removeNetwork(net)
-
-
 def _run_commands(commands):
     """ If there are any needed changes in OVS network listed in commands,
     apply them. Otherwise do nothing.
@@ -310,19 +283,13 @@
 
 
 def prepare_ovs(nets, bonds, running_config):
-    """ Prepare OVS commands and collect libvirt network to add and remove.
-    This function is separate because of no rollback is needed here.
-    """
-    libvirt_create, libvirt_remove = _get_libvirt_changes(nets, running_config)
     nets_by_nic = _get_nets_by_nic(running_config)
     commands = []
     commands.extend(_handle_removal(nets, bonds, running_config, nets_by_nic))
     commands.extend(_handle_setup(nets, bonds, running_config, nets_by_nic))
-    return commands, libvirt_create, libvirt_remove
+    return commands
 
 
-def configure_ovs(commands, libvirt_create, libvirt_remove, running_config):
-    _remove_libvirt_nets(libvirt_remove)
+def configure_ovs(commands, running_config):
     _run_commands(commands)
     _remove_redundant_ovs_bridge(running_config)
-    _create_libvirt_nets(libvirt_create)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I775edc776c738822ed955ffb0b7885dae450b667
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Petr Horáček <phoracek at redhat.com>


More information about the vdsm-patches mailing list