aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-07-10 09:34:23 +0200
committerGuido Günther <agx@sigxcpu.org>2012-07-20 21:54:34 +0200
commita91067fa0d92e2716db32e0db07b3e4f3623fa90 (patch)
tree1506c2a7621db0733e21386f76e30bb559cb9649
parentReport 'errno' in int1 field of virErrorPtr (diff)
downloadlibvirt-a91067fa0d92e2716db32e0db07b3e4f3623fa90.tar.gz
libvirt-a91067fa0d92e2716db32e0db07b3e4f3623fa90.tar.bz2
libvirt-a91067fa0d92e2716db32e0db07b3e4f3623fa90.zip
Add virDomainGetHostname
to query a guests's hostname. Containers like LXC and OpenVZ allow to set a hostname different from the hosts name and QEMU's guest agent could provide similar functionality.
-rw-r--r--include/libvirt/libvirt.h.in2
-rw-r--r--src/driver.h6
-rw-r--r--src/libvirt.c45
-rw-r--r--src/libvirt_public.syms5
4 files changed, 58 insertions, 0 deletions
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index e34438cda..fcef461a1 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1540,6 +1540,8 @@ int virDomainSetMemoryFlags (virDomainPtr domain,
int virDomainGetMaxVcpus (virDomainPtr domain);
int virDomainGetSecurityLabel (virDomainPtr domain,
virSecurityLabelPtr seclabel);
+char * virDomainGetHostname (virDomainPtr domain,
+ unsigned int flags);
typedef enum {
VIR_DOMAIN_METADATA_DESCRIPTION = 0, /* Operate on <description> */
diff --git a/src/driver.h b/src/driver.h
index b3c1740a5..46d98467b 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -142,6 +142,11 @@ typedef int
unsigned int flags);
typedef char *
(*virDrvDomainGetOSType) (virDomainPtr domain);
+
+typedef char *
+ (*virDrvDomainGetHostname) (virDomainPtr domain,
+ unsigned int flags);
+
typedef unsigned long long
(*virDrvDomainGetMaxMemory) (virDomainPtr domain);
typedef int
@@ -904,6 +909,7 @@ struct _virDriver {
virDrvDomainDestroy domainDestroy;
virDrvDomainDestroyFlags domainDestroyFlags;
virDrvDomainGetOSType domainGetOSType;
+ virDrvDomainGetHostname domainGetHostname;
virDrvDomainGetMaxMemory domainGetMaxMemory;
virDrvDomainSetMaxMemory domainSetMaxMemory;
virDrvDomainSetMemory domainSetMemory;
diff --git a/src/libvirt.c b/src/libvirt.c
index df78e8aca..8315b4fca 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -18977,3 +18977,48 @@ error:
virDispatchError(dom->conn);
return -1;
}
+
+/**
+ * virDomainGetHostname:
+ * @domain: a domain object
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Get the hostname for that domain.
+ *
+ * Dependent on hypervisor used, this may require a guest agent to be
+ * available.
+ *
+ * Returns the hostname which must be freed by the caller, or
+ * NULL if there was an error.
+ */
+char *
+virDomainGetHostname(virDomainPtr domain, unsigned int flags)
+{
+ virConnectPtr conn;
+
+ VIR_DOMAIN_DEBUG(domain);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+ virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+ virDispatchError(NULL);
+ return NULL;
+ }
+
+ conn = domain->conn;
+
+ if (conn->driver->domainGetHostname) {
+ char *ret;
+ ret = conn->driver->domainGetHostname (domain, flags);
+ if (!ret)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ virDispatchError(domain->conn);
+ return NULL;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 2913a8190..1a8e58aed 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -544,4 +544,9 @@ LIBVIRT_0.9.13 {
virDomainSnapshotRef;
} LIBVIRT_0.9.11;
+LIBVIRT_0.9.14 {
+ global:
+ virDomainGetHostname;
+} LIBVIRT_0.9.13;
+
# .... define new API here using predicted next version number ....