Hello Dan Kenigsberg,
I'd like you to do a code review. Please visit
https://gerrit.ovirt.org/46372
to review the following change.
Change subject: network: add ifcfg write hook
......................................................................
network: add ifcfg write hook
Added a new hook point which is executed before and after
an ifcfg file is writen on the host as a result of
executing setupNetworks.
An example can be a use case where the user would like
to tweak the vdsm-produced ifcfg files by adding
PEERDNS=no to it.
The hook script receives a json file containing the
following dict:
name: the name of the interface being configured
ifcfg_file: full path of the interface file being written
config: the contents of the config file being written
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=965929
Change-Id: I2206ccf97b210bd58f03777d4ccd016785b02939
Signed-off-by: Marcin Mirecki <[email protected]>
Reviewed-on: https://gerrit.ovirt.org/44552
Reviewed-by: Dan Kenigsberg <[email protected]>
Continuous-Integration: Jenkins CI
---
M debian/vdsm.dirs
M vdsm.spec.in
M vdsm/hooks.py
M vdsm/network/configurators/ifcfg.py
M vdsm/vdsmd.8.in
M vdsm_hooks/Makefile.am
6 files changed, 54 insertions(+), 8 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/46372/1
diff --git a/debian/vdsm.dirs b/debian/vdsm.dirs
index ee2bccd..7e75399 100644
--- a/debian/vdsm.dirs
+++ b/debian/vdsm.dirs
@@ -39,6 +39,7 @@
usr/libexec/vdsm/hooks/after_vm_pause
usr/libexec/vdsm/hooks/after_vm_set_ticket
usr/libexec/vdsm/hooks/after_vm_start
+usr/libexec/vdsm/hooks/after_ifcfg_write
usr/libexec/vdsm/hooks/before_device_create
usr/libexec/vdsm/hooks/before_device_destroy
usr/libexec/vdsm/hooks/before_device_migrate_destination
@@ -65,6 +66,7 @@
usr/libexec/vdsm/hooks/before_vm_pause
usr/libexec/vdsm/hooks/before_vm_set_ticket
usr/libexec/vdsm/hooks/before_vm_start
+usr/libexec/vdsm/hooks/before_ifcfg_write
var/lib/libvirt/qemu/channels
var/lib/vdsm
var/lib/vdsm/netconfback
diff --git a/vdsm.spec.in b/vdsm.spec.in
index f000f63..3e5e3d1 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -979,6 +979,9 @@
%dir %{_libexecdir}/%{vdsm_name}/hooks/before_get_stats
%dir %{_libexecdir}/%{vdsm_name}/hooks/after_get_stats
%dir %{_libexecdir}/%{vdsm_name}/hooks/after_hostdev_list_by_caps
+%dir %{_libexecdir}/%{vdsm_name}/hooks/before_ifcfg_write
+%dir %{_libexecdir}/%{vdsm_name}/hooks/after_ifcfg_write
+
%{_datadir}/%{vdsm_name}/dumpStorageTable.py*
%{_datadir}/%{vdsm_name}/get-conf-item
%{_datadir}/%{vdsm_name}/kaxmlrpclib.py*
diff --git a/vdsm/hooks.py b/vdsm/hooks.py
index 5a4d25e..2aa5882 100644
--- a/vdsm/hooks.py
+++ b/vdsm/hooks.py
@@ -391,6 +391,16 @@
hookType=_JSON_HOOK)
+def before_ifcfg_write(hook_dict):
+ return _runHooksDir(hook_dict, 'before_ifcfg_write', raiseError=True,
+ hookType=_JSON_HOOK)
+
+
+def after_ifcfg_write(hook_dict):
+ return _runHooksDir(hook_dict, 'after_ifcfg_write', raiseError=False,
+ hookType=_JSON_HOOK)
+
+
def after_hostdev_list_by_caps(devices):
return _runHooksDir(devices, 'after_hostdev_list_by_caps',
raiseError=False, hookType=_JSON_HOOK)
diff --git a/vdsm/network/configurators/ifcfg.py
b/vdsm/network/configurators/ifcfg.py
index e629cc6..eae734a 100644
--- a/vdsm/network/configurators/ifcfg.py
+++ b/vdsm/network/configurators/ifcfg.py
@@ -21,6 +21,7 @@
import copy
import errno
import glob
+import hooks
import logging
import os
import pipes
@@ -543,7 +544,15 @@
cfg += '%s=%s\n' % (k.upper(), pipes.quote(kwargs[k]))
else:
logging.debug('ignoring variable %s', k)
- self.writeConfFile(netinfo.NET_CONF_PREF + name, cfg)
+
+ ifcfg_file = netinfo.NET_CONF_PREF + name
+ hook_dict = _build_ifcfg_write_hook_dict(name,
+ netinfo.NET_CONF_PREF + name,
+ cfg)
+ hook_return = hooks.before_ifcfg_write(hook_dict)
+ ifcfg_file = hook_return['ifcfg_file']
+ cfg = hook_return['config']
+ self.writeConfFile(ifcfg_file, cfg)
def addBridge(self, bridge, **opts):
""" Create ifcfg-* file with proper fields for bridge """
@@ -936,3 +945,10 @@
ifcfgs.add(ROUTE_PATH % top_level_device)
return ifcfgs
+
+
+def _build_ifcfg_write_hook_dict(name, ifcfg_file, conf):
+ hook_dict = {'name': name,
+ 'ifcfg_file': ifcfg_file,
+ 'config': conf}
+ return hook_dict
diff --git a/vdsm/vdsmd.8.in b/vdsm/vdsmd.8.in
index 5dcac3f..903c08c 100644
--- a/vdsm/vdsmd.8.in
+++ b/vdsm/vdsmd.8.in
@@ -64,19 +64,20 @@
before_get_caps, after_get_caps,
before_get_stats, after_get_stats,
after_hostdev_list_by_caps,
- before_memory_hotplug, after_memory_hotplug.
+ before_memory_hotplug, after_memory_hotplug,
+ before_ifcfg_write, after_ifcfg_write.
Each hook executes the scripts under
.FN /usr/libexec/vdsm/hooks/<hook-name>/
in lexicographic order.
.SS Hook environment
-Each hook script (except before_vdsm_start, after_vdsm_stop,
+Each hook script (except before_vdsm_start, after_vdsm_stop,
before_network_setup and after_network_setup, before_get_vm_stats,
after_get_vm_stats, before_get_all_vm_stats, after_get_all_vm_stats,
before_get_caps, after_get_caps,
-before_get_stats, after_get_stats,
-and after_hostdev_list_by_caps) inherit
+before_get_stats, after_get_stats, after_hostdev_list_by_caps,
+before_ifcfg_write and after_ifcfg_write) inherit
the environment of the VDSM process, with an additional variable
.B _hook_domxml
which holds the path of libvirt's
@@ -86,8 +87,8 @@
available as the environment variable
.B vmId.
-The before_network_setup and after_network_setup hooks do also include an
-extra environment variable
+The before_network_setup, after_network_setup, before_ifcfg_write and
+after_ifcfg_write hooks do also include an extra environment variable
.B _hook_json
which holds a pointer to a file with the network parameters that vdsm is
setting up (
@@ -96,7 +97,8 @@
, the request may be modified by the before_network_setup hook as thus affect
the operation ultimately taken place by Vdsm.
-The JSON format of this file has one section: request, this section
+The JSON format of this file for before_network_setup and
+after_network_setup has one section: request, this section
contains networks, bondings and options, those parameters are specified
in the setupNetworks VDSM API call.
@@ -110,6 +112,17 @@
}
.fi
+The JSON format of this file for before_ifcfg_write and
+after_ifcfg_write has the following parameters: name, ifcfg_file and config.
+
+.nf
+{
+ "name": "eth0",
+ "ifcfg_file": "/etc/sysconfig/network-scripts/ifcfg-eth0",
+ "config": "IPADDR=192.168.1.2\nNETMASK=255.255.255.0"
+ }
+.fi
+
Hooks that handle NIC hotplug, hotunplug and update device
have the _hook_domxml variable but it contains the representation of the NIC
rather than the VM. Hotplug/hotunplug disk hooks also have the _hook_dom_xml
variable,
diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am
index 7dc9ff2..2f7638c 100644
--- a/vdsm_hooks/Makefile.am
+++ b/vdsm_hooks/Makefile.am
@@ -130,6 +130,8 @@
after_hostdev_list_by_caps \
before_memory_hotplug \
after_memory_hotplug \
+ before_ifcfg_write \
+ after_ifcfg_write \
$(NULL)
all-local: \
--
To view, visit https://gerrit.ovirt.org/46372
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2206ccf97b210bd58f03777d4ccd016785b02939
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Marcin Mirecki <[email protected]>
Gerrit-Reviewer: Dan Kenigsberg <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches