New APIs: set-network and get-network to enable network support.
authorRichard Jones <rjones@redhat.com>
Tue, 24 Aug 2010 10:53:40 +0000 (11:53 +0100)
committerRichard Jones <rjones@redhat.com>
Tue, 24 Aug 2010 11:37:54 +0000 (12:37 +0100)
guestfs_set_network (g, true) enables network support in the appliance.

configure.ac
src/generator.ml
src/guestfs-internal.h
src/guestfs.c
src/guestfs.pod
src/launch.c

index 0ba4157..62998ba 100644 (file)
@@ -300,14 +300,14 @@ AC_ARG_WITH([drive-if],
 AC_DEFINE_UNQUOTED([DRIVE_IF],["$with_drive_if"],[Default drive interface.])
 
 dnl Set interface used by the network.  Normally you should
 AC_DEFINE_UNQUOTED([DRIVE_IF],["$with_drive_if"],[Default drive interface.])
 
 dnl Set interface used by the network.  Normally you should
-dnl leave this at the default (virtio) but you can use the
+dnl leave this at the default (virtio-net-pci) but you can use the
 dnl alternative (ne2k_pci) because of bugs in virtio networking
 dnl eg. https://bugzilla.redhat.com/show_bug.cgi?id=516022
 AC_ARG_WITH([net-if],
         [AS_HELP_STRING([--with-net-if],
 dnl alternative (ne2k_pci) because of bugs in virtio networking
 dnl eg. https://bugzilla.redhat.com/show_bug.cgi?id=516022
 AC_ARG_WITH([net-if],
         [AS_HELP_STRING([--with-net-if],
-          [set default net driver (virtio|ne2k_pci) @<:@default=virtio@:>@])],
+          [set default net driver (virtio-net-pci|ne2k_pci) @<:@default=virtio-net-pci@:>@])],
         [],
         [],
-        [with_net_if=virtio])
+        [with_net_if=virtio-net-pci])
 AC_DEFINE_UNQUOTED([NET_IF],["$with_net_if"],[Default network interface.])
 
 dnl Check for febootstrap etc.
 AC_DEFINE_UNQUOTED([NET_IF],["$with_net_if"],[Default network interface.])
 
 dnl Check for febootstrap etc.
index 233f8bd..00caa6a 100755 (executable)
@@ -1289,6 +1289,25 @@ for a filesystem to be shared between operating systems.
 Please read L<guestfs(3)/INSPECTION> for more details.
 See also C<guestfs_inspect_get_mountpoints>.");
 
 Please read L<guestfs(3)/INSPECTION> for more details.
 See also C<guestfs_inspect_get_mountpoints>.");
 
+  ("set_network", (RErr, [Bool "network"]), -1, [FishAlias "network"],
+   [],
+   "set enable network flag",
+   "\
+If C<network> is true, then the network is enabled in the
+libguestfs appliance.  The default is false.
+
+This affects whether commands are able to access the network
+(see L<guestfs(3)/RUNNING COMMANDS>).
+
+You must call this before calling C<guestfs_launch>, otherwise
+it has no effect.");
+
+  ("get_network", (RBool "network", []), -1, [],
+   [],
+   "get enable network flag",
+   "\
+This returns the enable network flag.");
+
 ]
 
 (* daemon_functions are any functions which cause some action
 ]
 
 (* daemon_functions are any functions which cause some action
index b534b6a..e37c9c2 100644 (file)
@@ -98,6 +98,7 @@ struct guestfs_h
   int autosync;
   int direct;
   int recovery_proc;
   int autosync;
   int direct;
   int recovery_proc;
+  int enable_network;
 
   char *path;                  /* Path to kernel, initrd. */
   char *qemu;                  /* Qemu binary. */
 
   char *path;                  /* Path to kernel, initrd. */
   char *qemu;                  /* Qemu binary. */
index 74de38c..eaacd39 100644 (file)
@@ -601,6 +601,19 @@ guestfs__get_recovery_proc (guestfs_h *g)
   return g->recovery_proc;
 }
 
   return g->recovery_proc;
 }
 
+int
+guestfs__set_network (guestfs_h *g, int v)
+{
+  g->enable_network = !!v;
+  return 0;
+}
+
+int
+guestfs__get_network (guestfs_h *g)
+{
+  return g->enable_network;
+}
+
 void
 guestfs_set_log_message_callback (guestfs_h *g,
                                   guestfs_log_message_cb cb, void *opaque)
 void
 guestfs_set_log_message_callback (guestfs_h *g,
                                   guestfs_log_message_cb cb, void *opaque)
index 4dafb07..590c768 100644 (file)
@@ -358,6 +358,11 @@ The command will be running in limited memory.
 
 =item *
 
 
 =item *
 
+The network may not be available unless you enable it
+(see L</guestfs_set_network>).
+
+=item *
+
 Only supports Linux guests (not Windows, BSD, etc).
 
 =item *
 Only supports Linux guests (not Windows, BSD, etc).
 
 =item *
index 1e1ea8e..9262cc5 100644 (file)
@@ -410,6 +410,14 @@ guestfs__launch (guestfs_h *g)
     add_cmdline (g, "-device");
     add_cmdline (g, "virtserialport,chardev=channel0,name=org.libguestfs.channel.0");
 
     add_cmdline (g, "-device");
     add_cmdline (g, "virtserialport,chardev=channel0,name=org.libguestfs.channel.0");
 
+    /* Enable user networking. */
+    if (g->enable_network) {
+      add_cmdline (g, "-netdev");
+      add_cmdline (g, "user,id=usernet");
+      add_cmdline (g, "-device");
+      add_cmdline (g, NET_IF ",netdev=usernet");
+    }
+
 #define LINUX_CMDLINE                                                  \
     "panic=1 "         /* force kernel to panic if daemon exits */     \
     "console=ttyS0 "   /* serial console */                            \
 #define LINUX_CMDLINE                                                  \
     "panic=1 "         /* force kernel to panic if daemon exits */     \
     "console=ttyS0 "   /* serial console */                            \