Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
domain.go | 33 +++++++++++++++++++++++++++++++++
domain_compat.go | 12 ++++++++++++
domain_compat.h | 41 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 86 insertions(+)
diff --git a/domain.go b/domain.go
index 5183726..36d77ba 100644
--- a/domain.go
+++ b/domain.go
@@ -4504,3 +4504,36 @@ func (d *Domain) ManagedSaveGetXMLDesc(flags uint32) (string,
error) {
C.free(unsafe.Pointer(ret))
return xml, nil
}
+
+type DomainLifecycle int
+
+const (
+ DOMAIN_LIFECYCLE_POWEROFF = DomainLifecycle(C.VIR_DOMAIN_LIFECYCLE_POWEROFF)
+ DOMAIN_LIFECYCLE_REBOOT = DomainLifecycle(C.VIR_DOMAIN_LIFECYCLE_REBOOT)
+ DOMAIN_LIFECYCLE_CRASH = DomainLifecycle(C.VIR_DOMAIN_LIFECYCLE_CRASH)
+)
+
+type DomainLifecycleAction int
+
+const (
+ DOMAIN_LIFECYCLE_ACTION_DESTROY =
DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY)
+ DOMAIN_LIFECYCLE_ACTION_RESTART =
DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_RESTART)
+ DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME =
DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME)
+ DOMAIN_LIFECYCLE_ACTION_PRESERVE =
DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE)
+ DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY =
DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY)
+ DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART =
DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART)
+)
+
+// See also
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetLifecycl...
+func (d *Domain) SetLifecycleAction(lifecycleType uint32, action uint32, flags uint32)
error {
+ if C.LIBVIR_VERSION_NUMBER < 3009000 {
+ return GetNotImplementedError("virDomainSetLifecycleAction")
+ }
+
+ ret := C.virDomainSetLifecycleActionCompat(d.ptr, C.uint(lifecycleType), C.uint(action),
C.uint(flags))
+ if ret == -1 {
+ return GetLastError()
+ }
+
+ return nil
+}
diff --git a/domain_compat.go b/domain_compat.go
index c59b00e..eada95c 100644
--- a/domain_compat.go
+++ b/domain_compat.go
@@ -345,5 +345,17 @@ int virDomainManagedSaveDefineXMLCompat(virDomainPtr domain,
#endif
}
+int virDomainSetLifecycleActionCompat(virDomainPtr domain,
+ unsigned int type,
+ unsigned int action,
+ unsigned int flags)
+{
+#if LIBVIR_VERSION_NUMBER < 3009000
+ assert(0); // Caller should have checked version
+#else
+ return virDomainSetLifecycleAction(domain, type, action, flags);
+#endif
+}
+
*/
import "C"
diff --git a/domain_compat.h b/domain_compat.h
index afef84d..2793b1b 100644
--- a/domain_compat.h
+++ b/domain_compat.h
@@ -977,4 +977,45 @@ int virDomainManagedSaveDefineXMLCompat(virDomainPtr domain,
#define VIR_DOMAIN_JOB_MEMORY_PAGE_SIZE "memory_page_size"
#endif
+#ifndef VIR_DOMAIN_LIFECYCLE_POWEROFF
+#define VIR_DOMAIN_LIFECYCLE_POWEROFF 0
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_REBOOT
+#define VIR_DOMAIN_LIFECYCLE_REBOOT 1
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_CRASH
+#define VIR_DOMAIN_LIFECYCLE_CRASH 2
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY
+#define VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY 0
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_RESTART
+#define VIR_DOMAIN_LIFECYCLE_ACTION_RESTART 1
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME
+#define VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME 2
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE
+#define VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE 3
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY
+#define VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY 4
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART
+#define VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART 5
+#endif
+
+int virDomainSetLifecycleActionCompat(virDomainPtr domain,
+ unsigned int type,
+ unsigned int action,
+ unsigned int flags);
+
#endif /* LIBVIRT_GO_DOMAIN_COMPAT_H__ */
--
2.13.6