]> xenbits.xensource.com Git - libvirt.git/commitdiff
bhyve: implement connectDomainXMLToNative
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Sun, 13 Apr 2014 09:48:17 +0000 (13:48 +0400)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Sun, 4 May 2014 13:43:55 +0000 (17:43 +0400)
The only accepted format for now is 'bhyve-argv' which
prints out a bhyve command corresponding to the given
domain definition.

src/bhyve/bhyve_command.h
src/bhyve/bhyve_driver.c

index 7a38353eac6fc3e98024967776636c36a60da705..31de97adf9399b9bac1cbf160595c1a41e0a2e4b 100644 (file)
@@ -27,6 +27,8 @@
 # include "domain_conf.h"
 # include "vircommand.h"
 
+# define BHYVE_CONFIG_FORMAT_ARGV "bhyve-argv"
+
 virCommandPtr virBhyveProcessBuildBhyveCmd(bhyveConnPtr,
                              virDomainDefPtr def, bool dryRun);
 
index 6d681fd6e49ad9747bdf7deb4d3ca804e57e5526..fe178337674ecede4cd7e0476fb71f5cf4cc0be0 100644 (file)
@@ -53,6 +53,7 @@
 #include "nodeinfo.h"
 
 #include "bhyve_driver.h"
+#include "bhyve_command.h"
 #include "bhyve_process.h"
 #include "bhyve_utils.h"
 #include "bhyve_capabilities.h"
@@ -593,6 +594,63 @@ bhyveConnectNumOfDefinedDomains(virConnectPtr conn)
     return count;
 }
 
+static char *
+bhyveConnectDomainXMLToNative(virConnectPtr conn,
+                              const char *format,
+                              const char *xmlData,
+                              unsigned int flags)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+    bhyveConnPtr privconn = conn->privateData;
+    virDomainDefPtr def = NULL;
+    virCommandPtr cmd = NULL, loadcmd = NULL;
+    virCapsPtr caps = NULL;
+    char *ret = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (virConnectDomainXMLToNativeEnsureACL(conn) < 0)
+        goto cleanup;
+
+    if (STRNEQ(format, BHYVE_CONFIG_FORMAT_ARGV)) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("Unsupported config type %s"), format);
+        goto cleanup;
+    }
+
+    if (!(caps = bhyveDriverGetCapabilities(privconn)))
+        goto cleanup;
+
+    if (!(def = virDomainDefParseString(xmlData, caps, privconn->xmlopt,
+                                  1 << VIR_DOMAIN_VIRT_BHYVE,
+                                  VIR_DOMAIN_XML_INACTIVE)))
+        goto cleanup;
+
+    if (!(loadcmd = virBhyveProcessBuildLoadCmd(privconn, def)))
+        goto cleanup;
+
+    if (!(cmd = virBhyveProcessBuildBhyveCmd(privconn, def, true)))
+        goto cleanup;
+
+    virBufferAdd(&buf, virCommandToString(loadcmd), -1);
+    virBufferAddChar(&buf, '\n');
+    virBufferAdd(&buf, virCommandToString(cmd), -1);
+
+    if (virBufferError(&buf)) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    ret = virBufferContentAndReset(&buf);
+
+ cleanup:
+    virCommandFree(loadcmd);
+    virCommandFree(cmd);
+    virDomainDefFree(def);
+    virObjectUnref(caps);
+    return ret;
+}
+
 static int
 bhyveConnectListAllDomains(virConnectPtr conn,
                            virDomainPtr **domains,
@@ -1187,6 +1245,7 @@ static virDriver bhyveDriver = {
     .connectListAllDomains = bhyveConnectListAllDomains, /* 1.2.2 */
     .connectListDefinedDomains = bhyveConnectListDefinedDomains, /* 1.2.2 */
     .connectNumOfDefinedDomains = bhyveConnectNumOfDefinedDomains, /* 1.2.2 */
+    .connectDomainXMLToNative = bhyveConnectDomainXMLToNative, /* 1.2.5 */
     .domainCreate = bhyveDomainCreate, /* 1.2.2 */
     .domainCreateWithFlags = bhyveDomainCreateWithFlags, /* 1.2.3 */
     .domainCreateXML = bhyveDomainCreateXML, /* 1.2.4 */