]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: implementing qemuAgentGetHostname() function.
authorJulio Faracco <jcfaracco@gmail.com>
Wed, 5 Sep 2018 04:20:53 +0000 (01:20 -0300)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 5 Sep 2018 17:13:37 +0000 (13:13 -0400)
This commit implements the function qemuAgentGetHostname() that uses
the QEMU guest agent command 'guest-get-host-name' to retrieve the
guest hostname of virtual machine running the QEMU-GA.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_agent.c
src/qemu/qemu_agent.h

index bf08871f18c2f8542e677ce1d70fc30319a9a38f..ee0798789a91ccacc30d6a74ec85f273e5332d3d 100644 (file)
@@ -1683,6 +1683,50 @@ qemuAgentUpdateCPUInfo(unsigned int nvcpus,
 }
 
 
+int
+qemuAgentGetHostname(qemuAgentPtr mon,
+                     char **hostname)
+{
+    int ret = -1;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr data = NULL;
+    const char *result = NULL;
+
+    cmd = qemuAgentMakeCommand("guest-get-host-name",
+                               NULL);
+
+    if (!cmd)
+        return ret;
+
+    if (qemuAgentCommand(mon, cmd, &reply, true,
+                         VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
+        goto cleanup;
+
+    if (!(data = virJSONValueObjectGet(reply, "return"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("malformed return value"));
+        goto cleanup;
+    }
+
+    if (!(result = virJSONValueObjectGetString(data, "host-name"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("'host-name' missing in guest-get-host-name reply"));
+        goto cleanup;
+    }
+
+    if (VIR_STRDUP(*hostname, result) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
+
+
 int
 qemuAgentGetTime(qemuAgentPtr mon,
                  long long *seconds,
index 6dd9c702ddcd0ec4caebdd63bae1002eee2d35d4..4354b7e0cf729c0b17699ee2e30275b9387b4d3b 100644 (file)
@@ -105,6 +105,10 @@ int qemuAgentUpdateCPUInfo(unsigned int nvcpus,
                            qemuAgentCPUInfoPtr cpuinfo,
                            int ncpuinfo);
 
+int
+qemuAgentGetHostname(qemuAgentPtr mon,
+                     char **hostname);
+
 int qemuAgentGetTime(qemuAgentPtr mon,
                      long long *seconds,
                      unsigned int *nseconds);