[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH libguestfs 3/4] Add attach-method "libvirt" or "libvirt:<URI>".



From: "Richard W.M. Jones" <rjones redhat com>

With this commit, you can set the attach method to libvirt,
but calling launch will give an error.
---
 generator/generator_actions.ml |    7 +++++++
 src/guestfs-internal.h         |    6 +++++-
 src/guestfs.c                  |   17 +++++++++++++++++
 src/guestfs.pod                |    2 ++
 src/launch.c                   |    4 ++++
 5 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index c25bda1..74f76bb 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -1576,6 +1576,13 @@ guestfsd daemon.  Possible methods are:
 Launch an appliance and connect to it.  This is the ordinary method
 and the default.
 
+=item C<libvirt>
+
+=item C<libvirt:I<URI>>
+
+Use libvirt to launch the appliance.  The optional I<URI> is the
+libvirt connection URI to use (see L<http://libvirt.org/uri.html>).
+
 =item C<unix:I<path>>
 
 Connect to the Unix domain socket I<path>.
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index f05cec2..8fbe2ec 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -122,7 +122,11 @@
 enum state { CONFIG, LAUNCHING, READY, NO_HANDLE };
 
 /* Attach method. */
-enum attach_method { ATTACH_METHOD_APPLIANCE = 0, ATTACH_METHOD_UNIX };
+enum attach_method {
+  ATTACH_METHOD_APPLIANCE,
+  ATTACH_METHOD_LIBVIRT,
+  ATTACH_METHOD_UNIX,
+};
 
 /* Event. */
 struct event {
diff --git a/src/guestfs.c b/src/guestfs.c
index e848ff8..e13dd9f 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -746,6 +746,16 @@ guestfs__set_attach_method (guestfs_h *g, const char *method)
     free (g->attach_method_arg);
     g->attach_method_arg = NULL;
   }
+  else if (STREQ (method, "libvirt")) {
+    g->attach_method = ATTACH_METHOD_LIBVIRT;
+    free (g->attach_method_arg);
+    g->attach_method_arg = NULL;
+  }
+  else if (STRPREFIX (method, "libvirt:") && strlen (method) > 8) {
+    g->attach_method = ATTACH_METHOD_LIBVIRT;
+    free (g->attach_method_arg);
+    g->attach_method_arg = safe_strdup (g, method + 8);
+  }
   else if (STRPREFIX (method, "unix:") && strlen (method) > 5) {
     g->attach_method = ATTACH_METHOD_UNIX;
     free (g->attach_method_arg);
@@ -770,6 +780,13 @@ guestfs__get_attach_method (guestfs_h *g)
     ret = safe_strdup (g, "appliance");
     break;
 
+  case ATTACH_METHOD_LIBVIRT:
+    if (g->attach_method_arg == NULL)
+      ret = safe_strdup (g, "libvirt");
+    else
+      ret = safe_asprintf (g, "libvirt:%s", g->attach_method_arg);
+    break;
+
   case ATTACH_METHOD_UNIX:
     ret = safe_asprintf (g, "unix:%s", g->attach_method_arg);
     break;
diff --git a/src/guestfs.pod b/src/guestfs.pod
index 72a5506..92bdca0 100644
--- a/src/guestfs.pod
+++ b/src/guestfs.pod
@@ -1076,6 +1076,8 @@ library connects to the C<guestfsd> daemon in L</guestfs_launch>
 
 The normal attach method is C<appliance>, where a small appliance is
 created containing the daemon, and then the library connects to this.
+C<libvirt> or C<libvirt:I<URI>> are alternatives that use libvirt to
+start the appliance.
 
 Setting attach method to C<unix:I<path>> (where I<path> is the path of
 a Unix domain socket) causes L</guestfs_launch> to connect to an
diff --git a/src/launch.c b/src/launch.c
index 93029e4..7c403ab 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -325,6 +325,10 @@ guestfs__launch (guestfs_h *g)
     g->attach_ops = &attach_ops_appliance;
     break;
 
+  case ATTACH_METHOD_LIBVIRT:
+    error (g, _("libvirt attach method is not yet supported"));
+    return -1;
+
   case ATTACH_METHOD_UNIX:
     g->attach_ops = &attach_ops_unix;
     break;
-- 
1.7.10.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]