Itzik Brown has uploaded a new change for review.

Change subject: Adding hooks support for NIC hotplug
......................................................................

Adding hooks support for NIC hotplug

Adding the ability to write hooks for events
of NIC hotplug and hotunplug.
Hooks are: before_nic_plug and after_nic_unplug

Change-Id: I253104ee9831a881e2fb06f0a658631662611d77
Signed-off-by: Itzik Brown <[email protected]>
---
M vdsm.spec.in
M vdsm/hooks.py
M vdsm/libvirtvm.py
M vdsm_hooks/Makefile.am
4 files changed, 15 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/24/7224/1

diff --git a/vdsm.spec.in b/vdsm.spec.in
index 23afd6b..0d5f82d 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -658,6 +658,8 @@
 %dir %{_libexecdir}/%{vdsm_name}/hooks/after_vm_destroy
 %dir %{_libexecdir}/%{vdsm_name}/hooks/before_vm_set_ticket
 %dir %{_libexecdir}/%{vdsm_name}/hooks/after_vm_set_ticket
+%dir %{_libexecdir}/%{vdsm_name}/hooks/before_nic_plug
+%dir %{_libexecdir}/%{vdsm_name}/hooks/after_nic_unplug
 %dir %{_libexecdir}/%{vdsm_name}/hooks/before_vdsm_start
 %dir %{_libexecdir}/%{vdsm_name}/hooks/after_vdsm_stop
 %{_datadir}/%{vdsm_name}/addNetwork
diff --git a/vdsm/hooks.py b/vdsm/hooks.py
index 5b79cee..64263b3 100644
--- a/vdsm/hooks.py
+++ b/vdsm/hooks.py
@@ -174,6 +174,14 @@
                         raiseError=False, params=params)
 
 
+def before_nic_hotplug(domxml, vmconf={}):
+    return _runHooksDir(domxml, 'before_vm_hotplug', vmconf=vmconf)
+
+
+def after_nic_unplug(domxml, vmconf={}):
+    return _runHooksDir(domxml, 'after_vm_unplug', vmconf=vmconf)
+
+
 def before_vdsm_start():
     return _runHooksDir(None, 'before_vdsm_start', raiseError=False)
 
diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py
index 3b7cfc5..4ae54f7 100644
--- a/vdsm/libvirtvm.py
+++ b/vdsm/libvirtvm.py
@@ -1395,12 +1395,14 @@
         nicParams = params.get('nic', {})
         nic = NetworkInterfaceDevice(self.conf, self.log, **nicParams)
         nicXml =  nic.getXML().toprettyxml(encoding='utf-8')
+        nicXml = hooks.before_nic_hotplug(nicXml, self.conf)
         self.log.debug("Hotplug NIC xml: %s" % (nicXml))
 
         try:
             self._dom.attachDevice(nicXml)
         except libvirt.libvirtError, e:
             self.log.error("Hotplug failed", exc_info=True)
+            nicXml = hooks.after_nic_unplug(nicXml, self.conf)
             if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
                 return errCode['noVM']
             return {'status' : {'code': 
errCode['hotplugNic']['status']['code'],
@@ -1454,6 +1456,7 @@
 
         try:
             self._dom.detachDevice(nicXml)
+            hooks.after_nic_unplug(nicXml, self.conf)
         except libvirt.libvirtError, e:
             self.log.error("Hotunplug failed", exc_info=True)
             if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am
index e6a8280..36919d9 100644
--- a/vdsm_hooks/Makefile.am
+++ b/vdsm_hooks/Makefile.am
@@ -74,6 +74,8 @@
        after_vm_destroy \
     before_vm_set_ticket \
        after_vm_set_ticket \
+    before_nic_plug \
+    after_nic_unplug \
        before_vdsm_start \
        after_vdsm_stop
 


--
To view, visit http://gerrit.ovirt.org/7224
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I253104ee9831a881e2fb06f0a658631662611d77
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Itzik Brown <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to