Allow qemu binary to be overridden at runtime.
[libguestfs.git] / ruby / ext / guestfs / _guestfs.c
index 3861d9b..4e1a2d4 100644 (file)
@@ -181,6 +181,44 @@ static VALUE ruby_guestfs_config (VALUE gv, VALUE qemuparamv, VALUE qemuvaluev)
   return Qnil;
 }
 
+static VALUE ruby_guestfs_set_qemu (VALUE gv, VALUE qemuv)
+{
+  guestfs_h *g;
+  Data_Get_Struct (gv, guestfs_h, g);
+  if (!g)
+    rb_raise (rb_eArgError, "%s: used handle after closing it", "set_qemu");
+
+  const char *qemu = StringValueCStr (qemuv);
+  if (!qemu)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "qemu", "set_qemu");
+
+  int r;
+
+  r = guestfs_set_qemu (g, qemu);
+  if (r == -1)
+    rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+  return Qnil;
+}
+
+static VALUE ruby_guestfs_get_qemu (VALUE gv)
+{
+  guestfs_h *g;
+  Data_Get_Struct (gv, guestfs_h, g);
+  if (!g)
+    rb_raise (rb_eArgError, "%s: used handle after closing it", "get_qemu");
+
+
+  const char *r;
+
+  r = guestfs_get_qemu (g);
+  if (r == NULL)
+    rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+  return rb_str_new2 (r);
+}
+
 static VALUE ruby_guestfs_set_path (VALUE gv, VALUE pathv)
 {
   guestfs_h *g;
@@ -2093,6 +2131,106 @@ static VALUE ruby_guestfs_checksum (VALUE gv, VALUE csumtypev, VALUE pathv)
   return rv;
 }
 
+static VALUE ruby_guestfs_tar_in (VALUE gv, VALUE tarfilev, VALUE directoryv)
+{
+  guestfs_h *g;
+  Data_Get_Struct (gv, guestfs_h, g);
+  if (!g)
+    rb_raise (rb_eArgError, "%s: used handle after closing it", "tar_in");
+
+  const char *tarfile = StringValueCStr (tarfilev);
+  if (!tarfile)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "tarfile", "tar_in");
+  const char *directory = StringValueCStr (directoryv);
+  if (!directory)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "directory", "tar_in");
+
+  int r;
+
+  r = guestfs_tar_in (g, tarfile, directory);
+  if (r == -1)
+    rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+  return Qnil;
+}
+
+static VALUE ruby_guestfs_tar_out (VALUE gv, VALUE directoryv, VALUE tarfilev)
+{
+  guestfs_h *g;
+  Data_Get_Struct (gv, guestfs_h, g);
+  if (!g)
+    rb_raise (rb_eArgError, "%s: used handle after closing it", "tar_out");
+
+  const char *directory = StringValueCStr (directoryv);
+  if (!directory)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "directory", "tar_out");
+  const char *tarfile = StringValueCStr (tarfilev);
+  if (!tarfile)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "tarfile", "tar_out");
+
+  int r;
+
+  r = guestfs_tar_out (g, directory, tarfile);
+  if (r == -1)
+    rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+  return Qnil;
+}
+
+static VALUE ruby_guestfs_tgz_in (VALUE gv, VALUE tarballv, VALUE directoryv)
+{
+  guestfs_h *g;
+  Data_Get_Struct (gv, guestfs_h, g);
+  if (!g)
+    rb_raise (rb_eArgError, "%s: used handle after closing it", "tgz_in");
+
+  const char *tarball = StringValueCStr (tarballv);
+  if (!tarball)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "tarball", "tgz_in");
+  const char *directory = StringValueCStr (directoryv);
+  if (!directory)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "directory", "tgz_in");
+
+  int r;
+
+  r = guestfs_tgz_in (g, tarball, directory);
+  if (r == -1)
+    rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+  return Qnil;
+}
+
+static VALUE ruby_guestfs_tgz_out (VALUE gv, VALUE directoryv, VALUE tarballv)
+{
+  guestfs_h *g;
+  Data_Get_Struct (gv, guestfs_h, g);
+  if (!g)
+    rb_raise (rb_eArgError, "%s: used handle after closing it", "tgz_out");
+
+  const char *directory = StringValueCStr (directoryv);
+  if (!directory)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "directory", "tgz_out");
+  const char *tarball = StringValueCStr (tarballv);
+  if (!tarball)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "tarball", "tgz_out");
+
+  int r;
+
+  r = guestfs_tgz_out (g, directory, tarball);
+  if (r == -1)
+    rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+  return Qnil;
+}
+
 /* Initialize the module. */
 void Init__guestfs ()
 {
@@ -2115,6 +2253,10 @@ void Init__guestfs ()
         ruby_guestfs_add_cdrom, 1);
   rb_define_method (c_guestfs, "config",
         ruby_guestfs_config, 2);
+  rb_define_method (c_guestfs, "set_qemu",
+        ruby_guestfs_set_qemu, 1);
+  rb_define_method (c_guestfs, "get_qemu",
+        ruby_guestfs_get_qemu, 0);
   rb_define_method (c_guestfs, "set_path",
         ruby_guestfs_set_path, 1);
   rb_define_method (c_guestfs, "get_path",
@@ -2277,4 +2419,12 @@ void Init__guestfs ()
         ruby_guestfs_download, 2);
   rb_define_method (c_guestfs, "checksum",
         ruby_guestfs_checksum, 2);
+  rb_define_method (c_guestfs, "tar_in",
+        ruby_guestfs_tar_in, 2);
+  rb_define_method (c_guestfs, "tar_out",
+        ruby_guestfs_tar_out, 2);
+  rb_define_method (c_guestfs, "tgz_in",
+        ruby_guestfs_tgz_in, 2);
+  rb_define_method (c_guestfs, "tgz_out",
+        ruby_guestfs_tgz_out, 2);
 }