From: Matt Coleman <matt(a)datto.com>
Co-authored-by: Sri Ramanujam <sramanujam(a)datto.com>
Signed-off-by: Matt Coleman <matt(a)datto.com>
---
NEWS.rst | 5 +++--
src/hyperv/hyperv_driver.c | 40 ++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/NEWS.rst b/NEWS.rst
index 05e129d9cf..ed6a0b5176 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -15,8 +15,9 @@ v6.9.0 (unreleased)
* hyperv: implement new APIs
- The ``virConnectGetCapabilities()``, ``virConnectGetMaxVcpus()``, and
- ``virConnectGetVersion()`` APIs have been implemented in the Hyper-V driver.
+ The ``virConnectGetCapabilities()``, ``virConnectGetMaxVcpus()``,
+ ``virConnectGetVersion()``, and ``virDomainGetAutostart()`` APIs have been
+ implemented in the Hyper-V driver.
* **Improvements**
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 14ebb4b62d..9fbd944437 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1280,6 +1280,45 @@ hypervDomainCreate(virDomainPtr domain)
+static int
+hypervDomainGetAutostart(virDomainPtr domain, int *autostart)
+{
+ int result = -1;
+ char uuid_string[VIR_UUID_STRING_BUFLEN];
+ hypervPrivate *priv = domain->conn->privateData;
+ g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
+ Msvm_VirtualSystemGlobalSettingData *vsgsd = NULL;
+ Msvm_VirtualSystemSettingData *vssd = NULL;
+
+ virUUIDFormat(domain->uuid, uuid_string);
+
+ if (priv->wmiVersion == HYPERV_WMI_VERSION_V1) {
+ virBufferEscapeSQL(&query,
+ MSVM_VIRTUALSYSTEMGLOBALSETTINGDATA_WQL_SELECT
+ "WHERE SystemName = \"%s\"",
uuid_string);
+
+ if (hypervGetWmiClass(Msvm_VirtualSystemGlobalSettingData, &vsgsd) < 0)
+ goto cleanup;
+
+ *autostart = vsgsd->data.common->AutomaticStartupAction == 2;
+ result = 0;
+ } else {
+ if (hypervGetVSSDFromUUID(priv, uuid_string, &vssd) < 0)
+ goto cleanup;
+
+ *autostart = vssd->data.v2->AutomaticStartupAction == 4;
+ result = 0;
+ }
+
+ cleanup:
+ hypervFreeObject(priv, (hypervObject *) vsgsd);
+ hypervFreeObject(priv, (hypervObject *) vssd);
+
+ return result;
+}
+
+
+
static int
hypervConnectIsEncrypted(virConnectPtr conn)
{
@@ -1830,6 +1869,7 @@ static virHypervisorDriver hypervHypervisorDriver = {
.connectNumOfDefinedDomains = hypervConnectNumOfDefinedDomains, /* 0.9.5 */
.domainCreate = hypervDomainCreate, /* 0.9.5 */
.domainCreateWithFlags = hypervDomainCreateWithFlags, /* 0.9.5 */
+ .domainGetAutostart = hypervDomainGetAutostart, /* 6.9.0 */
.connectIsEncrypted = hypervConnectIsEncrypted, /* 0.9.5 */
.connectIsSecure = hypervConnectIsSecure, /* 0.9.5 */
.domainIsActive = hypervDomainIsActive, /* 0.9.5 */
--
2.27.0