@@ -11257,6 +11257,35 @@ def report_to_management_node():
1125711257 content = traceback.format_exc()
1125811258 logger.warn("traceback: %s" % content)
1125911259
11260+ def _vm_shutdown_event_from_guest(self, conn, dom, event, detail, opaque):
11261+ try:
11262+ event = LibvirtEventManager.event_to_string(event)
11263+ if event not in (LibvirtEventManager.EVENT_SHUTDOWN,):
11264+ return
11265+
11266+ if detail != libvirt.VIR_DOMAIN_EVENT_SHUTDOWN_GUEST:
11267+ return
11268+
11269+ vm_uuid = dom.name()
11270+ logger.info("vm shutdown event from guest " + vm_uuid)
11271+ # this is an operation outside zstack, report it
11272+ url = self.config.get(kvmagent.SEND_COMMAND_URL)
11273+ if not url:
11274+ logger.warn('cannot find SEND_COMMAND_URL, unable to report shutdown event of vm[uuid:%s]' % vm_uuid)
11275+ return
11276+
11277+ @thread.AsyncThread
11278+ def report_to_management_node():
11279+ cmd = ReportVmShutdownEventCmd()
11280+ cmd.vmUuid = vm_uuid
11281+ syslog.syslog('report shutdown event for guest ' + vm_uuid)
11282+ http.json_dump_post(url, cmd, {'commandpath': '/kvm/reportvmshutdown/from/guest'})
11283+
11284+ report_to_management_node()
11285+ except:
11286+ content = traceback.format_exc()
11287+ logger.warn("traceback: %s" % content)
11288+
1126011289 def _vm_start_event(self, conn, dom, event, detail, opaque):
1126111290 try:
1126211291 event = LibvirtEventManager.event_to_string(event)
@@ -11399,6 +11428,7 @@ def register_libvirt_event(self):
1139911428 self._set_vnc_port_iptable_rule)
1140011429 LibvirtAutoReconnect.add_libvirt_callback(libvirt.VIR_DOMAIN_EVENT_ID_REBOOT, self._vm_reboot_event)
1140111430 LibvirtAutoReconnect.add_libvirt_callback(libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, self._vm_shutdown_event)
11431+ LibvirtAutoReconnect.add_libvirt_callback(libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, self._vm_shutdown_event_from_guest)
1140211432 LibvirtAutoReconnect.add_libvirt_callback(libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, self._vm_start_event)
1140311433 LibvirtAutoReconnect.add_libvirt_callback(libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, self._vm_crashed_event)
1140411434 LibvirtAutoReconnect.add_libvirt_callback(libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, self._release_sharedblocks)
0 commit comments