Hello Ido Barkan, Dan Kenigsberg,
I'd like you to do a code review. Please visit
https://gerrit.ovirt.org/43274
to review the following change.
Change subject: hooks: introduce before/after_get_stats hook points
......................................................................
hooks: introduce before/after_get_stats hook points
This patches adds a hook point that allows to modify the host statistics
which Vdsm reports on its getVdsStats API. This hook can become useful
if a hook writer would like to provide fake usage statistics to a fake
network that is reported by an after_get_caps hook script.
Change-Id: Id1ff93837abb73f88ececc7571115645b95486cf
Signed-off-by: Dan Kenigsberg <[email protected]>
Reviewed-on: https://gerrit.ovirt.org/40403
Reviewed-by: Ido Barkan <[email protected]>
Reviewed-by: Petr Horáček <[email protected]>
Reviewed-by: Federico Simoncelli <[email protected]>
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1234867
---
M debian/vdsm.dirs
M vdsm.spec.in
M vdsm/API.py
M vdsm/hooks.py
M vdsm/vdsmd.8.in
M vdsm_hooks/Makefile.am
6 files changed, 27 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/74/43274/1
diff --git a/debian/vdsm.dirs b/debian/vdsm.dirs
index 7b5db1b..743550d 100644
--- a/debian/vdsm.dirs
+++ b/debian/vdsm.dirs
@@ -17,6 +17,7 @@
usr/libexec/vdsm/hooks/after_disk_hotunplug
usr/libexec/vdsm/hooks/after_get_all_vm_stats
usr/libexec/vdsm/hooks/after_get_caps
+usr/libexec/vdsm/hooks/after_get_stats
usr/libexec/vdsm/hooks/after_get_vm_stats
usr/libexec/vdsm/hooks/after_network_setup
usr/libexec/vdsm/hooks/after_nic_hotplug
@@ -44,6 +45,7 @@
usr/libexec/vdsm/hooks/before_disk_hotunplug
usr/libexec/vdsm/hooks/before_get_all_vm_stats
usr/libexec/vdsm/hooks/before_get_caps
+usr/libexec/vdsm/hooks/before_get_stats
usr/libexec/vdsm/hooks/before_get_vm_stats
usr/libexec/vdsm/hooks/before_network_setup
usr/libexec/vdsm/hooks/before_nic_hotplug
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 8a54ed8..0711055 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1192,6 +1192,8 @@
%dir %{_libexecdir}/%{vdsm_name}/hooks/after_get_all_vm_stats
%dir %{_libexecdir}/%{vdsm_name}/hooks/before_get_caps
%dir %{_libexecdir}/%{vdsm_name}/hooks/after_get_caps
+%dir %{_libexecdir}/%{vdsm_name}/hooks/before_get_stats
+%dir %{_libexecdir}/%{vdsm_name}/hooks/after_get_stats
%{_datadir}/%{vdsm_name}/addNetwork
%{_datadir}/%{vdsm_name}/delNetwork
%{_datadir}/%{vdsm_name}/dumpStorageTable.py*
diff --git a/vdsm/API.py b/vdsm/API.py
index 36fafe2..e892590 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -1303,6 +1303,7 @@
meminfo = utils.readMemInfo()
return meminfo['SwapTotal'] / 1024, meminfo['SwapFree'] / 1024
+ hooks.before_get_stats()
stats = {}
decStats = self._cif._hostStats.get()
@@ -1342,6 +1343,7 @@
# For backwards compatibility, will be removed in the future
stats['haScore'] = stats['haStats']['score']
+ stats = hooks.after_get_stats(stats)
return {'status': doneCode, 'info': stats}
def setLogLevel(self, level):
diff --git a/vdsm/hooks.py b/vdsm/hooks.py
index 9dbfcba..1d6605f 100644
--- a/vdsm/hooks.py
+++ b/vdsm/hooks.py
@@ -369,6 +369,16 @@
hookType=_JSON_HOOK)
+def before_get_stats():
+ return _runHooksDir({}, 'before_get_stats', raiseError=True,
+ hookType=_JSON_HOOK)
+
+
+def after_get_stats(caps):
+ return _runHooksDir(caps, 'after_get_stats', raiseError=False,
+ hookType=_JSON_HOOK)
+
+
def _getScriptInfo(path):
try:
with file(path) as f:
diff --git a/vdsm/vdsmd.8.in b/vdsm/vdsmd.8.in
index cca7fac..61df3e8 100644
--- a/vdsm/vdsmd.8.in
+++ b/vdsm/vdsmd.8.in
@@ -61,7 +61,8 @@
before_set_num_of_cpus, after_set_num_of_cpus,
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_caps, after_get_caps,
+ before_get_stats, after_get_stats.
Each hook executes the scripts under
.FN /usr/libexec/vdsm/hooks/<hook-name>/
@@ -71,7 +72,8 @@
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 and after_get_caps) inherit
+before_get_caps, after_get_caps,
+before_get_stats, after_get_stats) inherit
the environment of the VDSM process, with an additional variable
.B _hook_domxml
which holds the path of libvirt's
@@ -162,6 +164,11 @@
a getVdsCapabilities API request.
after_get_caps receives the complete capabilities dictionary within _hook_json.
+before_get_stats and after_get_stats are called before (and after)
+a getVdsStats API request.
+after_get_stats receives the complete host statistics dictionary within
+_hook_json.
+
.SS Hook execution
before_vdsm_start and after_vdsm_stop scripts are executed as user
.I root.
diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am
index 028d25a..128d017 100644
--- a/vdsm_hooks/Makefile.am
+++ b/vdsm_hooks/Makefile.am
@@ -115,6 +115,8 @@
after_get_all_vm_stats \
before_get_caps \
after_get_caps \
+ before_get_stats \
+ after_get_stats \
$(NULL)
all-local: \
--
To view, visit https://gerrit.ovirt.org/43274
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1ff93837abb73f88ececc7571115645b95486cf
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Petr Horáček <[email protected]>
Gerrit-Reviewer: Dan Kenigsberg <[email protected]>
Gerrit-Reviewer: Ido Barkan <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches