Dan Kenigsberg has uploaded a new change for review.
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 danken@redhat.com --- 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, 29 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/03/40403/1
diff --git a/debian/vdsm.dirs b/debian/vdsm.dirs index 87703cd..82ba929 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_hostdev_list_by_caps usr/libexec/vdsm/hooks/after_network_setup @@ -45,6 +46,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 76ed135..212155e 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -1264,6 +1264,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 %dir %{_libexecdir}/%{vdsm_name}/hooks/after_hostdev_list_by_caps %{_datadir}/%{vdsm_name}/addNetwork %{_datadir}/%{vdsm_name}/delNetwork diff --git a/vdsm/API.py b/vdsm/API.py index 3cdc465..3050735 100644 --- a/vdsm/API.py +++ b/vdsm/API.py @@ -1321,6 +1321,7 @@ meminfo = utils.readMemInfo() return meminfo['SwapTotal'] / 1024, meminfo['SwapFree'] / 1024
+ hooks.before_get_stats() stats = {} decStats = self._cif._hostStats.get()
@@ -1354,6 +1355,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 cedf2be..965459d 100644 --- a/vdsm/hooks.py +++ b/vdsm/hooks.py @@ -371,6 +371,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 after_hostdev_list_by_caps(devices): return _runHooksDir(devices, 'after_hostdev_list_by_caps', raiseError=False, hookType=_JSON_HOOK) diff --git a/vdsm/vdsmd.8.in b/vdsm/vdsmd.8.in index f6e7158..78989cd 100644 --- a/vdsm/vdsmd.8.in +++ b/vdsm/vdsmd.8.in @@ -61,7 +61,9 @@ 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, after_hostdev_list_by_caps. + before_get_caps, after_get_caps, + before_get_stats, after_get_stats, + after_hostdev_list_by_caps.
Each hook executes the scripts under .FN /usr/libexec/vdsm/hooks/<hook-name>/ @@ -71,7 +73,9 @@ 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 and after_hostdev_list_by_caps) inherit +before_get_caps, after_get_caps, +before_get_stats, after_get_stats, +and after_hostdev_list_by_caps) inherit the environment of the VDSM process, with an additional variable .B _hook_domxml which holds the path of libvirt's @@ -162,6 +166,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 337284b..d1aa8b6 100644 --- a/vdsm_hooks/Makefile.am +++ b/vdsm_hooks/Makefile.am @@ -124,6 +124,8 @@ after_get_all_vm_stats \ before_get_caps \ after_get_caps \ + before_get_stats \ + after_get_stats \ after_hostdev_list_by_caps \ $(NULL)
automation@ovirt.org has posted comments on this change.
Change subject: hooks: introduce before/after_get_stats hook points ......................................................................
Patch Set 1:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Dan Kenigsberg has posted comments on this change.
Change subject: hooks: introduce before/after_get_stats hook points ......................................................................
Patch Set 1: Verified+1
the after_ hook below works as it should.
import hooking
stats = hooking.read_json() stats['foo'] = 'bar' hooking.write_json(stats)
Ido Barkan has posted comments on this change.
Change subject: hooks: introduce before/after_get_stats hook points ......................................................................
Patch Set 1: Code-Review+1
Petr Horáček has posted comments on this change.
Change subject: hooks: introduce before/after_get_stats hook points ......................................................................
Patch Set 1: Code-Review+1
Federico Simoncelli has posted comments on this change.
Change subject: hooks: introduce before/after_get_stats hook points ......................................................................
Patch Set 1: Code-Review+2
Dan Kenigsberg has submitted this change and it was merged.
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 danken@redhat.com Reviewed-on: https://gerrit.ovirt.org/40403 Reviewed-by: Ido Barkan ibarkan@redhat.com Reviewed-by: Petr Horáček phoracek@redhat.com Reviewed-by: Federico Simoncelli fsimonce@redhat.com --- 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, 29 insertions(+), 2 deletions(-)
Approvals: Ido Barkan: Looks good to me, but someone else must approve Federico Simoncelli: Looks good to me, approved Petr Horáček: Looks good to me, but someone else must approve Dan Kenigsberg: Verified
automation@ovirt.org has posted comments on this change.
Change subject: hooks: introduce before/after_get_stats hook points ......................................................................
Patch Set 2:
* Update tracker::IGNORE, no Bug-Url found * Set MODIFIED::IGNORE, no Bug-Url found.
vdsm-patches@lists.fedorahosted.org