]> xenbits.xensource.com Git - libvirt.git/commitdiff
openvz: Add openvzVEGetStringParam
authorGuido Günther <agx@sigxcpu.org>
Tue, 10 Jul 2012 11:57:38 +0000 (13:57 +0200)
committerGuido Günther <agx@sigxcpu.org>
Fri, 20 Jul 2012 19:54:35 +0000 (21:54 +0200)
to retrieve a VEs config parameters as a single string. This will be
used by the upcoming domainGetHostname implementation.

src/libvirt_openvz.syms
src/openvz/openvz_util.c
src/openvz/openvz_util.h

index 11c5587f4b85683e4abf74e90305e6b2c2bc3e51..1993eb5f14b34d85c1ed9b0921d95fb042788bf9 100644 (file)
@@ -1,7 +1,7 @@
 #
 # These symbols are dependent upon --with-openvz via WITH_OPENVZ
 #
-
 openvzReadConfigParam;
 openvzReadNetworkConf;
 openvzLocateConfFile;
+openvzVEGetStringParam;
index 1989ec53b1e72c57c8f5c51609b7d30c57f964bd..a878dd6c0891a456bf8f450c84bb9840168e18c1 100644 (file)
@@ -26,6 +26,9 @@
 #include "internal.h"
 
 #include "virterror_internal.h"
+#include "command.h"
+#include "datatypes.h"
+#include "memory.h"
 
 #include "openvz_conf.h"
 #include "openvz_util.h"
@@ -50,3 +53,32 @@ openvzKBPerPages(void)
     }
     return kb_per_pages;
 }
+
+char*
+openvzVEGetStringParam(virDomainPtr domain, const char* param)
+{
+    int len;
+    char *output = NULL;
+
+    virCommandPtr cmd = virCommandNewArgList(VZLIST,
+                                             "-o",
+                                             param,
+                                             domain->name,
+                                             "-H" , NULL);
+
+    virCommandSetOutputBuffer(cmd, &output);
+    if (virCommandRun(cmd, NULL) < 0) {
+        VIR_FREE(output);
+        /* virCommandRun sets the virError */
+        goto cleanup;
+    }
+
+    /* delete trailing newline */
+    len = strlen(output);
+    if (len && output[len - 1] == '\n')
+        output[len - 1] = '\0';
+
+cleanup:
+    virCommandFree(cmd);
+    return output;
+}
index a0d9bbbddcccf60304c7e29554b4adbe93848189..94c527f29e19d18c1954553026d8b34900881bf8 100644 (file)
@@ -24,5 +24,6 @@
 # define OPENVZ_UTIL_H
 
 long openvzKBPerPages(void);
+char *openvzVEGetStringParam(virDomainPtr dom, const char *param);
 
 #endif