[libvirt] Patch for Ruby Bindings to include attach & detach device

Martin Gajdos unabatede at gmail.com
Thu Jun 18 10:31:12 UTC 2009


Hi

David Lutterkort asked me to send this patch to the list so it could be
reviewed.

What this small patch does is, it adds two functions to call
"virDomainAttachDevice" & "virDomainDetachDevice" which allow devices to be
attached & detached at run-time. The Ruby methods are called "attach_device"
& "detach_device" and belong to the Domain class.

Martin

--- orig_libvirt.c    2009-06-18 12:17:47.000000000 +0200
+++ mine_libvirt.c    2009-06-18 12:22:25.000000000 +0200
@@ -970,6 +970,22 @@
 }

 /*
+ * Call +virDomainAttachDevice+[
http://www.libvirt.org/html/libvirt-libvirt.html#virDomainAttachDevice]
+ */
+VALUE libvirt_dom_attach_device(VALUE s, VALUE xml) {
+    gen_call_void(virDomainAttachDevice, conn(s),
+                  domain_get(s), StringValueCStr(xml));
+}
+
+/*
+ * Call +virDomainDetachDevice+[
http://www.libvirt.org/html/libvirt-libvirt.html#virDomainDetachDevice]
+ */
+VALUE libvirt_dom_detach_device(VALUE s, VALUE xml) {
+    gen_call_void(virDomainDetachDevice, conn(s),
+                  domain_get(s), StringValueCStr(xml));
+}
+
+/*
  * Call +virDomainCreateLinux+[
http://www.libvirt.org/html/libvirt-libvirt.html#virDomainCreateLinux]
  */
 VALUE libvirt_conn_create_linux(int argc, VALUE *argv, VALUE c) {
@@ -1921,6 +1937,8 @@
     rb_define_method(c_domain, "autostart", libvirt_dom_autostart, 0);
     rb_define_method(c_domain, "autostart=", libvirt_dom_autostart_set, 1);
     rb_define_method(c_domain, "free", libvirt_dom_free, 0);
+    rb_define_method(c_domain, "attach_device", libvirt_dom_attach_device,
1);
+    rb_define_method(c_domain, "detach_device", libvirt_dom_detach_device,
1);

     /*
      * Class Libvirt::Domain::Info
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20090618/731c2f39/attachment-0001.htm>


More information about the libvir-list mailing list