ruby-libvirt-0.8.4/0000755000175000017500000000000014652707704014317 5ustar abolognaabolognaruby-libvirt-0.8.4/ext/0000755000175000017500000000000014652707704015117 5ustar abolognaabolognaruby-libvirt-0.8.4/ext/libvirt/0000755000175000017500000000000014652707704016572 5ustar abolognaabolognaruby-libvirt-0.8.4/ext/libvirt/storage.c0000644000175000017500000010316414641546211020377 0ustar abolognaabologna/* * storage.c: virStoragePool and virStorageVolume methods * * Copyright (C) 2007,2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "common.h" #include "connect.h" #include "extconf.h" #include "stream.h" /* this has to be here (as opposed to below with the rest of the volume * stuff) because libvirt_storage_vol_get_pool() relies on it */ static virStorageVolPtr vol_get(VALUE v) { ruby_libvirt_get_struct(StorageVol, v); } static VALUE c_storage_pool; static VALUE c_storage_pool_info; /* * Class Libvirt::StoragePool */ static void pool_free(void *d) { ruby_libvirt_free_struct(StoragePool, d); } static virStoragePoolPtr pool_get(VALUE p) { ruby_libvirt_get_struct(StoragePool, p); } VALUE pool_new(virStoragePoolPtr p, VALUE conn) { return ruby_libvirt_new_class(c_storage_pool, p, conn, pool_free); } /* * call-seq: * vol.pool -> Libvirt::StoragePool * * Call virStoragePoolLookupByVolume[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByVolume] * to retrieve the storage pool for this volume. */ static VALUE libvirt_storage_vol_pool(VALUE v) { virStoragePoolPtr pool; pool = virStoragePoolLookupByVolume(vol_get(v)); ruby_libvirt_raise_error_if(pool == NULL, e_RetrieveError, "virStoragePoolLookupByVolume", ruby_libvirt_connect_get(v)); return pool_new(pool, ruby_libvirt_conn_attr(v)); } /* * call-seq: * pool.build(flags=0) -> nil * * Call virStoragePoolBuild[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolBuild] * to build this storage pool. */ static VALUE libvirt_storage_pool_build(int argc, VALUE *argv, VALUE p) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virStoragePoolBuild, ruby_libvirt_connect_get(p), pool_get(p), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * pool.undefine -> nil * * Call virStoragePoolUndefine[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolUndefine] * to undefine this storage pool. */ static VALUE libvirt_storage_pool_undefine(VALUE p) { ruby_libvirt_generate_call_nil(virStoragePoolUndefine, ruby_libvirt_connect_get(p), pool_get(p)); } /* * call-seq: * pool.create(flags=0) -> nil * * Call virStoragePoolCreate[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolCreate] * to start this storage pool. */ static VALUE libvirt_storage_pool_create(int argc, VALUE *argv, VALUE p) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virStoragePoolCreate, ruby_libvirt_connect_get(p), pool_get(p), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * pool.destroy -> nil * * Call virStoragePoolDestroy[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDestroy] * to shutdown this storage pool. */ static VALUE libvirt_storage_pool_destroy(VALUE p) { ruby_libvirt_generate_call_nil(virStoragePoolDestroy, ruby_libvirt_connect_get(p), pool_get(p)); } /* * call-seq: * pool.delete(flags=0) -> nil * * Call virStoragePoolDelete[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDelete] * to delete the data corresponding to this data pool. This is a destructive * operation. */ static VALUE libvirt_storage_pool_delete(int argc, VALUE *argv, VALUE p) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virStoragePoolDelete, ruby_libvirt_connect_get(p), pool_get(p), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * pool.refresh(flags=0) -> nil * * Call virStoragePoolRefresh[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefresh] * to refresh the list of volumes in this storage pool. */ static VALUE libvirt_storage_pool_refresh(int argc, VALUE *argv, VALUE p) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virStoragePoolRefresh, ruby_libvirt_connect_get(p), pool_get(p), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * pool.name -> String * * Call virStoragePoolGetName[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetName] * to retrieve the name of this storage pool. */ static VALUE libvirt_storage_pool_name(VALUE p) { ruby_libvirt_generate_call_string(virStoragePoolGetName, ruby_libvirt_connect_get(p), 0, pool_get(p)); } /* * call-seq: * pool.uuid -> String * * Call virStoragePoolGetUUIDString[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetUUIDString] * to retrieve the UUID of this storage pool. */ static VALUE libvirt_storage_pool_uuid(VALUE p) { ruby_libvirt_generate_uuid(virStoragePoolGetUUIDString, ruby_libvirt_connect_get(p), pool_get(p)); } /* * call-seq: * pool.info -> Libvirt::StoragePoolInfo * * Call virStoragePoolGetInfo[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetInfo] * to retrieve information about this storage pool. */ static VALUE libvirt_storage_pool_info(VALUE p) { virStoragePoolInfo info; int r; VALUE result; r = virStoragePoolGetInfo(pool_get(p), &info); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virStoragePoolGetInfo", ruby_libvirt_connect_get(p)); result = rb_class_new_instance(0, NULL, c_storage_pool_info); rb_iv_set(result, "@state", INT2NUM(info.state)); rb_iv_set(result, "@capacity", ULL2NUM(info.capacity)); rb_iv_set(result, "@allocation", ULL2NUM(info.allocation)); rb_iv_set(result, "@available", ULL2NUM(info.available)); return result; } /* * call-seq: * pool.xml_desc(flags=0) -> String * * Call virStoragePoolGetXMLDesc[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetXMLDesc] * to retrieve the XML for this storage pool. */ static VALUE libvirt_storage_pool_xml_desc(int argc, VALUE *argv, VALUE p) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virStoragePoolGetXMLDesc, ruby_libvirt_connect_get(p), 1, pool_get(p), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * pool.autostart? -> [true|false] * * Call virStoragePoolGetAutostart[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetAutostart] * to determine whether this storage pool will autostart when libvirtd starts. */ static VALUE libvirt_storage_pool_autostart(VALUE p) { int r, autostart; r = virStoragePoolGetAutostart(pool_get(p), &autostart); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virStoragePoolGetAutostart", ruby_libvirt_connect_get(p)); return autostart ? Qtrue : Qfalse; } /* * call-seq: * pool.autostart = [true|false] * * Call virStoragePoolSetAutostart[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolSetAutostart] * to make this storage pool start when libvirtd starts. */ static VALUE libvirt_storage_pool_autostart_equal(VALUE p, VALUE autostart) { if (autostart != Qtrue && autostart != Qfalse) { rb_raise(rb_eTypeError, "wrong argument type (expected TrueClass or FalseClass)"); } ruby_libvirt_generate_call_nil(virStoragePoolSetAutostart, ruby_libvirt_connect_get(p), pool_get(p), RTEST(autostart) ? 1 : 0); } /* * call-seq: * pool.num_of_volumes -> Fixnum * * Call virStoragePoolNumOfVolumes[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolNumOfVolumes] * to retrieve the number of volumes in this storage pool. */ static VALUE libvirt_storage_pool_num_of_volumes(VALUE p) { int n; n = virStoragePoolNumOfVolumes(pool_get(p)); ruby_libvirt_raise_error_if(n < 0, e_RetrieveError, "virStoragePoolNumOfVolumes", ruby_libvirt_connect_get(p)); return INT2NUM(n); } /* * call-seq: * pool.list_volumes -> list * * Call virStoragePoolListVolumes[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolListVolumes] * to retrieve a list of volume names in this storage pools. */ static VALUE libvirt_storage_pool_list_volumes(VALUE p) { int r, num; char **names; num = virStoragePoolNumOfVolumes(pool_get(p)); ruby_libvirt_raise_error_if(num < 0, e_RetrieveError, "virStoragePoolNumOfVolumes", ruby_libvirt_connect_get(p)); if (num == 0) { return rb_ary_new2(num); } names = alloca(sizeof(char *) * num); r = virStoragePoolListVolumes(pool_get(p), names, num); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virStoragePoolListVolumes", ruby_libvirt_connect_get(p)); return ruby_libvirt_generate_list(r, names); } /* * call-seq: * pool.free -> nil * * Call virStoragePoolFree[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolFree] * to free this storage pool object. After this call the storage pool object * is no longer valid. */ static VALUE libvirt_storage_pool_free(VALUE p) { ruby_libvirt_generate_call_free(StoragePool, p); } /* * Libvirt::StorageVol */ static VALUE c_storage_vol; static VALUE c_storage_vol_info; static void vol_free(void *d) { ruby_libvirt_free_struct(StorageVol, d); } static VALUE vol_new(virStorageVolPtr v, VALUE conn) { return ruby_libvirt_new_class(c_storage_vol, v, conn, vol_free); } /* * call-seq: * pool.lookup_volume_by_name(name) -> Libvirt::StorageVol * * Call virStorageVolLookupByName[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByName] * to retrieve a storage volume object by name. */ static VALUE libvirt_storage_pool_lookup_vol_by_name(VALUE p, VALUE name) { virStorageVolPtr vol; vol = virStorageVolLookupByName(pool_get(p), StringValueCStr(name)); ruby_libvirt_raise_error_if(vol == NULL, e_RetrieveError, "virStorageVolLookupByName", ruby_libvirt_connect_get(p)); return vol_new(vol, ruby_libvirt_conn_attr(p)); } /* * call-seq: * pool.lookup_volume_by_key(key) -> Libvirt::StorageVol * * Call virStorageVolLookupByKey[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByKey] * to retrieve a storage volume object by key. */ static VALUE libvirt_storage_pool_lookup_vol_by_key(VALUE p, VALUE key) { virStorageVolPtr vol; /* FIXME: Why does this take a connection, not a pool? */ vol = virStorageVolLookupByKey(ruby_libvirt_connect_get(p), StringValueCStr(key)); ruby_libvirt_raise_error_if(vol == NULL, e_RetrieveError, "virStorageVolLookupByKey", ruby_libvirt_connect_get(p)); return vol_new(vol, ruby_libvirt_conn_attr(p)); } /* * call-seq: * pool.lookup_volume_by_path(path) -> Libvirt::StorageVol * * Call virStorageVolLookupByPath[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByPath] * to retrieve a storage volume object by path. */ static VALUE libvirt_storage_pool_lookup_vol_by_path(VALUE p, VALUE path) { virStorageVolPtr vol; /* FIXME: Why does this take a connection, not a pool? */ vol = virStorageVolLookupByPath(ruby_libvirt_connect_get(p), StringValueCStr(path)); ruby_libvirt_raise_error_if(vol == NULL, e_RetrieveError, "virStorageVolLookupByPath", ruby_libvirt_connect_get(p)); return vol_new(vol, ruby_libvirt_conn_attr(p)); } /* * call-seq: * pool.list_all_volumes(flags=0) -> Array * * Call virStoragePoolListAllVolumes[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolListAllVolumes] * to get an array of volume objects for all volumes. */ static VALUE libvirt_storage_pool_list_all_volumes(int argc, VALUE *argv, VALUE p) { ruby_libvirt_generate_call_list_all(virStorageVolPtr, argc, argv, virStoragePoolListAllVolumes, pool_get(p), ruby_libvirt_conn_attr(p), vol_new, virStorageVolFree); } /* * call-seq: * vol.name -> String * * Call virStorageVolGetName[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetName] * to retrieve the name of this storage volume. */ static VALUE libvirt_storage_vol_name(VALUE v) { ruby_libvirt_generate_call_string(virStorageVolGetName, ruby_libvirt_connect_get(v), 0, vol_get(v)); } /* * call-seq: * vol.key -> String * * Call virStorageVolGetKey[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetKey] * to retrieve the key for this storage volume. */ static VALUE libvirt_storage_vol_key(VALUE v) { ruby_libvirt_generate_call_string(virStorageVolGetKey, ruby_libvirt_connect_get(v), 0, vol_get(v)); } /* * call-seq: * pool.create_volume_xml(xml, flags=0) -> Libvirt::StorageVol * * Call virStorageVolCreateXML[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXML] * to create a new storage volume from xml. */ static VALUE libvirt_storage_pool_create_volume_xml(int argc, VALUE *argv, VALUE p) { virStorageVolPtr vol; VALUE xml, flags = RUBY_Qnil; rb_scan_args(argc, argv, "11", &xml, &flags); vol = virStorageVolCreateXML(pool_get(p), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(vol == NULL, e_Error, "virStorageVolCreateXML", ruby_libvirt_connect_get(p)); return vol_new(vol, ruby_libvirt_conn_attr(p)); } /* * call-seq: * pool.create_volume_xml_from(xml, clonevol, flags=0) -> Libvirt::StorageVol * * Call virStorageVolCreateXMLFrom[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXMLFrom] * to clone a volume from an existing volume with the properties specified in * xml. */ static VALUE libvirt_storage_pool_create_volume_xml_from(int argc, VALUE *argv, VALUE p) { virStorageVolPtr vol; VALUE xml, flags = RUBY_Qnil, cloneval = RUBY_Qnil; rb_scan_args(argc, argv, "21", &xml, &cloneval, &flags); vol = virStorageVolCreateXMLFrom(pool_get(p), StringValueCStr(xml), vol_get(cloneval), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(vol == NULL, e_Error, "virStorageVolCreateXMLFrom", ruby_libvirt_connect_get(p)); return vol_new(vol, ruby_libvirt_conn_attr(p)); } /* * call-seq: * pool.active? -> [true|false] * * Call virStoragePoolIsActive[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolIsActive] * to determine if this storage pool is active. */ static VALUE libvirt_storage_pool_active_p(VALUE p) { ruby_libvirt_generate_call_truefalse(virStoragePoolIsActive, ruby_libvirt_connect_get(p), pool_get(p)); } /* * call-seq: * pool.persistent? -> [true|false] * * Call virStoragePoolIsPersistent[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolIsPersistent] * to determine if this storage pool is persistent. */ static VALUE libvirt_storage_pool_persistent_p(VALUE p) { ruby_libvirt_generate_call_truefalse(virStoragePoolIsPersistent, ruby_libvirt_connect_get(p), pool_get(p)); } /* * call-seq: * vol.delete(flags=0) -> nil * * Call virStorageVolDelete[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolDelete] * to delete this volume. This is a destructive operation. */ static VALUE libvirt_storage_vol_delete(int argc, VALUE *argv, VALUE v) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virStorageVolDelete, ruby_libvirt_connect_get(v), vol_get(v), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * vol.wipe(flags=0) -> nil * * Call virStorageVolWipe[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolWipe] * to wipe the data from this storage volume. This is a destructive operation. */ static VALUE libvirt_storage_vol_wipe(int argc, VALUE *argv, VALUE v) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virStorageVolWipe, ruby_libvirt_connect_get(v), vol_get(v), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * vol.info -> Libvirt::StorageVolInfo * * Call virStorageVolGetInfo[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetInfo] * to retrieve information about this storage volume. */ static VALUE libvirt_storage_vol_info(VALUE v) { virStorageVolInfo info; int r; VALUE result; r = virStorageVolGetInfo(vol_get(v), &info); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virStorageVolGetInfo", ruby_libvirt_connect_get(v)); result = rb_class_new_instance(0, NULL, c_storage_vol_info); rb_iv_set(result, "@type", INT2NUM(info.type)); rb_iv_set(result, "@capacity", ULL2NUM(info.capacity)); rb_iv_set(result, "@allocation", ULL2NUM(info.allocation)); return result; } /* * call-seq: * vol.xml_desc(flags=0) -> String * * Call virStorageVolGetXMLDesc[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetXMLDesc] * to retrieve the xml for this storage volume. */ static VALUE libvirt_storage_vol_xml_desc(int argc, VALUE *argv, VALUE v) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virStorageVolGetXMLDesc, ruby_libvirt_connect_get(v), 1, vol_get(v), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * vol.path -> String * * Call virStorageVolGetPath[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetPath] * to retrieve the path for this storage volume. */ static VALUE libvirt_storage_vol_path(VALUE v) { ruby_libvirt_generate_call_string(virStorageVolGetPath, ruby_libvirt_connect_get(v), 1, vol_get(v)); } /* * call-seq: * vol.free -> nil * * Call virStorageVolFree[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolFree] * to free the storage volume object. After this call the storage volume object * is no longer valid. */ static VALUE libvirt_storage_vol_free(VALUE v) { ruby_libvirt_generate_call_free(StorageVol, v); } /* * call-seq: * vol.download(stream, offset, length, flags=0) -> nil * * Call virStorageVolDownload[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolDownload] * to download the content of a volume as a stream. */ static VALUE libvirt_storage_vol_download(int argc, VALUE *argv, VALUE v) { VALUE st = RUBY_Qnil, offset = RUBY_Qnil, length = RUBY_Qnil, flags = RUBY_Qnil; rb_scan_args(argc, argv, "31", &st, &offset, &length, &flags); ruby_libvirt_generate_call_nil(virStorageVolDownload, ruby_libvirt_connect_get(v), vol_get(v), ruby_libvirt_stream_get(st), NUM2ULL(offset), NUM2ULL(length), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * vol.upload(stream, offset, length, flags=0) -> nil * * Call virStorageVolUpload[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolUpload] * to upload new content to a volume from a stream. */ static VALUE libvirt_storage_vol_upload(int argc, VALUE *argv, VALUE v) { VALUE st = RUBY_Qnil, offset = RUBY_Qnil, length = RUBY_Qnil, flags = RUBY_Qnil; rb_scan_args(argc, argv, "31", &st, &offset, &length, &flags); ruby_libvirt_generate_call_nil(virStorageVolUpload, ruby_libvirt_connect_get(v), vol_get(v), ruby_libvirt_stream_get(st), NUM2ULL(offset), NUM2ULL(length), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * vol.wipe_pattern(alg, flags=0) -> nil * * Call virStorageVolWipePattern[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolWipePattern] * to wipe the data from this storage volume. This is a destructive operation. */ static VALUE libvirt_storage_vol_wipe_pattern(int argc, VALUE *argv, VALUE v) { VALUE alg = RUBY_Qnil, flags = RUBY_Qnil; rb_scan_args(argc, argv, "11", &alg, &flags); ruby_libvirt_generate_call_nil(virStorageVolWipePattern, ruby_libvirt_connect_get(v), vol_get(v), NUM2UINT(alg), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * vol.resize(capacity, flags=0) -> nil * * Call virStorageVolResize[https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolResize] * to resize the associated storage volume. */ static VALUE libvirt_storage_vol_resize(int argc, VALUE *argv, VALUE v) { VALUE capacity = RUBY_Qnil, flags = RUBY_Qnil; rb_scan_args(argc, argv, "11", &capacity, &flags); ruby_libvirt_generate_call_nil(virStorageVolResize, ruby_libvirt_connect_get(v), vol_get(v), NUM2ULL(capacity), ruby_libvirt_value_to_uint(flags)); } void ruby_libvirt_storage_init(void) { /* * Class Libvirt::StoragePool and Libvirt::StoragePoolInfo */ c_storage_pool_info = rb_define_class_under(m_libvirt, "StoragePoolInfo", rb_cObject); rb_define_attr(c_storage_pool_info, "state", 1, 0); rb_define_attr(c_storage_pool_info, "capacity", 1, 0); rb_define_attr(c_storage_pool_info, "allocation", 1, 0); rb_define_attr(c_storage_pool_info, "available", 1, 0); c_storage_pool = rb_define_class_under(m_libvirt, "StoragePool", rb_cObject); rb_undef_alloc_func(c_storage_pool); rb_define_singleton_method(c_storage_pool, "new", ruby_libvirt_new_not_allowed, -1); rb_define_attr(c_storage_pool, "connection", 1, 0); /* virStoragePoolState */ rb_define_const(c_storage_pool, "INACTIVE", INT2NUM(VIR_STORAGE_POOL_INACTIVE)); rb_define_const(c_storage_pool, "BUILDING", INT2NUM(VIR_STORAGE_POOL_BUILDING)); rb_define_const(c_storage_pool, "RUNNING", INT2NUM(VIR_STORAGE_POOL_RUNNING)); rb_define_const(c_storage_pool, "DEGRADED", INT2NUM(VIR_STORAGE_POOL_DEGRADED)); rb_define_const(c_storage_pool, "INACCESSIBLE", INT2NUM(VIR_STORAGE_POOL_INACCESSIBLE)); rb_define_const(c_storage_pool, "XML_INACTIVE", INT2NUM(VIR_STORAGE_XML_INACTIVE)); /* virStoragePoolBuildFlags */ rb_define_const(c_storage_pool, "BUILD_NEW", INT2NUM(VIR_STORAGE_POOL_BUILD_NEW)); rb_define_const(c_storage_pool, "BUILD_REPAIR", INT2NUM(VIR_STORAGE_POOL_BUILD_REPAIR)); rb_define_const(c_storage_pool, "BUILD_RESIZE", INT2NUM(VIR_STORAGE_POOL_BUILD_RESIZE)); /* virStoragePoolDeleteFlags */ rb_define_const(c_storage_pool, "DELETE_NORMAL", INT2NUM(VIR_STORAGE_POOL_DELETE_NORMAL)); rb_define_const(c_storage_pool, "DELETE_ZEROED", INT2NUM(VIR_STORAGE_POOL_DELETE_ZEROED)); rb_define_const(c_storage_pool, "CREATE_PREALLOC_METADATA", INT2NUM(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA)); rb_define_const(c_storage_pool, "CREATE_REFLINK", INT2NUM(VIR_STORAGE_VOL_CREATE_REFLINK)); rb_define_const(c_storage_pool, "CREATE_NORMAL", INT2NUM(VIR_STORAGE_POOL_CREATE_NORMAL)); rb_define_const(c_storage_pool, "CREATE_WITH_BUILD", INT2NUM(VIR_STORAGE_POOL_CREATE_WITH_BUILD)); rb_define_const(c_storage_pool, "CREATE_WITH_BUILD_OVERWRITE", INT2NUM(VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE)); rb_define_const(c_storage_pool, "CREATE_WITH_BUILD_NO_OVERWRITE", INT2NUM(VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE)); /* Creating/destroying pools */ rb_define_method(c_storage_pool, "build", libvirt_storage_pool_build, -1); rb_define_method(c_storage_pool, "undefine", libvirt_storage_pool_undefine, 0); rb_define_method(c_storage_pool, "create", libvirt_storage_pool_create, -1); rb_define_method(c_storage_pool, "destroy", libvirt_storage_pool_destroy, 0); rb_define_method(c_storage_pool, "delete", libvirt_storage_pool_delete, -1); rb_define_method(c_storage_pool, "refresh", libvirt_storage_pool_refresh, -1); /* StoragePool information */ rb_define_method(c_storage_pool, "name", libvirt_storage_pool_name, 0); rb_define_method(c_storage_pool, "uuid", libvirt_storage_pool_uuid, 0); rb_define_method(c_storage_pool, "info", libvirt_storage_pool_info, 0); rb_define_method(c_storage_pool, "xml_desc", libvirt_storage_pool_xml_desc, -1); rb_define_method(c_storage_pool, "autostart", libvirt_storage_pool_autostart, 0); rb_define_method(c_storage_pool, "autostart?", libvirt_storage_pool_autostart, 0); rb_define_method(c_storage_pool, "autostart=", libvirt_storage_pool_autostart_equal, 1); /* List/lookup storage volumes within a pool */ rb_define_method(c_storage_pool, "num_of_volumes", libvirt_storage_pool_num_of_volumes, 0); rb_define_method(c_storage_pool, "list_volumes", libvirt_storage_pool_list_volumes, 0); /* Lookup volumes based on various attributes */ rb_define_method(c_storage_pool, "lookup_volume_by_name", libvirt_storage_pool_lookup_vol_by_name, 1); rb_define_method(c_storage_pool, "lookup_volume_by_key", libvirt_storage_pool_lookup_vol_by_key, 1); rb_define_method(c_storage_pool, "lookup_volume_by_path", libvirt_storage_pool_lookup_vol_by_path, 1); rb_define_method(c_storage_pool, "free", libvirt_storage_pool_free, 0); rb_define_method(c_storage_pool, "create_volume_xml", libvirt_storage_pool_create_volume_xml, -1); rb_define_alias(c_storage_pool, "create_vol_xml", "create_volume_xml"); rb_define_method(c_storage_pool, "create_volume_xml_from", libvirt_storage_pool_create_volume_xml_from, -1); rb_define_alias(c_storage_pool, "create_vol_xml_from", "create_volume_xml_from"); rb_define_method(c_storage_pool, "active?", libvirt_storage_pool_active_p, 0); rb_define_method(c_storage_pool, "persistent?", libvirt_storage_pool_persistent_p, 0); rb_define_method(c_storage_pool, "list_all_volumes", libvirt_storage_pool_list_all_volumes, -1); rb_define_const(c_storage_pool, "BUILD_NO_OVERWRITE", INT2NUM(VIR_STORAGE_POOL_BUILD_NO_OVERWRITE)); rb_define_const(c_storage_pool, "BUILD_OVERWRITE", INT2NUM(VIR_STORAGE_POOL_BUILD_OVERWRITE)); /* * Class Libvirt::StorageVol and Libvirt::StorageVolInfo */ c_storage_vol_info = rb_define_class_under(m_libvirt, "StorageVolInfo", rb_cObject); rb_define_attr(c_storage_vol_info, "type", 1, 0); rb_define_attr(c_storage_vol_info, "capacity", 1, 0); rb_define_attr(c_storage_vol_info, "allocation", 1, 0); c_storage_vol = rb_define_class_under(m_libvirt, "StorageVol", rb_cObject); rb_undef_alloc_func(c_storage_vol); rb_define_singleton_method(c_storage_vol, "new", ruby_libvirt_new_not_allowed, -1); rb_define_const(c_storage_vol, "XML_INACTIVE", INT2NUM(VIR_STORAGE_XML_INACTIVE)); /* virStorageVolType */ rb_define_const(c_storage_vol, "FILE", INT2NUM(VIR_STORAGE_VOL_FILE)); rb_define_const(c_storage_vol, "BLOCK", INT2NUM(VIR_STORAGE_VOL_BLOCK)); rb_define_const(c_storage_vol, "DIR", INT2NUM(VIR_STORAGE_VOL_DIR)); rb_define_const(c_storage_vol, "NETWORK", INT2NUM(VIR_STORAGE_VOL_NETWORK)); rb_define_const(c_storage_vol, "NETDIR", INT2NUM(VIR_STORAGE_VOL_NETDIR)); /* virStorageVolDeleteFlags */ rb_define_const(c_storage_vol, "DELETE_NORMAL", INT2NUM(VIR_STORAGE_VOL_DELETE_NORMAL)); rb_define_const(c_storage_vol, "DELETE_ZEROED", INT2NUM(VIR_STORAGE_VOL_DELETE_ZEROED)); rb_define_const(c_storage_vol, "DELETE_WITH_SNAPSHOTS", INT2NUM(VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS)); rb_define_method(c_storage_vol, "pool", libvirt_storage_vol_pool, 0); rb_define_method(c_storage_vol, "name", libvirt_storage_vol_name, 0); rb_define_method(c_storage_vol, "key", libvirt_storage_vol_key, 0); rb_define_method(c_storage_vol, "delete", libvirt_storage_vol_delete, -1); rb_define_method(c_storage_vol, "wipe", libvirt_storage_vol_wipe, -1); rb_define_method(c_storage_vol, "wipe_pattern", libvirt_storage_vol_wipe_pattern, -1); rb_define_const(c_storage_vol, "WIPE_ALG_ZERO", INT2NUM(VIR_STORAGE_VOL_WIPE_ALG_ZERO)); rb_define_const(c_storage_vol, "WIPE_ALG_NNSA", INT2NUM(VIR_STORAGE_VOL_WIPE_ALG_NNSA)); rb_define_const(c_storage_vol, "WIPE_ALG_DOD", INT2NUM(VIR_STORAGE_VOL_WIPE_ALG_DOD)); rb_define_const(c_storage_vol, "WIPE_ALG_BSI", INT2NUM(VIR_STORAGE_VOL_WIPE_ALG_BSI)); rb_define_const(c_storage_vol, "WIPE_ALG_GUTMANN", INT2NUM(VIR_STORAGE_VOL_WIPE_ALG_GUTMANN)); rb_define_const(c_storage_vol, "WIPE_ALG_SCHNEIER", INT2NUM(VIR_STORAGE_VOL_WIPE_ALG_SCHNEIER)); rb_define_const(c_storage_vol, "WIPE_ALG_PFITZNER7", INT2NUM(VIR_STORAGE_VOL_WIPE_ALG_PFITZNER7)); rb_define_const(c_storage_vol, "WIPE_ALG_PFITZNER33", INT2NUM(VIR_STORAGE_VOL_WIPE_ALG_PFITZNER33)); rb_define_const(c_storage_vol, "WIPE_ALG_RANDOM", INT2NUM(VIR_STORAGE_VOL_WIPE_ALG_RANDOM)); rb_define_method(c_storage_vol, "info", libvirt_storage_vol_info, 0); rb_define_method(c_storage_vol, "xml_desc", libvirt_storage_vol_xml_desc, -1); rb_define_method(c_storage_vol, "path", libvirt_storage_vol_path, 0); rb_define_method(c_storage_vol, "free", libvirt_storage_vol_free, 0); rb_define_method(c_storage_vol, "download", libvirt_storage_vol_download, -1); rb_define_method(c_storage_vol, "upload", libvirt_storage_vol_upload, -1); rb_define_const(c_storage_vol, "RESIZE_ALLOCATE", INT2NUM(VIR_STORAGE_VOL_RESIZE_ALLOCATE)); rb_define_const(c_storage_vol, "RESIZE_DELTA", INT2NUM(VIR_STORAGE_VOL_RESIZE_DELTA)); rb_define_const(c_storage_vol, "RESIZE_SHRINK", INT2NUM(VIR_STORAGE_VOL_RESIZE_SHRINK)); rb_define_method(c_storage_vol, "resize", libvirt_storage_vol_resize, -1); } ruby-libvirt-0.8.4/ext/libvirt/connect.c0000644000175000017500000036252114641546211020370 0ustar abolognaabologna/* * connect.c: virConnect methods * * Copyright (C) 2007,2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "extconf.h" #include "common.h" #include "domain.h" #include "network.h" #include "interface.h" #include "nodedevice.h" #include "nwfilter.h" #include "secret.h" #include "stream.h" /* * Generate a call to a virConnectNumOf... function. C is the Ruby VALUE * holding the connection and OBJS is a token indicating what objects to * get the number of, e.g. 'Domains' */ #define gen_conn_num_of(c, objs) \ do { \ int r; \ r = virConnectNumOf##objs(ruby_libvirt_connect_get(c)); \ ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virConnectNumOf" # objs, ruby_libvirt_connect_get(c)); \ return INT2NUM(r); \ } while(0) /* * Generate a call to a virConnectList... function. C is the Ruby VALUE * holding the connection and OBJS is a token indicating what objects to * get the number of, e.g. 'Domains' The list function must return an array * of strings, which is returned as a Ruby array */ #define gen_conn_list_names(c, objs) \ do { \ int r, num; \ char **names; \ num = virConnectNumOf##objs(ruby_libvirt_connect_get(c)); \ ruby_libvirt_raise_error_if(num < 0, e_RetrieveError, "virConnectNumOf" # objs, ruby_libvirt_connect_get(c)); \ if (num == 0) { \ /* if num is 0, don't call virConnectList* function */ \ return rb_ary_new2(num); \ } \ names = alloca(sizeof(char *) * num); \ r = virConnectList##objs(ruby_libvirt_connect_get(c), names, num); \ ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virConnectList" # objs, ruby_libvirt_connect_get(c)); \ return ruby_libvirt_generate_list(r, names); \ } while(0) static VALUE c_connect; VALUE c_node_security_model; static VALUE c_node_info; static void connect_close(void *c) { int r; if (!c) { return; } r = virConnectClose((virConnectPtr) c); ruby_libvirt_raise_error_if(r < 0, rb_eSystemCallError, "virConnectClose", c); } VALUE ruby_libvirt_connect_new(virConnectPtr c) { return Data_Wrap_Struct(c_connect, NULL, connect_close, c); } VALUE ruby_libvirt_conn_attr(VALUE c) { if (rb_obj_is_instance_of(c, c_connect) != Qtrue) { c = rb_iv_get(c, "@connection"); } if (rb_obj_is_instance_of(c, c_connect) != Qtrue) { rb_raise(rb_eArgError, "Expected Connection object"); } return c; } virConnectPtr ruby_libvirt_connect_get(VALUE c) { c = ruby_libvirt_conn_attr(c); ruby_libvirt_get_struct(Connect, c); } /* * call-seq: * conn.close -> nil * * Call virConnectClose[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectClose] * to close the connection. */ static VALUE libvirt_connect_close(VALUE c) { virConnectPtr conn; Data_Get_Struct(c, virConnect, conn); if (conn) { connect_close(conn); DATA_PTR(c) = NULL; } return Qnil; } /* * call-seq: * conn.closed? -> [True|False] * * Return +true+ if the connection is closed, +false+ if it is open. */ static VALUE libvirt_connect_closed_p(VALUE c) { virConnectPtr conn; Data_Get_Struct(c, virConnect, conn); return (conn == NULL) ? Qtrue : Qfalse; } /* * call-seq: * conn.type -> String * * Call virConnectGetType[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetType] * to retrieve the type of hypervisor for this connection. */ static VALUE libvirt_connect_type(VALUE c) { ruby_libvirt_generate_call_string(virConnectGetType, ruby_libvirt_connect_get(c), 0, ruby_libvirt_connect_get(c)); } /* * call-seq: * conn.version -> Fixnum * * Call virConnectGetVersion[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetVersion] * to retrieve the version of the hypervisor for this connection. */ static VALUE libvirt_connect_version(VALUE c) { int r; unsigned long v; r = virConnectGetVersion(ruby_libvirt_connect_get(c), &v); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virConnectGetVersion", ruby_libvirt_connect_get(c)); return ULONG2NUM(v); } /* * call-seq: * conn.libversion -> Fixnum * * Call virConnectGetLibVersion[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetLibVersion] * to retrieve the version of the libvirt library for this connection. */ static VALUE libvirt_connect_libversion(VALUE c) { int r; unsigned long v; r = virConnectGetLibVersion(ruby_libvirt_connect_get(c), &v); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virConnectGetLibVersion", ruby_libvirt_connect_get(c)); return ULONG2NUM(v); } /* * call-seq: * conn.hostname -> String * * Call virConnectGetHostname[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetHostname] * to retrieve the hostname of the hypervisor for this connection. */ static VALUE libvirt_connect_hostname(VALUE c) { ruby_libvirt_generate_call_string(virConnectGetHostname, ruby_libvirt_connect_get(c), 1, ruby_libvirt_connect_get(c)); } /* * call-seq: * conn.uri -> String * * Call virConnectGetURI[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetURI] * to retrieve the canonical URI for this connection. */ static VALUE libvirt_connect_uri(VALUE c) { ruby_libvirt_generate_call_string(virConnectGetURI, ruby_libvirt_connect_get(c), 1, ruby_libvirt_connect_get(c)); } /* * call-seq: * conn.max_vcpus(type=nil) -> Fixnum * * Call virConnectGetMaxVcpus[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetMaxVcpus] * to retrieve the maximum number of virtual cpus supported by the hypervisor * for this connection. */ static VALUE libvirt_connect_max_vcpus(int argc, VALUE *argv, VALUE c) { VALUE type; rb_scan_args(argc, argv, "01", &type); ruby_libvirt_generate_call_int(virConnectGetMaxVcpus, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), ruby_libvirt_get_cstring_or_null(type)); } /* * call-seq: * conn.node_info -> Libvirt::Connect::Nodeinfo * * Call virNodeGetInfo[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetInfo] * to retrieve information about the node for this connection. */ static VALUE libvirt_connect_node_info(VALUE c) { int r; virNodeInfo nodeinfo; VALUE result; r = virNodeGetInfo(ruby_libvirt_connect_get(c), &nodeinfo); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virNodeGetInfo", ruby_libvirt_connect_get(c)); result = rb_class_new_instance(0, NULL, c_node_info); rb_iv_set(result, "@model", rb_str_new2(nodeinfo.model)); rb_iv_set(result, "@memory", ULONG2NUM(nodeinfo.memory)); rb_iv_set(result, "@cpus", UINT2NUM(nodeinfo.cpus)); rb_iv_set(result, "@mhz", UINT2NUM(nodeinfo.mhz)); rb_iv_set(result, "@nodes", UINT2NUM(nodeinfo.nodes)); rb_iv_set(result, "@sockets", UINT2NUM(nodeinfo.sockets)); rb_iv_set(result, "@cores", UINT2NUM(nodeinfo.cores)); rb_iv_set(result, "@threads", UINT2NUM(nodeinfo.threads)); return result; } /* * call-seq: * conn.node_free_memory -> Fixnum * * Call virNodeGetFreeMemory[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetFreeMemory] * to retrieve the amount of free memory available on the host for this * connection. */ static VALUE libvirt_connect_node_free_memory(VALUE c) { unsigned long long freemem; freemem = virNodeGetFreeMemory(ruby_libvirt_connect_get(c)); ruby_libvirt_raise_error_if(freemem == 0, e_RetrieveError, "virNodeGetFreeMemory", ruby_libvirt_connect_get(c)); return ULL2NUM(freemem); } /* * call-seq: * conn.node_cells_free_memory(startCell=0, maxCells=#nodeCells) -> list * * Call virNodeGetCellsFreeMemory[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCellsFreeMemory] * to retrieve the amount of free memory in each NUMA cell on the host for * this connection. */ static VALUE libvirt_connect_node_cells_free_memory(int argc, VALUE *argv, VALUE c) { int i, r; VALUE cells, start, max; unsigned long long *freeMems; virNodeInfo nodeinfo; unsigned int startCell, maxCells; rb_scan_args(argc, argv, "02", &start, &max); if (NIL_P(start)) { startCell = 0; } else { startCell = NUM2UINT(start); } if (NIL_P(max)) { r = virNodeGetInfo(ruby_libvirt_connect_get(c), &nodeinfo); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virNodeGetInfo", ruby_libvirt_connect_get(c)); maxCells = nodeinfo.nodes; } else { maxCells = NUM2UINT(max); } freeMems = alloca(sizeof(unsigned long long) * maxCells); r = virNodeGetCellsFreeMemory(ruby_libvirt_connect_get(c), freeMems, startCell, maxCells); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virNodeGetCellsFreeMemory", ruby_libvirt_connect_get(c)); cells = rb_ary_new2(r); for (i = 0; i < r; i++) { rb_ary_store(cells, i, ULL2NUM(freeMems[i])); } return cells; } /* * call-seq: * conn.node_security_model -> Libvirt::Connect::NodeSecurityModel * * Call virNodeGetSecurityModel[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetSecurityModel] * to retrieve the security model in use on the host for this connection. */ static VALUE libvirt_connect_node_security_model(VALUE c) { virSecurityModel secmodel; int r; VALUE result; r = virNodeGetSecurityModel(ruby_libvirt_connect_get(c), &secmodel); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virNodeGetSecurityModel", ruby_libvirt_connect_get(c)); result = rb_class_new_instance(0, NULL, c_node_security_model); rb_iv_set(result, "@model", rb_str_new2(secmodel.model)); rb_iv_set(result, "@doi", rb_str_new2(secmodel.doi)); return result; } /* * call-seq: * conn.encrypted? -> [True|False] * * Call virConnectIsEncrypted[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectIsEncrypted] * to determine if the connection is encrypted. */ static VALUE libvirt_connect_encrypted_p(VALUE c) { ruby_libvirt_generate_call_truefalse(virConnectIsEncrypted, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c)); } /* * call-seq: * conn.secure? -> [True|False] * * Call virConnectIsSecure[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectIsSecure] * to determine if the connection is secure. */ static VALUE libvirt_connect_secure_p(VALUE c) { ruby_libvirt_generate_call_truefalse(virConnectIsSecure, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c)); } /* * call-seq: * conn.capabilities -> String * * Call virConnectGetCapabilities[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetCapabilities] * to retrieve the capabilities XML for this connection. */ static VALUE libvirt_connect_capabilities(VALUE c) { ruby_libvirt_generate_call_string(virConnectGetCapabilities, ruby_libvirt_connect_get(c), 1, ruby_libvirt_connect_get(c)); } /* * call-seq: * conn.compare_cpu(xml, flags=0) -> compareflag * * Call virConnectCompareCPU[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectCompareCPU] * to compare the host CPU with the XML contained in xml. Returns one of * Libvirt::CPU_COMPARE_ERROR, Libvirt::CPU_COMPARE_INCOMPATIBLE, * Libvirt::CPU_COMPARE_IDENTICAL, or Libvirt::CPU_COMPARE_SUPERSET. */ static VALUE libvirt_connect_compare_cpu(int argc, VALUE *argv, VALUE c) { VALUE xml, flags; rb_scan_args(argc, argv, "11", &xml, &flags); ruby_libvirt_generate_call_int(virConnectCompareCPU, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * conn.baseline_cpu([xml, xml2, ...], flags=0) -> XML * * Call virConnectBaselineCPU[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectBaselineCPU] * to compare the most feature-rich CPU which is compatible with all * given host CPUs. */ static VALUE libvirt_connect_baseline_cpu(int argc, VALUE *argv, VALUE c) { VALUE xmlcpus, flags, retval, entry; char *r; unsigned int ncpus; const char **xmllist; int exception = 0; unsigned int i; rb_scan_args(argc, argv, "11", &xmlcpus, &flags); Check_Type(xmlcpus, T_ARRAY); if (RARRAY_LEN(xmlcpus) < 1) { rb_raise(rb_eArgError, "wrong number of cpu arguments (%ld for 1 or more)", RARRAY_LEN(xmlcpus)); } ncpus = RARRAY_LEN(xmlcpus); xmllist = alloca(sizeof(const char *) * ncpus); for (i = 0; i < ncpus; i++) { entry = rb_ary_entry(xmlcpus, i); xmllist[i] = StringValueCStr(entry); } r = virConnectBaselineCPU(ruby_libvirt_connect_get(c), xmllist, ncpus, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r == NULL, e_RetrieveError, "virConnectBaselineCPU", ruby_libvirt_connect_get(c)); retval = rb_protect(ruby_libvirt_str_new2_wrap, (VALUE)&r, &exception); free(r); if (exception) { rb_jump_tag(exception); } return retval; } static int domain_event_lifecycle_callback(virConnectPtr conn, virDomainPtr dom, int event, int detail, void *opaque) { VALUE passthrough = (VALUE)opaque; VALUE cb, cb_opaque, newc; Check_Type(passthrough, T_ARRAY); if (RARRAY_LEN(passthrough) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(passthrough)); } cb = rb_ary_entry(passthrough, 0); cb_opaque = rb_ary_entry(passthrough, 1); newc = ruby_libvirt_connect_new(conn); if (strcmp(rb_obj_classname(cb), "Symbol") == 0) { rb_funcall(rb_class_of(cb), rb_to_id(cb), 5, newc, ruby_libvirt_domain_new(dom, newc), INT2NUM(event), INT2NUM(detail), cb_opaque); } else if (strcmp(rb_obj_classname(cb), "Proc") == 0) { rb_funcall(cb, rb_intern("call"), 5, newc, ruby_libvirt_domain_new(dom, newc), INT2NUM(event), INT2NUM(detail), cb_opaque); } else { rb_raise(rb_eTypeError, "wrong domain event lifecycle callback (expected Symbol or Proc)"); } return 0; } static int domain_event_reboot_callback(virConnectPtr conn, virDomainPtr dom, void *opaque) { VALUE passthrough = (VALUE)opaque; VALUE cb, cb_opaque, newc; Check_Type(passthrough, T_ARRAY); if (RARRAY_LEN(passthrough) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(passthrough)); } cb = rb_ary_entry(passthrough, 0); cb_opaque = rb_ary_entry(passthrough, 1); newc = ruby_libvirt_connect_new(conn); if (strcmp(rb_obj_classname(cb), "Symbol") == 0) { rb_funcall(rb_class_of(cb), rb_to_id(cb), 3, newc, ruby_libvirt_domain_new(dom, newc), cb_opaque); } else if (strcmp(rb_obj_classname(cb), "Proc") == 0) { rb_funcall(cb, rb_intern("call"), 3, newc, ruby_libvirt_domain_new(dom, newc), cb_opaque); } else { rb_raise(rb_eTypeError, "wrong domain event reboot callback (expected Symbol or Proc)"); } return 0; } static int domain_event_rtc_callback(virConnectPtr conn, virDomainPtr dom, long long utc_offset, void *opaque) { VALUE passthrough = (VALUE)opaque; VALUE cb, cb_opaque, newc; Check_Type(passthrough, T_ARRAY); if (RARRAY_LEN(passthrough) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(passthrough)); } cb = rb_ary_entry(passthrough, 0); cb_opaque = rb_ary_entry(passthrough, 1); newc = ruby_libvirt_connect_new(conn); if (strcmp(rb_obj_classname(cb), "Symbol") == 0) { rb_funcall(rb_class_of(cb), rb_to_id(cb), 4, newc, ruby_libvirt_domain_new(dom, newc), LL2NUM(utc_offset), cb_opaque); } else if (strcmp(rb_obj_classname(cb), "Proc") == 0) { rb_funcall(cb, rb_intern("call"), 4, newc, ruby_libvirt_domain_new(dom, newc), LL2NUM(utc_offset), cb_opaque); } else { rb_raise(rb_eTypeError, "wrong domain event rtc callback (expected Symbol or Proc)"); } return 0; } static int domain_event_watchdog_callback(virConnectPtr conn, virDomainPtr dom, int action, void *opaque) { VALUE passthrough = (VALUE)opaque; VALUE cb, cb_opaque, newc; Check_Type(passthrough, T_ARRAY); if (RARRAY_LEN(passthrough) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(passthrough)); } cb = rb_ary_entry(passthrough, 0); cb_opaque = rb_ary_entry(passthrough, 1); newc = ruby_libvirt_connect_new(conn); if (strcmp(rb_obj_classname(cb), "Symbol") == 0) { rb_funcall(rb_class_of(cb), rb_to_id(cb), 4, newc, ruby_libvirt_domain_new(dom, newc), INT2NUM(action), cb_opaque); } else if (strcmp(rb_obj_classname(cb), "Proc") == 0) { rb_funcall(cb, rb_intern("call"), 4, newc, ruby_libvirt_domain_new(dom, newc), INT2NUM(action), cb_opaque); } else { rb_raise(rb_eTypeError, "wrong domain event watchdog callback (expected Symbol or Proc)"); } return 0; } static int domain_event_io_error_callback(virConnectPtr conn, virDomainPtr dom, const char *src_path, const char *dev_alias, int action, void *opaque) { VALUE passthrough = (VALUE)opaque; VALUE cb, cb_opaque, newc; Check_Type(passthrough, T_ARRAY); if (RARRAY_LEN(passthrough) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(passthrough)); } cb = rb_ary_entry(passthrough, 0); cb_opaque = rb_ary_entry(passthrough, 1); newc = ruby_libvirt_connect_new(conn); if (strcmp(rb_obj_classname(cb), "Symbol") == 0) { rb_funcall(rb_class_of(cb), rb_to_id(cb), 6, newc, ruby_libvirt_domain_new(dom, newc), rb_str_new2(src_path), rb_str_new2(dev_alias), INT2NUM(action), cb_opaque); } else if (strcmp(rb_obj_classname(cb), "Proc") == 0) { rb_funcall(cb, rb_intern("call"), 6, newc, ruby_libvirt_domain_new(dom, newc), rb_str_new2(src_path), rb_str_new2(dev_alias), INT2NUM(action), cb_opaque); } else { rb_raise(rb_eTypeError, "wrong domain event IO error callback (expected Symbol or Proc)"); } return 0; } static int domain_event_io_error_reason_callback(virConnectPtr conn, virDomainPtr dom, const char *src_path, const char *dev_alias, int action, const char *reason, void *opaque) { VALUE passthrough = (VALUE)opaque; VALUE cb, cb_opaque, newc; Check_Type(passthrough, T_ARRAY); if (RARRAY_LEN(passthrough) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(passthrough)); } cb = rb_ary_entry(passthrough, 0); cb_opaque = rb_ary_entry(passthrough, 1); newc = ruby_libvirt_connect_new(conn); if (strcmp(rb_obj_classname(cb), "Symbol") == 0) { rb_funcall(rb_class_of(cb), rb_to_id(cb), 7, newc, ruby_libvirt_domain_new(dom, newc), rb_str_new2(src_path), rb_str_new2(dev_alias), INT2NUM(action), rb_str_new2(reason), cb_opaque); } else if (strcmp(rb_obj_classname(cb), "Proc") == 0) { rb_funcall(cb, rb_intern("call"), 7, newc, ruby_libvirt_domain_new(dom, newc), rb_str_new2(src_path), rb_str_new2(dev_alias), INT2NUM(action), rb_str_new2(reason), cb_opaque); } else { rb_raise(rb_eTypeError, "wrong domain event IO error reason callback (expected Symbol or Proc)"); } return 0; } static int domain_event_graphics_callback(virConnectPtr conn, virDomainPtr dom, int phase, virDomainEventGraphicsAddressPtr local, virDomainEventGraphicsAddressPtr remote, const char *authScheme, virDomainEventGraphicsSubjectPtr subject, void *opaque) { VALUE passthrough = (VALUE)opaque; VALUE cb, cb_opaque, newc, local_hash, remote_hash, subject_array, pair; int i; Check_Type(passthrough, T_ARRAY); if (RARRAY_LEN(passthrough) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(passthrough)); } cb = rb_ary_entry(passthrough, 0); cb_opaque = rb_ary_entry(passthrough, 1); local_hash = rb_hash_new(); rb_hash_aset(local_hash, rb_str_new2("family"), INT2NUM(local->family)); rb_hash_aset(local_hash, rb_str_new2("node"), rb_str_new2(local->node)); rb_hash_aset(local_hash, rb_str_new2("service"), rb_str_new2(local->service)); remote_hash = rb_hash_new(); rb_hash_aset(remote_hash, rb_str_new2("family"), INT2NUM(remote->family)); rb_hash_aset(remote_hash, rb_str_new2("node"), rb_str_new2(remote->node)); rb_hash_aset(remote_hash, rb_str_new2("service"), rb_str_new2(remote->service)); subject_array = rb_ary_new(); for (i = 0; i < subject->nidentity; i++) { pair = rb_ary_new(); rb_ary_store(pair, 0, rb_str_new2(subject->identities[i].type)); rb_ary_store(pair, 1, rb_str_new2(subject->identities[i].name)); rb_ary_store(subject_array, i, pair); } newc = ruby_libvirt_connect_new(conn); if (strcmp(rb_obj_classname(cb), "Symbol") == 0) { rb_funcall(rb_class_of(cb), rb_to_id(cb), 8, newc, ruby_libvirt_domain_new(dom, newc), INT2NUM(phase), local_hash, remote_hash, rb_str_new2(authScheme), subject_array, cb_opaque); } else if (strcmp(rb_obj_classname(cb), "Proc") == 0) { rb_funcall(cb, rb_intern("call"), 8, newc, ruby_libvirt_domain_new(dom, newc), INT2NUM(phase), local_hash, remote_hash, rb_str_new2(authScheme), subject_array, cb_opaque); } else { rb_raise(rb_eTypeError, "wrong domain event graphics callback (expected Symbol or Proc)"); } return 0; } /* * call-seq: * conn.domain_event_register_any(eventID, callback, dom=nil, opaque=nil) -> Fixnum * * Call virConnectDomainEventRegisterAny[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventRegisterAny] * to register callback for eventID with libvirt. The eventID must be one of * the Libvirt::Connect::DOMAIN_EVENT_ID_* constants. The callback can either * be a Symbol (that is the name of a method to callback) or a Proc. Note that * the callback must accept different numbers of arguments depending on the * eventID passed in. The arguments are as follows: * * - DOMAIN_EVENT_ID_LIFECYCLE: Libvirt::Connect, Libvirt::Domain, event, detail, opaque * - DOMAIN_EVENT_ID_REBOOT: Libvirt::Connect, Libvirt::Domain, opaque * - DOMAIN_EVENT_ID_RTC_CHANGE: Libvirt::Connect, Libvirt::Domain, utc_offset, opaque * - DOMAIN_EVENT_ID_WATCHDOG: Libvirt::Connect, Libvirt::Domain, action, opaque * - DOMAIN_EVENT_ID_IO_ERROR: Libvirt::Connect, Libvirt::Domain, src_path, dev_alias, action, opaque * - DOMAIN_EVENT_ID_IO_ERROR_REASON: Libvirt::Connect, Libvirt::Domain, src_path, dev_alias, action, reason, opaque * - DOMAIN_EVENT_ID_GRAPHICS: Libvirt::Connect, Libvirt::Domain, phase, local, remote, auth_scheme, subject, opaque * If dom is a valid Libvirt::Domain object, then only events from that * domain will be seen. The opaque parameter can be any valid ruby type, and * will be passed into callback as "opaque". This method returns a * libvirt-specific handle, which must be used by the application to * deregister the callback later (see domain_event_deregister_any). */ static VALUE libvirt_connect_domain_event_register_any(int argc, VALUE *argv, VALUE c) { VALUE eventID, cb, dom, opaque, passthrough; virDomainPtr domain; virConnectDomainEventGenericCallback internalcb = NULL; rb_scan_args(argc, argv, "22", &eventID, &cb, &dom, &opaque); if (!ruby_libvirt_is_symbol_or_proc(cb)) { rb_raise(rb_eTypeError, "wrong argument type (expected Symbol or Proc)"); } if (NIL_P(dom)) { domain = NULL; } else { domain = ruby_libvirt_domain_get(dom); } switch(NUM2INT(eventID)) { case VIR_DOMAIN_EVENT_ID_LIFECYCLE: internalcb = VIR_DOMAIN_EVENT_CALLBACK(domain_event_lifecycle_callback); break; case VIR_DOMAIN_EVENT_ID_REBOOT: internalcb = VIR_DOMAIN_EVENT_CALLBACK(domain_event_reboot_callback); break; case VIR_DOMAIN_EVENT_ID_RTC_CHANGE: internalcb = VIR_DOMAIN_EVENT_CALLBACK(domain_event_rtc_callback); break; case VIR_DOMAIN_EVENT_ID_WATCHDOG: internalcb = VIR_DOMAIN_EVENT_CALLBACK(domain_event_watchdog_callback); break; case VIR_DOMAIN_EVENT_ID_IO_ERROR: internalcb = VIR_DOMAIN_EVENT_CALLBACK(domain_event_io_error_callback); break; case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON: internalcb = VIR_DOMAIN_EVENT_CALLBACK(domain_event_io_error_reason_callback); break; case VIR_DOMAIN_EVENT_ID_GRAPHICS: internalcb = VIR_DOMAIN_EVENT_CALLBACK(domain_event_graphics_callback); break; default: rb_raise(rb_eArgError, "invalid eventID argument %d", NUM2INT(eventID)); break; } passthrough = rb_ary_new(); rb_ary_store(passthrough, 0, cb); rb_ary_store(passthrough, 1, opaque); ruby_libvirt_generate_call_int(virConnectDomainEventRegisterAny, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), domain, NUM2INT(eventID), internalcb, (void *)passthrough, NULL); } /* * call-seq: * conn.domain_event_deregister_any(callbackID) -> nil * * Call virConnectDomainEventDeregisterAny[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventDeregisterAny] * to deregister a callback from libvirt. The callbackID must be a * libvirt-specific handle returned by domain_event_register_any. */ static VALUE libvirt_connect_domain_event_deregister_any(VALUE c, VALUE callbackID) { ruby_libvirt_generate_call_nil(virConnectDomainEventDeregisterAny, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), NUM2INT(callbackID)); } /* * this is a bit of silliness. Because libvirt internals track the address * of the function pointer, trying to use domain_event_lifecycle_callback * for both register and register_any would mean that we could only register * one or the other for lifecycle callbacks. Instead we do a simple wrapper * so that the addresses are different */ static int domain_event_callback(virConnectPtr conn, virDomainPtr dom, int event, int detail, void *opaque) { return domain_event_lifecycle_callback(conn, dom, event, detail, opaque); } /* * call-seq: * conn.domain_event_register(callback, opaque=nil) -> nil * * Call virConnectDomainEventRegister[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventRegister] * to register callback for domain lifecycle events with libvirt. The * callback can either be a Symbol (that is the name of a method to callback) * or a Proc. The callback must accept 5 parameters: Libvirt::Connect, * Libvirt::Domain, event, detail, opaque. The opaque parameter to * domain_event_register can be any valid ruby type, and will be passed into * callback as "opaque". This method is deprecated in favor of * domain_event_register_any. */ static VALUE libvirt_connect_domain_event_register(int argc, VALUE *argv, VALUE c) { VALUE cb, opaque, passthrough; rb_scan_args(argc, argv, "11", &cb, &opaque); if (!ruby_libvirt_is_symbol_or_proc(cb)) { rb_raise(rb_eTypeError, "wrong argument type (expected Symbol or Proc)"); } passthrough = rb_ary_new(); rb_ary_store(passthrough, 0, cb); rb_ary_store(passthrough, 1, opaque); ruby_libvirt_generate_call_nil(virConnectDomainEventRegister, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), domain_event_callback, (void *)passthrough, NULL); } /* * call-seq: * conn.domain_event_deregister(callback) -> nil * * Call virConnectDomainEventDeregister[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventDeregister] * to deregister the event callback from libvirt. This method is deprecated * in favor of domain_event_deregister_any (though they cannot be mixed; if * the callback was registered with domain_event_register, it must be * deregistered with domain_event_deregister). */ static VALUE libvirt_connect_domain_event_deregister(VALUE c) { ruby_libvirt_generate_call_nil(virConnectDomainEventDeregister, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), domain_event_callback); } /* * call-seq: * conn.num_of_domains -> Fixnum * * Call virConnectNumOfDomains[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectNumOfDomains] * to retrieve the number of active domains on this connection. */ static VALUE libvirt_connect_num_of_domains(VALUE c) { gen_conn_num_of(c, Domains); } /* * call-seq: * conn.list_domains -> list * * Call virConnectListDomains[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListDomains] * to retrieve a list of active domain IDs on this connection. */ static VALUE libvirt_connect_list_domains(VALUE c) { int i, r, num, *ids; VALUE result; num = virConnectNumOfDomains(ruby_libvirt_connect_get(c)); ruby_libvirt_raise_error_if(num < 0, e_RetrieveError, "virConnectNumOfDomains", ruby_libvirt_connect_get(c)); result = rb_ary_new2(num); if (num == 0) { return result; } ids = alloca(sizeof(int) * num); r = virConnectListDomains(ruby_libvirt_connect_get(c), ids, num); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virConnectListDomains", ruby_libvirt_connect_get(c)); for (i = 0; i < num; i++) { rb_ary_store(result, i, INT2NUM(ids[i])); } return result; } /* * call-seq: * conn.num_of_defined_domains -> Fixnum * * Call virConnectNumOfDefinedDomains[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectNumOfDefinedDomains] * to retrieve the number of inactive domains on this connection. */ static VALUE libvirt_connect_num_of_defined_domains(VALUE c) { gen_conn_num_of(c, DefinedDomains); } /* * call-seq: * conn.list_defined_domains -> list * * Call virConnectListDefinedDomains[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListDefinedDomains] * to retrieve a list of inactive domain names on this connection. */ static VALUE libvirt_connect_list_defined_domains(VALUE c) { gen_conn_list_names(c, DefinedDomains); } /* * call-seq: * conn.create_domain_linux(xml, flags=0) -> Libvirt::Domain * * Call virDomainCreateLinux[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateLinux] * to start a transient domain from the given XML. Deprecated; use * conn.create_domain_xml instead. */ static VALUE libvirt_connect_create_linux(int argc, VALUE *argv, VALUE c) { virDomainPtr dom; VALUE flags, xml; rb_scan_args(argc, argv, "11", &xml, &flags); dom = virDomainCreateLinux(ruby_libvirt_connect_get(c), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(dom == NULL, e_Error, "virDomainCreateLinux", ruby_libvirt_connect_get(c)); return ruby_libvirt_domain_new(dom, c); } /* * call-seq: * conn.create_domain_xml(xml, flags=0) -> Libvirt::Domain * * Call virDomainCreateXML[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateXML] * to start a transient domain from the given XML. */ static VALUE libvirt_connect_create_domain_xml(int argc, VALUE *argv, VALUE c) { virDomainPtr dom; VALUE flags, xml; rb_scan_args(argc, argv, "11", &xml, &flags); dom = virDomainCreateXML(ruby_libvirt_connect_get(c), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(dom == NULL, e_Error, "virDomainCreateXML", ruby_libvirt_connect_get(c)); return ruby_libvirt_domain_new(dom, c); } /* * call-seq: * conn.lookup_domain_by_name(name) -> Libvirt::Domain * * Call virDomainLookupByName[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByName] * to retrieve a domain object for name. */ static VALUE libvirt_connect_lookup_domain_by_name(VALUE c, VALUE name) { virDomainPtr dom; dom = virDomainLookupByName(ruby_libvirt_connect_get(c), StringValueCStr(name)); ruby_libvirt_raise_error_if(dom == NULL, e_RetrieveError, "virDomainLookupByName", ruby_libvirt_connect_get(c)); return ruby_libvirt_domain_new(dom, c); } /* * call-seq: * conn.lookup_domain_by_id(id) -> Libvirt::Domain * * Call virDomainLookupByID[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByID] * to retrieve a domain object for id. */ static VALUE libvirt_connect_lookup_domain_by_id(VALUE c, VALUE id) { virDomainPtr dom; dom = virDomainLookupByID(ruby_libvirt_connect_get(c), NUM2INT(id)); ruby_libvirt_raise_error_if(dom == NULL, e_RetrieveError, "virDomainLookupByID", ruby_libvirt_connect_get(c)); return ruby_libvirt_domain_new(dom, c); } /* * call-seq: * conn.lookup_domain_by_uuid(uuid) -> Libvirt::Domain * * Call virDomainLookupByUUIDString[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByUUIDString] * to retrieve a domain object for uuid. */ static VALUE libvirt_connect_lookup_domain_by_uuid(VALUE c, VALUE uuid) { virDomainPtr dom; dom = virDomainLookupByUUIDString(ruby_libvirt_connect_get(c), StringValueCStr(uuid)); ruby_libvirt_raise_error_if(dom == NULL, e_RetrieveError, "virDomainLookupByUUID", ruby_libvirt_connect_get(c)); return ruby_libvirt_domain_new(dom, c); } /* * call-seq: * conn.define_domain_xml(xml, flags=0) -> Libvirt::Domain * * Call virDomainDefineXML[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDefineXML] * to define a permanent domain on this connection. */ static VALUE libvirt_connect_define_domain_xml(int argc, VALUE *argv, VALUE c) { virDomainPtr dom; VALUE xml; VALUE flags; rb_scan_args(argc, argv, "11", &xml, &flags); if (ruby_libvirt_value_to_uint(flags) != 0) { dom = virDomainDefineXMLFlags(ruby_libvirt_connect_get(c), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); } else { dom = virDomainDefineXML(ruby_libvirt_connect_get(c), StringValueCStr(xml)); } ruby_libvirt_raise_error_if(dom == NULL, e_DefinitionError, "virDomainDefineXML", ruby_libvirt_connect_get(c)); return ruby_libvirt_domain_new(dom, c); } /* * call-seq: * conn.domain_xml_from_native(nativeFormat, xml, flags=0) -> String * * Call virConnectDomainXMLFromNative[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainXMLFromNative] * to convert a native hypervisor domain representation to libvirt XML. */ static VALUE libvirt_connect_domain_xml_from_native(int argc, VALUE *argv, VALUE c) { VALUE nativeFormat, xml, flags; rb_scan_args(argc, argv, "21", &nativeFormat, &xml, &flags); ruby_libvirt_generate_call_string(virConnectDomainXMLFromNative, ruby_libvirt_connect_get(c), 1, ruby_libvirt_connect_get(c), StringValueCStr(nativeFormat), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * conn.domain_xml_to_native(nativeFormat, xml, flags=0) -> String * * Call virConnectDomainXMLToNative[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainXMLToNative] * to convert libvirt XML to a native domain hypervisor representation. */ static VALUE libvirt_connect_domain_xml_to_native(int argc, VALUE *argv, VALUE c) { VALUE nativeFormat, xml, flags; rb_scan_args(argc, argv, "21", &nativeFormat, &xml, &flags); ruby_libvirt_generate_call_string(virConnectDomainXMLToNative, ruby_libvirt_connect_get(c), 1, ruby_libvirt_connect_get(c), StringValueCStr(nativeFormat), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * conn.num_of_interfaces -> Fixnum * * Call virConnectNumOfInterfaces[https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectNumOfInterfaces] * to retrieve the number of active interfaces on this connection. */ static VALUE libvirt_connect_num_of_interfaces(VALUE c) { gen_conn_num_of(c, Interfaces); } /* * call-seq: * conn.list_interfaces -> list * * Call virConnectListInterfaces[https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectListInterfaces] * to retrieve a list of active interface names on this connection. */ static VALUE libvirt_connect_list_interfaces(VALUE c) { gen_conn_list_names(c, Interfaces); } /* * call-seq: * conn.num_of_defined_interfaces -> Fixnum * * Call virConnectNumOfDefinedInterfaces[https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectNumOfDefinedInterfaces] * to retrieve the number of inactive interfaces on this connection. */ static VALUE libvirt_connect_num_of_defined_interfaces(VALUE c) { gen_conn_num_of(c, DefinedInterfaces); } /* * call-seq: * conn.list_defined_interfaces -> list * * Call virConnectListDefinedInterfaces[https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectListDefinedInterfaces] * to retrieve a list of inactive interface names on this connection. */ static VALUE libvirt_connect_list_defined_interfaces(VALUE c) { gen_conn_list_names(c, DefinedInterfaces); } /* * call-seq: * conn.lookup_interface_by_name(name) -> Libvirt::Interface * * Call virInterfaceLookupByName[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceLookupByName] * to retrieve an interface object by name. */ static VALUE libvirt_connect_lookup_interface_by_name(VALUE c, VALUE name) { virInterfacePtr iface; iface = virInterfaceLookupByName(ruby_libvirt_connect_get(c), StringValueCStr(name)); ruby_libvirt_raise_error_if(iface == NULL, e_RetrieveError, "virInterfaceLookupByName", ruby_libvirt_connect_get(c)); return ruby_libvirt_interface_new(iface, c); } /* * call-seq: * conn.lookup_interface_by_mac(mac) -> Libvirt::Interface * * Call virInterfaceLookupByMACString[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceLookupByMACString] * to retrieve an interface object by MAC address. */ static VALUE libvirt_connect_lookup_interface_by_mac(VALUE c, VALUE mac) { virInterfacePtr iface; iface = virInterfaceLookupByMACString(ruby_libvirt_connect_get(c), StringValueCStr(mac)); ruby_libvirt_raise_error_if(iface == NULL, e_RetrieveError, "virInterfaceLookupByMACString", ruby_libvirt_connect_get(c)); return ruby_libvirt_interface_new(iface, c); } /* * call-seq: * conn.define_interface_xml(xml, flags=0) -> Libvirt::Interface * * Call virInterfaceDefineXML[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDefineXML] * to define a new interface from xml. */ static VALUE libvirt_connect_define_interface_xml(int argc, VALUE *argv, VALUE c) { virInterfacePtr iface; VALUE xml, flags; rb_scan_args(argc, argv, "11", &xml, &flags); iface = virInterfaceDefineXML(ruby_libvirt_connect_get(c), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(iface == NULL, e_DefinitionError, "virInterfaceDefineXML", ruby_libvirt_connect_get(c)); return ruby_libvirt_interface_new(iface, c); } /* * call-seq: * conn.num_of_networks -> Fixnum * * Call virConnectNumOfNetworks[https://libvirt.org/html/libvirt-libvirt-network.html#virConnectNumOfNetworks] * to retrieve the number of active networks on this connection. */ static VALUE libvirt_connect_num_of_networks(VALUE c) { gen_conn_num_of(c, Networks); } /* * call-seq: * conn.list_networks -> list * * Call virConnectListNetworks[https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListNetworks] * to retrieve a list of active network names on this connection. */ static VALUE libvirt_connect_list_networks(VALUE c) { gen_conn_list_names(c, Networks); } /* * call-seq: * conn.num_of_defined_networks -> Fixnum * * Call virConnectNumOfDefinedNetworks[https://libvirt.org/html/libvirt-libvirt-network.html#virConnectNumOfDefinedNetworks] * to retrieve the number of inactive networks on this connection. */ static VALUE libvirt_connect_num_of_defined_networks(VALUE c) { gen_conn_num_of(c, DefinedNetworks); } /* * call-seq: * conn.list_of_defined_networks -> list * * Call virConnectListDefinedNetworks[https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListDefinedNetworks] * to retrieve a list of inactive network names on this connection. */ static VALUE libvirt_connect_list_defined_networks(VALUE c) { gen_conn_list_names(c, DefinedNetworks); } /* * call-seq: * conn.lookup_network_by_name(name) -> Libvirt::Network * * Call virNetworkLookupByName[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName] * to retrieve a network object by name. */ static VALUE libvirt_connect_lookup_network_by_name(VALUE c, VALUE name) { virNetworkPtr netw; netw = virNetworkLookupByName(ruby_libvirt_connect_get(c), StringValueCStr(name)); ruby_libvirt_raise_error_if(netw == NULL, e_RetrieveError, "virNetworkLookupByName", ruby_libvirt_connect_get(c)); return ruby_libvirt_network_new(netw, c); } /* * call-seq: * conn.lookup_network_by_uuid(uuid) -> Libvirt::Network * * Call virNetworkLookupByUUIDString[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByUUIDString] * to retrieve a network object by UUID. */ static VALUE libvirt_connect_lookup_network_by_uuid(VALUE c, VALUE uuid) { virNetworkPtr netw; netw = virNetworkLookupByUUIDString(ruby_libvirt_connect_get(c), StringValueCStr(uuid)); ruby_libvirt_raise_error_if(netw == NULL, e_RetrieveError, "virNetworkLookupByUUID", ruby_libvirt_connect_get(c)); return ruby_libvirt_network_new(netw, c); } /* * call-seq: * conn.create_network_xml(xml) -> Libvirt::Network * * Call virNetworkCreateXML[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreateXML] * to start a new transient network from xml. */ static VALUE libvirt_connect_create_network_xml(VALUE c, VALUE xml) { virNetworkPtr netw; netw = virNetworkCreateXML(ruby_libvirt_connect_get(c), StringValueCStr(xml)); ruby_libvirt_raise_error_if(netw == NULL, e_Error, "virNetworkCreateXML", ruby_libvirt_connect_get(c)); return ruby_libvirt_network_new(netw, c); } /* * call-seq: * conn.define_network_xml(xml) -> Libvirt::Network * * Call virNetworkDefineXML[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkDefineXML] * to define a new permanent network from xml. */ static VALUE libvirt_connect_define_network_xml(VALUE c, VALUE xml) { virNetworkPtr netw; netw = virNetworkDefineXML(ruby_libvirt_connect_get(c), StringValueCStr(xml)); ruby_libvirt_raise_error_if(netw == NULL, e_DefinitionError, "virNetworkDefineXML", ruby_libvirt_connect_get(c)); return ruby_libvirt_network_new(netw, c); } /* * call-seq: * conn.num_of_nodedevices(cap=nil, flags=0) -> Fixnum * * Call virNodeNumOfDevices[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeNumOfDevices] * to retrieve the number of node devices on this connection. */ static VALUE libvirt_connect_num_of_nodedevices(int argc, VALUE *argv, VALUE c) { int result; VALUE cap, flags; rb_scan_args(argc, argv, "02", &cap, &flags); result = virNodeNumOfDevices(ruby_libvirt_connect_get(c), ruby_libvirt_get_cstring_or_null(cap), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(result < 0, e_RetrieveError, "virNodeNumOfDevices", ruby_libvirt_connect_get(c)); return INT2NUM(result); } /* * call-seq: * conn.list_nodedevices(cap=nil, flags=0) -> list * * Call virNodeListDevices[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeListDevices] * to retrieve a list of node device names on this connection. */ static VALUE libvirt_connect_list_nodedevices(int argc, VALUE *argv, VALUE c) { int r, num; VALUE cap, flags; char *capstr; char **names; rb_scan_args(argc, argv, "02", &cap, &flags); if (TYPE(flags) != T_NIL && TYPE(flags) != T_FIXNUM) { rb_raise(rb_eTypeError, "wrong argument type (expected Number)"); } capstr = ruby_libvirt_get_cstring_or_null(cap); num = virNodeNumOfDevices(ruby_libvirt_connect_get(c), capstr, 0); ruby_libvirt_raise_error_if(num < 0, e_RetrieveError, "virNodeNumOfDevices", ruby_libvirt_connect_get(c)); if (num == 0) { /* if num is 0, don't call virNodeListDevices function */ return rb_ary_new2(num); } names = alloca(sizeof(char *) * num); r = virNodeListDevices(ruby_libvirt_connect_get(c), capstr, names, num, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virNodeListDevices", ruby_libvirt_connect_get(c)); return ruby_libvirt_generate_list(r, names); } /* * call-seq: * conn.lookup_nodedevice_by_name(name) -> Libvirt::NodeDevice * * Call virNodeDeviceLookupByName[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceLookupByName] * to retrieve a nodedevice object by name. */ static VALUE libvirt_connect_lookup_nodedevice_by_name(VALUE c, VALUE name) { virNodeDevicePtr nodedev; nodedev = virNodeDeviceLookupByName(ruby_libvirt_connect_get(c), StringValueCStr(name)); ruby_libvirt_raise_error_if(nodedev == NULL, e_RetrieveError, "virNodeDeviceLookupByName", ruby_libvirt_connect_get(c)); return ruby_libvirt_nodedevice_new(nodedev, c); } /* * call-seq: * conn.create_nodedevice_xml(xml, flags=0) -> Libvirt::NodeDevice * * Call virNodeDeviceCreateXML[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceCreateXML] * to create a new node device from xml. */ static VALUE libvirt_connect_create_nodedevice_xml(int argc, VALUE *argv, VALUE c) { virNodeDevicePtr nodedev; VALUE xml, flags; rb_scan_args(argc, argv, "11", &xml, &flags); nodedev = virNodeDeviceCreateXML(ruby_libvirt_connect_get(c), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(nodedev == NULL, e_Error, "virNodeDeviceCreateXML", ruby_libvirt_connect_get(c)); return ruby_libvirt_nodedevice_new(nodedev, c); } /* * call-seq: * conn.num_of_nwfilters -> Fixnum * * Call virConnectNumOfNWFilters[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virConnectNumOfNWFilters] * to retrieve the number of network filters on this connection. */ static VALUE libvirt_connect_num_of_nwfilters(VALUE c) { gen_conn_num_of(c, NWFilters); } /* * call-seq: * conn.list_nwfilters -> list * * Call virConnectListNWFilters[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virConnectListNWFilters] * to retrieve a list of network filter names on this connection. */ static VALUE libvirt_connect_list_nwfilters(VALUE c) { gen_conn_list_names(c, NWFilters); } /* * call-seq: * conn.lookup_nwfilter_by_name(name) -> Libvirt::NWFilter * * Call virNWFilterLookupByName[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterLookupByName] * to retrieve a network filter object by name. */ static VALUE libvirt_connect_lookup_nwfilter_by_name(VALUE c, VALUE name) { virNWFilterPtr nwfilter; nwfilter = virNWFilterLookupByName(ruby_libvirt_connect_get(c), StringValueCStr(name)); ruby_libvirt_raise_error_if(nwfilter == NULL, e_RetrieveError, "virNWFilterLookupByName", ruby_libvirt_connect_get(c)); return ruby_libvirt_nwfilter_new(nwfilter, c); } /* * call-seq: * conn.lookup_nwfilter_by_uuid(uuid) -> Libvirt::NWFilter * * Call virNWFilterLookupByUUIDString[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterLookupByUUIDString] * to retrieve a network filter object by UUID. */ static VALUE libvirt_connect_lookup_nwfilter_by_uuid(VALUE c, VALUE uuid) { virNWFilterPtr nwfilter; nwfilter = virNWFilterLookupByUUIDString(ruby_libvirt_connect_get(c), StringValueCStr(uuid)); ruby_libvirt_raise_error_if(nwfilter == NULL, e_RetrieveError, "virNWFilterLookupByUUIDString", ruby_libvirt_connect_get(c)); return ruby_libvirt_nwfilter_new(nwfilter, c); } /* * call-seq: * conn.define_nwfilter_xml(xml) -> Libvirt::NWFilter * * Call virNWFilterDefineXML[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterDefineXML] * to define a new network filter from xml. */ static VALUE libvirt_connect_define_nwfilter_xml(VALUE c, VALUE xml) { virNWFilterPtr nwfilter; nwfilter = virNWFilterDefineXML(ruby_libvirt_connect_get(c), StringValueCStr(xml)); ruby_libvirt_raise_error_if(nwfilter == NULL, e_DefinitionError, "virNWFilterDefineXML", ruby_libvirt_connect_get(c)); return ruby_libvirt_nwfilter_new(nwfilter, c); } /* * call-seq: * conn.num_of_secrets -> Fixnum * * Call virConnectNumOfSecrets[https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectNumOfSecrets] * to retrieve the number of secrets on this connection. */ static VALUE libvirt_connect_num_of_secrets(VALUE c) { gen_conn_num_of(c, Secrets); } /* * call-seq: * conn.list_secrets -> list * * Call virConnectListSecrets[https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectListSecrets] * to retrieve a list of secret UUIDs on this connection. */ static VALUE libvirt_connect_list_secrets(VALUE c) { gen_conn_list_names(c, Secrets); } /* * call-seq: * conn.lookup_secret_by_uuid(uuid) -> Libvirt::Secret * * Call virSecretLookupByUUID[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretLookupByUUID] * to retrieve a network object from uuid. */ static VALUE libvirt_connect_lookup_secret_by_uuid(VALUE c, VALUE uuid) { virSecretPtr secret; secret = virSecretLookupByUUIDString(ruby_libvirt_connect_get(c), StringValueCStr(uuid)); ruby_libvirt_raise_error_if(secret == NULL, e_RetrieveError, "virSecretLookupByUUID", ruby_libvirt_connect_get(c)); return ruby_libvirt_secret_new(secret, c); } /* * call-seq: * conn.lookup_secret_by_usage(usagetype, usageID) -> Libvirt::Secret * * Call virSecretLookupByUsage[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretLookupByUsage] * to retrieve a secret by usagetype. */ static VALUE libvirt_connect_lookup_secret_by_usage(VALUE c, VALUE usagetype, VALUE usageID) { virSecretPtr secret; secret = virSecretLookupByUsage(ruby_libvirt_connect_get(c), NUM2UINT(usagetype), StringValueCStr(usageID)); ruby_libvirt_raise_error_if(secret == NULL, e_RetrieveError, "virSecretLookupByUsage", ruby_libvirt_connect_get(c)); return ruby_libvirt_secret_new(secret, c); } /* * call-seq: * conn.define_secret_xml(xml, flags=0) -> Libvirt::Secret * * Call virSecretDefineXML[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretDefineXML] * to define a new secret from xml. */ static VALUE libvirt_connect_define_secret_xml(int argc, VALUE *argv, VALUE c) { virSecretPtr secret; VALUE xml, flags; rb_scan_args(argc, argv, "11", &xml, &flags); secret = virSecretDefineXML(ruby_libvirt_connect_get(c), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(secret == NULL, e_DefinitionError, "virSecretDefineXML", ruby_libvirt_connect_get(c)); return ruby_libvirt_secret_new(secret, c); } VALUE pool_new(virStoragePoolPtr n, VALUE conn); /* * call-seq: * conn.list_storage_pools -> list * * Call virConnectListStoragePools[https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectListStoragePools] * to retrieve a list of active storage pool names on this connection. */ static VALUE libvirt_connect_list_storage_pools(VALUE c) { gen_conn_list_names(c, StoragePools); } /* * call-seq: * conn.num_of_storage_pools -> Fixnum * * Call virConnectNumOfStoragePools[https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectNumOfStoragePools] * to retrieve the number of active storage pools on this connection. */ static VALUE libvirt_connect_num_of_storage_pools(VALUE c) { gen_conn_num_of(c, StoragePools); } /* * call-seq: * conn.list_defined_storage_pools -> list * * Call virConnectListDefinedStoragePools[https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectListDefinedStoragePools] * to retrieve a list of inactive storage pool names on this connection. */ static VALUE libvirt_connect_list_defined_storage_pools(VALUE c) { gen_conn_list_names(c, DefinedStoragePools); } /* * call-seq: * conn.num_of_defined_storage_pools -> Fixnum * * Call virConnectNumOfDefinedStoragePools[https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectNumOfDefinedStoragePools] * to retrieve the number of inactive storage pools on this connection. */ static VALUE libvirt_connect_num_of_defined_storage_pools(VALUE c) { gen_conn_num_of(c, DefinedStoragePools); } /* * call-seq: * conn.lookup_storage_pool_by_name(name) -> Libvirt::StoragePool * * Call virStoragePoolLookupByName[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByName] * to retrieve a storage pool object by name. */ static VALUE libvirt_connect_lookup_pool_by_name(VALUE c, VALUE name) { virStoragePoolPtr pool; pool = virStoragePoolLookupByName(ruby_libvirt_connect_get(c), StringValueCStr(name)); ruby_libvirt_raise_error_if(pool == NULL, e_RetrieveError, "virStoragePoolLookupByName", ruby_libvirt_connect_get(c)); return pool_new(pool, c); } /* * call-seq: * conn.lookup_storage_pool_by_uuid(uuid) -> Libvirt::StoragePool * * Call virStoragePoolLookupByUUIDString[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByUUIDString] * to retrieve a storage pool object by uuid. */ static VALUE libvirt_connect_lookup_pool_by_uuid(VALUE c, VALUE uuid) { virStoragePoolPtr pool; pool = virStoragePoolLookupByUUIDString(ruby_libvirt_connect_get(c), StringValueCStr(uuid)); ruby_libvirt_raise_error_if(pool == NULL, e_RetrieveError, "virStoragePoolLookupByUUID", ruby_libvirt_connect_get(c)); return pool_new(pool, c); } /* * call-seq: * conn.create_storage_pool_xml(xml, flags=0) -> Libvirt::StoragePool * * Call virStoragePoolCreateXML[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolCreateXML] * to start a new transient storage pool from xml. */ static VALUE libvirt_connect_create_pool_xml(int argc, VALUE *argv, VALUE c) { virStoragePoolPtr pool; VALUE xml, flags; rb_scan_args(argc, argv, "11", &xml, &flags); pool = virStoragePoolCreateXML(ruby_libvirt_connect_get(c), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(pool == NULL, e_Error, "virStoragePoolCreateXML", ruby_libvirt_connect_get(c)); return pool_new(pool, c); } /* * call-seq: * conn.define_storage_pool_xml(xml, flags=0) -> Libvirt::StoragePool * * Call virStoragePoolDefineXML[https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDefineXML] * to define a permanent storage pool from xml. */ static VALUE libvirt_connect_define_pool_xml(int argc, VALUE *argv, VALUE c) { virStoragePoolPtr pool; VALUE xml, flags; rb_scan_args(argc, argv, "11", &xml, &flags); pool = virStoragePoolDefineXML(ruby_libvirt_connect_get(c), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(pool == NULL, e_DefinitionError, "virStoragePoolDefineXML", ruby_libvirt_connect_get(c)); return pool_new(pool, c); } /* * call-seq: * conn.discover_storage_pool_sources(type, srcSpec=nil, flags=0) -> String * * Call virConnectFindStoragePoolSources[https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectFindStoragePoolSources] * to find the storage pool sources corresponding to type. */ static VALUE libvirt_connect_find_storage_pool_sources(int argc, VALUE *argv, VALUE c) { VALUE type, srcSpec, flags; rb_scan_args(argc, argv, "12", &type, &srcSpec, &flags); ruby_libvirt_generate_call_string(virConnectFindStoragePoolSources, ruby_libvirt_connect_get(c), 1, ruby_libvirt_connect_get(c), StringValueCStr(type), ruby_libvirt_get_cstring_or_null(srcSpec), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * conn.sys_info(flags=0) -> String * * Call virConnectGetSysinfo[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetSysinfo] * to get machine-specific information about the hypervisor. This may include * data such as the host UUID, the BIOS version, etc. */ static VALUE libvirt_connect_sys_info(int argc, VALUE *argv, VALUE c) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virConnectGetSysinfo, ruby_libvirt_connect_get(c), 1, ruby_libvirt_connect_get(c), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * conn.stream(flags=0) -> Libvirt::Stream * * Call virStreamNew[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamNew] * to create a new stream. */ static VALUE libvirt_connect_stream(int argc, VALUE *argv, VALUE c) { VALUE flags; virStreamPtr stream; rb_scan_args(argc, argv, "01", &flags); stream = virStreamNew(ruby_libvirt_connect_get(c), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(stream == NULL, e_RetrieveError, "virStreamNew", ruby_libvirt_connect_get(c)); return ruby_libvirt_stream_new(stream, c); } /* * call-seq: * conn.interface_change_begin(flags=0) -> nil * * Call virInterfaceChangeBegin[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeBegin] * to create a restore point for interface changes. Once changes have been * made, conn.interface_change_commit can be used to commit the result or * conn.interface_change_rollback can be used to rollback to this restore point. */ static VALUE libvirt_connect_interface_change_begin(int argc, VALUE *argv, VALUE c) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virInterfaceChangeBegin, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * conn.interface_change_commit(flags=0) -> nil * * Call virInterfaceChangeCommit[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeCommit] * to commit the interface changes since the last conn.interface_change_begin. */ static VALUE libvirt_connect_interface_change_commit(int argc, VALUE *argv, VALUE c) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virInterfaceChangeCommit, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * conn.interface_change_rollback(flags=0) -> nil * * Call virInterfaceChangeRollback[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeRollback] * to rollback to the restore point saved by conn.interface_change_begin. */ static VALUE libvirt_connect_interface_change_rollback(int argc, VALUE *argv, VALUE c) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virInterfaceChangeRollback, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), ruby_libvirt_value_to_uint(flags)); } static void cpu_stats_set(void *voidparams, int i, VALUE result) { virNodeCPUStatsPtr params = (virNodeCPUStatsPtr)voidparams; rb_hash_aset(result, rb_str_new2(params[i].field), ULL2NUM(params[i].value)); } static const char *cpu_stats_nparams(VALUE d, unsigned int flags, void *opaque, int *nparams) { int intparam = *((int *)opaque); if (virNodeGetCPUStats(ruby_libvirt_connect_get(d), intparam, NULL, nparams, flags) < 0) { return "virNodeGetCPUStats"; } return NULL; } static const char *cpu_stats_get(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *opaque) { int intparam = *((int *)opaque); virNodeCPUStatsPtr params = (virNodeCPUStatsPtr)voidparams; if (virNodeGetCPUStats(ruby_libvirt_connect_get(d), intparam, params, nparams, flags) < 0) { return "virNodeGetCPUStats"; } return NULL; } /* * call-seq: * conn.node_cpu_stats(cpuNum=-1, flags=0) -> Hash * * Call virNodeGetCPUStats[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUStats] * to retrieve cpu statistics from the virtualization host. */ static VALUE libvirt_connect_node_cpu_stats(int argc, VALUE *argv, VALUE c) { VALUE intparam, flags; int tmp; rb_scan_args(argc, argv, "02", &intparam, &flags); if (NIL_P(intparam)) { tmp = -1; } else { tmp = ruby_libvirt_value_to_int(intparam); } return ruby_libvirt_get_parameters(c, ruby_libvirt_value_to_uint(flags), (void *)&tmp, sizeof(virNodeCPUStats), cpu_stats_nparams, cpu_stats_get, cpu_stats_set); } static void memory_stats_set(void *voidparams, int i, VALUE result) { virNodeMemoryStatsPtr params = (virNodeMemoryStatsPtr)voidparams; rb_hash_aset(result, rb_str_new2(params[i].field), ULL2NUM(params[i].value)); } static const char *memory_stats_nparams(VALUE d, unsigned int flags, void *opaque, int *nparams) { int intparam = *((int *)opaque); if (virNodeGetMemoryStats(ruby_libvirt_connect_get(d), intparam, NULL, nparams, flags) < 0) { return "virNodeGetMemoryStats"; } return NULL; } static const char *memory_stats_get(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *opaque) { int intparam = *((int *)opaque); virNodeMemoryStatsPtr params = (virNodeMemoryStatsPtr)voidparams; if (virNodeGetMemoryStats(ruby_libvirt_connect_get(d), intparam, params, nparams, flags) < 0) { return "virNodeGetMemoryStats"; } return NULL; } /* * call-seq: * conn.node_memory_stats(cellNum=-1, flags=0) -> Hash * * Call virNodeGetMemoryStats[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetMemoryStats] * to retrieve memory statistics from the virtualization host. */ static VALUE libvirt_connect_node_memory_stats(int argc, VALUE *argv, VALUE c) { VALUE intparam, flags; int tmp; rb_scan_args(argc, argv, "02", &intparam, &flags); if (NIL_P(intparam)) { tmp = -1; } else { tmp = ruby_libvirt_value_to_int(intparam); } return ruby_libvirt_get_parameters(c, ruby_libvirt_value_to_uint(flags), (void *)&tmp, sizeof(virNodeMemoryStats), memory_stats_nparams, memory_stats_get, memory_stats_set); } /* * call-seq: * conn.save_image_xml_desc(filename, flags=0) -> String * * Call virDomainSaveImageGetXMLDesc[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSaveImageGetXMLDesc] * to get the XML corresponding to a save file. */ static VALUE libvirt_connect_save_image_xml_desc(int argc, VALUE *argv, VALUE c) { VALUE filename, flags; rb_scan_args(argc, argv, "11", &filename, &flags); ruby_libvirt_generate_call_string(virDomainSaveImageGetXMLDesc, ruby_libvirt_connect_get(c), 1, ruby_libvirt_connect_get(c), StringValueCStr(filename), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * conn.define_save_image_xml(filename, newxml, flags=0) -> nil * * Call virDomainSaveImageDefineXML[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSaveImageDefineXML] * to define new XML for a saved image. */ static VALUE libvirt_connect_define_save_image_xml(int argc, VALUE *argv, VALUE c) { VALUE filename, newxml, flags; rb_scan_args(argc, argv, "21", &filename, &newxml, &flags); ruby_libvirt_generate_call_nil(virDomainSaveImageDefineXML, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), StringValueCStr(filename), StringValueCStr(newxml), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * conn.node_suspend_for_duration(target, duration, flags=0) -> nil * * Call virNodeSuspendForDuration[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeSuspendForDuration] * to suspend the hypervisor for the specified duration. */ static VALUE libvirt_connect_node_suspend_for_duration(int argc, VALUE *argv, VALUE c) { VALUE target, duration, flags; rb_scan_args(argc, argv, "21", &target, &duration, &flags); ruby_libvirt_generate_call_nil(virNodeSuspendForDuration, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), NUM2UINT(target), NUM2ULL(duration), ruby_libvirt_value_to_uint(flags)); } static const char *node_memory_nparams(VALUE d, unsigned int flags, void *RUBY_LIBVIRT_UNUSED(opaque), int *nparams) { if (virNodeGetMemoryParameters(ruby_libvirt_connect_get(d), NULL, nparams, flags) < 0) { return "virNodeGetMemoryParameters"; } return NULL; } static const char *node_memory_get(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *RUBY_LIBVIRT_UNUSED(opaque)) { virTypedParameterPtr params = (virTypedParameterPtr)voidparams; if (virNodeGetMemoryParameters(ruby_libvirt_connect_get(d), params, nparams, flags) < 0) { return "virNodeGetMemoryParameters"; } return NULL; } static const char *node_memory_set(VALUE d, unsigned int flags, virTypedParameterPtr params, int nparams, void *RUBY_LIBVIRT_UNUSED(opaque)) { if (virNodeSetMemoryParameters(ruby_libvirt_connect_get(d), params, nparams, flags) < 0) { return "virNodeSetMemoryParameters"; } return NULL; } /* * call-seq: * conn.node_memory_parameters(flags=0) -> Hash * * Call virNodeGetMemoryParameters[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetMemoryParameters] * to get information about memory on the host node. */ static VALUE libvirt_connect_node_memory_parameters(int argc, VALUE *argv, VALUE c) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); return ruby_libvirt_get_typed_parameters(c, ruby_libvirt_value_to_uint(flags), NULL, node_memory_nparams, node_memory_get); } static struct ruby_libvirt_typed_param memory_allowed[] = { {VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN, VIR_TYPED_PARAM_UINT}, {VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS, VIR_TYPED_PARAM_UINT}, {VIR_NODE_MEMORY_SHARED_PAGES_SHARED, VIR_TYPED_PARAM_ULLONG}, {VIR_NODE_MEMORY_SHARED_PAGES_SHARING, VIR_TYPED_PARAM_ULLONG}, {VIR_NODE_MEMORY_SHARED_PAGES_UNSHARED, VIR_TYPED_PARAM_ULLONG}, {VIR_NODE_MEMORY_SHARED_PAGES_VOLATILE, VIR_TYPED_PARAM_ULLONG}, {VIR_NODE_MEMORY_SHARED_FULL_SCANS, VIR_TYPED_PARAM_ULLONG}, {VIR_NODE_MEMORY_SHARED_MERGE_ACROSS_NODES, VIR_TYPED_PARAM_UINT}, }; /* * call-seq: * conn.node_memory_parameters = Hash,flags=0 * * Call virNodeSetMemoryParameters[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeSetMemoryParameters] * to set the memory parameters for this host node. */ static VALUE libvirt_connect_node_memory_parameters_equal(VALUE c, VALUE input) { VALUE hash, flags; ruby_libvirt_assign_hash_and_flags(input, &hash, &flags); return ruby_libvirt_set_typed_parameters(c, hash, NUM2UINT(flags), NULL, memory_allowed, ARRAY_SIZE(memory_allowed), node_memory_set); } struct cpu_map_field_to_value { VALUE result; int cpu; int used; }; static VALUE cpu_map_field_to_value(VALUE input) { struct cpu_map_field_to_value *ftv = (struct cpu_map_field_to_value *)input; char cpuname[10]; snprintf(cpuname, sizeof(cpuname), "%d", ftv->cpu); rb_hash_aset(ftv->result, rb_str_new2(cpuname), ftv->used ? Qtrue : Qfalse); return Qnil; } /* * call-seq: * conn.node_cpu_map -> Hash * * Call virNodeGetCPUMap[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUMap] * to get a map of online host CPUs. */ static VALUE libvirt_connect_node_cpu_map(int argc, VALUE *argv, VALUE c) { VALUE flags, result; unsigned char *map; unsigned int online; int ret, i, exception = 0; struct cpu_map_field_to_value ftv; rb_scan_args(argc, argv, "01", &flags); ret = virNodeGetCPUMap(ruby_libvirt_connect_get(c), &map, &online, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virNodeGetCPUMap", ruby_libvirt_connect_get(c)); result = rb_hash_new(); for (i = 0; i < ret; i++) { ftv.result = result; ftv.cpu = i; ftv.used = VIR_CPU_USED(map, i); rb_protect(cpu_map_field_to_value, (VALUE)&ftv, &exception); if (exception) { free(map); rb_jump_tag(exception); } } free(map); return result; } /* * call-seq: * conn.set_keepalive(interval, count) -> Fixnum * * Call virConnectSetKeepAlive[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectSetKeepAlive] * to start sending keepalive messages. Deprecated; use conn.keepalive= * instead. */ static VALUE libvirt_connect_set_keepalive(VALUE c, VALUE interval, VALUE count) { ruby_libvirt_generate_call_int(virConnectSetKeepAlive, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), NUM2INT(interval), NUM2UINT(count)); } /* * call-seq: * conn.keepalive = interval,count * * Call virConnectSetKeepAlive[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectSetKeepAlive] * to start sending keepalive messages. */ static VALUE libvirt_connect_keepalive_equal(VALUE c, VALUE in) { VALUE interval, count; Check_Type(in, T_ARRAY); if (RARRAY_LEN(in) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(in)); } interval = rb_ary_entry(in, 0); count = rb_ary_entry(in, 1); ruby_libvirt_generate_call_int(virConnectSetKeepAlive, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), NUM2INT(interval), NUM2UINT(count)); } /* * call-seq: * conn.list_all_domains(flags=0) -> Array * * Call virConnectListAllDomains[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListAllDomains] * to get an array of domain objects for all domains. */ static VALUE libvirt_connect_list_all_domains(int argc, VALUE *argv, VALUE c) { ruby_libvirt_generate_call_list_all(virDomainPtr, argc, argv, virConnectListAllDomains, ruby_libvirt_connect_get(c), c, ruby_libvirt_domain_new, virDomainFree); } /* * call-seq: * conn.list_all_networks(flags=0) -> Array * * Call virConnectListAllNetworks[https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListAllNetworks] * to get an array of network objects for all networks. */ static VALUE libvirt_connect_list_all_networks(int argc, VALUE *argv, VALUE c) { ruby_libvirt_generate_call_list_all(virNetworkPtr, argc, argv, virConnectListAllNetworks, ruby_libvirt_connect_get(c), c, ruby_libvirt_network_new, virNetworkFree); } /* * call-seq: * conn.list_all_interfaces(flags=0) -> Array * * Call virConnectListAllInterfaces[https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectListAllInterfaces] * to get an array of interface objects for all interfaces. */ static VALUE libvirt_connect_list_all_interfaces(int argc, VALUE *argv, VALUE c) { ruby_libvirt_generate_call_list_all(virInterfacePtr, argc, argv, virConnectListAllInterfaces, ruby_libvirt_connect_get(c), c, ruby_libvirt_interface_new, virInterfaceFree); } /* * call-seq: * conn.list_all_secrets(flags=0) -> Array * * Call virConnectListAllSecrets[https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectListAllSecrets] * to get an array of secret objects for all secrets. */ static VALUE libvirt_connect_list_all_secrets(int argc, VALUE *argv, VALUE c) { ruby_libvirt_generate_call_list_all(virSecretPtr, argc, argv, virConnectListAllSecrets, ruby_libvirt_connect_get(c), c, ruby_libvirt_secret_new, virSecretFree); } /* * call-seq: * conn.list_all_nodedevices(flags=0) -> Array * * Call virConnectListAllNodeDevices[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virConnectListAllNodeDevices] * to get an array of nodedevice objects for all nodedevices. */ static VALUE libvirt_connect_list_all_nodedevices(int argc, VALUE *argv, VALUE c) { ruby_libvirt_generate_call_list_all(virNodeDevicePtr, argc, argv, virConnectListAllNodeDevices, ruby_libvirt_connect_get(c), c, ruby_libvirt_nodedevice_new, virNodeDeviceFree); } /* * call-seq: * conn.list_all_storage_pools(flags=0) -> Array * * Call virConnectListAllStoragePools[https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectListAllStoragePools] * to get an array of storage pool objects for all storage pools. */ static VALUE libvirt_connect_list_all_storage_pools(int argc, VALUE *argv, VALUE c) { ruby_libvirt_generate_call_list_all(virStoragePoolPtr, argc, argv, virConnectListAllStoragePools, ruby_libvirt_connect_get(c), c, pool_new, virStoragePoolFree); } /* * call-seq: * conn.list_all_nwfilters(flags=0) -> Array * * Call virConnectListAllNWFilters[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virConnectListAllNWFilters] * to get an array of nwfilters for all nwfilter objects. */ static VALUE libvirt_connect_list_all_nwfilters(int argc, VALUE *argv, VALUE c) { ruby_libvirt_generate_call_list_all(virNWFilterPtr, argc, argv, virConnectListAllNWFilters, ruby_libvirt_connect_get(c), c, ruby_libvirt_nwfilter_new, virNWFilterFree); } /* * call-seq: * conn.alive? -> [True|False] * * Call virConnectIsAlive[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectIsAlive] * to determine if the connection is alive. */ static VALUE libvirt_connect_alive_p(VALUE c) { ruby_libvirt_generate_call_truefalse(virConnectIsAlive, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c)); } /* * call-seq: * conn.create_domain_xml_with_files(xml, fds=nil, flags=0) -> Libvirt::Domain * * Call virDomainCreateXMLWithFiles[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateXMLWithFiles] * to launch a new guest domain with a set of open file descriptors. */ static VALUE libvirt_connect_create_domain_xml_with_files(int argc, VALUE *argv, VALUE c) { VALUE xml, fds, flags; int *files; unsigned int numfiles, i; virDomainPtr dom; rb_scan_args(argc, argv, "12", &xml, &fds, &flags); Check_Type(xml, T_STRING); if (TYPE(fds) == T_NIL) { files = NULL; numfiles = 0; } else if (TYPE(fds) == T_ARRAY) { numfiles = RARRAY_LEN(fds); files = alloca(numfiles * sizeof(int)); for (i = 0; i < numfiles; i++) { files[i] = NUM2INT(rb_ary_entry(fds, i)); } } else { rb_raise(rb_eTypeError, "wrong argument type (expected Array)"); } dom = virDomainCreateXMLWithFiles(ruby_libvirt_connect_get(c), ruby_libvirt_get_cstring_or_null(xml), numfiles, files, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(dom == NULL, e_Error, "virDomainCreateXMLWithFiles", ruby_libvirt_connect_get(c)); return ruby_libvirt_domain_new(dom, c); } /* * call-seq: * conn.qemu_attach(pid, flags=0) -> Libvirt::Domain * * Call virDomainQemuAttach * to attach to the Qemu process pid. */ static VALUE libvirt_connect_qemu_attach(int argc, VALUE *argv, VALUE c) { VALUE pid, flags; virDomainPtr dom; rb_scan_args(argc, argv, "11", &pid, &flags); dom = virDomainQemuAttach(ruby_libvirt_connect_get(c), NUM2UINT(pid), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(dom == NULL, e_Error, "virDomainQemuAttach", ruby_libvirt_connect_get(c)); return ruby_libvirt_domain_new(dom, c); } /* * call-seq: * conn.cpu_model_names(arch, flags=0) -> Array * * Call virConnectGetCPUModelNames[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetCPUModelNames] * to get an array of CPU model names. */ static VALUE libvirt_connect_cpu_model_names(int argc, VALUE *argv, VALUE c) { VALUE arch, flags, result; char **models; int i = 0, j, elems = 0; struct ruby_libvirt_str_new2_and_ary_store_arg args; int exception; rb_scan_args(argc, argv, "11", &arch, &flags); elems = virConnectGetCPUModelNames(ruby_libvirt_connect_get(c), StringValueCStr(arch), &models, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(elems < 0, e_RetrieveError, "virConnectGetCPUModelNames", ruby_libvirt_connect_get(c)); result = rb_protect(ruby_libvirt_ary_new2_wrap, (VALUE)&elems, &exception); if (exception) { goto error; } for (i = 0; i < elems; i++) { args.arr = result; args.index = i; args.value = models[i]; rb_protect(ruby_libvirt_str_new2_and_ary_store_wrap, (VALUE)&args, &exception); if (exception) { goto error; } free(models[i]); } free(models); return result; error: for (j = i; j < elems; j++) { free(models[j]); } free(models); rb_jump_tag(exception); return Qnil; } /* * call-seq: * conn.node_alloc_pages(page_arr, cells=nil, flags=0) -> Fixnum * * Call virNodeAllocPages[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeAllocPages] * to reserve huge pages in the system pool. */ static VALUE libvirt_connect_node_alloc_pages(int argc, VALUE *argv, VALUE c) { VALUE page_arr, cells, flags, entry, size, count, tmp; int i, arraylen, start_cell, ret; unsigned int *page_sizes; unsigned long long *page_counts; unsigned int cell_count; rb_scan_args(argc, argv, "12", &page_arr, &cells, &flags); Check_Type(page_arr, T_ARRAY); arraylen = RARRAY_LEN(page_arr); page_sizes = alloca(arraylen * sizeof(unsigned int)); page_counts = alloca(arraylen * sizeof(unsigned long long)); for (i = 0; i < arraylen; i++) { entry = rb_ary_entry(page_arr, i); Check_Type(entry, T_HASH); size = rb_hash_aref(entry, rb_str_new2("size")); Check_Type(size, T_FIXNUM); count = rb_hash_aref(entry, rb_str_new2("count")); Check_Type(count, T_FIXNUM); page_sizes[i] = NUM2UINT(size); page_counts[i] = NUM2ULL(count); } if (NIL_P(cells)) { start_cell = -1; cell_count = 0; } else { Check_Type(cells, T_HASH); tmp = rb_hash_aref(cells, rb_str_new2("start")); Check_Type(tmp, T_FIXNUM); start_cell = NUM2INT(tmp); tmp = rb_hash_aref(cells, rb_str_new2("count")); Check_Type(tmp, T_FIXNUM); cell_count = NUM2UINT(tmp); } ret = virNodeAllocPages(ruby_libvirt_connect_get(c), arraylen, page_sizes, page_counts, start_cell, cell_count, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_Error, "virNodeAllocPages", ruby_libvirt_connect_get(c)); return INT2NUM(ret); } /* * call-seq: * conn.domain_capabilities(emulatorbin, arch, machine, virttype, flags=0) -> String * * Call virConnectGetDomainCapabilities[https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectGetDomainCapabilities] * to get the capabilities of the underlying emulator. */ static VALUE libvirt_connect_domain_capabilities(int argc, VALUE *argv, VALUE c) { VALUE emulatorbin, arch, machine, virttype, flags; rb_scan_args(argc, argv, "41", &emulatorbin, &arch, &machine, &virttype, &flags); ruby_libvirt_generate_call_string(virConnectGetDomainCapabilities, ruby_libvirt_connect_get(c), 1, ruby_libvirt_connect_get(c), ruby_libvirt_get_cstring_or_null(emulatorbin), ruby_libvirt_get_cstring_or_null(arch), ruby_libvirt_get_cstring_or_null(machine), ruby_libvirt_get_cstring_or_null(virttype), NUM2UINT(flags)); } /* * call-seq: * conn.node_free_pages(pages, cells, flags=0) -> Hash * * Call virNodeGetFreePages[https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetFreePages] * to query the host system on free pages of specified size. */ static VALUE libvirt_connect_node_free_pages(int argc, VALUE *argv, VALUE c) { VALUE pageArr = RUBY_Qnil, cells = RUBY_Qnil, flags = RUBY_Qnil, result; unsigned int *pages; unsigned int npages, i, cellCount; int startCell, ret; unsigned long long *counts; rb_scan_args(argc, argv, "21", &pageArr, &cells, &flags); Check_Type(pageArr, T_ARRAY); Check_Type(cells, T_HASH); npages = RARRAY_LEN(pageArr); pages = alloca(npages); for (i = 0; i < npages; i++) { pages[i] = NUM2UINT(rb_ary_entry(pageArr, i)); } startCell = NUM2INT(rb_hash_aref(cells, rb_str_new2("startCell"))); cellCount = NUM2UINT(rb_hash_aref(cells, rb_str_new2("cellCount"))); counts = alloca(npages * cellCount * sizeof(long long)); ret = virNodeGetFreePages(ruby_libvirt_connect_get(c), npages, pages, startCell, cellCount, counts, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_Error, "virNodeGetFreePages", ruby_libvirt_connect_get(c)); result = rb_hash_new(); for (i = 0; i < npages; i++) { rb_hash_aset(result, UINT2NUM(pages[i]), ULL2NUM(counts[i])); } return result; } /* * Class Libvirt::Connect */ void ruby_libvirt_connect_init(void) { c_connect = rb_define_class_under(m_libvirt, "Connect", rb_cObject); rb_undef_alloc_func(c_connect); rb_define_singleton_method(c_connect, "new", ruby_libvirt_new_not_allowed, -1); /* * Class Libvirt::Connect::Nodeinfo */ c_node_info = rb_define_class_under(c_connect, "Nodeinfo", rb_cObject); rb_define_attr(c_node_info, "model", 1, 0); rb_define_attr(c_node_info, "memory", 1, 0); rb_define_attr(c_node_info, "cpus", 1, 0); rb_define_attr(c_node_info, "mhz", 1, 0); rb_define_attr(c_node_info, "nodes", 1, 0); rb_define_attr(c_node_info, "sockets", 1, 0); rb_define_attr(c_node_info, "cores", 1, 0); rb_define_attr(c_node_info, "threads", 1, 0); /* * Class Libvirt::Connect::NodeSecurityModel */ c_node_security_model = rb_define_class_under(c_connect, "NodeSecurityModel", rb_cObject); rb_define_attr(c_node_security_model, "model", 1, 0); rb_define_attr(c_node_security_model, "doi", 1, 0); rb_define_method(c_connect, "close", libvirt_connect_close, 0); rb_define_method(c_connect, "closed?", libvirt_connect_closed_p, 0); rb_define_method(c_connect, "type", libvirt_connect_type, 0); rb_define_method(c_connect, "version", libvirt_connect_version, 0); rb_define_method(c_connect, "libversion", libvirt_connect_libversion, 0); rb_define_method(c_connect, "hostname", libvirt_connect_hostname, 0); rb_define_method(c_connect, "uri", libvirt_connect_uri, 0); rb_define_method(c_connect, "max_vcpus", libvirt_connect_max_vcpus, -1); rb_define_method(c_connect, "node_info", libvirt_connect_node_info, 0); rb_define_alias(c_connect, "node_get_info", "node_info"); rb_define_method(c_connect, "node_free_memory", libvirt_connect_node_free_memory, 0); rb_define_method(c_connect, "node_cells_free_memory", libvirt_connect_node_cells_free_memory, -1); rb_define_method(c_connect, "node_security_model", libvirt_connect_node_security_model, 0); rb_define_alias(c_connect, "node_get_security_model", "node_security_model"); rb_define_method(c_connect, "encrypted?", libvirt_connect_encrypted_p, 0); rb_define_method(c_connect, "secure?", libvirt_connect_secure_p, 0); rb_define_method(c_connect, "capabilities", libvirt_connect_capabilities, 0); rb_define_const(c_connect, "CPU_COMPARE_ERROR", INT2NUM(VIR_CPU_COMPARE_ERROR)); rb_define_const(c_connect, "CPU_COMPARE_INCOMPATIBLE", INT2NUM(VIR_CPU_COMPARE_INCOMPATIBLE)); rb_define_const(c_connect, "CPU_COMPARE_IDENTICAL", INT2NUM(VIR_CPU_COMPARE_IDENTICAL)); rb_define_const(c_connect, "CPU_COMPARE_SUPERSET", INT2NUM(VIR_CPU_COMPARE_SUPERSET)); rb_define_method(c_connect, "compare_cpu", libvirt_connect_compare_cpu, -1); rb_define_const(c_connect, "COMPARE_CPU_FAIL_INCOMPATIBLE", INT2NUM(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE)); rb_define_method(c_connect, "baseline_cpu", libvirt_connect_baseline_cpu, -1); rb_define_const(c_connect, "BASELINE_CPU_EXPAND_FEATURES", INT2NUM(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES)); rb_define_const(c_connect, "DOMAIN_EVENT_DEFINED", INT2NUM(VIR_DOMAIN_EVENT_DEFINED)); rb_define_const(c_connect, "DOMAIN_EVENT_DEFINED_ADDED", INT2NUM(VIR_DOMAIN_EVENT_DEFINED_ADDED)); rb_define_const(c_connect, "DOMAIN_EVENT_DEFINED_UPDATED", INT2NUM(VIR_DOMAIN_EVENT_DEFINED_UPDATED)); rb_define_const(c_connect, "DOMAIN_EVENT_UNDEFINED", INT2NUM(VIR_DOMAIN_EVENT_UNDEFINED)); rb_define_const(c_connect, "DOMAIN_EVENT_UNDEFINED_REMOVED", INT2NUM(VIR_DOMAIN_EVENT_UNDEFINED_REMOVED)); rb_define_const(c_connect, "DOMAIN_EVENT_STARTED_BOOTED", INT2NUM(VIR_DOMAIN_EVENT_STARTED_BOOTED)); rb_define_const(c_connect, "DOMAIN_EVENT_STARTED_MIGRATED", INT2NUM(VIR_DOMAIN_EVENT_STARTED_MIGRATED)); rb_define_const(c_connect, "DOMAIN_EVENT_STARTED_RESTORED", INT2NUM(VIR_DOMAIN_EVENT_STARTED_RESTORED)); rb_define_const(c_connect, "DOMAIN_EVENT_SUSPENDED_PAUSED", INT2NUM(VIR_DOMAIN_EVENT_SUSPENDED_PAUSED)); rb_define_const(c_connect, "DOMAIN_EVENT_SUSPENDED_MIGRATED", INT2NUM(VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED)); rb_define_const(c_connect, "DOMAIN_EVENT_RESUMED_UNPAUSED", INT2NUM(VIR_DOMAIN_EVENT_RESUMED_UNPAUSED)); rb_define_const(c_connect, "DOMAIN_EVENT_RESUMED_MIGRATED", INT2NUM(VIR_DOMAIN_EVENT_RESUMED_MIGRATED)); rb_define_const(c_connect, "DOMAIN_EVENT_STOPPED_SHUTDOWN", INT2NUM(VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN)); rb_define_const(c_connect, "DOMAIN_EVENT_STOPPED_DESTROYED", INT2NUM(VIR_DOMAIN_EVENT_STOPPED_DESTROYED)); rb_define_const(c_connect, "DOMAIN_EVENT_STOPPED_CRASHED", INT2NUM(VIR_DOMAIN_EVENT_STOPPED_CRASHED)); rb_define_const(c_connect, "DOMAIN_EVENT_STOPPED_MIGRATED", INT2NUM(VIR_DOMAIN_EVENT_STOPPED_MIGRATED)); rb_define_const(c_connect, "DOMAIN_EVENT_STOPPED_SAVED", INT2NUM(VIR_DOMAIN_EVENT_STOPPED_SAVED)); rb_define_const(c_connect, "DOMAIN_EVENT_STOPPED_FAILED", INT2NUM(VIR_DOMAIN_EVENT_STOPPED_FAILED)); rb_define_const(c_connect, "DOMAIN_EVENT_STARTED", INT2NUM(VIR_DOMAIN_EVENT_STARTED)); rb_define_const(c_connect, "DOMAIN_EVENT_SUSPENDED", INT2NUM(VIR_DOMAIN_EVENT_SUSPENDED)); rb_define_const(c_connect, "DOMAIN_EVENT_RESUMED", INT2NUM(VIR_DOMAIN_EVENT_RESUMED)); rb_define_const(c_connect, "DOMAIN_EVENT_STOPPED", INT2NUM(VIR_DOMAIN_EVENT_STOPPED)); rb_define_const(c_connect, "DOMAIN_EVENT_STARTED_FROM_SNAPSHOT", INT2NUM(VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT)); rb_define_const(c_connect, "DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT", INT2NUM(VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT)); rb_define_const(c_connect, "DOMAIN_EVENT_SUSPENDED_IOERROR", INT2NUM(VIR_DOMAIN_EVENT_SUSPENDED_IOERROR)); rb_define_const(c_connect, "DOMAIN_EVENT_SUSPENDED_WATCHDOG", INT2NUM(VIR_DOMAIN_EVENT_SUSPENDED_WATCHDOG)); rb_define_const(c_connect, "DOMAIN_EVENT_ID_WATCHDOG", INT2NUM(VIR_DOMAIN_EVENT_ID_WATCHDOG)); rb_define_const(c_connect, "DOMAIN_EVENT_WATCHDOG_NONE", INT2NUM(VIR_DOMAIN_EVENT_WATCHDOG_NONE)); rb_define_const(c_connect, "DOMAIN_EVENT_WATCHDOG_PAUSE", INT2NUM(VIR_DOMAIN_EVENT_WATCHDOG_PAUSE)); rb_define_const(c_connect, "DOMAIN_EVENT_WATCHDOG_RESET", INT2NUM(VIR_DOMAIN_EVENT_WATCHDOG_RESET)); rb_define_const(c_connect, "DOMAIN_EVENT_WATCHDOG_POWEROFF", INT2NUM(VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF)); rb_define_const(c_connect, "DOMAIN_EVENT_WATCHDOG_SHUTDOWN", INT2NUM(VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN)); rb_define_const(c_connect, "DOMAIN_EVENT_WATCHDOG_DEBUG", INT2NUM(VIR_DOMAIN_EVENT_WATCHDOG_DEBUG)); rb_define_const(c_connect, "DOMAIN_EVENT_ID_IO_ERROR", INT2NUM(VIR_DOMAIN_EVENT_ID_IO_ERROR)); rb_define_const(c_connect, "DOMAIN_EVENT_IO_ERROR_NONE", INT2NUM(VIR_DOMAIN_EVENT_IO_ERROR_NONE)); rb_define_const(c_connect, "DOMAIN_EVENT_IO_ERROR_PAUSE", INT2NUM(VIR_DOMAIN_EVENT_IO_ERROR_PAUSE)); rb_define_const(c_connect, "DOMAIN_EVENT_IO_ERROR_REPORT", INT2NUM(VIR_DOMAIN_EVENT_IO_ERROR_REPORT)); rb_define_const(c_connect, "DOMAIN_EVENT_ID_GRAPHICS", INT2NUM(VIR_DOMAIN_EVENT_ID_GRAPHICS)); rb_define_const(c_connect, "DOMAIN_EVENT_GRAPHICS_CONNECT", INT2NUM(VIR_DOMAIN_EVENT_GRAPHICS_CONNECT)); rb_define_const(c_connect, "DOMAIN_EVENT_GRAPHICS_INITIALIZE", INT2NUM(VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE)); rb_define_const(c_connect, "DOMAIN_EVENT_GRAPHICS_DISCONNECT", INT2NUM(VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT)); rb_define_const(c_connect, "DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4", INT2NUM(VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4)); rb_define_const(c_connect, "DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6", INT2NUM(VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6)); rb_define_const(c_connect, "DOMAIN_EVENT_ID_LIFECYCLE", INT2NUM(VIR_DOMAIN_EVENT_ID_LIFECYCLE)); rb_define_const(c_connect, "DOMAIN_EVENT_ID_REBOOT", INT2NUM(VIR_DOMAIN_EVENT_ID_REBOOT)); rb_define_const(c_connect, "DOMAIN_EVENT_ID_RTC_CHANGE", INT2NUM(VIR_DOMAIN_EVENT_ID_RTC_CHANGE)); rb_define_const(c_connect, "DOMAIN_EVENT_ID_IO_ERROR_REASON", INT2NUM(VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON)); rb_define_const(c_connect, "DOMAIN_EVENT_ID_CONTROL_ERROR", INT2NUM(VIR_DOMAIN_EVENT_ID_CONTROL_ERROR)); rb_define_const(c_connect, "DOMAIN_EVENT_SHUTDOWN", INT2NUM(VIR_DOMAIN_EVENT_SHUTDOWN)); rb_define_const(c_connect, "DOMAIN_EVENT_PMSUSPENDED", INT2NUM(VIR_DOMAIN_EVENT_PMSUSPENDED)); rb_define_const(c_connect, "DOMAIN_EVENT_CRASHED", INT2NUM(VIR_DOMAIN_EVENT_CRASHED)); rb_define_const(c_connect, "DOMAIN_EVENT_STARTED_WAKEUP", INT2NUM(VIR_DOMAIN_EVENT_STARTED_WAKEUP)); rb_define_const(c_connect, "DOMAIN_EVENT_SUSPENDED_RESTORED", INT2NUM(VIR_DOMAIN_EVENT_SUSPENDED_RESTORED)); rb_define_const(c_connect, "DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT", INT2NUM(VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT)); rb_define_const(c_connect, "DOMAIN_EVENT_SUSPENDED_API_ERROR", INT2NUM(VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR)); rb_define_const(c_connect, "DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT", INT2NUM(VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT)); rb_define_const(c_connect, "DOMAIN_EVENT_SHUTDOWN_FINISHED", INT2NUM(VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED)); rb_define_const(c_connect, "DOMAIN_EVENT_PMSUSPENDED_MEMORY", INT2NUM(VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY)); rb_define_const(c_connect, "DOMAIN_EVENT_PMSUSPENDED_DISK", INT2NUM(VIR_DOMAIN_EVENT_PMSUSPENDED_DISK)); rb_define_const(c_connect, "DOMAIN_EVENT_CRASHED_PANICKED", INT2NUM(VIR_DOMAIN_EVENT_CRASHED_PANICKED)); rb_define_const(c_connect, "DOMAIN_EVENT_GRAPHICS_ADDRESS_UNIX", INT2NUM(VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_UNIX)); rb_define_method(c_connect, "domain_event_register", libvirt_connect_domain_event_register, -1); rb_define_method(c_connect, "domain_event_deregister", libvirt_connect_domain_event_deregister, 0); rb_define_method(c_connect, "domain_event_register_any", libvirt_connect_domain_event_register_any, -1); rb_define_method(c_connect, "domain_event_deregister_any", libvirt_connect_domain_event_deregister_any, 1); /* Domain creation/lookup */ rb_define_method(c_connect, "num_of_domains", libvirt_connect_num_of_domains, 0); rb_define_method(c_connect, "list_domains", libvirt_connect_list_domains, 0); rb_define_method(c_connect, "num_of_defined_domains", libvirt_connect_num_of_defined_domains, 0); rb_define_method(c_connect, "list_defined_domains", libvirt_connect_list_defined_domains, 0); rb_define_method(c_connect, "create_domain_linux", libvirt_connect_create_linux, -1); rb_define_method(c_connect, "create_domain_xml", libvirt_connect_create_domain_xml, -1); rb_define_method(c_connect, "lookup_domain_by_name", libvirt_connect_lookup_domain_by_name, 1); rb_define_method(c_connect, "lookup_domain_by_id", libvirt_connect_lookup_domain_by_id, 1); rb_define_method(c_connect, "lookup_domain_by_uuid", libvirt_connect_lookup_domain_by_uuid, 1); rb_define_const(c_connect, "DOMAIN_DEFINE_VALIDATE", INT2NUM(VIR_DOMAIN_DEFINE_VALIDATE)); rb_define_method(c_connect, "define_domain_xml", libvirt_connect_define_domain_xml, -1); rb_define_method(c_connect, "domain_xml_from_native", libvirt_connect_domain_xml_from_native, -1); rb_define_method(c_connect, "domain_xml_to_native", libvirt_connect_domain_xml_to_native, -1); /* Interface lookup/creation methods */ rb_define_method(c_connect, "num_of_interfaces", libvirt_connect_num_of_interfaces, 0); rb_define_method(c_connect, "list_interfaces", libvirt_connect_list_interfaces, 0); rb_define_method(c_connect, "num_of_defined_interfaces", libvirt_connect_num_of_defined_interfaces, 0); rb_define_method(c_connect, "list_defined_interfaces", libvirt_connect_list_defined_interfaces, 0); rb_define_method(c_connect, "lookup_interface_by_name", libvirt_connect_lookup_interface_by_name, 1); rb_define_method(c_connect, "lookup_interface_by_mac", libvirt_connect_lookup_interface_by_mac, 1); rb_define_method(c_connect, "define_interface_xml", libvirt_connect_define_interface_xml, -1); /* Network lookup/creation methods */ rb_define_method(c_connect, "num_of_networks", libvirt_connect_num_of_networks, 0); rb_define_method(c_connect, "list_networks", libvirt_connect_list_networks, 0); rb_define_method(c_connect, "num_of_defined_networks", libvirt_connect_num_of_defined_networks, 0); rb_define_method(c_connect, "list_defined_networks", libvirt_connect_list_defined_networks, 0); rb_define_method(c_connect, "lookup_network_by_name", libvirt_connect_lookup_network_by_name, 1); rb_define_method(c_connect, "lookup_network_by_uuid", libvirt_connect_lookup_network_by_uuid, 1); rb_define_method(c_connect, "create_network_xml", libvirt_connect_create_network_xml, 1); rb_define_method(c_connect, "define_network_xml", libvirt_connect_define_network_xml, 1); /* Node device lookup/creation methods */ rb_define_method(c_connect, "num_of_nodedevices", libvirt_connect_num_of_nodedevices, -1); rb_define_method(c_connect, "list_nodedevices", libvirt_connect_list_nodedevices, -1); rb_define_method(c_connect, "lookup_nodedevice_by_name", libvirt_connect_lookup_nodedevice_by_name, 1); rb_define_method(c_connect, "create_nodedevice_xml", libvirt_connect_create_nodedevice_xml, -1); /* NWFilter lookup/creation methods */ rb_define_method(c_connect, "num_of_nwfilters", libvirt_connect_num_of_nwfilters, 0); rb_define_method(c_connect, "list_nwfilters", libvirt_connect_list_nwfilters, 0); rb_define_method(c_connect, "lookup_nwfilter_by_name", libvirt_connect_lookup_nwfilter_by_name, 1); rb_define_method(c_connect, "lookup_nwfilter_by_uuid", libvirt_connect_lookup_nwfilter_by_uuid, 1); rb_define_method(c_connect, "define_nwfilter_xml", libvirt_connect_define_nwfilter_xml, 1); /* Secret lookup/creation methods */ rb_define_method(c_connect, "num_of_secrets", libvirt_connect_num_of_secrets, 0); rb_define_method(c_connect, "list_secrets", libvirt_connect_list_secrets, 0); rb_define_method(c_connect, "lookup_secret_by_uuid", libvirt_connect_lookup_secret_by_uuid, 1); rb_define_method(c_connect, "lookup_secret_by_usage", libvirt_connect_lookup_secret_by_usage, 2); rb_define_method(c_connect, "define_secret_xml", libvirt_connect_define_secret_xml, -1); /* StoragePool lookup/creation methods */ rb_define_method(c_connect, "num_of_storage_pools", libvirt_connect_num_of_storage_pools, 0); rb_define_method(c_connect, "list_storage_pools", libvirt_connect_list_storage_pools, 0); rb_define_method(c_connect, "num_of_defined_storage_pools", libvirt_connect_num_of_defined_storage_pools, 0); rb_define_method(c_connect, "list_defined_storage_pools", libvirt_connect_list_defined_storage_pools, 0); rb_define_method(c_connect, "lookup_storage_pool_by_name", libvirt_connect_lookup_pool_by_name, 1); rb_define_method(c_connect, "lookup_storage_pool_by_uuid", libvirt_connect_lookup_pool_by_uuid, 1); rb_define_method(c_connect, "create_storage_pool_xml", libvirt_connect_create_pool_xml, -1); rb_define_method(c_connect, "define_storage_pool_xml", libvirt_connect_define_pool_xml, -1); rb_define_method(c_connect, "discover_storage_pool_sources", libvirt_connect_find_storage_pool_sources, -1); rb_define_method(c_connect, "sys_info", libvirt_connect_sys_info, -1); rb_define_method(c_connect, "stream", libvirt_connect_stream, -1); rb_define_method(c_connect, "interface_change_begin", libvirt_connect_interface_change_begin, -1); rb_define_method(c_connect, "interface_change_commit", libvirt_connect_interface_change_commit, -1); rb_define_method(c_connect, "interface_change_rollback", libvirt_connect_interface_change_rollback, -1); rb_define_method(c_connect, "node_cpu_stats", libvirt_connect_node_cpu_stats, -1); rb_define_const(c_connect, "NODE_CPU_STATS_ALL_CPUS", INT2NUM(VIR_NODE_CPU_STATS_ALL_CPUS)); rb_define_method(c_connect, "node_memory_stats", libvirt_connect_node_memory_stats, -1); rb_define_const(c_connect, "NODE_MEMORY_STATS_ALL_CELLS", INT2NUM(VIR_NODE_MEMORY_STATS_ALL_CELLS)); rb_define_method(c_connect, "save_image_xml_desc", libvirt_connect_save_image_xml_desc, -1); rb_define_method(c_connect, "define_save_image_xml", libvirt_connect_define_save_image_xml, -1); rb_define_const(c_connect, "NODE_SUSPEND_TARGET_MEM", INT2NUM(VIR_NODE_SUSPEND_TARGET_MEM)); rb_define_const(c_connect, "NODE_SUSPEND_TARGET_DISK", INT2NUM(VIR_NODE_SUSPEND_TARGET_DISK)); rb_define_const(c_connect, "NODE_SUSPEND_TARGET_HYBRID", INT2NUM(VIR_NODE_SUSPEND_TARGET_HYBRID)); rb_define_method(c_connect, "node_suspend_for_duration", libvirt_connect_node_suspend_for_duration, -1); rb_define_method(c_connect, "node_memory_parameters", libvirt_connect_node_memory_parameters, -1); rb_define_method(c_connect, "node_memory_parameters=", libvirt_connect_node_memory_parameters_equal, 1); rb_define_method(c_connect, "node_cpu_map", libvirt_connect_node_cpu_map, -1); rb_define_alias(c_connect, "node_get_cpu_map", "node_cpu_map"); rb_define_method(c_connect, "set_keepalive", libvirt_connect_set_keepalive, 2); rb_define_method(c_connect, "keepalive=", libvirt_connect_keepalive_equal, 1); rb_define_const(c_connect, "LIST_DOMAINS_ACTIVE", INT2NUM(VIR_CONNECT_LIST_DOMAINS_ACTIVE)); rb_define_const(c_connect, "LIST_DOMAINS_INACTIVE", INT2NUM(VIR_CONNECT_LIST_DOMAINS_INACTIVE)); rb_define_const(c_connect, "LIST_DOMAINS_PERSISTENT", INT2NUM(VIR_CONNECT_LIST_DOMAINS_PERSISTENT)); rb_define_const(c_connect, "LIST_DOMAINS_TRANSIENT", INT2NUM(VIR_CONNECT_LIST_DOMAINS_TRANSIENT)); rb_define_const(c_connect, "LIST_DOMAINS_RUNNING", INT2NUM(VIR_CONNECT_LIST_DOMAINS_RUNNING)); rb_define_const(c_connect, "LIST_DOMAINS_PAUSED", INT2NUM(VIR_CONNECT_LIST_DOMAINS_PAUSED)); rb_define_const(c_connect, "LIST_DOMAINS_SHUTOFF", INT2NUM(VIR_CONNECT_LIST_DOMAINS_SHUTOFF)); rb_define_const(c_connect, "LIST_DOMAINS_OTHER", INT2NUM(VIR_CONNECT_LIST_DOMAINS_OTHER)); rb_define_const(c_connect, "LIST_DOMAINS_MANAGEDSAVE", INT2NUM(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE)); rb_define_const(c_connect, "LIST_DOMAINS_NO_MANAGEDSAVE", INT2NUM(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE)); rb_define_const(c_connect, "LIST_DOMAINS_AUTOSTART", INT2NUM(VIR_CONNECT_LIST_DOMAINS_AUTOSTART)); rb_define_const(c_connect, "LIST_DOMAINS_NO_AUTOSTART", INT2NUM(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)); rb_define_const(c_connect, "LIST_DOMAINS_HAS_SNAPSHOT", INT2NUM(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT)); rb_define_const(c_connect, "LIST_DOMAINS_NO_SNAPSHOT", INT2NUM(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT)); rb_define_method(c_connect, "list_all_domains", libvirt_connect_list_all_domains, -1); rb_define_const(c_connect, "LIST_NETWORKS_ACTIVE", INT2NUM(VIR_CONNECT_LIST_NETWORKS_ACTIVE)); rb_define_const(c_connect, "LIST_NETWORKS_INACTIVE", INT2NUM(VIR_CONNECT_LIST_NETWORKS_INACTIVE)); rb_define_const(c_connect, "LIST_NETWORKS_PERSISTENT", INT2NUM(VIR_CONNECT_LIST_NETWORKS_PERSISTENT)); rb_define_const(c_connect, "LIST_NETWORKS_TRANSIENT", INT2NUM(VIR_CONNECT_LIST_NETWORKS_TRANSIENT)); rb_define_const(c_connect, "LIST_NETWORKS_AUTOSTART", INT2NUM(VIR_CONNECT_LIST_NETWORKS_AUTOSTART)); rb_define_const(c_connect, "LIST_NETWORKS_NO_AUTOSTART", INT2NUM(VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART)); rb_define_method(c_connect, "list_all_networks", libvirt_connect_list_all_networks, -1); rb_define_const(c_connect, "LIST_INTERFACES_INACTIVE", INT2NUM(VIR_CONNECT_LIST_INTERFACES_INACTIVE)); rb_define_const(c_connect, "LIST_INTERFACES_ACTIVE", INT2NUM(VIR_CONNECT_LIST_INTERFACES_ACTIVE)); rb_define_method(c_connect, "list_all_interfaces", libvirt_connect_list_all_interfaces, -1); rb_define_const(c_connect, "LIST_SECRETS_EPHEMERAL", INT2NUM(VIR_CONNECT_LIST_SECRETS_EPHEMERAL)); rb_define_const(c_connect, "LIST_SECRETS_NO_EPHEMERAL", INT2NUM(VIR_CONNECT_LIST_SECRETS_NO_EPHEMERAL)); rb_define_const(c_connect, "LIST_SECRETS_PRIVATE", INT2NUM(VIR_CONNECT_LIST_SECRETS_PRIVATE)); rb_define_const(c_connect, "LIST_SECRETS_NO_PRIVATE", INT2NUM(VIR_CONNECT_LIST_SECRETS_NO_PRIVATE)); rb_define_method(c_connect, "list_all_secrets", libvirt_connect_list_all_secrets, -1); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_SYSTEM", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_PCI_DEV", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_USB_DEV", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_USB_INTERFACE", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_NET", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_SCSI_HOST", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_SCSI_TARGET", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_SCSI", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_STORAGE", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_FC_HOST", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_VPORTS", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS)); rb_define_const(c_connect, "LIST_NODE_DEVICES_CAP_SCSI_GENERIC", INT2NUM(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC)); rb_define_method(c_connect, "list_all_nodedevices", libvirt_connect_list_all_nodedevices, -1); rb_define_const(c_connect, "LIST_STORAGE_POOLS_INACTIVE", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_ACTIVE", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_PERSISTENT", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_TRANSIENT", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_AUTOSTART", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_NO_AUTOSTART", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_DIR", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_DIR)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_FS", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_FS)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_NETFS", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_NETFS)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_LOGICAL", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_DISK", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_DISK)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_ISCSI", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_SCSI", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_SCSI)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_MPATH", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_MPATH)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_RBD", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_RBD)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_SHEEPDOG", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG)); rb_define_method(c_connect, "list_all_storage_pools", libvirt_connect_list_all_storage_pools, -1); rb_define_const(c_connect, "LIST_STORAGE_POOLS_GLUSTER", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER)); rb_define_const(c_connect, "LIST_STORAGE_POOLS_ZFS", INT2NUM(VIR_CONNECT_LIST_STORAGE_POOLS_ZFS)); rb_define_method(c_connect, "list_all_nwfilters", libvirt_connect_list_all_nwfilters, -1); rb_define_method(c_connect, "alive?", libvirt_connect_alive_p, 0); rb_define_method(c_connect, "create_domain_xml_with_files", libvirt_connect_create_domain_xml_with_files, -1); rb_define_method(c_connect, "qemu_attach", libvirt_connect_qemu_attach, -1); rb_define_method(c_connect, "cpu_model_names", libvirt_connect_cpu_model_names, -1); rb_define_const(c_connect, "NODE_ALLOC_PAGES_ADD", INT2NUM(VIR_NODE_ALLOC_PAGES_ADD)); rb_define_const(c_connect, "NODE_ALLOC_PAGES_SET", INT2NUM(VIR_NODE_ALLOC_PAGES_SET)); rb_define_method(c_connect, "node_alloc_pages", libvirt_connect_node_alloc_pages, -1); rb_define_method(c_connect, "domain_capabilities", libvirt_connect_domain_capabilities, -1); rb_define_method(c_connect, "node_free_pages", libvirt_connect_node_free_pages, -1); } ruby-libvirt-0.8.4/ext/libvirt/interface.c0000644000175000017500000001437514641546211020700 0ustar abolognaabologna/* * interface.c: virInterface methods * * Copyright (C) 2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "common.h" #include "connect.h" #include "extconf.h" static VALUE c_interface; static void interface_free(void *i) { ruby_libvirt_free_struct(Interface, i); } static virInterfacePtr interface_get(VALUE i) { ruby_libvirt_get_struct(Interface, i); } VALUE ruby_libvirt_interface_new(virInterfacePtr i, VALUE conn) { return ruby_libvirt_new_class(c_interface, i, conn, interface_free); } /* * call-seq: * interface.undefine -> nil * * Call virInterfaceUndefine[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceUndefine] * to undefine this interface. */ static VALUE libvirt_interface_undefine(VALUE i) { ruby_libvirt_generate_call_nil(virInterfaceUndefine, ruby_libvirt_connect_get(i), interface_get(i)); } /* * call-seq: * interface.create(flags=0) -> nil * * Call virInterfaceCreate[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceCreate] * to start this interface. */ static VALUE libvirt_interface_create(int argc, VALUE *argv, VALUE i) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virInterfaceCreate, ruby_libvirt_connect_get(i), interface_get(i), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * interface.destroy(flags=0) -> nil * * Call virInterfaceDestroy[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDestroy] * to shutdown this interface. */ static VALUE libvirt_interface_destroy(int argc, VALUE *argv, VALUE i) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virInterfaceDestroy, ruby_libvirt_connect_get(i), interface_get(i), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * interface.active? -> [true|false] * * Call virInterfaceIsActive[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceIsActive] * to determine if this interface is currently active. */ static VALUE libvirt_interface_active_p(VALUE p) { ruby_libvirt_generate_call_truefalse(virInterfaceIsActive, ruby_libvirt_connect_get(p), interface_get(p)); } /* * call-seq: * interface.name -> String * * Call virInterfaceGetName[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetName] * to retrieve the name of this interface. */ static VALUE libvirt_interface_name(VALUE i) { ruby_libvirt_generate_call_string(virInterfaceGetName, ruby_libvirt_connect_get(i), 0, interface_get(i)); } /* * call-seq: * interface.mac -> String * * Call virInterfaceGetMACString[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetMACString] * to retrieve the MAC address of this interface. */ static VALUE libvirt_interface_mac(VALUE i) { ruby_libvirt_generate_call_string(virInterfaceGetMACString, ruby_libvirt_connect_get(i), 0, interface_get(i)); } /* * call-seq: * interface.xml_desc -> String * * Call virInterfaceGetXMLDesc[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetXMLDesc] * to retrieve the XML of this interface. */ static VALUE libvirt_interface_xml_desc(int argc, VALUE *argv, VALUE i) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virInterfaceGetXMLDesc, ruby_libvirt_connect_get(i), 1, interface_get(i), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * interface.free -> nil * * Call virInterfaceFree[https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceFree] * to free this interface. The object will no longer be valid after this call. */ static VALUE libvirt_interface_free(VALUE i) { ruby_libvirt_generate_call_free(Interface, i); } /* * Class Libvirt::Interface */ void ruby_libvirt_interface_init(void) { c_interface = rb_define_class_under(m_libvirt, "Interface", rb_cObject); rb_undef_alloc_func(c_interface); rb_define_singleton_method(c_interface, "new", ruby_libvirt_new_not_allowed, -1); rb_define_const(c_interface, "XML_INACTIVE", INT2NUM(VIR_INTERFACE_XML_INACTIVE)); rb_define_attr(c_interface, "connection", 1, 0); /* Interface object methods */ rb_define_method(c_interface, "name", libvirt_interface_name, 0); rb_define_method(c_interface, "mac", libvirt_interface_mac, 0); rb_define_method(c_interface, "xml_desc", libvirt_interface_xml_desc, -1); rb_define_method(c_interface, "undefine", libvirt_interface_undefine, 0); rb_define_method(c_interface, "create", libvirt_interface_create, -1); rb_define_method(c_interface, "destroy", libvirt_interface_destroy, -1); rb_define_method(c_interface, "free", libvirt_interface_free, 0); rb_define_method(c_interface, "active?", libvirt_interface_active_p, 0); } ruby-libvirt-0.8.4/ext/libvirt/nodedevice.h0000644000175000017500000000024014557177263021051 0ustar abolognaabologna#ifndef NODEDEVICE_H #define NODEDEVICE_H void ruby_libvirt_nodedevice_init(void); VALUE ruby_libvirt_nodedevice_new(virNodeDevicePtr n, VALUE conn); #endif ruby-libvirt-0.8.4/ext/libvirt/network.h0000644000175000017500000000022114557177263020434 0ustar abolognaabologna#ifndef NETWORK_H #define NETWORK_H void ruby_libvirt_network_init(void); VALUE ruby_libvirt_network_new(virNetworkPtr n, VALUE conn); #endif ruby-libvirt-0.8.4/ext/libvirt/domain.h0000644000175000017500000000034214557177263020216 0ustar abolognaabologna#ifndef DOMAIN_H #define DOMAIN_H void ruby_libvirt_domain_init(void); VALUE ruby_libvirt_domain_new(virDomainPtr d, VALUE conn); virDomainPtr ruby_libvirt_domain_get(VALUE s); extern VALUE c_domain_security_label; #endif ruby-libvirt-0.8.4/ext/libvirt/storage.h0000644000175000017500000000012314557177263020410 0ustar abolognaabologna#ifndef STORAGE_H #define STORAGE_H void ruby_libvirt_storage_init(void); #endif ruby-libvirt-0.8.4/ext/libvirt/interface.h0000644000175000017500000000023314565714675020711 0ustar abolognaabologna#ifndef INTERFACE_H #define INTERFACE_H void ruby_libvirt_interface_init(void); VALUE ruby_libvirt_interface_new(virInterfacePtr i, VALUE conn); #endif ruby-libvirt-0.8.4/ext/libvirt/stream.c0000644000175000017500000003273214641546211020230 0ustar abolognaabologna/* * stream.c: virStream methods * * Copyright (C) 2007,2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "common.h" #include "connect.h" #include "extconf.h" static VALUE c_stream; static void stream_free(void *s) { ruby_libvirt_free_struct(Stream, s); } virStreamPtr ruby_libvirt_stream_get(VALUE s) { ruby_libvirt_get_struct(Stream, s); } VALUE ruby_libvirt_stream_new(virStreamPtr s, VALUE conn) { return ruby_libvirt_new_class(c_stream, s, conn, stream_free); } /* * call-seq: * stream.send(buffer) -> Fixnum * * Call virStreamSend[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamSend] * to send the data in buffer out to the stream. The return value is the * number of bytes sent, which may be less than the size of the buffer. If * an error occurred, -1 is returned. If the transmit buffers are full and the * stream is marked non-blocking, returns -2. */ static VALUE libvirt_stream_send(VALUE s, VALUE buffer) { int ret; StringValue(buffer); ret = virStreamSend(ruby_libvirt_stream_get(s), RSTRING_PTR(buffer), RSTRING_LEN(buffer)); ruby_libvirt_raise_error_if(ret == -1, e_RetrieveError, "virStreamSend", ruby_libvirt_connect_get(s)); return INT2NUM(ret); } /* * call-seq: * stream.recv(bytes) -> [return_value, data] * * Call virStreamRecv[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamRecv] * to receive up to bytes amount of data from the stream. The return is an * array with two elements; the return code from the virStreamRecv call and * the data (as a String) read from the stream. If an error occurred, the * return_value is set to -1. If there is no data pending and the stream is * marked as non-blocking, return_value is set to -2. */ static VALUE libvirt_stream_recv(VALUE s, VALUE bytes) { char *data; int ret; VALUE result; data = alloca(sizeof(char) * NUM2INT(bytes)); ret = virStreamRecv(ruby_libvirt_stream_get(s), data, NUM2INT(bytes)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virStreamRecv", ruby_libvirt_connect_get(s)); result = rb_ary_new2(2); rb_ary_store(result, 0, INT2NUM(ret)); rb_ary_store(result, 1, rb_str_new(data, ret)); return result; } static int internal_sendall(virStreamPtr RUBY_LIBVIRT_UNUSED(st), char *data, size_t nbytes, void *opaque) { VALUE result, retcode, buffer; result = rb_yield_values(2, (VALUE)opaque, INT2NUM(nbytes)); if (TYPE(result) != T_ARRAY) { rb_raise(rb_eTypeError, "wrong type (expected Array)"); } if (RARRAY_LEN(result) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(result)); } retcode = rb_ary_entry(result, 0); buffer = rb_ary_entry(result, 1); if (NUM2INT(retcode) < 0) { return NUM2INT(retcode); } StringValue(buffer); if (RSTRING_LEN(buffer) > (int)nbytes) { rb_raise(rb_eArgError, "asked for %zd bytes, block returned %ld", nbytes, RSTRING_LEN(buffer)); } memcpy(data, RSTRING_PTR(buffer), RSTRING_LEN(buffer)); return RSTRING_LEN(buffer); } /* * call-seq: * stream.sendall(opaque=nil){|opaque, nbytes| send block} -> nil * * Call virStreamSendAll[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamSendAll] * to send the entire data stream. The send block is required and is executed * one or more times to send data. Each invocation of the send block yields * the opaque data passed into the initial call and the number of bytes this * iteration is prepared to handle. The send block should return an array of * 2 elements; the first element should be the return code from the block * (-1 for error, 0 otherwise), and the second element should be the data * that the block prepared to send. */ static VALUE libvirt_stream_sendall(int argc, VALUE *argv, VALUE s) { VALUE opaque = RUBY_Qnil; int ret; if (!rb_block_given_p()) { rb_raise(rb_eRuntimeError, "A block must be provided"); } rb_scan_args(argc, argv, "01", &opaque); ret = virStreamSendAll(ruby_libvirt_stream_get(s), internal_sendall, (void *)opaque); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virStreamSendAll", ruby_libvirt_connect_get(s)); return Qnil; } static int internal_recvall(virStreamPtr RUBY_LIBVIRT_UNUSED(st), const char *buf, size_t nbytes, void *opaque) { VALUE result; result = rb_yield_values(2, rb_str_new(buf, nbytes), (VALUE)opaque); if (TYPE(result) != T_FIXNUM) { rb_raise(rb_eArgError, "wrong type (expected an integer)"); } return NUM2INT(result); } /* * call-seq: * stream.recvall(opaque){|data, opaque| receive block} -> nil * * Call virStreamRecvAll[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamRecvAll] * to receive the entire data stream. The receive block is required and is * called one or more times to receive data. Each invocation of the receive * block yields the data received and the opaque data passed into the initial * call. The block should return -1 if an error occurred and 0 otherwise. */ static VALUE libvirt_stream_recvall(int argc, VALUE *argv, VALUE s) { VALUE opaque = RUBY_Qnil; int ret; if (!rb_block_given_p()) { rb_raise(rb_eRuntimeError, "A block must be provided"); } rb_scan_args(argc, argv, "01", &opaque); ret = virStreamRecvAll(ruby_libvirt_stream_get(s), internal_recvall, (void *)opaque); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virStreamRecvAll", ruby_libvirt_connect_get(s)); return Qnil; } static void stream_event_callback(virStreamPtr st, int events, void *opaque) { VALUE passthrough = (VALUE)opaque; VALUE cb, cb_opaque, news, s; if (TYPE(passthrough) != T_ARRAY) { rb_raise(rb_eTypeError, "wrong domain event lifecycle callback argument type (expected Array)"); } if (RARRAY_LEN(passthrough) != 3) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 3)", RARRAY_LEN(passthrough)); } cb = rb_ary_entry(passthrough, 0); cb_opaque = rb_ary_entry(passthrough, 1); s = rb_ary_entry(passthrough, 2); news = ruby_libvirt_stream_new(st, ruby_libvirt_conn_attr(s)); if (strcmp(rb_obj_classname(cb), "Symbol") == 0) { rb_funcall(rb_class_of(cb), rb_to_id(cb), 3, news, INT2NUM(events), cb_opaque); } else if (strcmp(rb_obj_classname(cb), "Proc") == 0) { rb_funcall(cb, rb_intern("call"), 3, news, INT2NUM(events), cb_opaque); } else { rb_raise(rb_eTypeError, "wrong stream event callback (expected Symbol or Proc)"); } } /* * call-seq: * stream.event_add_callback(events, callback, opaque=nil) -> nil * * Call virStreamEventAddCallback[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamEventAddCallback] * to register a callback to be notified when a stream becomes readable or * writeable. The events parameter is an integer representing the events the * user is interested in; it should be one or more of EVENT_READABLE, * EVENT_WRITABLE, EVENT_ERROR, and EVENT_HANGUP, ORed together. The callback * can either be a Symbol (that is the name of a method to callback) or a Proc. * The callback should accept 3 parameters: a pointer to the Stream object * itself, the integer that represents the events that actually occurred, and * an opaque pointer that was (optionally) passed into * stream.event_add_callback to begin with. */ static VALUE libvirt_stream_event_add_callback(int argc, VALUE *argv, VALUE s) { VALUE events = RUBY_Qnil, callback = RUBY_Qnil, opaque = RUBY_Qnil, passthrough; int ret; rb_scan_args(argc, argv, "21", &events, &callback, &opaque); if (!ruby_libvirt_is_symbol_or_proc(callback)) { rb_raise(rb_eTypeError, "wrong argument type (expected Symbol or Proc)"); } passthrough = rb_ary_new2(3); rb_ary_store(passthrough, 0, callback); rb_ary_store(passthrough, 1, opaque); rb_ary_store(passthrough, 2, s); ret = virStreamEventAddCallback(ruby_libvirt_stream_get(s), NUM2INT(events), stream_event_callback, (void *)passthrough, NULL); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virStreamEventAddCallback", ruby_libvirt_connect_get(s)); return Qnil; } /* * call-seq: * stream.event_update_callback(events) -> nil * * Call virStreamEventUpdateCallback[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamEventUpdateCallback] * to change the events that the event callback is looking for. The events * parameter is an integer representing the events the user is interested in; * it should be one or more of EVENT_READABLE, EVENT_WRITABLE, EVENT_ERROR, * and EVENT_HANGUP, ORed together. */ static VALUE libvirt_stream_event_update_callback(VALUE s, VALUE events) { ruby_libvirt_generate_call_nil(virStreamEventUpdateCallback, ruby_libvirt_connect_get(s), ruby_libvirt_stream_get(s), NUM2INT(events)); } /* * call-seq: * stream.event_remove_callback -> nil * * Call virStreamEventRemoveCallback[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamEventRemoveCallback] * to remove the event callback currently registered to this stream. */ static VALUE libvirt_stream_event_remove_callback(VALUE s) { ruby_libvirt_generate_call_nil(virStreamEventRemoveCallback, ruby_libvirt_connect_get(s), ruby_libvirt_stream_get(s)); } /* * call-seq: * stream.finish -> nil * * Call virStreamFinish[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamFinish] * to finish this stream. Finish is typically used when the stream is no * longer needed and needs to be cleaned up. */ static VALUE libvirt_stream_finish(VALUE s) { ruby_libvirt_generate_call_nil(virStreamFinish, ruby_libvirt_connect_get(s), ruby_libvirt_stream_get(s)); } /* * call-seq: * stream.abort -> nil * * Call virStreamAbort[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamAbort] * to abort this stream. Abort is typically used when something on the stream * has failed, and the stream needs to be cleaned up. */ static VALUE libvirt_stream_abort(VALUE s) { ruby_libvirt_generate_call_nil(virStreamAbort, ruby_libvirt_connect_get(s), ruby_libvirt_stream_get(s)); } /* * call-seq: * stream.free -> nil * * Call virStreamFree[https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamFree] * to free this stream. The object will no longer be valid after this call. */ static VALUE libvirt_stream_free(VALUE s) { ruby_libvirt_generate_call_free(Stream, s); } /* * Class Libvirt::Stream */ void ruby_libvirt_stream_init(void) { c_stream = rb_define_class_under(m_libvirt, "Stream", rb_cObject); rb_undef_alloc_func(c_stream); rb_define_singleton_method(c_stream, "new", ruby_libvirt_new_not_allowed, -1); rb_define_attr(c_stream, "connection", 1, 0); rb_define_const(c_stream, "NONBLOCK", INT2NUM(VIR_STREAM_NONBLOCK)); rb_define_const(c_stream, "EVENT_READABLE", INT2NUM(VIR_STREAM_EVENT_READABLE)); rb_define_const(c_stream, "EVENT_WRITABLE", INT2NUM(VIR_STREAM_EVENT_WRITABLE)); rb_define_const(c_stream, "EVENT_ERROR", INT2NUM(VIR_STREAM_EVENT_ERROR)); rb_define_const(c_stream, "EVENT_HANGUP", INT2NUM(VIR_STREAM_EVENT_HANGUP)); rb_define_method(c_stream, "send", libvirt_stream_send, 1); rb_define_method(c_stream, "recv", libvirt_stream_recv, 1); rb_define_method(c_stream, "sendall", libvirt_stream_sendall, -1); rb_define_method(c_stream, "recvall", libvirt_stream_recvall, -1); rb_define_method(c_stream, "event_add_callback", libvirt_stream_event_add_callback, -1); rb_define_method(c_stream, "event_update_callback", libvirt_stream_event_update_callback, 1); rb_define_method(c_stream, "event_remove_callback", libvirt_stream_event_remove_callback, 0); rb_define_method(c_stream, "finish", libvirt_stream_finish, 0); rb_define_method(c_stream, "abort", libvirt_stream_abort, 0); rb_define_method(c_stream, "free", libvirt_stream_free, 0); } ruby-libvirt-0.8.4/ext/libvirt/nodedevice.c0000644000175000017500000002253614641546211021043 0ustar abolognaabologna/* * nodedevice.c: virNodeDevice methods * * Copyright (C) 2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "common.h" #include "connect.h" #include "extconf.h" static VALUE c_nodedevice; static void nodedevice_free(void *s) { ruby_libvirt_free_struct(NodeDevice, s); } static virNodeDevicePtr nodedevice_get(VALUE n) { ruby_libvirt_get_struct(NodeDevice, n); } VALUE ruby_libvirt_nodedevice_new(virNodeDevicePtr n, VALUE conn) { return ruby_libvirt_new_class(c_nodedevice, n, conn, nodedevice_free); } /* * call-seq: * nodedevice.name -> String * * Call virNodeDeviceGetName[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetName] * to retrieve the name of the node device. */ static VALUE libvirt_nodedevice_name(VALUE c) { ruby_libvirt_generate_call_string(virNodeDeviceGetName, ruby_libvirt_connect_get(c), 0, nodedevice_get(c)); } /* * call-seq: * nodedevice.parent -> String * * Call virNodeDeviceGetParent[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetParent] * to retrieve the parent of the node device. */ static VALUE libvirt_nodedevice_parent(VALUE c) { /* unfortunately we can't use ruby_libvirt_generate_call_string() here * because virNodeDeviceGetParent() returns NULL as a valid value (when this * device has no parent). Hand-code it instead */ const char *str; str = virNodeDeviceGetParent(nodedevice_get(c)); if (str == NULL) { return Qnil; } else { return rb_str_new2(str); } } /* * call-seq: * nodedevice.num_of_caps -> Fixnum * * Call virNodeDeviceNumOfCaps[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceNumOfCaps] * to retrieve the number of capabilities of the node device. */ static VALUE libvirt_nodedevice_num_of_caps(VALUE c) { ruby_libvirt_generate_call_int(virNodeDeviceNumOfCaps, ruby_libvirt_connect_get(c), nodedevice_get(c)); } /* * call-seq: * nodedevice.list_caps -> list * * Call virNodeDeviceListCaps[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceListCaps] * to retrieve a list of capabilities of the node device. */ static VALUE libvirt_nodedevice_list_caps(VALUE c) { int r, num; char **names; num = virNodeDeviceNumOfCaps(nodedevice_get(c)); ruby_libvirt_raise_error_if(num < 0, e_RetrieveError, "virNodeDeviceNumOfCaps", ruby_libvirt_connect_get(c)); if (num == 0) { /* if num is 0, don't call virNodeDeviceListCaps function */ return rb_ary_new2(num); } names = alloca(sizeof(char *) * num); r = virNodeDeviceListCaps(nodedevice_get(c), names, num); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virNodeDeviceListCaps", ruby_libvirt_connect_get(c)); return ruby_libvirt_generate_list(r, names); } /* * call-seq: * nodedevice.xml_desc(flags=0) -> String * * Call virNodeDeviceGetXMLDesc[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetXMLDesc] * to retrieve the XML for the node device. */ static VALUE libvirt_nodedevice_xml_desc(int argc, VALUE *argv, VALUE n) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virNodeDeviceGetXMLDesc, ruby_libvirt_connect_get(n), 1, nodedevice_get(n), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * nodedevice.detach(driver=nil, flags=0) -> nil * * Call virNodeDeviceDettach[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDettach] * to detach the node device from the node. */ static VALUE libvirt_nodedevice_detach(int argc, VALUE *argv, VALUE n) { VALUE driver = RUBY_Qnil, flags = RUBY_Qnil; rb_scan_args(argc, argv, "02", &driver, &flags); if (ruby_libvirt_value_to_uint(flags) != 0 || ruby_libvirt_get_cstring_or_null(driver) != NULL) { ruby_libvirt_generate_call_nil(virNodeDeviceDetachFlags, ruby_libvirt_connect_get(n), nodedevice_get(n), ruby_libvirt_get_cstring_or_null(driver), ruby_libvirt_value_to_uint(flags)); } else { ruby_libvirt_generate_call_nil(virNodeDeviceDettach, ruby_libvirt_connect_get(n), nodedevice_get(n)); } } /* * call-seq: * nodedevice.reattach -> nil * * Call virNodeDeviceReAttach[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReAttach] * to reattach the node device to the node. */ static VALUE libvirt_nodedevice_reattach(VALUE n) { ruby_libvirt_generate_call_nil(virNodeDeviceReAttach, ruby_libvirt_connect_get(n), nodedevice_get(n)); } /* * call-seq: * nodedevice.reset -> nil * * Call virNodeDeviceReset[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReset] * to reset the node device. */ static VALUE libvirt_nodedevice_reset(VALUE n) { ruby_libvirt_generate_call_nil(virNodeDeviceReset, ruby_libvirt_connect_get(n), nodedevice_get(n)); } /* * call-seq: * nodedevice.destroy -> nil * * Call virNodeDeviceDestroy[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDestroy] * to shutdown the node device. */ static VALUE libvirt_nodedevice_destroy(VALUE n) { ruby_libvirt_generate_call_nil(virNodeDeviceDestroy, ruby_libvirt_connect_get(n), nodedevice_get(n)); } /* * call-seq: * nodedevice.free -> nil * * Call virNodeDeviceFree[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceFree] * to free the node device object. After this call the node device object is * no longer valid. */ static VALUE libvirt_nodedevice_free(VALUE n) { ruby_libvirt_generate_call_free(NodeDevice, n); } /* * call-seq: * nodedevice.lookup_scsi_host_by_wwn(wwnn, wwpn, flags=0) -> Libvirt::NodeDevice * * Call virNodeDeviceLookupSCSIHostByWWN[https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceLookupSCSIHostByWWN] * to look up a SCSI host by its WWNN and WWPN. */ static VALUE libvirt_nodedevice_lookup_scsi_host_by_wwn(int argc, VALUE *argv, VALUE n) { VALUE wwnn, wwpn, flags = RUBY_Qnil; virNodeDevicePtr nd; rb_scan_args(argc, argv, "21", &wwnn, &wwpn, &flags); nd = virNodeDeviceLookupSCSIHostByWWN(ruby_libvirt_connect_get(n), StringValueCStr(wwnn), StringValueCStr(wwpn), ruby_libvirt_value_to_uint(flags)); if (nd == NULL) { return Qnil; } return ruby_libvirt_nodedevice_new(nd, ruby_libvirt_conn_attr(n)); } /* * Class Libvirt::NodeDevice */ void ruby_libvirt_nodedevice_init(void) { c_nodedevice = rb_define_class_under(m_libvirt, "NodeDevice", rb_cObject); rb_undef_alloc_func(c_nodedevice); rb_define_singleton_method(c_nodedevice, "new", ruby_libvirt_new_not_allowed, -1); rb_define_attr(c_nodedevice, "connection", 1, 0); rb_define_method(c_nodedevice, "name", libvirt_nodedevice_name, 0); rb_define_method(c_nodedevice, "parent", libvirt_nodedevice_parent, 0); rb_define_method(c_nodedevice, "num_of_caps", libvirt_nodedevice_num_of_caps, 0); rb_define_method(c_nodedevice, "list_caps", libvirt_nodedevice_list_caps, 0); rb_define_method(c_nodedevice, "xml_desc", libvirt_nodedevice_xml_desc, -1); rb_define_method(c_nodedevice, "detach", libvirt_nodedevice_detach, -1); rb_define_method(c_nodedevice, "reattach", libvirt_nodedevice_reattach, 0); rb_define_method(c_nodedevice, "reset", libvirt_nodedevice_reset, 0); rb_define_method(c_nodedevice, "destroy", libvirt_nodedevice_destroy, 0); rb_define_method(c_nodedevice, "free", libvirt_nodedevice_free, 0); rb_define_method(c_nodedevice, "lookup_scsi_host_by_wwn", libvirt_nodedevice_lookup_scsi_host_by_wwn, -1); } ruby-libvirt-0.8.4/ext/libvirt/secret.c0000644000175000017500000002013214641546211020211 0ustar abolognaabologna/* * secret.c: virSecret methods * * Copyright (C) 2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "common.h" #include "connect.h" #include "extconf.h" static VALUE c_secret; static void secret_free(void *s) { ruby_libvirt_free_struct(Secret, s); } static virSecretPtr secret_get(VALUE s) { ruby_libvirt_get_struct(Secret, s); } VALUE ruby_libvirt_secret_new(virSecretPtr s, VALUE conn) { return ruby_libvirt_new_class(c_secret, s, conn, secret_free); } /* * call-seq: * secret.uuid -> String * * Call virSecretGetUUIDString[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUUIDString] * to retrieve the UUID for this secret. */ static VALUE libvirt_secret_uuid(VALUE s) { ruby_libvirt_generate_uuid(virSecretGetUUIDString, ruby_libvirt_connect_get(s), secret_get(s)); } /* * call-seq: * secret.usagetype -> Fixnum * * Call virSecretGetUsageType[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageType] * to retrieve the usagetype for this secret. */ static VALUE libvirt_secret_usagetype(VALUE s) { ruby_libvirt_generate_call_int(virSecretGetUsageType, ruby_libvirt_connect_get(s), secret_get(s)); } /* * call-seq: * secret.usageid -> String * * Call virSecretGetUsageID[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageID] * to retrieve the usageid for this secret. */ static VALUE libvirt_secret_usageid(VALUE s) { ruby_libvirt_generate_call_string(virSecretGetUsageID, ruby_libvirt_connect_get(s), 0, secret_get(s)); } /* * call-seq: * secret.xml_desc(flags=0) -> String * * Call virSecretGetXMLDesc[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetXMLDesc] * to retrieve the XML for this secret. */ static VALUE libvirt_secret_xml_desc(int argc, VALUE *argv, VALUE s) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virSecretGetXMLDesc, ruby_libvirt_connect_get(s), 1, secret_get(s), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * secret.set_value(value, flags=0) -> nil * * Call virSecretSetValue[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretSetValue] * to set a new value in this secret. Deprecated; use secret.value= instead. */ static VALUE libvirt_secret_set_value(int argc, VALUE *argv, VALUE s) { VALUE flags = RUBY_Qnil, value; rb_scan_args(argc, argv, "11", &value, &flags); StringValue(value); ruby_libvirt_generate_call_nil(virSecretSetValue, ruby_libvirt_connect_get(s), secret_get(s), (unsigned char *)RSTRING_PTR(value), RSTRING_LEN(value), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * secret.value = value,flags=0 * * Call virSecretSetValue[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretSetValue] * to set a new value in this secret. */ static VALUE libvirt_secret_value_equal(VALUE s, VALUE in) { VALUE flags, value; if (TYPE(in) == T_STRING) { value = in; flags = INT2NUM(0); } else if (TYPE(in) == T_ARRAY) { if (RARRAY_LEN(in) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(in)); } value = rb_ary_entry(in, 0); flags = rb_ary_entry(in, 1); } else { rb_raise(rb_eTypeError, "wrong argument type (expected Number or Array)"); } StringValue(value); ruby_libvirt_generate_call_nil(virSecretSetValue, ruby_libvirt_connect_get(s), secret_get(s), (unsigned char *)RSTRING_PTR(value), RSTRING_LEN(value), NUM2UINT(flags)); } /* * call-seq: * secret.value(flags=0) -> String * * Call virSecretGetValue[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetValue] * to retrieve the value from this secret. */ static VALUE libvirt_secret_value(int argc, VALUE *argv, VALUE s) { VALUE flags = RUBY_Qnil, ret; unsigned char *val; size_t value_size; int exception = 0; struct ruby_libvirt_str_new_arg args; rb_scan_args(argc, argv, "01", &flags); val = virSecretGetValue(secret_get(s), &value_size, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(val == NULL, e_RetrieveError, "virSecretGetValue", ruby_libvirt_connect_get(s)); args.val = (char *)val; args.size = value_size; ret = rb_protect(ruby_libvirt_str_new_wrap, (VALUE)&args, &exception); free(val); if (exception) { rb_jump_tag(exception); } return ret; } /* * call-seq: * secret.undefine -> nil * * Call virSecretUndefine[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretUndefine] * to undefine this secret. */ static VALUE libvirt_secret_undefine(VALUE s) { ruby_libvirt_generate_call_nil(virSecretUndefine, ruby_libvirt_connect_get(s), secret_get(s)); } /* * call-seq: * secret.free -> nil * * Call virSecretFree[https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretFree] * to free this secret. After this call the secret object is no longer valid. */ static VALUE libvirt_secret_free(VALUE s) { ruby_libvirt_generate_call_free(Secret, s); } /* * Class Libvirt::Secret */ void ruby_libvirt_secret_init(void) { c_secret = rb_define_class_under(m_libvirt, "Secret", rb_cObject); rb_undef_alloc_func(c_secret); rb_define_singleton_method(c_secret, "new", ruby_libvirt_new_not_allowed, -1); rb_define_attr(c_secret, "connection", 1, 0); rb_define_const(c_secret, "USAGE_TYPE_VOLUME", INT2NUM(VIR_SECRET_USAGE_TYPE_VOLUME)); rb_define_const(c_secret, "USAGE_TYPE_CEPH", INT2NUM(VIR_SECRET_USAGE_TYPE_CEPH)); rb_define_const(c_secret, "USAGE_TYPE_ISCSI", INT2NUM(VIR_SECRET_USAGE_TYPE_ISCSI)); rb_define_const(c_secret, "USAGE_TYPE_NONE", INT2NUM(VIR_SECRET_USAGE_TYPE_NONE)); /* Secret object methods */ rb_define_method(c_secret, "uuid", libvirt_secret_uuid, 0); rb_define_method(c_secret, "usagetype", libvirt_secret_usagetype, 0); rb_define_method(c_secret, "usageid", libvirt_secret_usageid, 0); rb_define_method(c_secret, "xml_desc", libvirt_secret_xml_desc, -1); rb_define_method(c_secret, "set_value", libvirt_secret_set_value, -1); rb_define_method(c_secret, "value=", libvirt_secret_value_equal, 1); rb_define_method(c_secret, "value", libvirt_secret_value, -1); rb_define_alias(c_secret, "get_value", "value"); rb_define_method(c_secret, "undefine", libvirt_secret_undefine, 0); rb_define_method(c_secret, "free", libvirt_secret_free, 0); } ruby-libvirt-0.8.4/ext/libvirt/common.c0000644000175000017500000003610514641546211020223 0ustar abolognaabologna/* * common.c: Common utilities for the ruby libvirt bindings * * Copyright (C) 2007,2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _GNU_SOURCE #define _GNU_SOURCE 1 #endif #include #include #include #include #include #include #include "common.h" #include "connect.h" struct rb_exc_new2_arg { VALUE error; char *msg; }; static VALUE ruby_libvirt_exc_new2_wrap(VALUE arg) { struct rb_exc_new2_arg *e = (struct rb_exc_new2_arg *)arg; VALUE ruby_msg = ruby_libvirt_str_new2_wrap((VALUE)&e->msg); return rb_exc_new3(e->error, ruby_msg); } VALUE ruby_libvirt_ary_new2_wrap(VALUE arg) { return rb_ary_new2(*((int *)arg)); } VALUE ruby_libvirt_ary_push_wrap(VALUE arg) { struct ruby_libvirt_ary_push_arg *e = (struct ruby_libvirt_ary_push_arg *)arg; return rb_ary_push(e->arr, e->value); } VALUE ruby_libvirt_ary_store_wrap(VALUE arg) { struct ruby_libvirt_ary_store_arg *e = (struct ruby_libvirt_ary_store_arg *)arg; rb_ary_store(e->arr, e->index, e->elem); return Qnil; } VALUE ruby_libvirt_str_new2_wrap(VALUE arg) { char **str = (char **)arg; VALUE ruby_msg = rb_str_new2(*str); int enc = rb_enc_find_index("UTF-8"); rb_enc_associate_index(ruby_msg, enc); return ruby_msg; } VALUE ruby_libvirt_str_new_wrap(VALUE arg) { struct ruby_libvirt_str_new_arg *e = (struct ruby_libvirt_str_new_arg *)arg; return rb_str_new(e->val, e->size); } VALUE ruby_libvirt_hash_aset_wrap(VALUE arg) { struct ruby_libvirt_hash_aset_arg *e = (struct ruby_libvirt_hash_aset_arg *)arg; return rb_hash_aset(e->hash, rb_str_new2(e->name), e->val); } VALUE ruby_libvirt_str_new2_and_ary_store_wrap(VALUE arg) { struct ruby_libvirt_str_new2_and_ary_store_arg *e = (struct ruby_libvirt_str_new2_and_ary_store_arg *)arg; rb_ary_store(e->arr, e->index, rb_str_new2(e->value)); return Qnil; } void ruby_libvirt_raise_error_if(const int condition, VALUE error, const char *method, virConnectPtr conn) { VALUE ruby_errinfo; virErrorPtr err; char *msg; int rc; struct rb_exc_new2_arg arg; int exception = 0; if (!condition) { return; } if (conn == NULL) { err = virGetLastError(); } else { err = virConnGetLastError(conn); } if (err != NULL && err->message != NULL) { rc = asprintf(&msg, "Call to %s failed: %s", method, err->message); } else { rc = asprintf(&msg, "Call to %s failed", method); } if (rc < 0) { /* there's not a whole lot we can do here; try to raise an * out-of-memory message */ rb_memerror(); } arg.error = error; arg.msg = msg; ruby_errinfo = rb_protect(ruby_libvirt_exc_new2_wrap, (VALUE)&arg, &exception); free(msg); if (exception) { rb_jump_tag(exception); } rb_iv_set(ruby_errinfo, "@libvirt_function_name", rb_str_new2(method)); if (err != NULL) { rb_iv_set(ruby_errinfo, "@libvirt_code", INT2NUM(err->code)); rb_iv_set(ruby_errinfo, "@libvirt_component", INT2NUM(err->domain)); rb_iv_set(ruby_errinfo, "@libvirt_level", INT2NUM(err->level)); if (err->message != NULL) { rb_iv_set(ruby_errinfo, "@libvirt_message", ruby_libvirt_str_new2_wrap((VALUE)&err->message)); } } rb_exc_raise(ruby_errinfo); }; char *ruby_libvirt_get_cstring_or_null(VALUE arg) { if (TYPE(arg) == T_NIL) { return NULL; } else if (TYPE(arg) == T_STRING) { return StringValueCStr(arg); } else { rb_raise(rb_eTypeError, "wrong argument type (expected String or nil)"); } return NULL; } VALUE ruby_libvirt_new_class(VALUE klass, void *ptr, VALUE conn, RUBY_DATA_FUNC free_func) { VALUE result; result = Data_Wrap_Struct(klass, NULL, free_func, ptr); rb_iv_set(result, "@connection", conn); return result; } int ruby_libvirt_is_symbol_or_proc(VALUE handle) { return ((strcmp(rb_obj_classname(handle), "Symbol") == 0) || (strcmp(rb_obj_classname(handle), "Proc") == 0)); } /* this is an odd function, because it has massive side-effects. * The intended usage of this function is after a list has been collected * from a libvirt list function, and now we want to make an array out of it. * However, it is possible that the act of creating an array causes an * exception, which would lead to a memory leak of the values we got from * libvirt. Therefore, this function not only wraps all of the relevant * calls with rb_protect, it also frees every individual entry in list after * it is done with it. Freeing list itself is left to the callers. */ VALUE ruby_libvirt_generate_list(int num, char **list) { VALUE result; int exception = 0; int i, j; struct ruby_libvirt_str_new2_and_ary_store_arg arg; i = 0; result = rb_protect(ruby_libvirt_ary_new2_wrap, (VALUE)&num, &exception); if (exception) { goto exception; } for (i = 0; i < num; i++) { arg.arr = result; arg.index = i; arg.value = list[i]; rb_protect(ruby_libvirt_str_new2_and_ary_store_wrap, (VALUE)&arg, &exception); if (exception) { goto exception; } xfree(list[i]); } return result; exception: for (j = i; j < num; j++) { xfree(list[j]); } rb_jump_tag(exception); /* not needed, but here to shut the compiler up */ return Qnil; } void ruby_libvirt_typed_params_to_hash(void *voidparams, int i, VALUE hash) { virTypedParameterPtr params = (virTypedParameterPtr)voidparams; VALUE val; switch (params[i].type) { case VIR_TYPED_PARAM_INT: val = INT2NUM(params[i].value.i); break; case VIR_TYPED_PARAM_UINT: val = UINT2NUM(params[i].value.ui); break; case VIR_TYPED_PARAM_LLONG: val = LL2NUM(params[i].value.l); break; case VIR_TYPED_PARAM_ULLONG: val = ULL2NUM(params[i].value.ul); break; case VIR_TYPED_PARAM_DOUBLE: val = rb_float_new(params[i].value.d); break; case VIR_TYPED_PARAM_BOOLEAN: val = (params[i].value.b == 0) ? Qfalse : Qtrue; break; case VIR_TYPED_PARAM_STRING: val = rb_str_new2(params[i].value.s); break; default: rb_raise(rb_eArgError, "Invalid parameter type"); } rb_hash_aset(hash, rb_str_new2(params[i].field), val); } VALUE ruby_libvirt_get_parameters(VALUE d, unsigned int flags, void *opaque, unsigned int typesize, const char *(*nparams_cb)(VALUE d, unsigned int flags, void *opaque, int *nparams), const char *(*get_cb)(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *opaque), void (*hash_set)(void *voidparams, int i, VALUE result)) { int nparams = 0; void *params; VALUE result; const char *errname; int i; errname = nparams_cb(d, flags, opaque, &nparams); ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname, ruby_libvirt_connect_get(d)); result = rb_hash_new(); if (nparams == 0) { return result; } params = alloca(typesize * nparams); errname = get_cb(d, flags, params, &nparams, opaque); ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname, ruby_libvirt_connect_get(d)); for (i = 0; i < nparams; i++) { hash_set(params, i, result); } return result; } VALUE ruby_libvirt_get_typed_parameters(VALUE d, unsigned int flags, void *opaque, const char *(*nparams_cb)(VALUE d, unsigned int flags, void *opaque, int *nparams), const char *(*get_cb)(VALUE d, unsigned int flags, void *params, int *nparams, void *opaque)) { return ruby_libvirt_get_parameters(d, flags, opaque, sizeof(virTypedParameter), nparams_cb, get_cb, ruby_libvirt_typed_params_to_hash); } void ruby_libvirt_assign_hash_and_flags(VALUE in, VALUE *hash, VALUE *flags) { if (TYPE(in) == T_HASH) { *hash = in; *flags = INT2NUM(0); } else if (TYPE(in) == T_ARRAY) { if (RARRAY_LEN(in) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 1 or 2)", RARRAY_LEN(in)); } *hash = rb_ary_entry(in, 0); *flags = rb_ary_entry(in, 1); } else { rb_raise(rb_eTypeError, "wrong argument type (expected Hash or Array)"); } } int ruby_libvirt_typed_parameter_assign(VALUE key, VALUE val, VALUE in) { struct ruby_libvirt_parameter_assign_args *args = (struct ruby_libvirt_parameter_assign_args *)in; char *keyname; unsigned int i; int found; keyname = StringValueCStr(key); found = 0; for (i = 0; i < args->num_allowed; i++) { if (strcmp(args->allowed[i].name, keyname) == 0) { args->params[args->i].type = args->allowed[i].type; switch (args->params[args->i].type) { case VIR_TYPED_PARAM_INT: args->params[i].value.i = NUM2INT(val); break; case VIR_TYPED_PARAM_UINT: args->params[i].value.ui = NUM2UINT(val); break; case VIR_TYPED_PARAM_LLONG: args->params[i].value.l = NUM2LL(val); break; case VIR_TYPED_PARAM_ULLONG: args->params[args->i].value.ul = NUM2ULL(val); break; case VIR_TYPED_PARAM_DOUBLE: args->params[i].value.d = NUM2DBL(val); break; case VIR_TYPED_PARAM_BOOLEAN: args->params[i].value.b = (val == Qtrue) ? 1 : 0; break; case VIR_TYPED_PARAM_STRING: args->params[args->i].value.s = StringValueCStr(val); break; default: rb_raise(rb_eArgError, "Invalid parameter type"); } /* ensure that the field is NULL-terminated */ args->params[args->i].field[VIR_TYPED_PARAM_FIELD_LENGTH - 1] = '\0'; strncpy(args->params[args->i].field, keyname, VIR_TYPED_PARAM_FIELD_LENGTH - 1); (args->i)++; found = 1; break; } } if (!found) { rb_raise(rb_eArgError, "Unknown key %s", keyname); } return ST_CONTINUE; } VALUE ruby_libvirt_set_typed_parameters(VALUE d, VALUE input, unsigned int flags, void *opaque, struct ruby_libvirt_typed_param *allowed, unsigned int num_allowed, const char *(*set_cb)(VALUE d, unsigned int flags, virTypedParameterPtr params, int nparams, void *opaque)) { const char *errname; struct ruby_libvirt_parameter_assign_args args; unsigned long hashsize; /* make sure input is a hash */ Check_Type(input, T_HASH); hashsize = RHASH_SIZE(input); if (hashsize == 0) { return Qnil; } args.allowed = allowed; args.num_allowed = num_allowed; args.params = alloca(sizeof(virTypedParameter) * hashsize); args.i = 0; rb_hash_foreach(input, ruby_libvirt_typed_parameter_assign, (VALUE)&args); errname = set_cb(d, flags, args.params, args.i, opaque); ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname, ruby_libvirt_connect_get(d)); return Qnil; } unsigned int ruby_libvirt_value_to_uint(VALUE in) { if (NIL_P(in)) { return 0; } return NUM2UINT(in); } int ruby_libvirt_value_to_int(VALUE in) { if (NIL_P(in)) { return 0; } return NUM2INT(in); } unsigned long ruby_libvirt_value_to_ulong(VALUE in) { if (NIL_P(in)) { return 0; } return NUM2ULONG(in); } unsigned long long ruby_libvirt_value_to_ulonglong(VALUE in) { if (NIL_P(in)) { return 0; } return NUM2ULL(in); } int ruby_libvirt_get_maxcpus(virConnectPtr conn) { int maxcpu = -1; virNodeInfo nodeinfo; maxcpu = virNodeGetCPUMap(conn, NULL, NULL, 0); if (maxcpu < 0) { /* fall back to nodeinfo */ ruby_libvirt_raise_error_if(virNodeGetInfo(conn, &nodeinfo) < 0, e_RetrieveError, "virNodeGetInfo", conn); maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo); } return maxcpu; } /* For classes where Ruby objects are just wrappers around C pointers, * the only acceptable way to create new instances is to use * Connect.create_domain_xml and similar. The use of Domain.new and * friends is explicitly disallowed by providing this functions as * implementation when defining the class */ VALUE ruby_libvirt_new_not_allowed(int argc, VALUE *argv, VALUE obj) { rb_raise(rb_eTypeError, "Not allowed for this class"); } ruby-libvirt-0.8.4/ext/libvirt/nwfilter.c0000644000175000017500000001034514641546211020563 0ustar abolognaabologna/* * nwfilter.c: virNWFilter methods * * Copyright (C) 2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "common.h" #include "connect.h" #include "extconf.h" static VALUE c_nwfilter; static void nwfilter_free(void *n) { ruby_libvirt_free_struct(NWFilter, n); } static virNWFilterPtr nwfilter_get(VALUE n) { ruby_libvirt_get_struct(NWFilter, n); } VALUE ruby_libvirt_nwfilter_new(virNWFilterPtr n, VALUE conn) { return ruby_libvirt_new_class(c_nwfilter, n, conn, nwfilter_free); } /* * call-seq: * nwfilter.undefine -> nil * * Call virNWFilterUndefine[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterUndefine] * to undefine the network filter. */ static VALUE libvirt_nwfilter_undefine(VALUE n) { ruby_libvirt_generate_call_nil(virNWFilterUndefine, ruby_libvirt_connect_get(n), nwfilter_get(n)); } /* * call-seq: * nwfilter.name -> String * * Call virNWFilterGetName[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetName] * to retrieve the network filter name. */ static VALUE libvirt_nwfilter_name(VALUE n) { ruby_libvirt_generate_call_string(virNWFilterGetName, ruby_libvirt_connect_get(n), 0, nwfilter_get(n)); } /* * call-seq: * nwfilter.uuid -> String * * Call virNWFilterGetUUIDString[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetUUIDString] * to retrieve the network filter UUID. */ static VALUE libvirt_nwfilter_uuid(VALUE n) { ruby_libvirt_generate_uuid(virNWFilterGetUUIDString, ruby_libvirt_connect_get(n), nwfilter_get(n)); } /* * call-seq: * nwfilter.xml_desc(flags=0) -> String * * Call virNWFilterGetXMLDesc[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetXMLDesc] * to retrieve the XML for this network filter. */ static VALUE libvirt_nwfilter_xml_desc(int argc, VALUE *argv, VALUE n) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virNWFilterGetXMLDesc, ruby_libvirt_connect_get(n), 1, nwfilter_get(n), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * nwfilter.free -> nil * * Call virNWFilterFree[https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterFree] * to free this network filter. After this call the network filter object is * no longer valid. */ static VALUE libvirt_nwfilter_free(VALUE n) { ruby_libvirt_generate_call_free(NWFilter, n); } /* * Class Libvirt::NWFilter */ void ruby_libvirt_nwfilter_init(void) { c_nwfilter = rb_define_class_under(m_libvirt, "NWFilter", rb_cObject); rb_undef_alloc_func(c_nwfilter); rb_define_singleton_method(c_nwfilter, "new", ruby_libvirt_new_not_allowed, -1); rb_define_attr(c_nwfilter, "connection", 1, 0); /* NWFilter object methods */ rb_define_method(c_nwfilter, "undefine", libvirt_nwfilter_undefine, 0); rb_define_method(c_nwfilter, "name", libvirt_nwfilter_name, 0); rb_define_method(c_nwfilter, "uuid", libvirt_nwfilter_uuid, 0); rb_define_method(c_nwfilter, "xml_desc", libvirt_nwfilter_xml_desc, -1); rb_define_method(c_nwfilter, "free", libvirt_nwfilter_free, 0); } ruby-libvirt-0.8.4/ext/libvirt/connect.h0000644000175000017500000000040214557177263020375 0ustar abolognaabologna#ifndef CONNECT_H #define CONNECT_H void ruby_libvirt_connect_init(void); VALUE ruby_libvirt_connect_new(virConnectPtr p); virConnectPtr ruby_libvirt_connect_get(VALUE s); VALUE ruby_libvirt_conn_attr(VALUE s); extern VALUE c_node_security_model; #endif ruby-libvirt-0.8.4/ext/libvirt/extconf.rb0000644000175000017500000000056514636561431020570 0ustar abolognaabolognarequire 'mkmf' extension_name = '_libvirt' unless pkg_config("libvirt") raise "libvirt library not found in default locations" end unless pkg_config("libvirt-qemu") raise "libvirt library not found in default locations" end unless pkg_config("libvirt-lxc") raise "libvirt library not found in default locations" end create_header create_makefile(extension_name) ruby-libvirt-0.8.4/ext/libvirt/common.h0000644000175000017500000003377314641546211020240 0ustar abolognaabologna#ifndef COMMON_H #define COMMON_H /* Macros to ease some of the boilerplate */ VALUE ruby_libvirt_new_class(VALUE klass, void *ptr, VALUE conn, RUBY_DATA_FUNC free_func); #define RUBY_LIBVIRT_UNUSED(x) UNUSED_ ## x __attribute__((__unused__)) #define ruby_libvirt_get_struct(kind, v) \ do { \ vir##kind##Ptr ptr; \ Data_Get_Struct(v, vir##kind, ptr); \ if (!ptr) { \ rb_raise(rb_eArgError, #kind " has been freed"); \ } \ return ptr; \ } while (0); #define ruby_libvirt_free_struct(kind, p) \ do { \ int r; \ r = vir##kind##Free((vir##kind##Ptr) p); \ if (r < 0) { \ rb_raise(rb_eSystemCallError, # kind " free failed"); \ } \ } while(0); void ruby_libvirt_raise_error_if(const int condition, VALUE error, const char *method, virConnectPtr conn); /* * Code generating macros. * * We only generate function bodies, not the whole function * declaration. */ /* Generate a call to a function FUNC which returns a string. The Ruby * function will return the string on success and throw an exception on * error. The string returned by FUNC is freed if dealloc is true. */ #define ruby_libvirt_generate_call_string(func, conn, dealloc, args...) \ do { \ const char *str; \ VALUE result; \ int exception; \ \ str = func(args); \ ruby_libvirt_raise_error_if(str == NULL, e_Error, # func, conn); \ if (dealloc) { \ result = rb_protect(ruby_libvirt_str_new2_wrap, (VALUE)&str, &exception); \ xfree((void *) str); \ if (exception) { \ rb_jump_tag(exception); \ } \ } \ else { \ result = ruby_libvirt_str_new2_wrap((VALUE)&str); \ } \ return result; \ } while(0) /* Generate a call to vir##KIND##Free and return Qnil. Set the the embedded * vir##KIND##Ptr to NULL. If that pointer is already NULL, do nothing. */ #define ruby_libvirt_generate_call_free(kind, s) \ do { \ vir##kind##Ptr ptr; \ Data_Get_Struct(s, vir##kind, ptr); \ if (ptr != NULL) { \ int r = vir##kind##Free(ptr); \ ruby_libvirt_raise_error_if(r < 0, e_Error, "vir" #kind "Free", ruby_libvirt_connect_get(s)); \ DATA_PTR(s) = NULL; \ } \ return Qnil; \ } while (0) /* Generate a call to a function FUNC which returns an int error, where -1 * indicates error and 0 success. The Ruby function will return Qnil on * success and throw an exception on error. */ #define ruby_libvirt_generate_call_nil(func, conn, args...) \ do { \ int _r_##func; \ _r_##func = func(args); \ ruby_libvirt_raise_error_if(_r_##func < 0, e_Error, #func, conn); \ return Qnil; \ } while(0) /* Generate a call to a function FUNC which returns an int; -1 indicates * error, 0 indicates Qfalse, and 1 indicates Qtrue. */ #define ruby_libvirt_generate_call_truefalse(func, conn, args...) \ do { \ int _r_##func; \ _r_##func = func(args); \ ruby_libvirt_raise_error_if(_r_##func < 0, e_Error, #func, conn); \ return _r_##func ? Qtrue : Qfalse; \ } while(0) /* Generate a call to a function FUNC which returns an int error, where -1 * indicates error and >= 0 success. The Ruby function will return the integer * success and throw an exception on error. */ #define ruby_libvirt_generate_call_int(func, conn, args...) \ do { \ int _r_##func; \ _r_##func = func(args); \ ruby_libvirt_raise_error_if(_r_##func < 0, e_RetrieveError, #func, conn); \ return INT2NUM(_r_##func); \ } while(0) #define ruby_libvirt_generate_uuid(func, conn, obj) \ do { \ char uuid[VIR_UUID_STRING_BUFLEN]; \ int _r_##func; \ _r_##func = func(obj, uuid); \ ruby_libvirt_raise_error_if(_r_##func < 0, e_RetrieveError, #func, conn); \ return rb_str_new2((char *) uuid); \ } while (0) #define ruby_libvirt_generate_call_list_all(type, argc, argv, listfunc, object, val, newfunc, freefunc) \ do { \ VALUE flags = RUBY_Qnil; \ type *list; \ int i; \ int ret; \ VALUE result; \ int exception = 0; \ struct ruby_libvirt_ary_push_arg arg; \ \ rb_scan_args(argc, argv, "01", &flags); \ ret = listfunc(object, &list, ruby_libvirt_value_to_uint(flags)); \ ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, #listfunc, ruby_libvirt_connect_get(val)); \ result = rb_protect(ruby_libvirt_ary_new2_wrap, (VALUE)&ret, &exception); \ if (exception) { \ goto exception; \ } \ for (i = 0; i < ret; i++) { \ arg.arr = result; \ arg.value = newfunc(list[i], val); \ rb_protect(ruby_libvirt_ary_push_wrap, (VALUE)&arg, &exception); \ if (exception) { \ goto exception; \ } \ } \ \ free(list); \ \ return result; \ \ exception: \ for (i = 0; i < ret; i++) { \ freefunc(list[i]); \ } \ free(list); \ rb_jump_tag(exception); \ \ /* not needed, but here to shut the compiler up */ \ return Qnil; \ } while(0) int ruby_libvirt_is_symbol_or_proc(VALUE handle); extern VALUE e_RetrieveError; extern VALUE e_Error; extern VALUE e_DefinitionError; extern VALUE e_NoSupportError; extern VALUE m_libvirt; char *ruby_libvirt_get_cstring_or_null(VALUE arg); VALUE ruby_libvirt_generate_list(int num, char **list); VALUE ruby_libvirt_get_parameters(VALUE d, unsigned int flags, void *opaque, unsigned int typesize, const char *(*nparams_cb)(VALUE d, unsigned int flags, void *opaque, int *nparams), const char *(*get_cb)(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *opaque), void (*hash_set)(void *voidparams, int i, VALUE result)); VALUE ruby_libvirt_get_typed_parameters(VALUE d, unsigned int flags, void *opaque, const char *(*nparams_cb)(VALUE d, unsigned int flags, void *opaque, int *nparams), const char *(*get_cb)(VALUE d, unsigned int flags, void *params, int *nparams, void *opaque)); struct ruby_libvirt_typed_param { const char *name; int type; }; struct ruby_libvirt_parameter_assign_args { struct ruby_libvirt_typed_param *allowed; unsigned int num_allowed; virTypedParameter *params; int i; }; int ruby_libvirt_typed_parameter_assign(VALUE key, VALUE val, VALUE in); VALUE ruby_libvirt_set_typed_parameters(VALUE d, VALUE input, unsigned int flags, void *opaque, struct ruby_libvirt_typed_param *allowed, unsigned int num_allowed, const char *(*set_cb)(VALUE d, unsigned int flags, virTypedParameterPtr params, int nparams, void *opaque)); int ruby_libvirt_get_maxcpus(virConnectPtr conn); void ruby_libvirt_typed_params_to_hash(void *voidparams, int i, VALUE hash); void ruby_libvirt_assign_hash_and_flags(VALUE in, VALUE *hash, VALUE *flags); unsigned int ruby_libvirt_value_to_uint(VALUE in); int ruby_libvirt_value_to_int(VALUE in); unsigned long ruby_libvirt_value_to_ulong(VALUE in); unsigned long long ruby_libvirt_value_to_ulonglong(VALUE in); VALUE ruby_libvirt_ary_new2_wrap(VALUE arg); struct ruby_libvirt_ary_push_arg { VALUE arr; VALUE value; }; VALUE ruby_libvirt_ary_push_wrap(VALUE arg); struct ruby_libvirt_ary_store_arg { VALUE arr; long index; VALUE elem; }; VALUE ruby_libvirt_ary_store_wrap(VALUE arg); VALUE ruby_libvirt_str_new2_wrap(VALUE arg); struct ruby_libvirt_str_new_arg { char *val; size_t size; }; VALUE ruby_libvirt_str_new_wrap(VALUE arg); struct ruby_libvirt_hash_aset_arg { VALUE hash; const char *name; VALUE val; }; VALUE ruby_libvirt_hash_aset_wrap(VALUE arg); struct ruby_libvirt_str_new2_and_ary_store_arg { VALUE arr; long index; char *value; }; VALUE ruby_libvirt_str_new2_and_ary_store_wrap(VALUE arg); VALUE ruby_libvirt_new_not_allowed(int argc, VALUE *argv, VALUE obj); #ifndef RARRAY_LEN #define RARRAY_LEN(ar) (RARRAY(ar)->len) #endif #ifndef RSTRING_PTR #define RSTRING_PTR(str) (RSTRING(str)->ptr) #endif #ifndef RSTRING_LEN #define RSTRING_LEN(str) (RSTRING(str)->len) #endif #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #endif ruby-libvirt-0.8.4/ext/libvirt/_libvirt.c0000644000175000017500000011555114565426642020562 0ustar abolognaabologna/* * libvirt.c: Ruby bindings for libvirt * * Copyright (C) 2007,2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: David Lutterkort */ #include #include #include #include #include "extconf.h" #include "common.h" #include "storage.h" #include "connect.h" #include "network.h" #include "nodedevice.h" #include "secret.h" #include "nwfilter.h" #include "interface.h" #include "domain.h" #include "stream.h" #if !LIBVIR_CHECK_VERSION(2, 0, 0) # error "Libvirt >= 2.0.0 is required for the ruby binding" #endif static VALUE c_libvirt_version; VALUE m_libvirt; /* define additional errors here */ static VALUE e_ConnectionError; /* ConnectionError - error during connection establishment */ VALUE e_DefinitionError; VALUE e_RetrieveError; VALUE e_Error; VALUE e_NoSupportError; /* custom error function to suppress libvirt printing to stderr */ static void rubyLibvirtErrorFunc(void *RUBY_LIBVIRT_UNUSED(userdata), virErrorPtr RUBY_LIBVIRT_UNUSED(err)) { } /* * call-seq: * Libvirt::version(type=nil) -> [ libvirt_version, type_version ] * * Call virGetVersion[https://libvirt.org/html/libvirt-libvirt-host.html#virGetVersion] * to get the version of libvirt and of the hypervisor TYPE. */ static VALUE libvirt_version(int argc, VALUE *argv, VALUE RUBY_LIBVIRT_UNUSED(m)) { unsigned long libVer, typeVer; VALUE type, result, rargv[2]; int r; rb_scan_args(argc, argv, "01", &type); r = virGetVersion(&libVer, ruby_libvirt_get_cstring_or_null(type), &typeVer); ruby_libvirt_raise_error_if(r < 0, rb_eArgError, "virGetVersion", NULL); result = rb_ary_new2(2); rargv[0] = rb_str_new2("libvirt"); rargv[1] = ULONG2NUM(libVer); rb_ary_store(result, 0, rb_class_new_instance(2, rargv, c_libvirt_version)); rargv[0] = type; rargv[1] = ULONG2NUM(typeVer); rb_ary_store(result, 1, rb_class_new_instance(2, rargv, c_libvirt_version)); return result; } /* * call-seq: * Libvirt::open(uri=nil) -> Libvirt::Connect * * Call virConnectOpen[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpen] * to open a connection to a URL. */ static VALUE libvirt_open(int argc, VALUE *argv, VALUE RUBY_LIBVIRT_UNUSED(m)) { VALUE uri; virConnectPtr conn; rb_scan_args(argc, argv, "01", &uri); conn = virConnectOpen(ruby_libvirt_get_cstring_or_null(uri)); ruby_libvirt_raise_error_if(conn == NULL, e_ConnectionError, "virConnectOpen", NULL); return ruby_libvirt_connect_new(conn); } /* * call-seq: * Libvirt::open_read_only(uri=nil) -> Libvirt::Connect * * Call virConnectOpenReadOnly[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpenReadOnly] * to open a read-only connection to a URL. */ static VALUE libvirt_open_read_only(int argc, VALUE *argv, VALUE RUBY_LIBVIRT_UNUSED(m)) { VALUE uri; virConnectPtr conn; rb_scan_args(argc, argv, "01", &uri); conn = virConnectOpenReadOnly(ruby_libvirt_get_cstring_or_null(uri)); ruby_libvirt_raise_error_if(conn == NULL, e_ConnectionError, "virConnectOpenReadOnly", NULL); return ruby_libvirt_connect_new(conn); } static int libvirt_auth_callback_wrapper(virConnectCredentialPtr cred, unsigned int ncred, void *cbdata) { VALUE userdata, newcred, result; unsigned int i; userdata = (VALUE)cbdata; if (!rb_block_given_p()) { rb_raise(rb_eRuntimeError, "No block given, this should never happen!\n"); } for (i = 0; i < ncred; i++) { newcred = rb_hash_new(); rb_hash_aset(newcred, rb_str_new2("type"), INT2NUM(cred[i].type)); rb_hash_aset(newcred, rb_str_new2("prompt"), rb_str_new2(cred[i].prompt)); if (cred[i].challenge) { rb_hash_aset(newcred, rb_str_new2("challenge"), rb_str_new2(cred[i].challenge)); } else { rb_hash_aset(newcred, rb_str_new2("challenge"), Qnil); } if (cred[i].defresult) { rb_hash_aset(newcred, rb_str_new2("defresult"), rb_str_new2(cred[i].defresult)); } else { rb_hash_aset(newcred, rb_str_new2("defresult"), Qnil); } rb_hash_aset(newcred, rb_str_new2("result"), Qnil); rb_hash_aset(newcred, rb_str_new2("userdata"), userdata); result = rb_yield(newcred); if (NIL_P(result)) { cred[i].result = NULL; cred[i].resultlen = 0; } else { cred[i].result = strdup(StringValueCStr(result)); cred[i].resultlen = strlen(cred[i].result); } } return 0; } /* * call-seq: * Libvirt::open_auth(uri=nil, credlist=nil, userdata=nil, flags=0) {|...| authentication block} -> Libvirt::Connect * * Call virConnectOpenAuth[https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpenAuth] * to open a connection to a libvirt URI, with a possible authentication block. * If an authentication block is desired, then credlist should be an array that * specifies which credentials the authentication block is willing to support; * the full list is available at https://libvirt.org/html/libvirt-libvirt.html#virConnectCredentialType. * If userdata is not nil and an authentication block is given, userdata will * be passed unaltered into the authentication block. The flags parameter * controls how to open connection. The only options currently available for * flags are 0 for a read/write connection and Libvirt::CONNECT_RO for a * read-only connection. * * If the credlist is not empty, and an authentication block is given, the * authentication block will be called once for each credential necessary * to complete the authentication. The authentication block will be passed a * single parameter, which is a hash of values containing information necessary * to complete authentication. This hash contains 5 elements: * * type - the type of credential to be examined * * prompt - a suggested prompt to show to the user * * challenge - any additional challenge information * * defresult - a default result to use if credentials could not be obtained * * userdata - the userdata passed into open_auth initially * * The authentication block should return the result of collecting the * information; these results will then be sent to libvirt for authentication. */ static VALUE libvirt_open_auth(int argc, VALUE *argv, VALUE RUBY_LIBVIRT_UNUSED(m)) { virConnectAuthPtr auth; VALUE uri, credlist, userdata, flags, tmp; virConnectPtr conn; unsigned int i; rb_scan_args(argc, argv, "04", &uri, &credlist, &userdata, &flags); if (rb_block_given_p()) { auth = alloca(sizeof(virConnectAuth)); if (TYPE(credlist) == T_NIL) { auth->ncredtype = 0; } else if (TYPE(credlist) == T_ARRAY) { auth->ncredtype = RARRAY_LEN(credlist); } else { rb_raise(rb_eTypeError, "wrong argument type (expected Array or nil)"); } auth->credtype = NULL; if (auth->ncredtype > 0) { auth->credtype = alloca(sizeof(int) * auth->ncredtype); for (i = 0; i < auth->ncredtype; i++) { tmp = rb_ary_entry(credlist, i); auth->credtype[i] = NUM2INT(tmp); } } auth->cb = libvirt_auth_callback_wrapper; auth->cbdata = (void *)userdata; } else { auth = virConnectAuthPtrDefault; } conn = virConnectOpenAuth(ruby_libvirt_get_cstring_or_null(uri), auth, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(conn == NULL, e_ConnectionError, "virConnectOpenAuth", NULL); return ruby_libvirt_connect_new(conn); } static VALUE add_handle, update_handle, remove_handle; static VALUE add_timeout, update_timeout, remove_timeout; /* * call-seq: * Libvirt::event_invoke_handle_callback(handle, fd, events, opaque) -> Qnil * * Unlike most of the other functions in the ruby-libvirt bindings, this one * does not directly correspond to a libvirt API function. Instead, this * module method (and event_invoke_timeout_callback) are meant to be called * when there is an event of interest to libvirt on one of the file descriptors * that libvirt uses. The application is notified of the file descriptors * that libvirt uses via the callbacks from Libvirt::event_register_impl. When * there is an event of interest, the application must call * event_invoke_timeout_callback to ensure proper operation. * * Libvirt::event_invoke_handle_callback takes 4 arguments: * * handle - an application specific handle ID. This can be any integer, but must be unique from all other libvirt handles in the application. * * fd - the file descriptor of interest. This was given to the application as a callback to add_handle of Libvirt::event_register_impl * * events - the events that have occured on the fd. Note that the events are libvirt specific, and are some combination of Libvirt::EVENT_HANDLE_READABLE, Libvirt::EVENT_HANDLE_WRITABLE, Libvirt::EVENT_HANDLE_ERROR, Libvirt::EVENT_HANDLE_HANGUP. To notify libvirt of more than one event at a time, these values should be logically OR'ed together. * * opaque - the opaque data passed from libvirt during the Libvirt::event_register_impl add_handle callback. To ensure proper operation this data must be passed through to event_invoke_handle_callback without modification. */ static VALUE libvirt_event_invoke_handle_callback(VALUE RUBY_LIBVIRT_UNUSED(m), VALUE handle, VALUE fd, VALUE events, VALUE opaque) { virEventHandleCallback cb; void *op; VALUE libvirt_cb, libvirt_opaque; Check_Type(opaque, T_HASH); libvirt_cb = rb_hash_aref(opaque, rb_str_new2("libvirt_cb")); /* This is equivalent to Data_Get_Struct; I reproduce it here because * I don't want the additional type-cast that Data_Get_Struct does */ Check_Type(libvirt_cb, T_DATA); cb = DATA_PTR(libvirt_cb); if (cb) { libvirt_opaque = rb_hash_aref(opaque, rb_str_new2("opaque")); Data_Get_Struct(libvirt_opaque, void *, op); cb(NUM2INT(handle), NUM2INT(fd), NUM2INT(events), op); } return Qnil; } /* * call-seq: * Libvirt::event_invoke_timeout_callback(timer, opaque) -> Qnil * * Unlike most of the other functions in the ruby-libvirt bindings, this one * does not directly correspond to a libvirt API function. Instead, this * module method (and event_invoke_handle_callback) are meant to be called * when there is a timeout of interest to libvirt. The application is * notified of the timers that libvirt uses via the callbacks from * Libvirt::event_register_impl. When a timeout expires, the application must * call event_invoke_timeout_callback to ensure proper operation. * * Libvirt::event_invoke_timeout_callback takes 2 arguments: * * handle - an application specific timer ID. This can be any integer, but must be unique from all other libvirt timers in the application. * * opaque - the opaque data passed from libvirt during the Libvirt::event_register_impl add_handle callback. To ensure proper operation this data must be passed through to event_invoke_handle_callback without modification. */ static VALUE libvirt_event_invoke_timeout_callback(VALUE RUBY_LIBVIRT_UNUSED(m), VALUE timer, VALUE opaque) { virEventTimeoutCallback cb; void *op; VALUE libvirt_cb, libvirt_opaque; Check_Type(opaque, T_HASH); libvirt_cb = rb_hash_aref(opaque, rb_str_new2("libvirt_cb")); /* This is equivalent to Data_Get_Struct; I reproduce it here because * I don't want the additional type-cast that Data_Get_Struct does */ Check_Type(libvirt_cb, T_DATA); cb = DATA_PTR(libvirt_cb); if (cb) { libvirt_opaque = rb_hash_aref(opaque, rb_str_new2("opaque")); Data_Get_Struct(libvirt_opaque, void *, op); cb(NUM2INT(timer), op); } return Qnil; } static int internal_add_handle_func(int fd, int events, virEventHandleCallback cb, void *opaque, virFreeCallback ff) { VALUE rubyargs, res; rubyargs = rb_hash_new(); rb_hash_aset(rubyargs, rb_str_new2("libvirt_cb"), Data_Wrap_Struct(rb_class_of(add_handle), NULL, NULL, cb)); rb_hash_aset(rubyargs, rb_str_new2("opaque"), Data_Wrap_Struct(rb_class_of(add_handle), NULL, NULL, opaque)); rb_hash_aset(rubyargs, rb_str_new2("free_func"), Data_Wrap_Struct(rb_class_of(add_handle), NULL, NULL, ff)); /* call out to the ruby object */ if (strcmp(rb_obj_classname(add_handle), "Symbol") == 0) { res = rb_funcall(rb_class_of(add_handle), rb_to_id(add_handle), 3, INT2NUM(fd), INT2NUM(events), rubyargs); } else if (strcmp(rb_obj_classname(add_handle), "Proc") == 0) { res = rb_funcall(add_handle, rb_intern("call"), 3, INT2NUM(fd), INT2NUM(events), rubyargs); } else { rb_raise(rb_eTypeError, "wrong add handle callback argument type (expected Symbol or Proc)"); } if (TYPE(res) != T_FIXNUM) { rb_raise(rb_eTypeError, "expected integer return from add_handle callback"); } return NUM2INT(res); } static void internal_update_handle_func(int watch, int event) { /* call out to the ruby object */ if (strcmp(rb_obj_classname(update_handle), "Symbol") == 0) { rb_funcall(rb_class_of(update_handle), rb_to_id(update_handle), 2, INT2NUM(watch), INT2NUM(event)); } else if (strcmp(rb_obj_classname(update_handle), "Proc") == 0) { rb_funcall(update_handle, rb_intern("call"), 2, INT2NUM(watch), INT2NUM(event)); } else { rb_raise(rb_eTypeError, "wrong update handle callback argument type (expected Symbol or Proc)"); } } static int internal_remove_handle_func(int watch) { VALUE res, libvirt_opaque, ff; virFreeCallback ff_cb; void *op; /* call out to the ruby object */ if (strcmp(rb_obj_classname(remove_handle), "Symbol") == 0) { res = rb_funcall(rb_class_of(remove_handle), rb_to_id(remove_handle), 1, INT2NUM(watch)); } else if (strcmp(rb_obj_classname(remove_handle), "Proc") == 0) { res = rb_funcall(remove_handle, rb_intern("call"), 1, INT2NUM(watch)); } else { rb_raise(rb_eTypeError, "wrong remove handle callback argument type (expected Symbol or Proc)"); } if (TYPE(res) != T_HASH) { rb_raise(rb_eTypeError, "expected opaque hash returned from remove_handle callback"); } ff = rb_hash_aref(res, rb_str_new2("free_func")); if (!NIL_P(ff)) { /* This is equivalent to Data_Get_Struct; I reproduce it here because * I don't want the additional type-cast that Data_Get_Struct does */ Check_Type(ff, T_DATA); ff_cb = DATA_PTR(ff); if (ff_cb) { libvirt_opaque = rb_hash_aref(res, rb_str_new2("opaque")); Data_Get_Struct(libvirt_opaque, void *, op); (*ff_cb)(op); } } return 0; } static int internal_add_timeout_func(int interval, virEventTimeoutCallback cb, void *opaque, virFreeCallback ff) { VALUE rubyargs, res; rubyargs = rb_hash_new(); rb_hash_aset(rubyargs, rb_str_new2("libvirt_cb"), Data_Wrap_Struct(rb_class_of(add_timeout), NULL, NULL, cb)); rb_hash_aset(rubyargs, rb_str_new2("opaque"), Data_Wrap_Struct(rb_class_of(add_timeout), NULL, NULL, opaque)); rb_hash_aset(rubyargs, rb_str_new2("free_func"), Data_Wrap_Struct(rb_class_of(add_timeout), NULL, NULL, ff)); /* call out to the ruby object */ if (strcmp(rb_obj_classname(add_timeout), "Symbol") == 0) { res = rb_funcall(rb_class_of(add_timeout), rb_to_id(add_timeout), 2, INT2NUM(interval), rubyargs); } else if (strcmp(rb_obj_classname(add_timeout), "Proc") == 0) { res = rb_funcall(add_timeout, rb_intern("call"), 2, INT2NUM(interval), rubyargs); } else { rb_raise(rb_eTypeError, "wrong add timeout callback argument type (expected Symbol or Proc)"); } if (TYPE(res) != T_FIXNUM) { rb_raise(rb_eTypeError, "expected integer return from add_timeout callback"); } return NUM2INT(res); } static void internal_update_timeout_func(int timer, int timeout) { /* call out to the ruby object */ if (strcmp(rb_obj_classname(update_timeout), "Symbol") == 0) { rb_funcall(rb_class_of(update_timeout), rb_to_id(update_timeout), 2, INT2NUM(timer), INT2NUM(timeout)); } else if (strcmp(rb_obj_classname(update_timeout), "Proc") == 0) { rb_funcall(update_timeout, rb_intern("call"), 2, INT2NUM(timer), INT2NUM(timeout)); } else { rb_raise(rb_eTypeError, "wrong update timeout callback argument type (expected Symbol or Proc)"); } } static int internal_remove_timeout_func(int timer) { VALUE res, libvirt_opaque, ff; virFreeCallback ff_cb; void *op; /* call out to the ruby object */ if (strcmp(rb_obj_classname(remove_timeout), "Symbol") == 0) { res = rb_funcall(rb_class_of(remove_timeout), rb_to_id(remove_timeout), 1, INT2NUM(timer)); } else if (strcmp(rb_obj_classname(remove_timeout), "Proc") == 0) { res = rb_funcall(remove_timeout, rb_intern("call"), 1, INT2NUM(timer)); } else { rb_raise(rb_eTypeError, "wrong remove timeout callback argument type (expected Symbol or Proc)"); } if (TYPE(res) != T_HASH) { rb_raise(rb_eTypeError, "expected opaque hash returned from remove_timeout callback"); } ff = rb_hash_aref(res, rb_str_new2("free_func")); if (!NIL_P(ff)) { /* This is equivalent to Data_Get_Struct; I reproduce it here because * I don't want the additional type-cast that Data_Get_Struct does */ Check_Type(ff, T_DATA); ff_cb = DATA_PTR(ff); if (ff_cb) { libvirt_opaque = rb_hash_aref(res, rb_str_new2("opaque")); Data_Get_Struct(libvirt_opaque, void *, op); (*ff_cb)(op); } } return 0; } #define set_event_func_or_null(type) \ do { \ if (NIL_P(type)) { \ type##_temp = NULL; \ } \ else { \ type##_temp = internal_##type##_func; \ } \ } while(0) static int is_symbol_proc_or_nil(VALUE handle) { if (NIL_P(handle)) { return 1; } return ruby_libvirt_is_symbol_or_proc(handle); } /* * call-seq: * Libvirt::event_register_impl(add_handle=nil, update_handle=nil, remove_handle=nil, add_timeout=nil, update_timeout=nil, remove_timeout=nil) -> Qnil * * Call virEventRegisterImpl[https://libvirt.org/html/libvirt-libvirt-event.html#virEventRegisterImpl] * to register callback handlers for handles and timeouts. These handles and * timeouts are used as part of the libvirt infrastructure for generating * domain events. Each callback must be a Symbol (that is the name of a * method to callback), a Proc, or nil (to disable the callback). In the * end-user application program, these callbacks are typically used to track * the file descriptors or timers that libvirt is interested in (and is intended * to be integrated into the "main loop" of a UI program). The individual * callbacks will be given a certain number of arguments, and must return * certain values. Those arguments and return types are: * * add_handle(fd, events, opaque) => Fixnum * * update_handle(handleID, event) => nil * * remove_handle(handleID) => opaque data from add_handle * * add_timeout(interval, opaque) => Fixnum * * update_timeout(timerID, timeout) => nil * * remove_timeout(timerID) => opaque data from add_timeout * * Any arguments marked as "opaque" must be accepted from the library and saved * without modification. The values passed to the callbacks are meant to be * passed to the event_invoke_handle_callback and event_invoke_timeout_callback * module methods; see the documentation for those methods for more details. */ static VALUE libvirt_conn_event_register_impl(int argc, VALUE *argv, VALUE RUBY_LIBVIRT_UNUSED(c)) { virEventAddHandleFunc add_handle_temp; virEventUpdateHandleFunc update_handle_temp; virEventRemoveHandleFunc remove_handle_temp; virEventAddTimeoutFunc add_timeout_temp; virEventUpdateTimeoutFunc update_timeout_temp; virEventRemoveTimeoutFunc remove_timeout_temp; /* * subtle; we put the arguments (callbacks) directly into the global * add_handle, update_handle, etc. variables. Then we register the * internal functions as the callbacks with virEventRegisterImpl */ rb_scan_args(argc, argv, "06", &add_handle, &update_handle, &remove_handle, &add_timeout, &update_timeout, &remove_timeout); if (!is_symbol_proc_or_nil(add_handle) || !is_symbol_proc_or_nil(update_handle) || !is_symbol_proc_or_nil(remove_handle) || !is_symbol_proc_or_nil(add_timeout) || !is_symbol_proc_or_nil(update_timeout) || !is_symbol_proc_or_nil(remove_timeout)) { rb_raise(rb_eTypeError, "wrong argument type (expected Symbol, Proc, or nil)"); } set_event_func_or_null(add_handle); set_event_func_or_null(update_handle); set_event_func_or_null(remove_handle); set_event_func_or_null(add_timeout); set_event_func_or_null(update_timeout); set_event_func_or_null(remove_timeout); /* virEventRegisterImpl returns void, so no error checking here */ virEventRegisterImpl(add_handle_temp, update_handle_temp, remove_handle_temp, add_timeout_temp, update_timeout_temp, remove_timeout_temp); return Qnil; } /* * call-seq: * Libvirt::lxc_enter_security_label(model, label, flags=0) -> Libvirt::Domain::SecurityLabel * * Call virDomainLxcEnterSecurityLabel * to attach to the security label specified by label in the security model * specified by model. The return object is a Libvirt::Domain::SecurityLabel * which may be able to be used to move back to the previous label. */ static VALUE libvirt_domain_lxc_enter_security_label(int argc, VALUE *argv, VALUE RUBY_LIBVIRT_UNUSED(c)) { VALUE model = RUBY_Qnil, label = RUBY_Qnil, flags = RUBY_Qnil, result, modiv, doiiv, labiv; virSecurityModel mod; char *modstr, *doistr, *labstr; virSecurityLabel lab, oldlab; int ret; rb_scan_args(argc, argv, "21", &model, &label, &flags); if (rb_class_of(model) != c_node_security_model) { rb_raise(rb_eTypeError, "wrong argument type (expected Libvirt::Connect::NodeSecurityModel)"); } if (rb_class_of(label) != c_domain_security_label) { rb_raise(rb_eTypeError, "wrong argument type (expected Libvirt::Domain::SecurityLabel)"); } modiv = rb_iv_get(model, "@model"); modstr = StringValueCStr(modiv); memcpy(mod.model, modstr, strlen(modstr)); doiiv = rb_iv_get(model, "@doi"); doistr = StringValueCStr(doiiv); memcpy(mod.doi, doistr, strlen(doistr)); labiv = rb_iv_get(label, "@label"); labstr = StringValueCStr(labiv); memcpy(lab.label, labstr, strlen(labstr)); lab.enforcing = NUM2INT(rb_iv_get(label, "@enforcing")); ret = virDomainLxcEnterSecurityLabel(&mod, &lab, &oldlab, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virDomainLxcEnterSecurityLabel", NULL); result = rb_class_new_instance(0, NULL, c_domain_security_label); rb_iv_set(result, "@label", rb_str_new2(oldlab.label)); rb_iv_set(result, "@enforcing", INT2NUM(oldlab.enforcing)); return result; } /* * Module Libvirt */ void Init__libvirt(void) { m_libvirt = rb_define_module("Libvirt"); c_libvirt_version = rb_define_class_under(m_libvirt, "Version", rb_cObject); rb_define_const(m_libvirt, "CONNECT_RO", INT2NUM(VIR_CONNECT_RO)); rb_define_const(m_libvirt, "CRED_USERNAME", INT2NUM(VIR_CRED_USERNAME)); rb_define_const(m_libvirt, "CRED_AUTHNAME", INT2NUM(VIR_CRED_AUTHNAME)); rb_define_const(m_libvirt, "CRED_LANGUAGE", INT2NUM(VIR_CRED_LANGUAGE)); rb_define_const(m_libvirt, "CRED_CNONCE", INT2NUM(VIR_CRED_CNONCE)); rb_define_const(m_libvirt, "CRED_PASSPHRASE", INT2NUM(VIR_CRED_PASSPHRASE)); rb_define_const(m_libvirt, "CRED_ECHOPROMPT", INT2NUM(VIR_CRED_ECHOPROMPT)); rb_define_const(m_libvirt, "CRED_NOECHOPROMPT", INT2NUM(VIR_CRED_NOECHOPROMPT)); rb_define_const(m_libvirt, "CRED_REALM", INT2NUM(VIR_CRED_REALM)); rb_define_const(m_libvirt, "CRED_EXTERNAL", INT2NUM(VIR_CRED_EXTERNAL)); rb_define_const(m_libvirt, "CONNECT_NO_ALIASES", INT2NUM(VIR_CONNECT_NO_ALIASES)); /* * Libvirt Errors */ e_Error = rb_define_class_under(m_libvirt, "Error", rb_eStandardError); e_ConnectionError = rb_define_class_under(m_libvirt, "ConnectionError", e_Error); e_DefinitionError = rb_define_class_under(m_libvirt, "DefinitionError", e_Error); e_RetrieveError = rb_define_class_under(m_libvirt, "RetrieveError", e_Error); e_NoSupportError = rb_define_class_under(m_libvirt, "NoSupportError", e_Error); rb_define_attr(e_Error, "libvirt_function_name", 1, 0); rb_define_attr(e_Error, "libvirt_message", 1, 0); rb_define_attr(e_Error, "libvirt_code", 1, 0); rb_define_attr(e_Error, "libvirt_component", 1, 0); rb_define_attr(e_Error, "libvirt_level", 1, 0); /* libvirt error components (domains) */ rb_define_const(e_Error, "FROM_NONE", INT2NUM(VIR_FROM_NONE)); rb_define_const(e_Error, "FROM_XEN", INT2NUM(VIR_FROM_XEN)); rb_define_const(e_Error, "FROM_XEND", INT2NUM(VIR_FROM_XEND)); rb_define_const(e_Error, "FROM_XENSTORE", INT2NUM(VIR_FROM_XENSTORE)); rb_define_const(e_Error, "FROM_SEXPR", INT2NUM(VIR_FROM_SEXPR)); rb_define_const(e_Error, "FROM_XML", INT2NUM(VIR_FROM_XML)); rb_define_const(e_Error, "FROM_DOM", INT2NUM(VIR_FROM_DOM)); rb_define_const(e_Error, "FROM_RPC", INT2NUM(VIR_FROM_RPC)); rb_define_const(e_Error, "FROM_PROXY", INT2NUM(VIR_FROM_PROXY)); rb_define_const(e_Error, "FROM_CONF", INT2NUM(VIR_FROM_CONF)); rb_define_const(e_Error, "FROM_QEMU", INT2NUM(VIR_FROM_QEMU)); rb_define_const(e_Error, "FROM_NET", INT2NUM(VIR_FROM_NET)); rb_define_const(e_Error, "FROM_TEST", INT2NUM(VIR_FROM_TEST)); rb_define_const(e_Error, "FROM_REMOTE", INT2NUM(VIR_FROM_REMOTE)); rb_define_const(e_Error, "FROM_OPENVZ", INT2NUM(VIR_FROM_OPENVZ)); rb_define_const(e_Error, "FROM_VMWARE", INT2NUM(VIR_FROM_VMWARE)); rb_define_const(e_Error, "FROM_XENXM", INT2NUM(VIR_FROM_XENXM)); rb_define_const(e_Error, "FROM_STATS_LINUX", INT2NUM(VIR_FROM_STATS_LINUX)); rb_define_const(e_Error, "FROM_LXC", INT2NUM(VIR_FROM_LXC)); rb_define_const(e_Error, "FROM_STORAGE", INT2NUM(VIR_FROM_STORAGE)); rb_define_const(e_Error, "FROM_NETWORK", INT2NUM(VIR_FROM_NETWORK)); rb_define_const(e_Error, "FROM_DOMAIN", INT2NUM(VIR_FROM_DOMAIN)); rb_define_const(e_Error, "FROM_UML", INT2NUM(VIR_FROM_UML)); rb_define_const(e_Error, "FROM_NODEDEV", INT2NUM(VIR_FROM_NODEDEV)); rb_define_const(e_Error, "FROM_XEN_INOTIFY", INT2NUM(VIR_FROM_XEN_INOTIFY)); rb_define_const(e_Error, "FROM_SECURITY", INT2NUM(VIR_FROM_SECURITY)); rb_define_const(e_Error, "FROM_VBOX", INT2NUM(VIR_FROM_VBOX)); rb_define_const(e_Error, "FROM_INTERFACE", INT2NUM(VIR_FROM_INTERFACE)); rb_define_const(e_Error, "FROM_ONE", INT2NUM(VIR_FROM_ONE)); rb_define_const(e_Error, "FROM_ESX", INT2NUM(VIR_FROM_ESX)); rb_define_const(e_Error, "FROM_PHYP", INT2NUM(VIR_FROM_PHYP)); rb_define_const(e_Error, "FROM_SECRET", INT2NUM(VIR_FROM_SECRET)); rb_define_const(e_Error, "FROM_CPU", INT2NUM(VIR_FROM_CPU)); rb_define_const(e_Error, "FROM_XENAPI", INT2NUM(VIR_FROM_XENAPI)); rb_define_const(e_Error, "FROM_NWFILTER", INT2NUM(VIR_FROM_NWFILTER)); rb_define_const(e_Error, "FROM_HOOK", INT2NUM(VIR_FROM_HOOK)); rb_define_const(e_Error, "FROM_DOMAIN_SNAPSHOT", INT2NUM(VIR_FROM_DOMAIN_SNAPSHOT)); rb_define_const(e_Error, "FROM_AUDIT", INT2NUM(VIR_FROM_AUDIT)); rb_define_const(e_Error, "FROM_SYSINFO", INT2NUM(VIR_FROM_SYSINFO)); rb_define_const(e_Error, "FROM_STREAMS", INT2NUM(VIR_FROM_STREAMS)); /* libvirt error codes */ rb_define_const(e_Error, "ERR_OK", INT2NUM(VIR_ERR_OK)); rb_define_const(e_Error, "ERR_INTERNAL_ERROR", INT2NUM(VIR_ERR_INTERNAL_ERROR)); rb_define_const(e_Error, "ERR_NO_MEMORY", INT2NUM(VIR_ERR_NO_MEMORY)); rb_define_const(e_Error, "ERR_NO_SUPPORT", INT2NUM(VIR_ERR_NO_SUPPORT)); rb_define_const(e_Error, "ERR_UNKNOWN_HOST", INT2NUM(VIR_ERR_UNKNOWN_HOST)); rb_define_const(e_Error, "ERR_NO_CONNECT", INT2NUM(VIR_ERR_NO_CONNECT)); rb_define_const(e_Error, "ERR_INVALID_CONN", INT2NUM(VIR_ERR_INVALID_CONN)); rb_define_const(e_Error, "ERR_INVALID_DOMAIN", INT2NUM(VIR_ERR_INVALID_DOMAIN)); rb_define_const(e_Error, "ERR_INVALID_ARG", INT2NUM(VIR_ERR_INVALID_ARG)); rb_define_const(e_Error, "ERR_OPERATION_FAILED", INT2NUM(VIR_ERR_OPERATION_FAILED)); rb_define_const(e_Error, "ERR_GET_FAILED", INT2NUM(VIR_ERR_GET_FAILED)); rb_define_const(e_Error, "ERR_POST_FAILED", INT2NUM(VIR_ERR_POST_FAILED)); rb_define_const(e_Error, "ERR_HTTP_ERROR", INT2NUM(VIR_ERR_HTTP_ERROR)); rb_define_const(e_Error, "ERR_SEXPR_SERIAL", INT2NUM(VIR_ERR_SEXPR_SERIAL)); rb_define_const(e_Error, "ERR_NO_XEN", INT2NUM(VIR_ERR_NO_XEN)); rb_define_const(e_Error, "ERR_XEN_CALL", INT2NUM(VIR_ERR_XEN_CALL)); rb_define_const(e_Error, "ERR_OS_TYPE", INT2NUM(VIR_ERR_OS_TYPE)); rb_define_const(e_Error, "ERR_NO_KERNEL", INT2NUM(VIR_ERR_NO_KERNEL)); rb_define_const(e_Error, "ERR_NO_ROOT", INT2NUM(VIR_ERR_NO_ROOT)); rb_define_const(e_Error, "ERR_NO_SOURCE", INT2NUM(VIR_ERR_NO_SOURCE)); rb_define_const(e_Error, "ERR_NO_TARGET", INT2NUM(VIR_ERR_NO_TARGET)); rb_define_const(e_Error, "ERR_NO_NAME", INT2NUM(VIR_ERR_NO_NAME)); rb_define_const(e_Error, "ERR_NO_OS", INT2NUM(VIR_ERR_NO_OS)); rb_define_const(e_Error, "ERR_NO_DEVICE", INT2NUM(VIR_ERR_NO_DEVICE)); rb_define_const(e_Error, "ERR_NO_XENSTORE", INT2NUM(VIR_ERR_NO_XENSTORE)); rb_define_const(e_Error, "ERR_DRIVER_FULL", INT2NUM(VIR_ERR_DRIVER_FULL)); rb_define_const(e_Error, "ERR_CALL_FAILED", INT2NUM(VIR_ERR_CALL_FAILED)); rb_define_const(e_Error, "ERR_XML_ERROR", INT2NUM(VIR_ERR_XML_ERROR)); rb_define_const(e_Error, "ERR_DOM_EXIST", INT2NUM(VIR_ERR_DOM_EXIST)); rb_define_const(e_Error, "ERR_OPERATION_DENIED", INT2NUM(VIR_ERR_OPERATION_DENIED)); rb_define_const(e_Error, "ERR_OPEN_FAILED", INT2NUM(VIR_ERR_OPEN_FAILED)); rb_define_const(e_Error, "ERR_READ_FAILED", INT2NUM(VIR_ERR_READ_FAILED)); rb_define_const(e_Error, "ERR_PARSE_FAILED", INT2NUM(VIR_ERR_PARSE_FAILED)); rb_define_const(e_Error, "ERR_CONF_SYNTAX", INT2NUM(VIR_ERR_CONF_SYNTAX)); rb_define_const(e_Error, "ERR_WRITE_FAILED", INT2NUM(VIR_ERR_WRITE_FAILED)); rb_define_const(e_Error, "ERR_XML_DETAIL", INT2NUM(VIR_ERR_XML_DETAIL)); rb_define_const(e_Error, "ERR_INVALID_NETWORK", INT2NUM(VIR_ERR_INVALID_NETWORK)); rb_define_const(e_Error, "ERR_NETWORK_EXIST", INT2NUM(VIR_ERR_NETWORK_EXIST)); rb_define_const(e_Error, "ERR_SYSTEM_ERROR", INT2NUM(VIR_ERR_SYSTEM_ERROR)); rb_define_const(e_Error, "ERR_RPC", INT2NUM(VIR_ERR_RPC)); rb_define_const(e_Error, "ERR_GNUTLS_ERROR", INT2NUM(VIR_ERR_GNUTLS_ERROR)); rb_define_const(e_Error, "WAR_NO_NETWORK", INT2NUM(VIR_WAR_NO_NETWORK)); rb_define_const(e_Error, "ERR_NO_DOMAIN", INT2NUM(VIR_ERR_NO_DOMAIN)); rb_define_const(e_Error, "ERR_NO_NETWORK", INT2NUM(VIR_ERR_NO_NETWORK)); rb_define_const(e_Error, "ERR_INVALID_MAC", INT2NUM(VIR_ERR_INVALID_MAC)); rb_define_const(e_Error, "ERR_AUTH_FAILED", INT2NUM(VIR_ERR_AUTH_FAILED)); rb_define_const(e_Error, "ERR_INVALID_STORAGE_POOL", INT2NUM(VIR_ERR_INVALID_STORAGE_POOL)); rb_define_const(e_Error, "ERR_INVALID_STORAGE_VOL", INT2NUM(VIR_ERR_INVALID_STORAGE_VOL)); rb_define_const(e_Error, "WAR_NO_STORAGE", INT2NUM(VIR_WAR_NO_STORAGE)); rb_define_const(e_Error, "ERR_NO_STORAGE_POOL", INT2NUM(VIR_ERR_NO_STORAGE_POOL)); rb_define_const(e_Error, "ERR_NO_STORAGE_VOL", INT2NUM(VIR_ERR_NO_STORAGE_VOL)); rb_define_const(e_Error, "WAR_NO_NODE", INT2NUM(VIR_WAR_NO_NODE)); rb_define_const(e_Error, "ERR_INVALID_NODE_DEVICE", INT2NUM(VIR_ERR_INVALID_NODE_DEVICE)); rb_define_const(e_Error, "ERR_NO_NODE_DEVICE", INT2NUM(VIR_ERR_NO_NODE_DEVICE)); rb_define_const(e_Error, "ERR_NO_SECURITY_MODEL", INT2NUM(VIR_ERR_NO_SECURITY_MODEL)); rb_define_const(e_Error, "ERR_OPERATION_INVALID", INT2NUM(VIR_ERR_OPERATION_INVALID)); rb_define_const(e_Error, "WAR_NO_INTERFACE", INT2NUM(VIR_WAR_NO_INTERFACE)); rb_define_const(e_Error, "ERR_NO_INTERFACE", INT2NUM(VIR_ERR_NO_INTERFACE)); rb_define_const(e_Error, "ERR_INVALID_INTERFACE", INT2NUM(VIR_ERR_INVALID_INTERFACE)); rb_define_const(e_Error, "ERR_MULTIPLE_INTERFACES", INT2NUM(VIR_ERR_MULTIPLE_INTERFACES)); rb_define_const(e_Error, "WAR_NO_NWFILTER", INT2NUM(VIR_WAR_NO_NWFILTER)); rb_define_const(e_Error, "ERR_INVALID_NWFILTER", INT2NUM(VIR_ERR_INVALID_NWFILTER)); rb_define_const(e_Error, "ERR_NO_NWFILTER", INT2NUM(VIR_ERR_NO_NWFILTER)); rb_define_const(e_Error, "ERR_BUILD_FIREWALL", INT2NUM(VIR_ERR_BUILD_FIREWALL)); rb_define_const(e_Error, "WAR_NO_SECRET", INT2NUM(VIR_WAR_NO_SECRET)); rb_define_const(e_Error, "ERR_INVALID_SECRET", INT2NUM(VIR_ERR_INVALID_SECRET)); rb_define_const(e_Error, "ERR_NO_SECRET", INT2NUM(VIR_ERR_NO_SECRET)); rb_define_const(e_Error, "ERR_CONFIG_UNSUPPORTED", INT2NUM(VIR_ERR_CONFIG_UNSUPPORTED)); rb_define_const(e_Error, "ERR_OPERATION_TIMEOUT", INT2NUM(VIR_ERR_OPERATION_TIMEOUT)); rb_define_const(e_Error, "ERR_MIGRATE_PERSIST_FAILED", INT2NUM(VIR_ERR_MIGRATE_PERSIST_FAILED)); rb_define_const(e_Error, "ERR_HOOK_SCRIPT_FAILED", INT2NUM(VIR_ERR_HOOK_SCRIPT_FAILED)); rb_define_const(e_Error, "ERR_INVALID_DOMAIN_SNAPSHOT", INT2NUM(VIR_ERR_INVALID_DOMAIN_SNAPSHOT)); rb_define_const(e_Error, "ERR_NO_DOMAIN_SNAPSHOT", INT2NUM(VIR_ERR_NO_DOMAIN_SNAPSHOT)); /* libvirt levels */ rb_define_const(e_Error, "LEVEL_NONE", INT2NUM(VIR_ERR_NONE)); rb_define_const(e_Error, "LEVEL_WARNING", INT2NUM(VIR_ERR_WARNING)); rb_define_const(e_Error, "LEVEL_ERROR", INT2NUM(VIR_ERR_ERROR)); rb_define_module_function(m_libvirt, "version", libvirt_version, -1); rb_define_module_function(m_libvirt, "open", libvirt_open, -1); rb_define_module_function(m_libvirt, "open_read_only", libvirt_open_read_only, -1); rb_define_module_function(m_libvirt, "open_auth", libvirt_open_auth, -1); rb_define_const(m_libvirt, "EVENT_HANDLE_READABLE", INT2NUM(VIR_EVENT_HANDLE_READABLE)); rb_define_const(m_libvirt, "EVENT_HANDLE_WRITABLE", INT2NUM(VIR_EVENT_HANDLE_WRITABLE)); rb_define_const(m_libvirt, "EVENT_HANDLE_ERROR", INT2NUM(VIR_EVENT_HANDLE_ERROR)); rb_define_const(m_libvirt, "EVENT_HANDLE_HANGUP", INT2NUM(VIR_EVENT_HANDLE_HANGUP)); /* since we are using globals, we have to register with the gc */ rb_global_variable(&add_handle); rb_global_variable(&update_handle); rb_global_variable(&remove_handle); rb_global_variable(&add_timeout); rb_global_variable(&update_timeout); rb_global_variable(&remove_timeout); rb_define_module_function(m_libvirt, "event_register_impl", libvirt_conn_event_register_impl, -1); rb_define_module_function(m_libvirt, "event_invoke_handle_callback", libvirt_event_invoke_handle_callback, 4); rb_define_module_function(m_libvirt, "event_invoke_timeout_callback", libvirt_event_invoke_timeout_callback, 2); rb_define_method(m_libvirt, "lxc_enter_security_label", libvirt_domain_lxc_enter_security_label, -1); ruby_libvirt_connect_init(); ruby_libvirt_storage_init(); ruby_libvirt_network_init(); ruby_libvirt_nodedevice_init(); ruby_libvirt_secret_init(); ruby_libvirt_nwfilter_init(); ruby_libvirt_interface_init(); ruby_libvirt_domain_init(); ruby_libvirt_stream_init(); virSetErrorFunc(NULL, rubyLibvirtErrorFunc); if (virInitialize() < 0) { rb_raise(rb_eSystemCallError, "virInitialize failed"); } } ruby-libvirt-0.8.4/ext/libvirt/secret.h0000644000175000017500000000021414557177263020232 0ustar abolognaabologna#ifndef SECRET_H #define SECRET_H void ruby_libvirt_secret_init(void); VALUE ruby_libvirt_secret_new(virSecretPtr s, VALUE conn); #endif ruby-libvirt-0.8.4/ext/libvirt/nwfilter.h0000644000175000017500000000022614557177263020602 0ustar abolognaabologna#ifndef NWFILTER_H #define NWFILTER_H void ruby_libvirt_nwfilter_init(void); VALUE ruby_libvirt_nwfilter_new(virNWFilterPtr n, VALUE conn); #endif ruby-libvirt-0.8.4/ext/libvirt/stream.h0000644000175000017500000000027314557177263020245 0ustar abolognaabologna#ifndef STREAM_H #define STREAM_H void ruby_libvirt_stream_init(void); VALUE ruby_libvirt_stream_new(virStreamPtr s, VALUE conn); virStreamPtr ruby_libvirt_stream_get(VALUE s); #endif ruby-libvirt-0.8.4/ext/libvirt/domain.c0000644000175000017500000061571014641546211020207 0ustar abolognaabologna/* * domain.c: virDomain methods * * Copyright (C) 2007,2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include /* we need to include st.h since ruby 1.8 needs it for RHash */ #include #include #include #include #include #include "common.h" #include "connect.h" #include "extconf.h" #include "stream.h" static VALUE c_domain; static VALUE c_domain_info; static VALUE c_domain_ifinfo; VALUE c_domain_security_label; static VALUE c_domain_block_stats; static VALUE c_domain_block_info; static VALUE c_domain_memory_stats; static VALUE c_domain_snapshot; static VALUE c_domain_job_info; static VALUE c_domain_vcpuinfo; static VALUE c_domain_control_info; static VALUE c_domain_block_job_info; static void domain_free(void *d) { ruby_libvirt_free_struct(Domain, d); } VALUE ruby_libvirt_domain_new(virDomainPtr d, VALUE conn) { return ruby_libvirt_new_class(c_domain, d, conn, domain_free); } virDomainPtr ruby_libvirt_domain_get(VALUE d) { ruby_libvirt_get_struct(Domain, d); } static void domain_input_to_fixnum_and_flags(VALUE in, VALUE *hash, VALUE *flags) { if (TYPE(in) == T_FIXNUM) { *hash = in; *flags = INT2NUM(0); } else if (TYPE(in) == T_ARRAY) { if (RARRAY_LEN(in) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(in)); } *hash = rb_ary_entry(in, 0); *flags = rb_ary_entry(in, 1); } else { rb_raise(rb_eTypeError, "wrong argument type (expected Number or Array)"); } } /* * call-seq: * dom.migrate(dconn, flags=0, dname=nil, uri=nil, bandwidth=0) -> Libvirt::Domain * * Call virDomainMigrate[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrate] * to migrate a domain from the host on this connection to the connection * referenced in dconn. */ static VALUE libvirt_domain_migrate(int argc, VALUE *argv, VALUE d) { VALUE dconn, flags, dname, uri, bandwidth; virDomainPtr ddom = NULL; rb_scan_args(argc, argv, "14", &dconn, &flags, &dname, &uri, &bandwidth); ddom = virDomainMigrate(ruby_libvirt_domain_get(d), ruby_libvirt_connect_get(dconn), ruby_libvirt_value_to_ulong(flags), ruby_libvirt_get_cstring_or_null(dname), ruby_libvirt_get_cstring_or_null(uri), ruby_libvirt_value_to_ulong(bandwidth)); ruby_libvirt_raise_error_if(ddom == NULL, e_Error, "virDomainMigrate", ruby_libvirt_connect_get(d)); return ruby_libvirt_domain_new(ddom, dconn); } /* * call-seq: * dom.migrate_to_uri(duri, flags=0, dname=nil, bandwidth=0) -> nil * * Call virDomainMigrateToURI[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateToURI] * to migrate a domain from the host on this connection to the host whose * libvirt URI is duri. */ static VALUE libvirt_domain_migrate_to_uri(int argc, VALUE *argv, VALUE d) { VALUE duri, flags, dname, bandwidth; rb_scan_args(argc, argv, "13", &duri, &flags, &dname, &bandwidth); ruby_libvirt_generate_call_nil(virDomainMigrateToURI, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(duri), NUM2ULONG(flags), ruby_libvirt_get_cstring_or_null(dname), ruby_libvirt_value_to_ulong(bandwidth)); } /* * call-seq: * dom.migrate_set_max_downtime(downtime, flags=0) -> nil * * Call virDomainMigrateSetMaxDowntime[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateSetMaxDowntime] * to set the maximum downtime desired for live migration. Deprecated; use * dom.migrate_max_downtime= instead. */ static VALUE libvirt_domain_migrate_set_max_downtime(int argc, VALUE *argv, VALUE d) { VALUE downtime, flags; rb_scan_args(argc, argv, "11", &downtime, &flags); ruby_libvirt_generate_call_nil(virDomainMigrateSetMaxDowntime, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2ULL(downtime), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.migrate_max_downtime = downtime,flags=0 * * Call virDomainMigrateSetMaxDowntime[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateSetMaxDowntime] * to set the maximum downtime desired for live migration. */ static VALUE libvirt_domain_migrate_max_downtime_equal(VALUE d, VALUE in) { VALUE downtime, flags; domain_input_to_fixnum_and_flags(in, &downtime, &flags); ruby_libvirt_generate_call_nil(virDomainMigrateSetMaxDowntime, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2ULL(downtime), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.migrate2(dconn, dxml=nil, flags=0, dname=nil, uri=nil, bandwidth=0) -> Libvirt::Domain * * Call virDomainMigrate2[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrate2] * to migrate a domain from the host on this connection to the connection * referenced in dconn. */ static VALUE libvirt_domain_migrate2(int argc, VALUE *argv, VALUE d) { VALUE dconn, dxml, flags, dname, uri, bandwidth; virDomainPtr ddom = NULL; rb_scan_args(argc, argv, "15", &dconn, &dxml, &flags, &dname, &uri, &bandwidth); ddom = virDomainMigrate2(ruby_libvirt_domain_get(d), ruby_libvirt_connect_get(dconn), ruby_libvirt_get_cstring_or_null(dxml), ruby_libvirt_value_to_ulong(flags), ruby_libvirt_get_cstring_or_null(dname), ruby_libvirt_get_cstring_or_null(uri), ruby_libvirt_value_to_ulong(bandwidth)); ruby_libvirt_raise_error_if(ddom == NULL, e_Error, "virDomainMigrate2", ruby_libvirt_connect_get(d)); return ruby_libvirt_domain_new(ddom, dconn); } /* * call-seq: * dom.migrate_to_uri2(duri=nil, migrate_uri=nil, dxml=nil, flags=0, dname=nil, bandwidth=0) -> nil * * Call virDomainMigrateToURI2[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateToURI2] * to migrate a domain from the host on this connection to the host whose * libvirt URI is duri. */ static VALUE libvirt_domain_migrate_to_uri2(int argc, VALUE *argv, VALUE d) { VALUE duri, migrate_uri, dxml, flags, dname, bandwidth; rb_scan_args(argc, argv, "06", &duri, &migrate_uri, &dxml, &flags, &dname, &bandwidth); ruby_libvirt_generate_call_nil(virDomainMigrateToURI2, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_get_cstring_or_null(duri), ruby_libvirt_get_cstring_or_null(migrate_uri), ruby_libvirt_get_cstring_or_null(dxml), ruby_libvirt_value_to_ulong(flags), ruby_libvirt_get_cstring_or_null(dname), ruby_libvirt_value_to_ulong(bandwidth)); } /* * call-seq: * dom.migrate_set_max_speed(bandwidth, flags=0) -> nil * * Call virDomainMigrateSetMaxSpeed[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateSetMaxSpeed] * to set the maximum bandwidth allowed for live migration. Deprecated; use * dom.migrate_max_speed= instead. */ static VALUE libvirt_domain_migrate_set_max_speed(int argc, VALUE *argv, VALUE d) { VALUE bandwidth, flags; rb_scan_args(argc, argv, "11", &bandwidth, &flags); ruby_libvirt_generate_call_nil(virDomainMigrateSetMaxSpeed, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2ULONG(bandwidth), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.migrate_max_speed = bandwidth,flags=0 * * Call virDomainMigrateSetMaxSpeed[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateSetMaxSpeed] * to set the maximum bandwidth allowed for live migration. */ static VALUE libvirt_domain_migrate_max_speed_equal(VALUE d, VALUE in) { VALUE bandwidth, flags; domain_input_to_fixnum_and_flags(in, &bandwidth, &flags); ruby_libvirt_generate_call_nil(virDomainMigrateSetMaxSpeed, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2ULONG(bandwidth), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.shutdown(flags=0) -> nil * * Call virDomainShutdown[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainShutdown] * to do a soft shutdown of the domain. The mechanism for doing the shutdown * is hypervisor specific, and may require software running inside the domain * to succeed. */ static VALUE libvirt_domain_shutdown(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); if (ruby_libvirt_value_to_uint(flags) != 0) { ruby_libvirt_generate_call_nil(virDomainShutdownFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } else { ruby_libvirt_generate_call_nil(virDomainShutdown, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } } /* * call-seq: * dom.reboot(flags=0) -> nil * * Call virDomainReboot[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainReboot] * to do a reboot of the domain. */ static VALUE libvirt_domain_reboot(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virDomainReboot, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.destroy(flags=0) -> nil * * Call virDomainDestroy[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDestroy] * to do a hard power-off of the domain. */ static VALUE libvirt_domain_destroy(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); if (ruby_libvirt_value_to_uint(flags) != 0) { ruby_libvirt_generate_call_nil(virDomainDestroyFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } else { ruby_libvirt_generate_call_nil(virDomainDestroy, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } } /* * call-seq: * dom.suspend -> nil * * Call virDomainSuspend[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSuspend] * to stop the domain from executing. The domain will still continue to * consume memory, but will not take any CPU time. */ static VALUE libvirt_domain_suspend(VALUE d) { ruby_libvirt_generate_call_nil(virDomainSuspend, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } /* * call-seq: * dom.resume -> nil * * Call virDomainResume[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainResume] * to resume a suspended domain. After this call the domain will start * consuming CPU resources again. */ static VALUE libvirt_domain_resume(VALUE d) { ruby_libvirt_generate_call_nil(virDomainResume, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } /* * call-seq: * dom.save(filename, dxml=nil, flags=0) -> nil * * Call virDomainSave[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSave] * to save the domain state to filename. After this call, the domain will no * longer be consuming any resources. */ static VALUE libvirt_domain_save(int argc, VALUE *argv, VALUE d) { VALUE flags, to, dxml; rb_scan_args(argc, argv, "12", &to, &dxml, &flags); if (ruby_libvirt_value_to_uint(flags) != 0 || TYPE(dxml) != T_NIL) { ruby_libvirt_generate_call_nil(virDomainSaveFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(to), ruby_libvirt_get_cstring_or_null(dxml), ruby_libvirt_value_to_uint(flags)); } else { ruby_libvirt_generate_call_nil(virDomainSave, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(to)); } } /* * call-seq: * dom.managed_save(flags=0) -> nil * * Call virDomainManagedSave[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainManagedSave] * to do a managed save of the domain. The domain will be saved to a place * of libvirt's choosing. */ static VALUE libvirt_domain_managed_save(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virDomainManagedSave, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.has_managed_save?(flags=0) -> [True|False] * * Call virDomainHasManagedSaveImage[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainHasManagedSaveImage] * to determine if a particular domain has a managed save image. */ static VALUE libvirt_domain_has_managed_save(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_truefalse(virDomainHasManagedSaveImage, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.managed_save_remove(flags=0) -> nil * * Call virDomainManagedSaveRemove[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainManagedSaveRemove] * to remove the managed save image for a domain. */ static VALUE libvirt_domain_managed_save_remove(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virDomainManagedSaveRemove, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.core_dump(filename, flags=0) -> nil * * Call virDomainCoreDump[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCoreDump] * to do a full memory dump of the domain to filename. */ static VALUE libvirt_domain_core_dump(int argc, VALUE *argv, VALUE d) { VALUE to, flags; rb_scan_args(argc, argv, "11", &to, &flags); ruby_libvirt_generate_call_nil(virDomainCoreDump, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(to), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * Libvirt::Domain::restore(conn, filename) -> nil * * Call virDomainRestore[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainRestore] * to restore the domain from the filename. */ static VALUE libvirt_domain_s_restore(VALUE RUBY_LIBVIRT_UNUSED(klass), VALUE c, VALUE from) { ruby_libvirt_generate_call_nil(virDomainRestore, ruby_libvirt_connect_get(c), ruby_libvirt_connect_get(c), StringValueCStr(from)); } /* * call-seq: * dom.info -> Libvirt::Domain::Info * * Call virDomainGetInfo[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetInfo] * to retrieve domain information. */ static VALUE libvirt_domain_info(VALUE d) { virDomainInfo info; int r; VALUE result; r = virDomainGetInfo(ruby_libvirt_domain_get(d), &info); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainGetInfo", ruby_libvirt_connect_get(d)); result = rb_class_new_instance(0, NULL, c_domain_info); rb_iv_set(result, "@state", CHR2FIX(info.state)); rb_iv_set(result, "@max_mem", ULONG2NUM(info.maxMem)); rb_iv_set(result, "@memory", ULONG2NUM(info.memory)); rb_iv_set(result, "@nr_virt_cpu", INT2NUM((int) info.nrVirtCpu)); rb_iv_set(result, "@cpu_time", ULL2NUM(info.cpuTime)); return result; } /* * call-seq: * dom.security_label -> Libvirt::Domain::SecurityLabel * * Call virDomainGetSecurityLabel[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSecurityLabel] * to retrieve the security label applied to this domain. */ static VALUE libvirt_domain_security_label(VALUE d) { virSecurityLabel seclabel; int r; VALUE result; r = virDomainGetSecurityLabel(ruby_libvirt_domain_get(d), &seclabel); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainGetSecurityLabel", ruby_libvirt_connect_get(d)); result = rb_class_new_instance(0, NULL, c_domain_security_label); rb_iv_set(result, "@label", rb_str_new2(seclabel.label)); rb_iv_set(result, "@enforcing", INT2NUM(seclabel.enforcing)); return result; } /* * call-seq: * dom.block_stats(path) -> Libvirt::Domain::BlockStats * * Call virDomainBlockStats[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockStats] * to retrieve statistics about domain block device path. */ static VALUE libvirt_domain_block_stats(VALUE d, VALUE path) { virDomainBlockStatsStruct stats; int r; VALUE result; r = virDomainBlockStats(ruby_libvirt_domain_get(d), StringValueCStr(path), &stats, sizeof(stats)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainBlockStats", ruby_libvirt_connect_get(d)); result = rb_class_new_instance(0, NULL, c_domain_block_stats); rb_iv_set(result, "@rd_req", LL2NUM(stats.rd_req)); rb_iv_set(result, "@rd_bytes", LL2NUM(stats.rd_bytes)); rb_iv_set(result, "@wr_req", LL2NUM(stats.wr_req)); rb_iv_set(result, "@wr_bytes", LL2NUM(stats.wr_bytes)); rb_iv_set(result, "@errs", LL2NUM(stats.errs)); return result; } /* * call-seq: * dom.memory_stats(flags=0) -> [ Libvirt::Domain::MemoryStats ] * * Call virDomainMemoryStats[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMemoryStats] * to retrieve statistics about the amount of memory consumed by a domain. */ static VALUE libvirt_domain_memory_stats(int argc, VALUE *argv, VALUE d) { virDomainMemoryStatStruct stats[6]; int i, r; VALUE result, flags, tmp; rb_scan_args(argc, argv, "01", &flags); r = virDomainMemoryStats(ruby_libvirt_domain_get(d), stats, 6, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainMemoryStats", ruby_libvirt_connect_get(d)); /* FIXME: the right rubyish way to have done this would have been to * create a hash with the values, something like: * * { 'SWAP_IN' => 0, 'SWAP_OUT' => 98, 'MAJOR_FAULT' => 45, * 'MINOR_FAULT' => 55, 'UNUSED' => 455, 'AVAILABLE' => 98 } * * Unfortunately this has already been released with the array version * so we have to maintain compatibility with that. We should probably add * a new memory_stats-like call that properly creates the hash. */ result = rb_ary_new2(r); for (i = 0; i < r; i++) { tmp = rb_class_new_instance(0, NULL, c_domain_memory_stats); rb_iv_set(tmp, "@tag", INT2NUM(stats[i].tag)); rb_iv_set(tmp, "@val", ULL2NUM(stats[i].val)); rb_ary_store(result, i, tmp); } return result; } /* * call-seq: * dom.blockinfo(path, flags=0) -> Libvirt::Domain::BlockInfo * * Call virDomainGetBlockInfo[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetBlockInfo] * to retrieve information about the backing file path for the domain. */ static VALUE libvirt_domain_block_info(int argc, VALUE *argv, VALUE d) { virDomainBlockInfo info; int r; VALUE result, flags, path; rb_scan_args(argc, argv, "11", &path, &flags); r = virDomainGetBlockInfo(ruby_libvirt_domain_get(d), StringValueCStr(path), &info, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainGetBlockInfo", ruby_libvirt_connect_get(d)); result = rb_class_new_instance(0, NULL, c_domain_block_info); rb_iv_set(result, "@capacity", ULL2NUM(info.capacity)); rb_iv_set(result, "@allocation", ULL2NUM(info.allocation)); rb_iv_set(result, "@physical", ULL2NUM(info.physical)); return result; } /* * call-seq: * dom.block_peek(path, offset, size, flags=0) -> String * * Call virDomainBlockPeek[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockPeek] * to read size number of bytes, starting at offset offset from domain backing * file path. Due to limitations of the libvirt remote protocol, the user * should never request more than 64k bytes. */ static VALUE libvirt_domain_block_peek(int argc, VALUE *argv, VALUE d) { VALUE path, offset, size, flags; char *buffer; int r; rb_scan_args(argc, argv, "31", &path, &offset, &size, &flags); buffer = alloca(sizeof(char) * NUM2UINT(size)); r = virDomainBlockPeek(ruby_libvirt_domain_get(d), StringValueCStr(path), NUM2ULL(offset), NUM2UINT(size), buffer, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainBlockPeek", ruby_libvirt_connect_get(d)); return rb_str_new(buffer, NUM2UINT(size)); } /* * call-seq: * dom.memory_peek(start, size, flags=Libvirt::Domain::MEMORY_VIRTUAL) -> String * * Call virDomainMemoryPeek[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMemoryPeek] * to read size number of bytes from offset start from the domain memory. * Due to limitations of the libvirt remote protocol, the user * should never request more than 64k bytes. */ static VALUE libvirt_domain_memory_peek(int argc, VALUE *argv, VALUE d) { VALUE start, size, flags; char *buffer; int r; rb_scan_args(argc, argv, "21", &start, &size, &flags); if (NIL_P(flags)) { flags = INT2NUM(VIR_MEMORY_VIRTUAL); } buffer = alloca(sizeof(char) * NUM2UINT(size)); r = virDomainMemoryPeek(ruby_libvirt_domain_get(d), NUM2ULL(start), NUM2UINT(size), buffer, NUM2UINT(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainMemoryPeek", ruby_libvirt_connect_get(d)); return rb_str_new(buffer, NUM2UINT(size)); } /* call-seq: * dom.vcpus -> [ Libvirt::Domain::VCPUInfo ] * * Call virDomainGetVcpus[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetVcpus] * to retrieve detailed information about the state of a domain's virtual CPUs. */ static VALUE libvirt_domain_vcpus(VALUE d) { virDomainInfo dominfo; virVcpuInfoPtr cpuinfo = NULL; unsigned char *cpumap; int cpumaplen, r, j, maxcpus; VALUE result, vcpuinfo, p2vcpumap; unsigned short i; r = virDomainGetInfo(ruby_libvirt_domain_get(d), &dominfo); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainGetInfo", ruby_libvirt_connect_get(d)); cpuinfo = alloca(sizeof(virVcpuInfo) * dominfo.nrVirtCpu); maxcpus = ruby_libvirt_get_maxcpus(ruby_libvirt_connect_get(d)); cpumaplen = VIR_CPU_MAPLEN(maxcpus); cpumap = alloca(sizeof(unsigned char) * cpumaplen * dominfo.nrVirtCpu); r = virDomainGetVcpus(ruby_libvirt_domain_get(d), cpuinfo, dominfo.nrVirtCpu, cpumap, cpumaplen); if (r < 0) { /* if the domain is not shutoff, then this is an error */ ruby_libvirt_raise_error_if(dominfo.state != VIR_DOMAIN_SHUTOFF, e_RetrieveError, "virDomainGetVcpus", ruby_libvirt_connect_get(d)); /* otherwise, we can try to call virDomainGetVcpuPinInfo to get the * information instead */ r = virDomainGetVcpuPinInfo(ruby_libvirt_domain_get(d), dominfo.nrVirtCpu, cpumap, cpumaplen, VIR_DOMAIN_AFFECT_CONFIG); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainGetVcpuPinInfo", ruby_libvirt_connect_get(d)); } result = rb_ary_new(); for (i = 0; i < r; i++) { vcpuinfo = rb_class_new_instance(0, NULL, c_domain_vcpuinfo); if (cpuinfo != NULL) { rb_iv_set(vcpuinfo, "@number", INT2NUM(cpuinfo[i].number)); rb_iv_set(vcpuinfo, "@state", INT2NUM(cpuinfo[i].state)); rb_iv_set(vcpuinfo, "@cpu_time", ULL2NUM(cpuinfo[i].cpuTime)); rb_iv_set(vcpuinfo, "@cpu", INT2NUM(cpuinfo[i].cpu)); } else { rb_iv_set(vcpuinfo, "@number", Qnil); rb_iv_set(vcpuinfo, "@state", Qnil); rb_iv_set(vcpuinfo, "@cpu_time", Qnil); rb_iv_set(vcpuinfo, "@cpu", Qnil); } p2vcpumap = rb_ary_new(); for (j = 0; j < maxcpus; j++) { rb_ary_push(p2vcpumap, (VIR_CPU_USABLE(cpumap, cpumaplen, i, j)) ? Qtrue : Qfalse); } rb_iv_set(vcpuinfo, "@cpumap", p2vcpumap); rb_ary_push(result, vcpuinfo); } return result; } /* * call-seq: * dom.active? -> [true|false] * * Call virDomainIsActive[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainIsActive] * to determine if this domain is currently active. */ static VALUE libvirt_domain_active_p(VALUE d) { ruby_libvirt_generate_call_truefalse(virDomainIsActive, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } /* * call-seq: * dom.persistent? -> [true|false] * * Call virDomainIsPersistent[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainIsPersistent] * to determine if this is a persistent domain. */ static VALUE libvirt_domain_persistent_p(VALUE d) { ruby_libvirt_generate_call_truefalse(virDomainIsPersistent, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } /* * call-seq: * dom.ifinfo(if) -> Libvirt::Domain::IfInfo * * Call virDomainInterfaceStats[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainInterfaceStats] * to retrieve statistics about domain interface if. */ static VALUE libvirt_domain_if_stats(VALUE d, VALUE sif) { char *ifname = ruby_libvirt_get_cstring_or_null(sif); virDomainInterfaceStatsStruct ifinfo; int r; VALUE result = Qnil; if (ifname) { r = virDomainInterfaceStats(ruby_libvirt_domain_get(d), ifname, &ifinfo, sizeof(virDomainInterfaceStatsStruct)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainInterfaceStats", ruby_libvirt_connect_get(d)); result = rb_class_new_instance(0, NULL, c_domain_ifinfo); rb_iv_set(result, "@rx_bytes", LL2NUM(ifinfo.rx_bytes)); rb_iv_set(result, "@rx_packets", LL2NUM(ifinfo.rx_packets)); rb_iv_set(result, "@rx_errs", LL2NUM(ifinfo.rx_errs)); rb_iv_set(result, "@rx_drop", LL2NUM(ifinfo.rx_drop)); rb_iv_set(result, "@tx_bytes", LL2NUM(ifinfo.tx_bytes)); rb_iv_set(result, "@tx_packets", LL2NUM(ifinfo.tx_packets)); rb_iv_set(result, "@tx_errs", LL2NUM(ifinfo.tx_errs)); rb_iv_set(result, "@tx_drop", LL2NUM(ifinfo.tx_drop)); } return result; } /* * call-seq: * dom.name -> String * * Call virDomainGetName[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetName] * to retrieve the name of this domain. */ static VALUE libvirt_domain_name(VALUE d) { ruby_libvirt_generate_call_string(virDomainGetName, ruby_libvirt_connect_get(d), 0, ruby_libvirt_domain_get(d)); } /* * call-seq: * dom.id -> Fixnum * * Call virDomainGetID[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetID] * to retrieve the ID of this domain. If the domain isn't running, this will * be -1. */ static VALUE libvirt_domain_id(VALUE d) { unsigned int id; int out; id = virDomainGetID(ruby_libvirt_domain_get(d)); /* we need to cast the unsigned int id to a signed int out to handle the * -1 case */ out = id; ruby_libvirt_raise_error_if(out == -1, e_RetrieveError, "virDomainGetID", ruby_libvirt_connect_get(d)); return INT2NUM(out); } /* * call-seq: * dom.uuid -> String * * Call virDomainGetUUIDString[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetUUIDString] * to retrieve the UUID of this domain. */ static VALUE libvirt_domain_uuid(VALUE d) { ruby_libvirt_generate_uuid(virDomainGetUUIDString, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } /* * call-seq: * dom.os_type -> String * * Call virDomainGetOSType[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetOSType] * to retrieve the os_type of this domain. In libvirt terms, os_type determines * whether this domain is fully virtualized, paravirtualized, or a container. */ static VALUE libvirt_domain_os_type(VALUE d) { ruby_libvirt_generate_call_string(virDomainGetOSType, ruby_libvirt_connect_get(d), 1, ruby_libvirt_domain_get(d)); } /* * call-seq: * dom.max_memory -> Fixnum * * Call virDomainGetMaxMemory[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMaxMemory] * to retrieve the maximum amount of memory this domain is allowed to access. * Note that the current amount of memory this domain is allowed to access may * be different (see dom.memory_set). */ static VALUE libvirt_domain_max_memory(VALUE d) { unsigned long max_memory; max_memory = virDomainGetMaxMemory(ruby_libvirt_domain_get(d)); ruby_libvirt_raise_error_if(max_memory == 0, e_RetrieveError, "virDomainGetMaxMemory", ruby_libvirt_connect_get(d)); return ULONG2NUM(max_memory); } /* * call-seq: * dom.max_memory = Fixnum * * Call virDomainSetMaxMemory[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMaxMemory] * to set the maximum amount of memory (in kilobytes) this domain should be * allowed to access. */ static VALUE libvirt_domain_max_memory_equal(VALUE d, VALUE max_memory) { int r; r = virDomainSetMaxMemory(ruby_libvirt_domain_get(d), NUM2ULONG(max_memory)); ruby_libvirt_raise_error_if(r < 0, e_DefinitionError, "virDomainSetMaxMemory", ruby_libvirt_connect_get(d)); return ULONG2NUM(max_memory); } /* * call-seq: * dom.memory = Fixnum,flags=0 * * Call virDomainSetMemory[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMemory] * to set the amount of memory (in kilobytes) this domain should currently * have. Note this will only succeed if both the hypervisor and the domain on * this connection support ballooning. */ static VALUE libvirt_domain_memory_equal(VALUE d, VALUE in) { VALUE memory, flags; int r; domain_input_to_fixnum_and_flags(in, &memory, &flags); if (ruby_libvirt_value_to_uint(flags) != 0) { r = virDomainSetMemoryFlags(ruby_libvirt_domain_get(d), NUM2ULONG(memory), ruby_libvirt_value_to_uint(flags)); } else { r = virDomainSetMemory(ruby_libvirt_domain_get(d), NUM2ULONG(memory)); } ruby_libvirt_raise_error_if(r < 0, e_DefinitionError, "virDomainSetMemory", ruby_libvirt_connect_get(d)); return ULONG2NUM(memory); } /* * call-seq: * dom.max_vcpus -> Fixnum * * Call virDomainGetMaxVcpus[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMaxVcpus] * to retrieve the maximum number of virtual CPUs this domain can use. */ static VALUE libvirt_domain_max_vcpus(VALUE d) { ruby_libvirt_generate_call_int(virDomainGetMaxVcpus, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } /* call-seq: * dom.num_vcpus(flags) -> Fixnum * * Call virDomainGetVcpusFlags[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetVcpusFlags] * to retrieve the number of virtual CPUs assigned to this domain. */ static VALUE libvirt_domain_num_vcpus(VALUE d, VALUE flags) { ruby_libvirt_generate_call_int(virDomainGetVcpusFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.vcpus = Fixnum,flags=0 * * Call virDomainSetVcpus[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetVcpus] * to set the current number of virtual CPUs this domain should have. Note * that this will only work if both the hypervisor and domain on this * connection support virtual CPU hotplug/hot-unplug. */ static VALUE libvirt_domain_vcpus_equal(VALUE d, VALUE in) { VALUE nvcpus, flags = Qnil; if (TYPE(in) == T_FIXNUM) { nvcpus = in; ruby_libvirt_generate_call_nil(virDomainSetVcpus, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2UINT(nvcpus)); } else if (TYPE(in) == T_ARRAY) { if (RARRAY_LEN(in) != 2) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)", RARRAY_LEN(in)); } nvcpus = rb_ary_entry(in, 0); flags = rb_ary_entry(in, 1); ruby_libvirt_generate_call_nil(virDomainSetVcpusFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2UINT(nvcpus), NUM2UINT(flags)); } else { rb_raise(rb_eTypeError, "wrong argument type (expected Number or Array)"); } } /* * call-seq: * dom.vcpus_flags = Fixnum,flags=0 * * Call virDomainSetVcpusFlags[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetVcpusFlags] * to set the current number of virtual CPUs this domain should have. The * flags parameter controls whether the change is made to the running domain * the domain configuration, or both, and must not be 0. Deprecated; * use dom.vcpus= instead. */ static VALUE libvirt_domain_vcpus_flags_equal(VALUE d, VALUE in) { VALUE nvcpus, flags; domain_input_to_fixnum_and_flags(in, &nvcpus, &flags); ruby_libvirt_generate_call_nil(virDomainSetVcpusFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2UINT(nvcpus), NUM2UINT(flags)); } /* * call-seq: * dom.pin_vcpu(vcpu, cpulist, flags=0) -> nil * * Call virDomainPinVcpu[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainPinVcpu] * to pin a particular virtual CPU to a range of physical processors. The * cpulist should be an array of Fixnums representing the physical processors * this virtual CPU should be allowed to be scheduled on. */ static VALUE libvirt_domain_pin_vcpu(int argc, VALUE *argv, VALUE d) { VALUE vcpu, cpulist, flags, e; int i, cpumaplen, maxcpus; unsigned char *cpumap; rb_scan_args(argc, argv, "21", &vcpu, &cpulist, &flags); Check_Type(cpulist, T_ARRAY); maxcpus = ruby_libvirt_get_maxcpus(ruby_libvirt_connect_get(d)); cpumaplen = VIR_CPU_MAPLEN(maxcpus); cpumap = alloca(sizeof(unsigned char) * cpumaplen); MEMZERO(cpumap, unsigned char, cpumaplen); for (i = 0; i < RARRAY_LEN(cpulist); i++) { e = rb_ary_entry(cpulist, i); VIR_USE_CPU(cpumap, NUM2UINT(e)); } if (ruby_libvirt_value_to_uint(flags) != 0) { ruby_libvirt_generate_call_nil(virDomainPinVcpuFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2UINT(vcpu), cpumap, cpumaplen, ruby_libvirt_value_to_uint(flags)); } else { ruby_libvirt_generate_call_nil(virDomainPinVcpu, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2UINT(vcpu), cpumap, cpumaplen); } } /* * call-seq: * dom.xml_desc(flags=0) -> String * * Call virDomainGetXMLDesc[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetXMLDesc] * to retrieve the XML describing this domain. */ static VALUE libvirt_domain_xml_desc(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virDomainGetXMLDesc, ruby_libvirt_connect_get(d), 1, ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.undefine(flags=0) -> nil * * Call virDomainUndefine[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainUndefine] * to undefine the domain. After this call, the domain object is no longer * valid. */ static VALUE libvirt_domain_undefine(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); if (ruby_libvirt_value_to_uint(flags) != 0) { ruby_libvirt_generate_call_nil(virDomainUndefineFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } else { ruby_libvirt_generate_call_nil(virDomainUndefine, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } } /* * call-seq: * dom.create(flags=0) -> nil * * Call virDomainCreate[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreate] * to start an already defined domain. */ static VALUE libvirt_domain_create(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); if (ruby_libvirt_value_to_uint(flags) != 0) { ruby_libvirt_generate_call_nil(virDomainCreateWithFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } else { ruby_libvirt_generate_call_nil(virDomainCreate, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } } /* * call-seq: * dom.autostart -> [true|false] * * Call virDomainGetAutostart[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetAutostart] * to find out the state of the autostart flag for a domain. */ static VALUE libvirt_domain_autostart(VALUE d) { int r, autostart; r = virDomainGetAutostart(ruby_libvirt_domain_get(d), &autostart); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainAutostart", ruby_libvirt_connect_get(d)); return autostart ? Qtrue : Qfalse; } /* * call-seq: * dom.autostart = [true|false] * * Call virDomainSetAutostart[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetAutostart] * to make this domain autostart when libvirtd starts up. */ static VALUE libvirt_domain_autostart_equal(VALUE d, VALUE autostart) { if (autostart != Qtrue && autostart != Qfalse) { rb_raise(rb_eTypeError, "wrong argument type (expected TrueClass or FalseClass)"); } ruby_libvirt_generate_call_nil(virDomainSetAutostart, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), RTEST(autostart) ? 1 : 0); } /* * call-seq: * dom.attach_device(device_xml, flags=0) -> nil * * Call virDomainAttachDeviceFlags[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainAttachDeviceFlags] * to attach the device described by the device_xml to the domain. */ static VALUE libvirt_domain_attach_device(int argc, VALUE *argv, VALUE d) { VALUE xml, flags; rb_scan_args(argc, argv, "11", &xml, &flags); /* NOTE: can't use virDomainAttachDevice() when flags==0 here * because that function only works on active domains and * VIR_DOMAIN_AFFECT_CURRENT==0. * * See https://gitlab.com/libvirt/libvirt-ruby/-/issues/11 */ ruby_libvirt_generate_call_nil(virDomainAttachDeviceFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.detach_device(device_xml, flags=0) -> nil * * Call virDomainDetachDeviceFlags[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDetachDeviceFlags] * to detach the device described by the device_xml from the domain. */ static VALUE libvirt_domain_detach_device(int argc, VALUE *argv, VALUE d) { VALUE xml, flags; rb_scan_args(argc, argv, "11", &xml, &flags); /* NOTE: can't use virDomainDetachDevice() when flags==0 here * because that function only works on active domains and * VIR_DOMAIN_AFFECT_CURRENT==0. * * See https://gitlab.com/libvirt/libvirt-ruby/-/issues/11 */ ruby_libvirt_generate_call_nil(virDomainDetachDeviceFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.update_device(device_xml, flags=0) -> nil * * Call virDomainUpdateDeviceFlags[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainUpdateDeviceFlags] * to update the device described by the device_xml. */ static VALUE libvirt_domain_update_device(int argc, VALUE *argv, VALUE d) { VALUE xml, flags; rb_scan_args(argc, argv, "11", &xml, &flags); ruby_libvirt_generate_call_nil(virDomainUpdateDeviceFlags, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(xml), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.free -> nil * * Call virDomainFree[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainFree] * to free a domain object. */ static VALUE libvirt_domain_free(VALUE d) { ruby_libvirt_generate_call_free(Domain, d); } static void domain_snapshot_free(void *d) { ruby_libvirt_free_struct(DomainSnapshot, d); } static VALUE domain_snapshot_new(virDomainSnapshotPtr d, VALUE domain) { VALUE result; result = ruby_libvirt_new_class(c_domain_snapshot, d, rb_iv_get(domain, "@connection"), domain_snapshot_free); rb_iv_set(result, "@domain", domain); return result; } static virDomainSnapshotPtr domain_snapshot_get(VALUE d) { ruby_libvirt_get_struct(DomainSnapshot, d); } /* * call-seq: * dom.snapshot_create_xml(snapshot_xml, flags=0) -> Libvirt::Domain::Snapshot * * Call virDomainSnapshotCreateXML[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotCreateXML] * to create a new snapshot based on snapshot_xml. */ static VALUE libvirt_domain_snapshot_create_xml(int argc, VALUE *argv, VALUE d) { VALUE xmlDesc, flags; virDomainSnapshotPtr ret; rb_scan_args(argc, argv, "11", &xmlDesc, &flags); ret = virDomainSnapshotCreateXML(ruby_libvirt_domain_get(d), StringValueCStr(xmlDesc), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret == NULL, e_Error, "virDomainSnapshotCreateXML", ruby_libvirt_connect_get(d)); return domain_snapshot_new(ret, d); } /* * call-seq: * dom.num_of_snapshots(flags=0) -> Fixnum * * Call virDomainSnapshotNum[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotNum] * to retrieve the number of available snapshots for this domain. */ static VALUE libvirt_domain_num_of_snapshots(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_int(virDomainSnapshotNum, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.list_snapshots(flags=0) -> list * * Call virDomainSnapshotListNames[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotListNames] * to retrieve a list of snapshot names available for this domain. */ static VALUE libvirt_domain_list_snapshots(int argc, VALUE *argv, VALUE d) { VALUE flags; int r, num; char **names; rb_scan_args(argc, argv, "01", &flags); if (TYPE(flags) != T_NIL && TYPE(flags) != T_FIXNUM) { rb_raise(rb_eTypeError, "wrong argument type (expected Number)"); } num = virDomainSnapshotNum(ruby_libvirt_domain_get(d), 0); ruby_libvirt_raise_error_if(num < 0, e_RetrieveError, "virDomainSnapshotNum", ruby_libvirt_connect_get(d)); if (num == 0) { /* if num is 0, don't call virDomainSnapshotListNames function */ return rb_ary_new2(num); } names = alloca(sizeof(char *) * num); r = virDomainSnapshotListNames(ruby_libvirt_domain_get(d), names, num, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainSnapshotListNames", ruby_libvirt_connect_get(d)); return ruby_libvirt_generate_list(r, names); } /* * call-seq: * dom.lookup_snapshot_by_name(name, flags=0) -> Libvirt::Domain::Snapshot * * Call virDomainSnapshotLookupByName[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotLookupByName] * to retrieve a snapshot object corresponding to snapshot name. */ static VALUE libvirt_domain_lookup_snapshot_by_name(int argc, VALUE *argv, VALUE d) { virDomainSnapshotPtr snap; VALUE name, flags; rb_scan_args(argc, argv, "11", &name, &flags); snap = virDomainSnapshotLookupByName(ruby_libvirt_domain_get(d), StringValueCStr(name), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(snap == NULL, e_RetrieveError, "virDomainSnapshotLookupByName", ruby_libvirt_connect_get(d)); return domain_snapshot_new(snap, d); } /* * call-seq: * dom.has_current_snapshot?(flags=0) -> [true|false] * * Call virDomainHasCurrentSnapshot[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainHasCurrentSnapshot] * to find out if this domain has a snapshot active. */ static VALUE libvirt_domain_has_current_snapshot_p(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_truefalse(virDomainHasCurrentSnapshot, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.revert_to_snapshot(snapshot_object, flags=0) -> nil * * Call virDomainRevertToSnapshot[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainRevertToSnapshot] * to restore this domain to a previously saved snapshot. */ static VALUE libvirt_domain_revert_to_snapshot(int argc, VALUE *argv, VALUE d) { VALUE snap, flags; rb_scan_args(argc, argv, "11", &snap, &flags); ruby_libvirt_generate_call_nil(virDomainRevertToSnapshot, ruby_libvirt_connect_get(d), domain_snapshot_get(snap), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.current_snapshot(flags=0) -> Libvirt::Domain::Snapshot * * Call virDomainCurrentSnapshot[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCurrentSnapshot] * to retrieve the current snapshot for this domain (if any). */ static VALUE libvirt_domain_current_snapshot(int argc, VALUE *argv, VALUE d) { VALUE flags; virDomainSnapshotPtr snap; rb_scan_args(argc, argv, "01", &flags); snap = virDomainSnapshotCurrent(ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(snap == NULL, e_RetrieveError, "virDomainSnapshotCurrent", ruby_libvirt_connect_get(d)); return domain_snapshot_new(snap, d); } /* * call-seq: * snapshot.xml_desc(flags=0) -> String * * Call virDomainSnapshotGetXMLDesc[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotGetXMLDesc] * to retrieve the xml description for this snapshot. */ static VALUE libvirt_domain_snapshot_xml_desc(int argc, VALUE *argv, VALUE s) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virDomainSnapshotGetXMLDesc, ruby_libvirt_connect_get(s), 1, domain_snapshot_get(s), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * snapshot.delete(flags=0) -> nil * * Call virDomainSnapshotDelete[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotDelete] * to delete this snapshot. */ static VALUE libvirt_domain_snapshot_delete(int argc, VALUE *argv, VALUE s) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virDomainSnapshotDelete, ruby_libvirt_connect_get(s), domain_snapshot_get(s), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * snapshot.free -> nil * * Call virDomainSnapshotFree[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotFree] * to free up the snapshot object. After this call the snapshot object is * no longer valid. */ static VALUE libvirt_domain_snapshot_free(VALUE s) { ruby_libvirt_generate_call_free(DomainSnapshot, s); } /* * call-seq: * snapshot.name -> String * * Call virDomainSnapshotGetName[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotGetName] * to get the name associated with a snapshot. */ static VALUE libvirt_domain_snapshot_name(VALUE s) { ruby_libvirt_generate_call_string(virDomainSnapshotGetName, ruby_libvirt_connect_get(s), 0, domain_snapshot_get(s)); } /* * call-seq: * dom.job_info -> Libvirt::Domain::JobInfo * * Call virDomainGetJobInfo[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobInfo] * to retrieve the current state of the running domain job. */ static VALUE libvirt_domain_job_info(VALUE d) { int r; virDomainJobInfo info; VALUE result; r = virDomainGetJobInfo(ruby_libvirt_domain_get(d), &info); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainGetJobInfo", ruby_libvirt_connect_get(d)); result = rb_class_new_instance(0, NULL, c_domain_job_info); rb_iv_set(result, "@type", INT2NUM(info.type)); rb_iv_set(result, "@time_elapsed", ULL2NUM(info.timeElapsed)); rb_iv_set(result, "@time_remaining", ULL2NUM(info.timeRemaining)); rb_iv_set(result, "@data_total", ULL2NUM(info.dataTotal)); rb_iv_set(result, "@data_processed", ULL2NUM(info.dataProcessed)); rb_iv_set(result, "@data_remaining", ULL2NUM(info.dataRemaining)); rb_iv_set(result, "@mem_total", ULL2NUM(info.memTotal)); rb_iv_set(result, "@mem_processed", ULL2NUM(info.memProcessed)); rb_iv_set(result, "@mem_remaining", ULL2NUM(info.memRemaining)); rb_iv_set(result, "@file_total", ULL2NUM(info.fileTotal)); rb_iv_set(result, "@file_processed", ULL2NUM(info.fileProcessed)); rb_iv_set(result, "@file_remaining", ULL2NUM(info.fileRemaining)); return result; } /* * call-seq: * dom.abort_job -> nil * * Call virDomainAbortJob[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainAbortJob] * to abort the currently running job on this domain. */ static VALUE libvirt_domain_abort_job(VALUE d) { ruby_libvirt_generate_call_nil(virDomainAbortJob, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } struct create_sched_type_args { char *type; int nparams; }; static VALUE create_sched_type_array(VALUE input) { struct create_sched_type_args *args; VALUE result; args = (struct create_sched_type_args *)input; result = rb_ary_new(); rb_ary_push(result, rb_str_new2(args->type)); rb_ary_push(result, INT2NUM(args->nparams)); return result; } /* * call-seq: * dom.scheduler_type -> [type, #params] * * Call virDomainGetSchedulerType[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSchedulerType] * to retrieve the scheduler type used on this domain. */ static VALUE libvirt_domain_scheduler_type(VALUE d) { int nparams, exception = 0; char *type; VALUE result; struct create_sched_type_args args; type = virDomainGetSchedulerType(ruby_libvirt_domain_get(d), &nparams); ruby_libvirt_raise_error_if(type == NULL, e_RetrieveError, "virDomainGetSchedulerType", ruby_libvirt_connect_get(d)); args.type = type; args.nparams = nparams; result = rb_protect(create_sched_type_array, (VALUE)&args, &exception); if (exception) { free(type); rb_jump_tag(exception); } return result; } /* * call-seq: * dom.qemu_monitor_command(cmd, flags=0) -> String * * Call virDomainQemuMonitorCommand * to send a qemu command directly to the monitor. Note that this will only * work on qemu hypervisors, and the input and output formats are not * guaranteed to be stable. Also note that using this command can severly * impede libvirt's ability to manage the domain; use with caution! */ static VALUE libvirt_domain_qemu_monitor_command(int argc, VALUE *argv, VALUE d) { VALUE cmd, flags, ret; char *result; int r, exception = 0; const char *type; rb_scan_args(argc, argv, "11", &cmd, &flags); type = virConnectGetType(ruby_libvirt_connect_get(d)); ruby_libvirt_raise_error_if(type == NULL, e_Error, "virConnectGetType", ruby_libvirt_connect_get(d)); /* The type != NULL check is actually redundant, since if type was NULL * we would have raised an exception above. It's here to shut clang, * since clang can't tell that we would never reach this. */ if (type != NULL && strcmp(type, "QEMU") != 0) { rb_raise(rb_eTypeError, "Tried to use virDomainQemuMonitor command on %s connection", type); } r = virDomainQemuMonitorCommand(ruby_libvirt_domain_get(d), StringValueCStr(cmd), &result, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainQemuMonitorCommand", ruby_libvirt_connect_get(d)); ret = rb_protect(ruby_libvirt_str_new2_wrap, (VALUE)&result, &exception); free(result); if (exception) { rb_jump_tag(exception); } return ret; } /* * call-seq: * dom.updated? -> [True|False] * * Call virDomainIsUpdated[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainIsUpdated] * to determine whether the definition for this domain has been updated. */ static VALUE libvirt_domain_is_updated(VALUE d) { ruby_libvirt_generate_call_truefalse(virDomainIsUpdated, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d)); } static const char *scheduler_nparams(VALUE d, unsigned int RUBY_LIBVIRT_UNUSED(flags), void *RUBY_LIBVIRT_UNUSED(opaque), int *nparams) { char *type; type = virDomainGetSchedulerType(ruby_libvirt_domain_get(d), nparams); if (type == NULL) { return "virDomainGetSchedulerType"; } xfree(type); return NULL; } static const char *scheduler_get(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *RUBY_LIBVIRT_UNUSED(opaque)) { virTypedParameterPtr params = (virTypedParameterPtr)voidparams; if (flags != 0) { if (virDomainGetSchedulerParametersFlags(ruby_libvirt_domain_get(d), params, nparams, flags) < 0) { return "virDomainGetSchedulerParameters"; } } else { if (virDomainGetSchedulerParameters(ruby_libvirt_domain_get(d), params, nparams) < 0) { return "virDomainGetSchedulerParameters"; } } return NULL; } static const char *scheduler_set(VALUE d, unsigned int flags, virTypedParameterPtr params, int nparams, void *RUBY_LIBVIRT_UNUSED(opaque)) { if (flags != 0) { if (virDomainSetSchedulerParametersFlags(ruby_libvirt_domain_get(d), params, nparams, flags) < 0) { return "virDomainSetSchedulerParameters"; } } else { if (virDomainSetSchedulerParameters(ruby_libvirt_domain_get(d), params, nparams) < 0) { return "virDomainSetSchedulerParameters"; } } return NULL; } /* * call-seq: * dom.scheduler_parameters(flags=0) -> Hash * * Call virDomainGetSchedulerParameters[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSchedulerParameters] * to retrieve all of the scheduler parameters for this domain. The keys and * values in the hash that is returned are hypervisor specific. */ static VALUE libvirt_domain_scheduler_parameters(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); return ruby_libvirt_get_typed_parameters(d, ruby_libvirt_value_to_uint(flags), NULL, scheduler_nparams, scheduler_get); } static struct ruby_libvirt_typed_param domain_scheduler_allowed[] = { {VIR_DOMAIN_SCHEDULER_CPU_SHARES, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_SCHEDULER_VCPU_PERIOD, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_SCHEDULER_VCPU_QUOTA, VIR_TYPED_PARAM_LLONG}, {VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA, VIR_TYPED_PARAM_LLONG}, {VIR_DOMAIN_SCHEDULER_WEIGHT, VIR_TYPED_PARAM_UINT}, {VIR_DOMAIN_SCHEDULER_CAP, VIR_TYPED_PARAM_UINT}, {VIR_DOMAIN_SCHEDULER_RESERVATION, VIR_TYPED_PARAM_LLONG}, {VIR_DOMAIN_SCHEDULER_LIMIT, VIR_TYPED_PARAM_LLONG}, {VIR_DOMAIN_SCHEDULER_SHARES, VIR_TYPED_PARAM_INT}, }; /* * call-seq: * dom.scheduler_parameters = Hash * * Call virDomainSetSchedulerParameters[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetSchedulerParameters] * to set the scheduler parameters for this domain. The keys and values in * the input hash are hypervisor specific. If an empty hash is given, no * changes are made (and no error is raised). */ static VALUE libvirt_domain_scheduler_parameters_equal(VALUE d, VALUE input) { VALUE hash, flags; ruby_libvirt_assign_hash_and_flags(input, &hash, &flags); return ruby_libvirt_set_typed_parameters(d, hash, NUM2UINT(flags), NULL, domain_scheduler_allowed, ARRAY_SIZE(domain_scheduler_allowed), scheduler_set); } static const char *memory_nparams(VALUE d, unsigned int flags, void *RUBY_LIBVIRT_UNUSED(opaque), int *nparams) { if (virDomainGetMemoryParameters(ruby_libvirt_domain_get(d), NULL, nparams, flags) < 0) { return "virDomainGetMemoryParameters"; } return NULL; } static const char *memory_get(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *RUBY_LIBVIRT_UNUSED(opaque)) { virTypedParameterPtr params = (virTypedParameterPtr)voidparams; if (virDomainGetMemoryParameters(ruby_libvirt_domain_get(d), params, nparams, flags) < 0) { return "virDomainGetMemoryParameters"; } return NULL; } static const char *memory_set(VALUE d, unsigned int flags, virTypedParameterPtr params, int nparams, void *RUBY_LIBVIRT_UNUSED(opaque)) { if (virDomainSetMemoryParameters(ruby_libvirt_domain_get(d), params, nparams, flags) < 0) { return "virDomainSetMemoryParameters"; } return NULL; } /* * call-seq: * dom.memory_parameters(flags=0) -> Hash * * Call virDomainGetMemoryParameters[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMemoryParameters] * to retrieve all of the memory parameters for this domain. The keys and * values in the hash that is returned are hypervisor specific. */ static VALUE libvirt_domain_memory_parameters(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); return ruby_libvirt_get_typed_parameters(d, ruby_libvirt_value_to_uint(flags), NULL, memory_nparams, memory_get); } static struct ruby_libvirt_typed_param domain_memory_allowed[] = { {VIR_DOMAIN_MEMORY_HARD_LIMIT, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_MEMORY_SOFT_LIMIT, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_MEMORY_MIN_GUARANTEE, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, VIR_TYPED_PARAM_ULLONG}, }; /* * call-seq: * dom.memory_parameters = Hash,flags=0 * * Call virDomainSetMemoryParameters[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMemoryParameters] * to set the memory parameters for this domain. The keys and values in * the input hash are hypervisor specific. */ static VALUE libvirt_domain_memory_parameters_equal(VALUE d, VALUE in) { VALUE hash, flags; ruby_libvirt_assign_hash_and_flags(in, &hash, &flags); return ruby_libvirt_set_typed_parameters(d, hash, NUM2UINT(flags), NULL, domain_memory_allowed, ARRAY_SIZE(domain_memory_allowed), memory_set); } static const char *blkio_nparams(VALUE d, unsigned int flags, void *RUBY_LIBVIRT_UNUSED(opaque), int *nparams) { if (virDomainGetBlkioParameters(ruby_libvirt_domain_get(d), NULL, nparams, flags) < 0) { return "virDomainGetBlkioParameters"; } return NULL; } static const char *blkio_get(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *RUBY_LIBVIRT_UNUSED(opaque)) { virTypedParameterPtr params = (virTypedParameterPtr)voidparams; if (virDomainGetBlkioParameters(ruby_libvirt_domain_get(d), params, nparams, flags) < 0) { return "virDomainGetBlkioParameters"; } return NULL; } static const char *blkio_set(VALUE d, unsigned int flags, virTypedParameterPtr params, int nparams, void *RUBY_LIBVIRT_UNUSED(opaque)) { if (virDomainSetBlkioParameters(ruby_libvirt_domain_get(d), params, nparams, flags) < 0) { return "virDomainSetBlkioParameters"; } return NULL; } /* * call-seq: * dom.blkio_parameters(flags=0) -> Hash * * Call virDomainGetBlkioParameters[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetBlkioParameters] * to retrieve all of the blkio parameters for this domain. The keys and * values in the hash that is returned are hypervisor specific. */ static VALUE libvirt_domain_blkio_parameters(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); return ruby_libvirt_get_typed_parameters(d, ruby_libvirt_value_to_uint(flags), NULL, blkio_nparams, blkio_get); } static struct ruby_libvirt_typed_param blkio_allowed[] = { {VIR_DOMAIN_BLKIO_WEIGHT, VIR_TYPED_PARAM_UINT}, {VIR_DOMAIN_BLKIO_DEVICE_WEIGHT, VIR_TYPED_PARAM_STRING}, }; /* * call-seq: * dom.blkio_parameters = Hash,flags=0 * * Call virDomainSetBlkioParameters[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetBlkioParameters] * to set the blkio parameters for this domain. The keys and values in * the input hash are hypervisor specific. */ static VALUE libvirt_domain_blkio_parameters_equal(VALUE d, VALUE in) { VALUE hash, flags; ruby_libvirt_assign_hash_and_flags(in, &hash, &flags); return ruby_libvirt_set_typed_parameters(d, hash, NUM2UINT(flags), NULL, blkio_allowed, ARRAY_SIZE(blkio_allowed), blkio_set); } /* * call-seq: * dom.state(flags=0) -> state, reason * * Call virDomainGetState[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetState] * to get the current state of the domain. */ static VALUE libvirt_domain_state(int argc, VALUE *argv, VALUE d) { VALUE result, flags; int state, reason, retval; rb_scan_args(argc, argv, "01", &flags); retval = virDomainGetState(ruby_libvirt_domain_get(d), &state, &reason, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(retval < 0, e_Error, "virDomainGetState", ruby_libvirt_connect_get(d)); result = rb_ary_new(); rb_ary_push(result, INT2NUM(state)); rb_ary_push(result, INT2NUM(reason)); return result; } /* * call-seq: * dom.open_console(device, stream, flags=0) -> nil * * Call virDomainOpenConsole[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainOpenConsole] * to open up a console to device over stream. */ static VALUE libvirt_domain_open_console(int argc, VALUE *argv, VALUE d) { VALUE dev, st, flags; rb_scan_args(argc, argv, "21", &dev, &st, &flags); ruby_libvirt_generate_call_nil(virDomainOpenConsole, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(dev), ruby_libvirt_stream_get(st), NUM2INT(flags)); } /* * call-seq: * dom.screenshot(stream, screen, flags=0) -> nil * * Call virDomainScreenshot[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainScreenshot] * to take a screenshot of the domain console as a stream. */ static VALUE libvirt_domain_screenshot(int argc, VALUE *argv, VALUE d) { VALUE st, screen, flags; rb_scan_args(argc, argv, "21", &st, &screen, &flags); ruby_libvirt_generate_call_string(virDomainScreenshot, ruby_libvirt_connect_get(d), 1, ruby_libvirt_domain_get(d), ruby_libvirt_stream_get(st), NUM2UINT(screen), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.inject_nmi(flags=0) -> nil * * Call virDomainInjectNMI[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainInjectNMI] * to send an NMI to the guest. */ static VALUE libvirt_domain_inject_nmi(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virDomainInjectNMI, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.control_info(flags=0) -> Libvirt::Domain::ControlInfo * * Call virDomainGetControlInfo[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetControlInfo] * to retrieve domain control interface information. */ static VALUE libvirt_domain_control_info(int argc, VALUE *argv, VALUE d) { VALUE flags, result; virDomainControlInfo info; int r; rb_scan_args(argc, argv, "01", &flags); r = virDomainGetControlInfo(ruby_libvirt_domain_get(d), &info, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainGetControlInfo", ruby_libvirt_connect_get(d)); result = rb_class_new_instance(0, NULL, c_domain_control_info); rb_iv_set(result, "@state", ULONG2NUM(info.state)); rb_iv_set(result, "@details", ULONG2NUM(info.details)); rb_iv_set(result, "@stateTime", ULL2NUM(info.stateTime)); return result; } /* * call-seq: * dom.send_key(codeset, holdtime, keycodes) * * Call virDomainSendKey[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSendKey] * to send key(s) to the domain. Keycodes has to be an array of keys to send. */ VALUE libvirt_domain_send_key(VALUE d, VALUE codeset, VALUE holdtime, VALUE keycodes) { unsigned int *codes; int i = 0; Check_Type(keycodes, T_ARRAY); codes = alloca(RARRAY_LEN(keycodes) * sizeof(unsigned int)); for (i = 0; i < RARRAY_LEN(keycodes); i++) { codes[i] = NUM2UINT(rb_ary_entry(keycodes,i)); } ruby_libvirt_generate_call_nil(virDomainSendKey, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2UINT(codeset), NUM2UINT(holdtime), codes, RARRAY_LEN(keycodes), 0); } /* * call-seq: * dom.migrate_max_speed(flags=0) -> Fixnum * * Call virDomainMigrateGetMaxSpeed[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateGetMaxSpeed] * to retrieve the maximum speed a migration can use. */ static VALUE libvirt_domain_migrate_max_speed(int argc, VALUE *argv, VALUE d) { VALUE flags; int r; unsigned long bandwidth; rb_scan_args(argc, argv, "01", &flags); r = virDomainMigrateGetMaxSpeed(ruby_libvirt_domain_get(d), &bandwidth, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainMigrateGetMaxSpeed", ruby_libvirt_connect_get(d)); return ULONG2NUM(bandwidth); } /* * call-seq: * dom.reset(flags=0) -> nil * * Call virDomainReset[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainReset] * to reset a domain immediately. */ static VALUE libvirt_domain_reset(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virDomainReset, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.hostname(flags=0) -> nil * * Call virDomainGetHostname[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetHostname] * to get the hostname from a domain. */ static VALUE libvirt_domain_hostname(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virDomainGetHostname, ruby_libvirt_connect_get(d), 1, ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.metadata(type, uri=nil, flags=0) -> String * * Call virDomainGetMetadata[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMetadata] * to get the metadata from a domain. */ static VALUE libvirt_domain_metadata(int argc, VALUE *argv, VALUE d) { VALUE uri, flags, type; rb_scan_args(argc, argv, "12", &type, &uri, &flags); ruby_libvirt_generate_call_string(virDomainGetMetadata, ruby_libvirt_connect_get(d), 1, ruby_libvirt_domain_get(d), NUM2INT(type), ruby_libvirt_get_cstring_or_null(uri), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.metadata = Fixnum,string/nil,key=nil,uri=nil,flags=0 -> nil * * Call virDomainSetMetadata[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMetadata] * to set the metadata for a domain. */ static VALUE libvirt_domain_metadata_equal(VALUE d, VALUE in) { VALUE type, metadata, key, uri, flags; Check_Type(in, T_ARRAY); if (RARRAY_LEN(in) < 2 || RARRAY_LEN(in) > 5) { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2, 3, 4, or 5)", RARRAY_LEN(in)); } type = rb_ary_entry(in, 0); metadata = rb_ary_entry(in, 1); key = Qnil; uri = Qnil; flags = INT2NUM(0); if (RARRAY_LEN(in) >= 3) { key = rb_ary_entry(in, 2); } if (RARRAY_LEN(in) >= 4) { uri = rb_ary_entry(in, 3); } if (RARRAY_LEN(in) == 5) { flags = rb_ary_entry(in, 4); } ruby_libvirt_generate_call_nil(virDomainSetMetadata, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2INT(type), ruby_libvirt_get_cstring_or_null(metadata), ruby_libvirt_get_cstring_or_null(key), ruby_libvirt_get_cstring_or_null(uri), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.send_process_signal(pid, signum, flags=0) -> nil * * Call virDomainSendProcessSignal[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSendProcessSignal] * to send a signal to a process inside the domain. */ static VALUE libvirt_domain_send_process_signal(int argc, VALUE *argv, VALUE d) { VALUE pid, signum, flags; rb_scan_args(argc, argv, "21", &pid, &signum, &flags); ruby_libvirt_generate_call_nil(virDomainSendProcessSignal, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2LL(pid), NUM2UINT(signum), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.list_all_snapshots(flags=0) -> Array * * Call virDomainListAllSnapshots[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainListAllSnapshots] * to get an array of snapshot objects for all snapshots. */ static VALUE libvirt_domain_list_all_snapshots(int argc, VALUE *argv, VALUE d) { ruby_libvirt_generate_call_list_all(virDomainSnapshotPtr, argc, argv, virDomainListAllSnapshots, ruby_libvirt_domain_get(d), d, domain_snapshot_new, virDomainSnapshotFree); } /* * call-seq: * snapshot.num_children(flags=0) -> Fixnum * * Call virDomainSnapshotNumChildren[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotNumChildren] * to get the number of children snapshots of this snapshot. */ static VALUE libvirt_domain_snapshot_num_children(int argc, VALUE *argv, VALUE s) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_int(virDomainSnapshotNumChildren, ruby_libvirt_connect_get(s), domain_snapshot_get(s), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * snapshot.list_children_names(flags=0) -> Array * * Call virDomainSnapshotListChildrenNames[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotListChildrenNames] * to get an array of strings representing the children of this snapshot. */ static VALUE libvirt_domain_snapshot_list_children_names(int argc, VALUE *argv, VALUE s) { VALUE flags, result; char **children; int num_children, ret, i, j, exception = 0; struct ruby_libvirt_str_new2_and_ary_store_arg arg; rb_scan_args(argc, argv, "01", &flags); num_children = virDomainSnapshotNumChildren(domain_snapshot_get(s), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(num_children < 0, e_RetrieveError, "virDomainSnapshotNumChildren", ruby_libvirt_connect_get(s)); result = rb_ary_new2(num_children); if (num_children == 0) { return result; } children = alloca(num_children * sizeof(char *)); ret = virDomainSnapshotListChildrenNames(domain_snapshot_get(s), children, num_children, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virDomainSnapshotListChildrenNames", ruby_libvirt_connect_get(s)); for (i = 0; i < ret; i++) { arg.arr = result; arg.index = i; arg.value = children[i]; rb_protect(ruby_libvirt_str_new2_and_ary_store_wrap, (VALUE)&arg, &exception); if (exception) { goto error; } free(children[i]); } return result; error: for (j = i; j < ret; j++) { free(children[j]); } rb_jump_tag(exception); /* not necessary, just to shut the compiler up */ return Qnil; } /* * call-seq: * snapshot.list_all_children(flags=0) -> Array * * Call virDomainSnapshotListAllChildren[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotListAllChildren] * to get an array of snapshot objects that are children of this snapshot. */ static VALUE libvirt_domain_snapshot_list_all_children(int argc, VALUE *argv, VALUE s) { ruby_libvirt_generate_call_list_all(virDomainSnapshotPtr, argc, argv, virDomainSnapshotListAllChildren, domain_snapshot_get(s), s, domain_snapshot_new, virDomainSnapshotFree); } /* * call-seq: * snapshot.parent(flags=0) -> [Libvirt::Domain::Snapshot|nil] * * Call virDomainSnapshotGetParent[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotGetParent] * to get the parent of this snapshot (nil will be returned if this is a root * snapshot). */ static VALUE libvirt_domain_snapshot_parent(int argc, VALUE *argv, VALUE s) { virDomainSnapshotPtr snap; VALUE flags; virErrorPtr err; rb_scan_args(argc, argv, "01", &flags); snap = virDomainSnapshotGetParent(domain_snapshot_get(s), ruby_libvirt_value_to_uint(flags)); if (snap == NULL) { /* snap may be NULL if there is a root, in which case we want to return * nil */ err = virConnGetLastError(ruby_libvirt_connect_get(s)); if (err->code == VIR_ERR_NO_DOMAIN_SNAPSHOT) { return Qnil; } ruby_libvirt_raise_error_if(snap == NULL, e_RetrieveError, "virDomainSnapshotGetParent", ruby_libvirt_connect_get(s)); } return domain_snapshot_new(snap, s); } /* * call-seq: * snapshot.current?(flags=0) -> [true|false] * * Call virDomainSnapshotIsCurrent[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotIsCurrent] * to determine if the snapshot is the domain's current snapshot. */ static VALUE libvirt_domain_snapshot_current_p(int argc, VALUE *argv, VALUE s) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_truefalse(virDomainSnapshotIsCurrent, ruby_libvirt_connect_get(s), domain_snapshot_get(s), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * snapshot.has_metadata?(flags=0) -> [true|false] * * Call virDomainSnapshotHasMetadata[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSnapshotHasMetadata] * to determine if the snapshot is associated with libvirt metadata. */ static VALUE libvirt_domain_snapshot_has_metadata_p(int argc, VALUE *argv, VALUE s) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_truefalse(virDomainSnapshotHasMetadata, ruby_libvirt_connect_get(s), domain_snapshot_get(s), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.memory_stats_period = Fixnum,flags=0 * * Call virDomainSetMemoryStatsPeriod[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMemoryStatsPeriod] * to set the memory statistics collection period. */ static VALUE libvirt_domain_memory_stats_period(VALUE d, VALUE in) { VALUE period, flags; domain_input_to_fixnum_and_flags(in, &period, &flags); ruby_libvirt_generate_call_nil(virDomainSetMemoryStatsPeriod, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2INT(period), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.fstrim(mountpoint=nil, minimum=0, flags=0) -> nil * * Call virDomainFSTrim[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainFSTrim] * to call FITRIM within the guest. */ static VALUE libvirt_domain_fstrim(int argc, VALUE *argv, VALUE d) { VALUE mountpoint, minimum, flags; rb_scan_args(argc, argv, "03", &mountpoint, &minimum, &flags); ruby_libvirt_generate_call_nil(virDomainFSTrim, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_get_cstring_or_null(mountpoint), ruby_libvirt_value_to_ulonglong(minimum), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.block_rebase(disk, base=nil, bandwidth=0, flags=0) -> nil * * Call virDomainBlockRebase[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockRebase] * to populate a disk image with data from its backing image chain. */ static VALUE libvirt_domain_block_rebase(int argc, VALUE *argv, VALUE d) { VALUE disk, base, bandwidth, flags; rb_scan_args(argc, argv, "13", &disk, &base, &bandwidth, &flags); ruby_libvirt_generate_call_nil(virDomainBlockRebase, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_get_cstring_or_null(disk), ruby_libvirt_get_cstring_or_null(base), ruby_libvirt_value_to_ulong(bandwidth), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.open_channel(name, stream, flags=0) -> nil * * Call virDomainOpenChannel[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainOpenChannel] * to open a channel on a guest. Note that name may be nil, in which case the * first channel on the guest is opened. */ static VALUE libvirt_domain_open_channel(int argc, VALUE *argv, VALUE d) { VALUE name, st, flags; rb_scan_args(argc, argv, "21", &name, &st, &flags); ruby_libvirt_generate_call_nil(virDomainOpenChannel, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_get_cstring_or_null(name), ruby_libvirt_stream_get(st), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.create_with_files(fds=nil, flags=0) -> nil * * Call virDomainCreateWithFiles[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateWithFiles] * to launch a defined domain with a set of open file descriptors. */ static VALUE libvirt_domain_create_with_files(int argc, VALUE *argv, VALUE d) { VALUE fds, flags; int *files; unsigned int numfiles, i; rb_scan_args(argc, argv, "02", &fds, &flags); if (TYPE(fds) == T_NIL) { files = NULL; numfiles = 0; } else if (TYPE(fds) == T_ARRAY) { numfiles = RARRAY_LEN(fds); files = alloca(numfiles * sizeof(int)); for (i = 0; i < numfiles; i++) { files[i] = NUM2INT(rb_ary_entry(fds, i)); } } else { rb_raise(rb_eTypeError, "wrong argument type (expected Array)"); } ruby_libvirt_generate_call_nil(virDomainCreateWithFiles, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), numfiles, files, ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.open_graphics(fd, idx=0, flags=0) -> nil * * Call virDomainOpenGraphics[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainOpenGraphics] * to connect a file descriptor to the graphics backend of the domain. */ static VALUE libvirt_domain_open_graphics(int argc, VALUE *argv, VALUE d) { VALUE fd, idx, flags; rb_scan_args(argc, argv, "12", &fd, &idx, &flags); ruby_libvirt_generate_call_nil(virDomainOpenGraphics, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(idx), NUM2INT(fd), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.pmwakeup(flags=0) -> nil * * Call virDomainPMWakeup[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainPMWakeup] * to inject a wakeup into the guest. */ static VALUE libvirt_domain_pmwakeup(int argc, VALUE *argv, VALUE d) { VALUE flags; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_nil(virDomainPMWakeup, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.block_resize(disk, size, flags=0) -> nil * * Call virDomainBlockResize[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockResize] * to resize a block device of domain. */ static VALUE libvirt_domain_block_resize(int argc, VALUE *argv, VALUE d) { VALUE disk, size, flags; rb_scan_args(argc, argv, "21", &disk, &size, &flags); ruby_libvirt_generate_call_nil(virDomainBlockResize, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(disk), NUM2ULL(size), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.pmsuspend_for_duration(target, duration, flags=0) -> nil * * Call virDomainPMSuspendForDuration[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainPMSuspendForDuration] * to have the domain enter the target power management suspend level. */ static VALUE libvirt_domain_pmsuspend_for_duration(int argc, VALUE *argv, VALUE d) { VALUE target, duration, flags; rb_scan_args(argc, argv, "21", &target, &duration, &flags); ruby_libvirt_generate_call_nil(virDomainPMSuspendForDuration, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2UINT(target), NUM2ULL(duration), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.migrate_compression_cache(flags=0) -> Fixnum * * Call virDomainMigrateGetCompressionCache[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateGetCompressionCache] * to get the current size of the migration cache. */ static VALUE libvirt_domain_migrate_compression_cache(int argc, VALUE *argv, VALUE d) { VALUE flags; int ret; unsigned long long cachesize; rb_scan_args(argc, argv, "01", &flags); ret = virDomainMigrateGetCompressionCache(ruby_libvirt_domain_get(d), &cachesize, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virDomainMigrateGetCompressionCache", ruby_libvirt_connect_get(d)); return ULL2NUM(cachesize); } /* * call-seq: * dom.migrate_compression_cache = Fixnum,flags=0 * * Call virDomainMigrateSetCompressionCache[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateSetCompressionCache] * to set the current size of the migration cache. */ static VALUE libvirt_domain_migrate_compression_cache_equal(VALUE d, VALUE in) { VALUE cachesize, flags; domain_input_to_fixnum_and_flags(in, &cachesize, &flags); ruby_libvirt_generate_call_nil(virDomainMigrateSetCompressionCache, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2ULL(cachesize), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.disk_errors(flags=0) -> Hash * * Call virDomainGetDiskErrors[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetDiskErrors] * to get errors on disks in the domain. */ static VALUE libvirt_domain_disk_errors(int argc, VALUE *argv, VALUE d) { VALUE flags, hash; int maxerr, ret, i; virDomainDiskErrorPtr errors; rb_scan_args(argc, argv, "01", &flags); maxerr = virDomainGetDiskErrors(ruby_libvirt_domain_get(d), NULL, 0, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(maxerr < 0, e_RetrieveError, "virDomainGetDiskErrors", ruby_libvirt_connect_get(d)); errors = alloca(maxerr * sizeof(virDomainDiskError)); ret = virDomainGetDiskErrors(ruby_libvirt_domain_get(d), errors, maxerr, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virDomainGetDiskErrors", ruby_libvirt_connect_get(d)); hash = rb_hash_new(); for (i = 0; i < ret; i++) { rb_hash_aset(hash, rb_str_new2(errors[i].disk), INT2NUM(errors[i].error)); } return hash; } /* * call-seq: * dom.emulator_pin_info(flags=0) -> Array * * Call virDomainGetEmulatorPinInfo[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetEmulatorPinInfo] * to an array representing the mapping of emulator threads to physical CPUs. * For each physical CPU in the machine, the array offset corresponding to that * CPU is 'true' if an emulator thread is running on that CPU, and 'false' * otherwise. */ static VALUE libvirt_domain_emulator_pin_info(int argc, VALUE *argv, VALUE d) { int maxcpus, ret, j; size_t cpumaplen; unsigned char *cpumap; VALUE emulator2cpumap, flags; rb_scan_args(argc, argv, "01", &flags); maxcpus = ruby_libvirt_get_maxcpus(ruby_libvirt_connect_get(d)); cpumaplen = VIR_CPU_MAPLEN(maxcpus); cpumap = alloca(sizeof(unsigned char) * cpumaplen); ret = virDomainGetEmulatorPinInfo(ruby_libvirt_domain_get(d), cpumap, cpumaplen, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virDomainGetEmulatorPinInfo", ruby_libvirt_connect_get(d)); emulator2cpumap = rb_ary_new(); for (j = 0; j < maxcpus; j++) { rb_ary_push(emulator2cpumap, VIR_CPU_USABLE(cpumap, cpumaplen, 0, j) ? Qtrue : Qfalse); } return emulator2cpumap; } /* * call-seq: * dom.pin_emulator(cpulist, flags=0) -> nil * * Call virDomainPinVcpu[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainPinVcpu] * to pin the emulator to a range of physical processors. The cpulist should * be an array of Fixnums representing the physical processors this domain's * emulator should be allowed to be scheduled on. */ static VALUE libvirt_domain_pin_emulator(int argc, VALUE *argv, VALUE d) { VALUE cpulist, flags, e; int i, maxcpus, cpumaplen; unsigned char *cpumap; rb_scan_args(argc, argv, "11", &cpulist, &flags); Check_Type(cpulist, T_ARRAY); maxcpus = ruby_libvirt_get_maxcpus(ruby_libvirt_connect_get(d)); cpumaplen = VIR_CPU_MAPLEN(maxcpus); cpumap = alloca(sizeof(unsigned char) * cpumaplen); MEMZERO(cpumap, unsigned char, cpumaplen); for (i = 0; i < RARRAY_LEN(cpulist); i++) { e = rb_ary_entry(cpulist, i); VIR_USE_CPU(cpumap, NUM2UINT(e)); } ruby_libvirt_generate_call_nil(virDomainPinEmulator, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), cpumap, cpumaplen, ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.security_label_list -> [ Libvirt::Domain::SecurityLabel ] * * Call virDomainGetSecurityLabelList[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSecurityLabelList] * to retrieve the security labels applied to this domain. */ static VALUE libvirt_domain_security_label_list(VALUE d) { virSecurityLabelPtr seclabels; int r, i; VALUE result, tmp; r = virDomainGetSecurityLabelList(ruby_libvirt_domain_get(d), &seclabels); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainGetSecurityLabel", ruby_libvirt_connect_get(d)); result = rb_ary_new2(r); for (i = 0; i < r; i++) { tmp = rb_class_new_instance(0, NULL, c_domain_security_label); rb_iv_set(tmp, "@label", rb_str_new2(seclabels[i].label)); rb_iv_set(tmp, "@enforcing", INT2NUM(seclabels[i].enforcing)); rb_ary_store(result, i, tmp); } return result; } struct params_to_hash_arg { virTypedParameterPtr params; int nparams; VALUE result; }; static VALUE params_to_hash(VALUE in) { struct params_to_hash_arg *args = (struct params_to_hash_arg *)in; int i; for (i = 0; i < args->nparams; i++) { ruby_libvirt_typed_params_to_hash(args->params, i, args->result); } return Qnil; } /* * call-seq: * dom.job_stats -> Hash * * Call virDomainGetJobStats[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobStats] * to retrieve information about progress of a background job on a domain. */ static VALUE libvirt_domain_job_stats(int argc, VALUE *argv, VALUE d) { VALUE flags, result; int type, exception = 0, nparams = 0, r; virTypedParameterPtr params = NULL; struct params_to_hash_arg args; struct ruby_libvirt_hash_aset_arg asetargs; rb_scan_args(argc, argv, "01", &flags); result = rb_hash_new(); r = virDomainGetJobStats(ruby_libvirt_domain_get(d), &type, ¶ms, &nparams, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainGetJobStats", ruby_libvirt_connect_get(d)); /* since virDomainGetJobsStats() allocated memory, we need to wrap all * calls below to make sure we don't leak memory */ asetargs.hash = result; asetargs.name = "type"; asetargs.val = INT2NUM(type); rb_protect(ruby_libvirt_hash_aset_wrap, (VALUE)&asetargs, &exception); if (exception) { virTypedParamsFree(params, nparams); rb_jump_tag(exception); } args.params = params; args.nparams = nparams; args.result = result; result = rb_protect(params_to_hash, (VALUE)&args, &exception); if (exception) { virTypedParamsFree(params, nparams); rb_jump_tag(exception); } virTypedParamsFree(params, nparams); return result; } static const char *iotune_nparams(VALUE d, unsigned int flags, void *opaque, int *nparams) { VALUE disk = (VALUE)opaque; if (virDomainGetBlockIoTune(ruby_libvirt_domain_get(d), ruby_libvirt_get_cstring_or_null(disk), NULL, nparams, flags) < 0) { return "virDomainGetBlockIoTune"; } return NULL; } static const char *iotune_get(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *opaque) { virTypedParameterPtr params = (virTypedParameterPtr)voidparams; VALUE disk = (VALUE)opaque; if (virDomainGetBlockIoTune(ruby_libvirt_domain_get(d), ruby_libvirt_get_cstring_or_null(disk), params, nparams, flags) < 0) { return "virDomainGetBlockIoTune"; } return NULL; } static const char *iotune_set(VALUE d, unsigned int flags, virTypedParameterPtr params, int nparams, void *opaque) { VALUE disk = (VALUE)opaque; if (virDomainSetBlockIoTune(ruby_libvirt_domain_get(d), StringValueCStr(disk), params, nparams, flags) < 0) { return "virDomainSetBlockIoTune"; } return NULL; } /* * call-seq: * dom.block_iotune(disk=nil, flags=0) -> Hash * * Call virDomainGetBlockIoTune[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetBlockIoTune] * to retrieve all of the block IO tune parameters for this domain. The keys * and values in the hash that is returned are hypervisor specific. */ static VALUE libvirt_domain_block_iotune(int argc, VALUE *argv, VALUE d) { VALUE disk, flags; rb_scan_args(argc, argv, "02", &disk, &flags); return ruby_libvirt_get_typed_parameters(d, ruby_libvirt_value_to_uint(flags), (void *)disk, iotune_nparams, iotune_get); } static struct ruby_libvirt_typed_param iotune_allowed[] = { {VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC, VIR_TYPED_PARAM_ULLONG}, {VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC, VIR_TYPED_PARAM_ULLONG}, }; /* * call-seq: * dom.block_iotune = disk,Hash,flags=0 * * Call virDomainSetBlockIoTune[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetBlockIoTune] * to set the block IO tune parameters for the supplied disk on this domain. * The keys and values in the input hash are hypervisor specific. */ static VALUE libvirt_domain_block_iotune_equal(VALUE d, VALUE in) { VALUE disk, hash, flags; Check_Type(in, T_ARRAY); if (RARRAY_LEN(in) == 2) { disk = rb_ary_entry(in, 0); hash = rb_ary_entry(in, 1); flags = INT2NUM(0); } else if (RARRAY_LEN(in) == 3) { disk = rb_ary_entry(in, 0); hash = rb_ary_entry(in, 1); flags = rb_ary_entry(in, 2); } else { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2 or 3)", RARRAY_LEN(in)); } return ruby_libvirt_set_typed_parameters(d, hash, NUM2UINT(flags), (void *)disk, iotune_allowed, ARRAY_SIZE(iotune_allowed), iotune_set); } /* * call-seq: * dom.block_commit(disk, base=nil, top=nil, bandwidth=0, flags=0) -> nil * * Call virDomainBlockCommit[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockCommit] * to commit changes from a top-level backing file into a lower level base file. */ static VALUE libvirt_domain_block_commit(int argc, VALUE *argv, VALUE d) { VALUE disk, base, top, bandwidth, flags; rb_scan_args(argc, argv, "14", &disk, &base, &top, &bandwidth, &flags); ruby_libvirt_generate_call_nil(virDomainBlockCommit, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(disk), ruby_libvirt_get_cstring_or_null(base), ruby_libvirt_get_cstring_or_null(top), ruby_libvirt_value_to_ulong(bandwidth), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.block_pull(disk, bandwidth=0, flags=0) -> nil * * Call virDomainBlockPull[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockPull] * to pull changes from a backing file into a disk image. */ static VALUE libvirt_domain_block_pull(int argc, VALUE *argv, VALUE d) { VALUE disk, bandwidth = RUBY_Qnil, flags = RUBY_Qnil; rb_scan_args(argc, argv, "12", &disk, &bandwidth, &flags); ruby_libvirt_generate_call_nil(virDomainBlockPull, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(disk), ruby_libvirt_value_to_ulong(bandwidth), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.block_job_speed = disk,bandwidth=0,flags=0 * * Call virDomainBlockJobSetSpeed[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockJobSetSpeed] * to set the maximum allowable bandwidth a block job may consume. */ static VALUE libvirt_domain_block_job_speed_equal(VALUE d, VALUE in) { VALUE disk, bandwidth, flags; if (TYPE(in) == T_STRING) { disk = in; bandwidth = INT2NUM(0); flags = INT2NUM(0); } else if (TYPE(in) == T_ARRAY) { if (RARRAY_LEN(in) == 2) { disk = rb_ary_entry(in, 0); bandwidth = rb_ary_entry(in, 1); flags = INT2NUM(0); } else if (RARRAY_LEN(in) == 3) { disk = rb_ary_entry(in, 0); bandwidth = rb_ary_entry(in, 1); flags = rb_ary_entry(in, 2); } else { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2 or 3)", RARRAY_LEN(in)); } } else { rb_raise(rb_eTypeError, "wrong argument type (expected Number or Array)"); } ruby_libvirt_generate_call_nil(virDomainBlockJobSetSpeed, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(disk), NUM2UINT(bandwidth), NUM2UINT(flags)); } /* * call-seq: * dom.block_job_info(disk, flags=0) -> Libvirt::Domain::BlockJobInfo * * Call virDomainGetBlockJobInfo[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetBlockJobInfo] * to get block job information for a given disk. */ static VALUE libvirt_domain_block_job_info(int argc, VALUE *argv, VALUE d) { VALUE disk, flags = RUBY_Qnil, result; virDomainBlockJobInfo info; int r; rb_scan_args(argc, argv, "11", &disk, &flags); memset(&info, 0, sizeof(virDomainBlockJobInfo)); r = virDomainGetBlockJobInfo(ruby_libvirt_domain_get(d), StringValueCStr(disk), &info, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virDomainGetBlockJobInfo", ruby_libvirt_connect_get(d)); result = rb_class_new_instance(0, NULL, c_domain_block_job_info); rb_iv_set(result, "@type", UINT2NUM(info.type)); rb_iv_set(result, "@bandwidth", ULONG2NUM(info.bandwidth)); rb_iv_set(result, "@cur", ULL2NUM(info.cur)); rb_iv_set(result, "@end", ULL2NUM(info.end)); return result; } /* * call-seq: * dom.block_job_abort(disk, flags=0) -> nil * * Call virDomainBlockJobAbort[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockJobAbort] * to cancel an active block job on the given disk. */ static VALUE libvirt_domain_block_job_abort(int argc, VALUE *argv, VALUE d) { VALUE disk, flags = RUBY_Qnil; rb_scan_args(argc, argv, "11", &disk, &flags); ruby_libvirt_generate_call_nil(virDomainBlockJobAbort, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(disk), ruby_libvirt_value_to_uint(flags)); } static const char *interface_nparams(VALUE d, unsigned int flags, void *opaque, int *nparams) { VALUE device = (VALUE)opaque; if (virDomainGetInterfaceParameters(ruby_libvirt_domain_get(d), StringValueCStr(device), NULL, nparams, flags) < 0) { return "virDomainGetInterfaceParameters"; } return NULL; } static const char *interface_get(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *opaque) { virTypedParameterPtr params = (virTypedParameterPtr)voidparams; VALUE interface = (VALUE)opaque; if (virDomainGetInterfaceParameters(ruby_libvirt_domain_get(d), StringValueCStr(interface), params, nparams, flags) < 0) { return "virDomainGetInterfaceParameters"; } return NULL; } static const char *interface_set(VALUE d, unsigned int flags, virTypedParameterPtr params, int nparams, void *opaque) { VALUE device = (VALUE)opaque; if (virDomainSetInterfaceParameters(ruby_libvirt_domain_get(d), StringValueCStr(device), params, nparams, flags) < 0) { return "virDomainSetIntefaceParameters"; } return NULL; } /* * call-seq: * dom.interface_parameters(interface, flags=0) -> Hash * * Call virDomainGetInterfaceParameters[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetInterfaceParameters] * to retrieve the interface parameters for the given interface on this domain. * The keys and values in the hash that is returned are hypervisor specific. */ static VALUE libvirt_domain_interface_parameters(int argc, VALUE *argv, VALUE d) { VALUE device = RUBY_Qnil, flags = RUBY_Qnil; rb_scan_args(argc, argv, "11", &device, &flags); Check_Type(device, T_STRING); return ruby_libvirt_get_typed_parameters(d, ruby_libvirt_value_to_uint(flags), (void *)device, interface_nparams, interface_get); } static struct ruby_libvirt_typed_param interface_allowed[] = { {VIR_DOMAIN_BANDWIDTH_IN_AVERAGE, VIR_TYPED_PARAM_UINT}, {VIR_DOMAIN_BANDWIDTH_IN_PEAK, VIR_TYPED_PARAM_UINT}, {VIR_DOMAIN_BANDWIDTH_IN_BURST, VIR_TYPED_PARAM_UINT}, {VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE, VIR_TYPED_PARAM_UINT}, {VIR_DOMAIN_BANDWIDTH_OUT_PEAK, VIR_TYPED_PARAM_UINT}, {VIR_DOMAIN_BANDWIDTH_OUT_BURST, VIR_TYPED_PARAM_UINT}, }; /* * call-seq: * dom.interface_parameters = device,Hash,flags=0 * * Call virDomainSetInterfaceParameters[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetInterfaceParameters] * to set the interface parameters for the supplied device on this domain. * The keys and values in the input hash are hypervisor specific. */ static VALUE libvirt_domain_interface_parameters_equal(VALUE d, VALUE in) { VALUE device, hash, flags; Check_Type(in, T_ARRAY); if (RARRAY_LEN(in) == 2) { device = rb_ary_entry(in, 0); hash = rb_ary_entry(in, 1); flags = INT2NUM(0); } else if (RARRAY_LEN(in) == 3) { device = rb_ary_entry(in, 0); hash = rb_ary_entry(in, 1); flags = rb_ary_entry(in, 2); } else { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2 or 3)", RARRAY_LEN(in)); } return ruby_libvirt_set_typed_parameters(d, hash, ruby_libvirt_value_to_uint(flags), (void *)device, interface_allowed, ARRAY_SIZE(interface_allowed), interface_set); } static const char *block_stats_nparams(VALUE d, unsigned int flags, void *opaque, int *nparams) { VALUE disk = (VALUE)opaque; if (virDomainBlockStatsFlags(ruby_libvirt_domain_get(d), StringValueCStr(disk), NULL, nparams, flags) < 0) { return "virDomainBlockStatsFlags"; } return NULL; } static const char *block_stats_get(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *opaque) { virTypedParameterPtr params = (virTypedParameterPtr)voidparams; VALUE disk = (VALUE)opaque; if (virDomainBlockStatsFlags(ruby_libvirt_domain_get(d), StringValueCStr(disk), params, nparams, flags) < 0) { return "virDomainBlockStatsFlags"; } return NULL; } /* * call-seq: * dom.block_stats_flags(disk, flags=0) -> Hash * * Call virDomainGetBlockStatsFlags[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetBlockStatsFlags] * to retrieve the block statistics for the given disk on this domain. * The keys and values in the hash that is returned are hypervisor specific. */ static VALUE libvirt_domain_block_stats_flags(int argc, VALUE *argv, VALUE d) { VALUE disk = RUBY_Qnil, flags = RUBY_Qnil; rb_scan_args(argc, argv, "11", &disk, &flags); Check_Type(disk, T_STRING); return ruby_libvirt_get_typed_parameters(d, ruby_libvirt_value_to_uint(flags), (void *)disk, block_stats_nparams, block_stats_get); } static const char *numa_nparams(VALUE d, unsigned int flags, void *RUBY_LIBVIRT_UNUSED(opaque), int *nparams) { if (virDomainGetNumaParameters(ruby_libvirt_domain_get(d), NULL, nparams, flags) < 0) { return "virDomainGetNumaParameters"; } return NULL; } static const char *numa_get(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *RUBY_LIBVIRT_UNUSED(opaque)) { virTypedParameterPtr params = (virTypedParameterPtr)voidparams; if (virDomainGetNumaParameters(ruby_libvirt_domain_get(d), params, nparams, flags) < 0) { return "virDomainGetNumaParameters"; } return NULL; } static const char *numa_set(VALUE d, unsigned int flags, virTypedParameterPtr params, int nparams, void *RUBY_LIBVIRT_UNUSED(opaque)) { if (virDomainSetNumaParameters(ruby_libvirt_domain_get(d), params, nparams, flags) < 0) { return "virDomainSetNumaParameters"; } return NULL; } /* * call-seq: * dom.numa_parameters(flags=0) -> Hash * * Call virDomainGetNumaParameters[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetNumaParameters] * to retrieve the numa parameters for this domain. The keys and values in * the hash that is returned are hypervisor specific. */ static VALUE libvirt_domain_numa_parameters(int argc, VALUE *argv, VALUE d) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); return ruby_libvirt_get_typed_parameters(d, ruby_libvirt_value_to_uint(flags), NULL, numa_nparams, numa_get); } static struct ruby_libvirt_typed_param numa_allowed[] = { {VIR_DOMAIN_NUMA_NODESET, VIR_TYPED_PARAM_STRING}, {VIR_DOMAIN_NUMA_MODE, VIR_TYPED_PARAM_INT}, }; /* * call-seq: * dom.numa_parameters = Hash,flags=0 * * Call virDomainSetNumaParameters[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetNumaParameters] * to set the numa parameters for this domain. The keys and values in the input * hash are hypervisor specific. */ static VALUE libvirt_domain_numa_parameters_equal(VALUE d, VALUE in) { VALUE hash, flags; ruby_libvirt_assign_hash_and_flags(in, &hash, &flags); return ruby_libvirt_set_typed_parameters(d, hash, ruby_libvirt_value_to_uint(flags), NULL, numa_allowed, ARRAY_SIZE(numa_allowed), numa_set); } /* * call-seq: * dom.lxc_open_namespace(flags=0) -> Array * * Call virDomainLxcOpenNamespace[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLxcOpenNamespace] * to open an LXC namespace. Note that this will only work on connections to * the LXC driver. The call will return an array of open file descriptors; * these should be closed when use of them is finished. */ static VALUE libvirt_domain_lxc_open_namespace(int argc, VALUE *argv, VALUE d) { VALUE flags = RUBY_Qnil, result; int *fdlist = NULL; int ret, i, exception = 0; struct ruby_libvirt_ary_store_arg args; rb_scan_args(argc, argv, "01", &flags); ret = virDomainLxcOpenNamespace(ruby_libvirt_domain_get(d), &fdlist, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virDomainLxcOpenNamespace", ruby_libvirt_connect_get(d)); result = rb_protect(ruby_libvirt_ary_new2_wrap, (VALUE)&ret, &exception); if (exception) { goto error; } for (i = 0; i < ret; i++) { args.arr = result; args.index = i; /* from reading the ruby sources, INT2NUM can't possibly throw an * exception, so this can't leak. */ args.elem = INT2NUM(fdlist[i]); rb_protect(ruby_libvirt_ary_store_wrap, (VALUE)&args, &exception); if (exception) { goto error; } } free(fdlist); return result; error: for (i = 0; i < ret; i++) { close(fdlist[i]); } free(fdlist); rb_jump_tag(exception); } /* * call-seq: * dom.qemu_agent_command(command, timeout=0, flags=0) -> String * * Call virDomainQemuAgentCommand[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainQemuAgentCommand] * to run an arbitrary command on the Qemu Agent. */ static VALUE libvirt_domain_qemu_agent_command(int argc, VALUE *argv, VALUE d) { VALUE command, timeout = RUBY_Qnil, flags = RUBY_Qnil, result; char *ret; int exception = 0; rb_scan_args(argc, argv, "12", &command, &timeout, &flags); if (NIL_P(timeout)) { timeout = INT2NUM(VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT); } ret = virDomainQemuAgentCommand(ruby_libvirt_domain_get(d), StringValueCStr(command), ruby_libvirt_value_to_int(timeout), ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret == NULL, e_RetrieveError, "virDomainQemuAgentCommand", ruby_libvirt_connect_get(d)); result = rb_protect(ruby_libvirt_str_new2_wrap, (VALUE)&ret, &exception); free(ret); if (exception) { rb_jump_tag(exception); } return result; } /* * call-seq: * dom.lxc_enter_namespace(fds, flags=0) -> Array * * Call virDomainLxcEnterNamespace[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLxcEnterNamespace] * to attach the process to the namespaces associated with the file descriptors * in the fds array. Note that this call does not actually enter the namespace; * the next call to fork will do that. Also note that this function will return * an array of old file descriptors that can be used to switch back to the * current namespace later. */ static VALUE libvirt_domain_lxc_enter_namespace(int argc, VALUE *argv, VALUE d) { VALUE fds = RUBY_Qnil, flags = RUBY_Qnil, result; int *fdlist; int ret, exception = 0; int *oldfdlist; unsigned int noldfdlist, i; struct ruby_libvirt_ary_store_arg args; rb_scan_args(argc, argv, "11", &fds, &flags); Check_Type(fds, T_ARRAY); fdlist = alloca(sizeof(int) * RARRAY_LEN(fds)); for (i = 0; i < RARRAY_LEN(fds); i++) { fdlist[i] = NUM2INT(rb_ary_entry(fds, i)); } ret = virDomainLxcEnterNamespace(ruby_libvirt_domain_get(d), RARRAY_LEN(fds), fdlist, &noldfdlist, &oldfdlist, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virDomainLxcEnterNamespace", ruby_libvirt_connect_get(d)); result = rb_protect(ruby_libvirt_ary_new2_wrap, (VALUE)&noldfdlist, &exception); if (exception) { free(oldfdlist); rb_jump_tag(exception); } for (i = 0; i < noldfdlist; i++) { args.arr = result; args.index = i; /* from reading the ruby sources, INT2NUM can't possibly throw an * exception, so this can't leak. */ args.elem = INT2NUM(oldfdlist[i]); rb_protect(ruby_libvirt_ary_store_wrap, (VALUE)&args, &exception); if (exception) { free(oldfdlist); rb_jump_tag(exception); } } free(oldfdlist); return result; } static struct ruby_libvirt_typed_param migrate3_allowed[] = { {VIR_MIGRATE_PARAM_URI, VIR_TYPED_PARAM_STRING}, {VIR_MIGRATE_PARAM_DEST_NAME, VIR_TYPED_PARAM_STRING}, {VIR_MIGRATE_PARAM_DEST_XML, VIR_TYPED_PARAM_STRING}, {VIR_MIGRATE_PARAM_BANDWIDTH, VIR_TYPED_PARAM_ULLONG}, {VIR_MIGRATE_PARAM_GRAPHICS_URI, VIR_TYPED_PARAM_STRING}, {VIR_MIGRATE_PARAM_LISTEN_ADDRESS, VIR_TYPED_PARAM_STRING}, }; /* * call-seq: * dom.migrate3(dconn, Hash=nil, flags=0) -> Libvirt::Domain * * Call virDomainMigrate3[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrate3] * to migrate a domain from the host on this connection to the connection * referenced in dconn. */ static VALUE libvirt_domain_migrate3(int argc, VALUE *argv, VALUE d) { VALUE dconn = RUBY_Qnil, hash = RUBY_Qnil, flags = RUBY_Qnil; virDomainPtr ddom = NULL; struct ruby_libvirt_parameter_assign_args args; unsigned long hashsize; rb_scan_args(argc, argv, "12", &dconn, &hash, &flags); Check_Type(hash, T_HASH); hashsize = RHASH_SIZE(hash); memset(&args, 0, sizeof(struct ruby_libvirt_parameter_assign_args)); if (hashsize > 0) { args.allowed = migrate3_allowed; args.num_allowed = ARRAY_SIZE(migrate3_allowed); args.params = alloca(sizeof(virTypedParameter) * hashsize); args.i = 0; rb_hash_foreach(hash, ruby_libvirt_typed_parameter_assign, (VALUE)&args); } ddom = virDomainMigrate3(ruby_libvirt_domain_get(d), ruby_libvirt_connect_get(dconn), args.params, args.i, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ddom == NULL, e_Error, "virDomainMigrate3", ruby_libvirt_connect_get(d)); return ruby_libvirt_domain_new(ddom, dconn); } /* * call-seq: * dom.migrate_to_uri3(duri=nil, Hash=nil, flags=0) -> nil * * Call virDomainMigrateToURI3[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateToURI3] * to migrate a domain from the host on this connection to the host whose * libvirt URI is duri. */ static VALUE libvirt_domain_migrate_to_uri3(int argc, VALUE *argv, VALUE d) { VALUE duri = RUBY_Qnil, hash = RUBY_Qnil, flags = RUBY_Qnil; struct ruby_libvirt_parameter_assign_args args; unsigned long hashsize; rb_scan_args(argc, argv, "03", &duri, &hash, &flags); Check_Type(hash, T_HASH); hashsize = RHASH_SIZE(hash); memset(&args, 0, sizeof(struct ruby_libvirt_parameter_assign_args)); if (hashsize > 0) { args.allowed = migrate3_allowed; args.num_allowed = ARRAY_SIZE(migrate3_allowed); args.params = alloca(sizeof(virTypedParameter) * hashsize); args.i = 0; rb_hash_foreach(hash, ruby_libvirt_typed_parameter_assign, (VALUE)&args); } ruby_libvirt_generate_call_nil(virDomainMigrateToURI3, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), ruby_libvirt_get_cstring_or_null(duri), args.params, args.i, ruby_libvirt_value_to_ulong(flags)); } /* * call-seq: * dom.cpu_stats(start_cpu=-1, numcpus=1, flags=0) -> Hash * * Call virDomainGetCPUStats[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetCPUStats] * to get statistics about CPU usage attributable to a single domain. If * start_cpu is -1, then numcpus must be 1 and statistics attributable to the * entire domain is returned. If start_cpu is any positive number, then it * represents which CPU to start with and numcpus represents how many * consecutive processors to query. */ static VALUE libvirt_domain_cpu_stats(int argc, VALUE *argv, VALUE d) { VALUE start_cpu = RUBY_Qnil, numcpus = RUBY_Qnil, flags = RUBY_Qnil, result, tmp; int ret, nparams, j; unsigned int i; virTypedParameterPtr params; rb_scan_args(argc, argv, "03", &start_cpu, &numcpus, &flags); if (NIL_P(start_cpu)) { start_cpu = INT2NUM(-1); } if (NIL_P(numcpus)) { numcpus = INT2NUM(1); } if (NIL_P(flags)) { flags = INT2NUM(0); } if (NUM2INT(start_cpu) == -1) { nparams = virDomainGetCPUStats(ruby_libvirt_domain_get(d), NULL, 0, NUM2INT(start_cpu), NUM2UINT(numcpus), NUM2UINT(flags)); ruby_libvirt_raise_error_if(nparams < 0, e_RetrieveError, "virDomainGetCPUStats", ruby_libvirt_connect_get(d)); params = alloca(nparams * sizeof(virTypedParameter)); ret = virDomainGetCPUStats(ruby_libvirt_domain_get(d), params, nparams, NUM2INT(start_cpu), NUM2UINT(numcpus), NUM2UINT(flags)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virDomainGetCPUStats", ruby_libvirt_connect_get(d)); result = rb_hash_new(); tmp = rb_hash_new(); for (j = 0; j < nparams; j++) { ruby_libvirt_typed_params_to_hash(params, j, tmp); } rb_hash_aset(result, rb_str_new2("all"), tmp); } else { nparams = virDomainGetCPUStats(ruby_libvirt_domain_get(d), NULL, 0, 0, 1, NUM2UINT(flags)); ruby_libvirt_raise_error_if(nparams < 0, e_RetrieveError, "virDomainGetCPUStats", ruby_libvirt_connect_get(d)); params = alloca(nparams * NUM2UINT(numcpus) * sizeof(virTypedParameter)); ret = virDomainGetCPUStats(ruby_libvirt_domain_get(d), params, nparams, NUM2INT(start_cpu), NUM2UINT(numcpus), NUM2UINT(flags)); ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError, "virDomainGetCPUStats", ruby_libvirt_connect_get(d)); result = rb_hash_new(); for (i = 0; i < NUM2UINT(numcpus); i++) { if (params[i * nparams].type == 0) { /* cpu is not in the map */ continue; } tmp = rb_hash_new(); for (j = 0; j < nparams; j++) { ruby_libvirt_typed_params_to_hash(params, j, tmp); } rb_hash_aset(result, INT2NUM(NUM2UINT(start_cpu) + i), tmp); } } return result; } /* * call-seq: * dom.time(flags=0) -> Hash * Call virDomainGetTime[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetTime] * to get information about the guest time. */ static VALUE libvirt_domain_get_time(int argc, VALUE *argv, VALUE d) { VALUE flags = RUBY_Qnil, result; long long seconds; unsigned int nseconds; int ret; rb_scan_args(argc, argv, "01", &flags); ret = virDomainGetTime(ruby_libvirt_domain_get(d), &seconds, &nseconds, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_Error, "virDomainGetTime", ruby_libvirt_connect_get(d)); result = rb_hash_new(); rb_hash_aset(result, rb_str_new2("seconds"), LL2NUM(seconds)); rb_hash_aset(result, rb_str_new2("nseconds"), UINT2NUM(nseconds)); return result; } /* * call-seq: * dom.time = Hash,flags=0 * Call virDomainSetTime[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetTime] * to set guest time. */ static VALUE libvirt_domain_time_equal(VALUE d, VALUE in) { VALUE hash, flags, seconds, nseconds; ruby_libvirt_assign_hash_and_flags(in, &hash, &flags); seconds = rb_hash_aref(hash, rb_str_new2("seconds")); nseconds = rb_hash_aref(hash, rb_str_new2("nseconds")); ruby_libvirt_generate_call_nil(virDomainSetTime, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), NUM2LL(seconds), NUM2UINT(nseconds), NUM2UINT(flags)); } /* * call-seq: * dom.core_dump_with_format(filename, dumpformat, flags=0) -> nil * * Call virDomainCoreDumpWithFormat[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCoreDump] * to do a full memory dump of the domain to filename. */ static VALUE libvirt_domain_core_dump_with_format(int argc, VALUE *argv, VALUE d) { VALUE to, dumpformat = RUBY_Qnil, flags = RUBY_Qnil; rb_scan_args(argc, argv, "21", &to, &dumpformat, &flags); ruby_libvirt_generate_call_nil(virDomainCoreDumpWithFormat, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(to), NUM2UINT(dumpformat), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.fs_freeze(mountpoints=nil, flags=0) -> Fixnum * * Call virDomainFSFreeze[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainFSFreeze] * to freeze the specified filesystems within the guest. */ static VALUE libvirt_domain_fs_freeze(int argc, VALUE *argv, VALUE d) { VALUE mountpoints = RUBY_Qnil, flags = RUBY_Qnil, entry; const char **mnt; unsigned int nmountpoints; int i; rb_scan_args(argc, argv, "02", &mountpoints, &flags); if (NIL_P(mountpoints)) { mnt = NULL; nmountpoints = 0; } else { Check_Type(mountpoints, T_ARRAY); nmountpoints = RARRAY_LEN(mountpoints); mnt = alloca(nmountpoints * sizeof(char *)); for (i = 0; i < nmountpoints; i++) { entry = rb_ary_entry(mountpoints, i); mnt[i] = StringValueCStr(entry); } } ruby_libvirt_generate_call_int(virDomainFSFreeze, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), mnt, nmountpoints, ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.fs_thaw(mountpoints=nil, flags=0) -> Fixnum * * Call virDomainFSThaw[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainFSThaw] * to thaw the specified filesystems within the guest. */ static VALUE libvirt_domain_fs_thaw(int argc, VALUE *argv, VALUE d) { VALUE mountpoints = RUBY_Qnil, flags = RUBY_Qnil, entry; const char **mnt; unsigned int nmountpoints; int i; rb_scan_args(argc, argv, "02", &mountpoints, &flags); if (NIL_P(mountpoints)) { mnt = NULL; nmountpoints = 0; } else { Check_Type(mountpoints, T_ARRAY); nmountpoints = RARRAY_LEN(mountpoints); mnt = alloca(nmountpoints * sizeof(char *)); for (i = 0; i < nmountpoints; i++) { entry = rb_ary_entry(mountpoints, i); mnt[i] = StringValueCStr(entry); } } ruby_libvirt_generate_call_int(virDomainFSThaw, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), mnt, nmountpoints, ruby_libvirt_value_to_uint(flags)); } struct fs_info_arg { virDomainFSInfoPtr *info; int ninfo; }; static VALUE fs_info_wrap(VALUE arg) { struct fs_info_arg *e = (struct fs_info_arg *)arg; VALUE aliases, entry, result; int i, j; result = rb_ary_new2(e->ninfo); for (i = 0; i < e->ninfo; i++) { aliases = rb_ary_new2(e->info[i]->ndevAlias); for (j = 0; j < e->info[i]->ndevAlias; j++) { rb_ary_store(aliases, j, rb_str_new2(e->info[i]->devAlias[j])); } entry = rb_hash_new(); rb_hash_aset(entry, rb_str_new2("mountpoint"), rb_str_new2(e->info[i]->mountpoint)); rb_hash_aset(entry, rb_str_new2("name"), rb_str_new2(e->info[i]->name)); rb_hash_aset(entry, rb_str_new2("fstype"), rb_str_new2(e->info[i]->fstype)); rb_hash_aset(entry, rb_str_new2("aliases"), aliases); rb_ary_store(result, i, entry); } return result; } /* * call-seq: * dom.fs_info(flags=0) -> [Hash] * * Call virDomainGetFSInfo[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetFSInfo] * to get information about the guest filesystems. */ static VALUE libvirt_domain_fs_info(int argc, VALUE *argv, VALUE d) { VALUE flags = RUBY_Qnil, result; virDomainFSInfoPtr *info; int ret, i = 0, exception; struct fs_info_arg args; rb_scan_args(argc, argv, "01", &flags); ret = virDomainGetFSInfo(ruby_libvirt_domain_get(d), &info, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(ret < 0, e_Error, "virDomainGetFSInfo", ruby_libvirt_connect_get(d)); args.info = info; args.ninfo = ret; result = rb_protect(fs_info_wrap, (VALUE)&args, &exception); for (i = 0; i < ret; i++) { virDomainFSInfoFree(info[i]); } free(info); if (exception) { rb_jump_tag(exception); } return result; } /* * call-seq: * dom.rename(name, flags=0) -> nil * * Call virDomainRename[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainRename] * to rename a domain. */ static VALUE libvirt_domain_rename(int argc, VALUE *argv, VALUE d) { VALUE flags = RUBY_Qnil, name; rb_scan_args(argc, argv, "11", &name, &flags); ruby_libvirt_generate_call_nil(virDomainRename, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(name), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * dom.user_password = user,password,flags=0 -> nil * * Call virDomainSetUserPassword[https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetUserPassword] * to set the user password on a domain. */ static VALUE libvirt_domain_user_password_equal(VALUE d, VALUE in) { VALUE user, password, flags; Check_Type(in, T_ARRAY); if (RARRAY_LEN(in) == 2) { user = rb_ary_entry(in, 0); password = rb_ary_entry(in, 1); flags = INT2NUM(0); } else if (RARRAY_LEN(in) == 3) { user = rb_ary_entry(in, 0); password = rb_ary_entry(in, 1); flags = rb_ary_entry(in, 2); } else { rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2 or 3)", RARRAY_LEN(in)); } ruby_libvirt_generate_call_nil(virDomainSetUserPassword, ruby_libvirt_connect_get(d), ruby_libvirt_domain_get(d), StringValueCStr(user), StringValueCStr(password), ruby_libvirt_value_to_uint(flags)); } /* * Class Libvirt::Domain */ void ruby_libvirt_domain_init(void) { c_domain = rb_define_class_under(m_libvirt, "Domain", rb_cObject); rb_undef_alloc_func(c_domain); rb_define_singleton_method(c_domain, "new", ruby_libvirt_new_not_allowed, -1); rb_define_const(c_domain, "NOSTATE", INT2NUM(VIR_DOMAIN_NOSTATE)); rb_define_const(c_domain, "RUNNING", INT2NUM(VIR_DOMAIN_RUNNING)); rb_define_const(c_domain, "BLOCKED", INT2NUM(VIR_DOMAIN_BLOCKED)); rb_define_const(c_domain, "PAUSED", INT2NUM(VIR_DOMAIN_PAUSED)); rb_define_const(c_domain, "SHUTDOWN", INT2NUM(VIR_DOMAIN_SHUTDOWN)); rb_define_const(c_domain, "SHUTOFF", INT2NUM(VIR_DOMAIN_SHUTOFF)); rb_define_const(c_domain, "CRASHED", INT2NUM(VIR_DOMAIN_CRASHED)); rb_define_const(c_domain, "PMSUSPENDED", INT2NUM(VIR_DOMAIN_PMSUSPENDED)); /* virDomainMigrateFlags */ rb_define_const(c_domain, "MIGRATE_LIVE", INT2NUM(VIR_MIGRATE_LIVE)); rb_define_const(c_domain, "MIGRATE_PEER2PEER", INT2NUM(VIR_MIGRATE_PEER2PEER)); rb_define_const(c_domain, "MIGRATE_TUNNELLED", INT2NUM(VIR_MIGRATE_TUNNELLED)); rb_define_const(c_domain, "MIGRATE_PERSIST_DEST", INT2NUM(VIR_MIGRATE_PERSIST_DEST)); rb_define_const(c_domain, "MIGRATE_UNDEFINE_SOURCE", INT2NUM(VIR_MIGRATE_UNDEFINE_SOURCE)); rb_define_const(c_domain, "MIGRATE_PAUSED", INT2NUM(VIR_MIGRATE_PAUSED)); rb_define_const(c_domain, "MIGRATE_NON_SHARED_DISK", INT2NUM(VIR_MIGRATE_NON_SHARED_DISK)); rb_define_const(c_domain, "MIGRATE_NON_SHARED_INC", INT2NUM(VIR_MIGRATE_NON_SHARED_INC)); rb_define_const(c_domain, "MIGRATE_CHANGE_PROTECTION", INT2NUM(VIR_MIGRATE_CHANGE_PROTECTION)); rb_define_const(c_domain, "MIGRATE_UNSAFE", INT2NUM(VIR_MIGRATE_UNSAFE)); rb_define_const(c_domain, "MIGRATE_OFFLINE", INT2NUM(VIR_MIGRATE_OFFLINE)); rb_define_const(c_domain, "MIGRATE_COMPRESSED", INT2NUM(VIR_MIGRATE_COMPRESSED)); rb_define_const(c_domain, "MIGRATE_ABORT_ON_ERROR", INT2NUM(VIR_MIGRATE_ABORT_ON_ERROR)); rb_define_const(c_domain, "MIGRATE_AUTO_CONVERGE", INT2NUM(VIR_MIGRATE_AUTO_CONVERGE)); rb_define_const(c_domain, "MIGRATE_RDMA_PIN_ALL", INT2NUM(VIR_MIGRATE_RDMA_PIN_ALL)); /* Ideally we would just have the "XML_SECURE" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_XML_SECURE" for * backwards compatibility. */ rb_define_const(c_domain, "XML_SECURE", INT2NUM(VIR_DOMAIN_XML_SECURE)); rb_define_const(c_domain, "DOMAIN_XML_SECURE", INT2NUM(VIR_DOMAIN_XML_SECURE)); /* Ideally we would just have the "XML_INACTIVE" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_XML_INACTIVE" for * backwards compatibility. */ rb_define_const(c_domain, "XML_INACTIVE", INT2NUM(VIR_DOMAIN_XML_INACTIVE)); rb_define_const(c_domain, "DOMAIN_XML_INACTIVE", INT2NUM(VIR_DOMAIN_XML_INACTIVE)); /* Ideally we would just have the "XML_UPDATE_CPU" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_XML_UPDATE_CPU" for * backwards compatibility. */ rb_define_const(c_domain, "XML_UPDATE_CPU", INT2NUM(VIR_DOMAIN_XML_UPDATE_CPU)); rb_define_const(c_domain, "DOMAIN_XML_UPDATE_CPU", INT2NUM(VIR_DOMAIN_XML_UPDATE_CPU)); rb_define_const(c_domain, "XML_MIGRATABLE", INT2NUM(VIR_DOMAIN_XML_MIGRATABLE)); rb_define_const(c_domain, "MEMORY_VIRTUAL", INT2NUM(VIR_MEMORY_VIRTUAL)); rb_define_const(c_domain, "MEMORY_PHYSICAL", INT2NUM(VIR_MEMORY_PHYSICAL)); rb_define_const(c_domain, "START_PAUSED", INT2NUM(VIR_DOMAIN_START_PAUSED)); rb_define_const(c_domain, "START_AUTODESTROY", INT2NUM(VIR_DOMAIN_START_AUTODESTROY)); rb_define_const(c_domain, "START_BYPASS_CACHE", INT2NUM(VIR_DOMAIN_START_BYPASS_CACHE)); rb_define_const(c_domain, "START_FORCE_BOOT", INT2NUM(VIR_DOMAIN_START_FORCE_BOOT)); rb_define_const(c_domain, "DUMP_CRASH", INT2NUM(VIR_DUMP_CRASH)); rb_define_const(c_domain, "DUMP_LIVE", INT2NUM(VIR_DUMP_LIVE)); rb_define_const(c_domain, "BYPASS_CACHE", INT2NUM(VIR_DUMP_BYPASS_CACHE)); rb_define_const(c_domain, "RESET", INT2NUM(VIR_DUMP_RESET)); rb_define_const(c_domain, "MEMORY_ONLY", INT2NUM(VIR_DUMP_MEMORY_ONLY)); rb_define_const(c_domain, "VCPU_LIVE", INT2NUM(VIR_DOMAIN_VCPU_LIVE)); rb_define_const(c_domain, "VCPU_CONFIG", INT2NUM(VIR_DOMAIN_VCPU_CONFIG)); rb_define_const(c_domain, "VCPU_MAXIMUM", INT2NUM(VIR_DOMAIN_VCPU_MAXIMUM)); rb_define_const(c_domain, "VCPU_CURRENT", INT2NUM(VIR_DOMAIN_VCPU_CURRENT)); rb_define_const(c_domain, "VCPU_GUEST", INT2NUM(VIR_DOMAIN_VCPU_GUEST)); rb_define_method(c_domain, "migrate", libvirt_domain_migrate, -1); rb_define_method(c_domain, "migrate_to_uri", libvirt_domain_migrate_to_uri, -1); rb_define_method(c_domain, "migrate_set_max_downtime", libvirt_domain_migrate_set_max_downtime, -1); rb_define_method(c_domain, "migrate_max_downtime=", libvirt_domain_migrate_max_downtime_equal, 1); rb_define_method(c_domain, "migrate2", libvirt_domain_migrate2, -1); rb_define_method(c_domain, "migrate_to_uri2", libvirt_domain_migrate_to_uri2, -1); rb_define_method(c_domain, "migrate_set_max_speed", libvirt_domain_migrate_set_max_speed, -1); rb_define_method(c_domain, "migrate_max_speed=", libvirt_domain_migrate_max_speed_equal, 1); rb_define_const(c_domain, "SAVE_BYPASS_CACHE", INT2NUM(VIR_DOMAIN_SAVE_BYPASS_CACHE)); rb_define_const(c_domain, "SAVE_RUNNING", INT2NUM(VIR_DOMAIN_SAVE_RUNNING)); rb_define_const(c_domain, "SAVE_PAUSED", INT2NUM(VIR_DOMAIN_SAVE_PAUSED)); rb_define_const(c_domain, "UNDEFINE_MANAGED_SAVE", INT2NUM(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)); rb_define_const(c_domain, "UNDEFINE_SNAPSHOTS_METADATA", INT2NUM(VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA)); rb_define_const(c_domain, "UNDEFINE_NVRAM", INT2NUM(VIR_DOMAIN_UNDEFINE_NVRAM)); #if LIBVIR_CHECK_VERSION(2, 3, 0) rb_define_const(c_domain, "UNDEFINE_KEEP_NVRAM", INT2NUM(VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)); #endif #if LIBVIR_CHECK_VERSION(5, 6, 0) rb_define_const(c_domain, "UNDEFINE_CHECKPOINTS_METADATA", INT2NUM(VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA)); #endif rb_define_attr(c_domain, "connection", 1, 0); rb_define_const(c_domain, "SHUTDOWN_DEFAULT", INT2NUM(VIR_DOMAIN_SHUTDOWN_DEFAULT)); rb_define_const(c_domain, "SHUTDOWN_ACPI_POWER_BTN", INT2NUM(VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN)); rb_define_const(c_domain, "SHUTDOWN_GUEST_AGENT", INT2NUM(VIR_DOMAIN_SHUTDOWN_GUEST_AGENT)); rb_define_const(c_domain, "SHUTDOWN_INITCTL", INT2NUM(VIR_DOMAIN_SHUTDOWN_INITCTL)); rb_define_const(c_domain, "SHUTDOWN_SIGNAL", INT2NUM(VIR_DOMAIN_SHUTDOWN_SIGNAL)); rb_define_const(c_domain, "SHUTDOWN_PARAVIRT", INT2NUM(VIR_DOMAIN_SHUTDOWN_PARAVIRT)); rb_define_method(c_domain, "shutdown", libvirt_domain_shutdown, -1); rb_define_const(c_domain, "REBOOT_DEFAULT", INT2NUM(VIR_DOMAIN_REBOOT_DEFAULT)); rb_define_const(c_domain, "REBOOT_ACPI_POWER_BTN", INT2NUM(VIR_DOMAIN_REBOOT_ACPI_POWER_BTN)); rb_define_const(c_domain, "REBOOT_GUEST_AGENT", INT2NUM(VIR_DOMAIN_REBOOT_GUEST_AGENT)); rb_define_const(c_domain, "REBOOT_INITCTL", INT2NUM(VIR_DOMAIN_REBOOT_INITCTL)); rb_define_const(c_domain, "REBOOT_SIGNAL", INT2NUM(VIR_DOMAIN_REBOOT_SIGNAL)); rb_define_const(c_domain, "REBOOT_PARAVIRT", INT2NUM(VIR_DOMAIN_REBOOT_PARAVIRT)); rb_define_method(c_domain, "reboot", libvirt_domain_reboot, -1); rb_define_const(c_domain, "DESTROY_DEFAULT", INT2NUM(VIR_DOMAIN_DESTROY_DEFAULT)); rb_define_const(c_domain, "DESTROY_GRACEFUL", INT2NUM(VIR_DOMAIN_DESTROY_GRACEFUL)); rb_define_method(c_domain, "destroy", libvirt_domain_destroy, -1); rb_define_method(c_domain, "suspend", libvirt_domain_suspend, 0); rb_define_method(c_domain, "resume", libvirt_domain_resume, 0); rb_define_method(c_domain, "save", libvirt_domain_save, -1); rb_define_singleton_method(c_domain, "restore", libvirt_domain_s_restore, 2); rb_define_method(c_domain, "core_dump", libvirt_domain_core_dump, -1); rb_define_method(c_domain, "info", libvirt_domain_info, 0); rb_define_method(c_domain, "ifinfo", libvirt_domain_if_stats, 1); rb_define_method(c_domain, "name", libvirt_domain_name, 0); rb_define_method(c_domain, "id", libvirt_domain_id, 0); rb_define_method(c_domain, "uuid", libvirt_domain_uuid, 0); rb_define_method(c_domain, "os_type", libvirt_domain_os_type, 0); rb_define_method(c_domain, "max_memory", libvirt_domain_max_memory, 0); rb_define_method(c_domain, "max_memory=", libvirt_domain_max_memory_equal, 1); rb_define_method(c_domain, "memory=", libvirt_domain_memory_equal, 1); rb_define_method(c_domain, "max_vcpus", libvirt_domain_max_vcpus, 0); rb_define_method(c_domain, "vcpus=", libvirt_domain_vcpus_equal, 1); rb_define_method(c_domain, "vcpus_flags=", libvirt_domain_vcpus_flags_equal, 1); rb_define_method(c_domain, "pin_vcpu", libvirt_domain_pin_vcpu, -1); rb_define_method(c_domain, "xml_desc", libvirt_domain_xml_desc, -1); rb_define_method(c_domain, "undefine", libvirt_domain_undefine, -1); rb_define_method(c_domain, "create", libvirt_domain_create, -1); rb_define_method(c_domain, "autostart", libvirt_domain_autostart, 0); rb_define_method(c_domain, "autostart?", libvirt_domain_autostart, 0); rb_define_method(c_domain, "autostart=", libvirt_domain_autostart_equal, 1); rb_define_method(c_domain, "free", libvirt_domain_free, 0); rb_define_const(c_domain, "DEVICE_MODIFY_CURRENT", INT2NUM(VIR_DOMAIN_DEVICE_MODIFY_CURRENT)); rb_define_const(c_domain, "DEVICE_MODIFY_LIVE", INT2NUM(VIR_DOMAIN_DEVICE_MODIFY_LIVE)); rb_define_const(c_domain, "DEVICE_MODIFY_CONFIG", INT2NUM(VIR_DOMAIN_DEVICE_MODIFY_CONFIG)); rb_define_const(c_domain, "DEVICE_MODIFY_FORCE", INT2NUM(VIR_DOMAIN_DEVICE_MODIFY_FORCE)); rb_define_method(c_domain, "attach_device", libvirt_domain_attach_device, -1); rb_define_method(c_domain, "detach_device", libvirt_domain_detach_device, -1); rb_define_method(c_domain, "update_device", libvirt_domain_update_device, -1); rb_define_method(c_domain, "scheduler_type", libvirt_domain_scheduler_type, 0); rb_define_method(c_domain, "managed_save", libvirt_domain_managed_save, -1); rb_define_method(c_domain, "has_managed_save?", libvirt_domain_has_managed_save, -1); rb_define_method(c_domain, "managed_save_remove", libvirt_domain_managed_save_remove, -1); rb_define_method(c_domain, "security_label", libvirt_domain_security_label, 0); rb_define_method(c_domain, "block_stats", libvirt_domain_block_stats, 1); rb_define_method(c_domain, "memory_stats", libvirt_domain_memory_stats, -1); rb_define_method(c_domain, "block_peek", libvirt_domain_block_peek, -1); rb_define_method(c_domain, "blockinfo", libvirt_domain_block_info, -1); rb_define_method(c_domain, "memory_peek", libvirt_domain_memory_peek, -1); rb_define_method(c_domain, "vcpus", libvirt_domain_vcpus, 0); rb_define_alias(c_domain, "get_vcpus", "vcpus"); rb_define_method(c_domain, "active?", libvirt_domain_active_p, 0); rb_define_method(c_domain, "persistent?", libvirt_domain_persistent_p, 0); rb_define_method(c_domain, "snapshot_create_xml", libvirt_domain_snapshot_create_xml, -1); rb_define_method(c_domain, "num_of_snapshots", libvirt_domain_num_of_snapshots, -1); rb_define_method(c_domain, "list_snapshots", libvirt_domain_list_snapshots, -1); rb_define_method(c_domain, "lookup_snapshot_by_name", libvirt_domain_lookup_snapshot_by_name, -1); rb_define_method(c_domain, "has_current_snapshot?", libvirt_domain_has_current_snapshot_p, -1); rb_define_method(c_domain, "revert_to_snapshot", libvirt_domain_revert_to_snapshot, -1); rb_define_method(c_domain, "current_snapshot", libvirt_domain_current_snapshot, -1); /* * Class Libvirt::Domain::Info */ c_domain_info = rb_define_class_under(c_domain, "Info", rb_cObject); rb_define_attr(c_domain_info, "state", 1, 0); rb_define_attr(c_domain_info, "max_mem", 1, 0); rb_define_attr(c_domain_info, "memory", 1, 0); rb_define_attr(c_domain_info, "nr_virt_cpu", 1, 0); rb_define_attr(c_domain_info, "cpu_time", 1, 0); /* * Class Libvirt::Domain::InterfaceInfo */ c_domain_ifinfo = rb_define_class_under(c_domain, "InterfaceInfo", rb_cObject); rb_define_attr(c_domain_ifinfo, "rx_bytes", 1, 0); rb_define_attr(c_domain_ifinfo, "rx_packets", 1, 0); rb_define_attr(c_domain_ifinfo, "rx_errs", 1, 0); rb_define_attr(c_domain_ifinfo, "rx_drop", 1, 0); rb_define_attr(c_domain_ifinfo, "tx_bytes", 1, 0); rb_define_attr(c_domain_ifinfo, "tx_packets", 1, 0); rb_define_attr(c_domain_ifinfo, "tx_errs", 1, 0); rb_define_attr(c_domain_ifinfo, "tx_drop", 1, 0); /* * Class Libvirt::Domain::SecurityLabel */ c_domain_security_label = rb_define_class_under(c_domain, "SecurityLabel", rb_cObject); rb_define_attr(c_domain_security_label, "label", 1, 0); rb_define_attr(c_domain_security_label, "enforcing", 1, 0); /* * Class Libvirt::Domain::BlockStats */ c_domain_block_stats = rb_define_class_under(c_domain, "BlockStats", rb_cObject); rb_define_attr(c_domain_block_stats, "rd_req", 1, 0); rb_define_attr(c_domain_block_stats, "rd_bytes", 1, 0); rb_define_attr(c_domain_block_stats, "wr_req", 1, 0); rb_define_attr(c_domain_block_stats, "wr_bytes", 1, 0); rb_define_attr(c_domain_block_stats, "errs", 1, 0); /* * Class Libvirt::Domain::BlockJobInfo */ c_domain_block_job_info = rb_define_class_under(c_domain, "BlockJobInfo", rb_cObject); rb_define_attr(c_domain_block_job_info, "type", 1, 0); rb_define_attr(c_domain_block_job_info, "bandwidth", 1, 0); rb_define_attr(c_domain_block_job_info, "cur", 1, 0); rb_define_attr(c_domain_block_job_info, "end", 1, 0); /* * Class Libvirt::Domain::MemoryStats */ c_domain_memory_stats = rb_define_class_under(c_domain, "MemoryStats", rb_cObject); rb_define_attr(c_domain_memory_stats, "tag", 1, 0); rb_define_attr(c_domain_memory_stats, "value", 1, 0); rb_define_const(c_domain_memory_stats, "SWAP_IN", INT2NUM(VIR_DOMAIN_MEMORY_STAT_SWAP_IN)); rb_define_const(c_domain_memory_stats, "SWAP_OUT", INT2NUM(VIR_DOMAIN_MEMORY_STAT_SWAP_OUT)); rb_define_const(c_domain_memory_stats, "MAJOR_FAULT", INT2NUM(VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT)); rb_define_const(c_domain_memory_stats, "MINOR_FAULT", INT2NUM(VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT)); rb_define_const(c_domain_memory_stats, "UNUSED", INT2NUM(VIR_DOMAIN_MEMORY_STAT_UNUSED)); rb_define_const(c_domain_memory_stats, "AVAILABLE", INT2NUM(VIR_DOMAIN_MEMORY_STAT_AVAILABLE)); rb_define_const(c_domain_memory_stats, "ACTUAL_BALLOON", INT2NUM(VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON)); rb_define_const(c_domain_memory_stats, "RSS", INT2NUM(VIR_DOMAIN_MEMORY_STAT_RSS)); /* * Class Libvirt::Domain::BlockInfo */ c_domain_block_info = rb_define_class_under(c_domain, "BlockInfo", rb_cObject); rb_define_attr(c_domain_block_info, "capacity", 1, 0); rb_define_attr(c_domain_block_info, "allocation", 1, 0); rb_define_attr(c_domain_block_info, "physical", 1, 0); /* * Class Libvirt::Domain::Snapshot */ c_domain_snapshot = rb_define_class_under(c_domain, "Snapshot", rb_cObject); rb_undef_alloc_func(c_domain_snapshot); rb_define_singleton_method(c_domain_snapshot, "new", ruby_libvirt_new_not_allowed, -1); rb_define_const(c_domain_snapshot, "DELETE_CHILDREN", INT2NUM(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN)); rb_define_method(c_domain_snapshot, "xml_desc", libvirt_domain_snapshot_xml_desc, -1); rb_define_method(c_domain_snapshot, "delete", libvirt_domain_snapshot_delete, -1); rb_define_method(c_domain_snapshot, "free", libvirt_domain_snapshot_free, 0); rb_define_const(c_domain_snapshot, "DELETE_METADATA_ONLY", INT2NUM(VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY)); rb_define_const(c_domain_snapshot, "DELETE_CHILDREN_ONLY", INT2NUM(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)); rb_define_method(c_domain_snapshot, "name", libvirt_domain_snapshot_name, 0); /* * Class Libvirt::Domain::VCPUInfo */ c_domain_vcpuinfo = rb_define_class_under(c_domain, "VCPUInfo", rb_cObject); rb_define_const(c_domain_vcpuinfo, "OFFLINE", VIR_VCPU_OFFLINE); rb_define_const(c_domain_vcpuinfo, "RUNNING", VIR_VCPU_RUNNING); rb_define_const(c_domain_vcpuinfo, "BLOCKED", VIR_VCPU_BLOCKED); rb_define_attr(c_domain_vcpuinfo, "number", 1, 0); rb_define_attr(c_domain_vcpuinfo, "state", 1, 0); rb_define_attr(c_domain_vcpuinfo, "cpu_time", 1, 0); rb_define_attr(c_domain_vcpuinfo, "cpu", 1, 0); rb_define_attr(c_domain_vcpuinfo, "cpumap", 1, 0); /* * Class Libvirt::Domain::JobInfo */ c_domain_job_info = rb_define_class_under(c_domain, "JobInfo", rb_cObject); rb_define_const(c_domain_job_info, "NONE", INT2NUM(VIR_DOMAIN_JOB_NONE)); rb_define_const(c_domain_job_info, "BOUNDED", INT2NUM(VIR_DOMAIN_JOB_BOUNDED)); rb_define_const(c_domain_job_info, "UNBOUNDED", INT2NUM(VIR_DOMAIN_JOB_UNBOUNDED)); rb_define_const(c_domain_job_info, "COMPLETED", INT2NUM(VIR_DOMAIN_JOB_COMPLETED)); rb_define_const(c_domain_job_info, "FAILED", INT2NUM(VIR_DOMAIN_JOB_FAILED)); rb_define_const(c_domain_job_info, "CANCELLED", INT2NUM(VIR_DOMAIN_JOB_CANCELLED)); rb_define_attr(c_domain_job_info, "type", 1, 0); rb_define_attr(c_domain_job_info, "time_elapsed", 1, 0); rb_define_attr(c_domain_job_info, "time_remaining", 1, 0); rb_define_attr(c_domain_job_info, "data_total", 1, 0); rb_define_attr(c_domain_job_info, "data_processed", 1, 0); rb_define_attr(c_domain_job_info, "data_remaining", 1, 0); rb_define_attr(c_domain_job_info, "mem_total", 1, 0); rb_define_attr(c_domain_job_info, "mem_processed", 1, 0); rb_define_attr(c_domain_job_info, "mem_remaining", 1, 0); rb_define_attr(c_domain_job_info, "file_total", 1, 0); rb_define_attr(c_domain_job_info, "file_processed", 1, 0); rb_define_attr(c_domain_job_info, "file_remaining", 1, 0); rb_define_method(c_domain, "job_info", libvirt_domain_job_info, 0); rb_define_method(c_domain, "abort_job", libvirt_domain_abort_job, 0); rb_define_method(c_domain, "qemu_monitor_command", libvirt_domain_qemu_monitor_command, -1); rb_define_method(c_domain, "num_vcpus", libvirt_domain_num_vcpus, 1); rb_define_method(c_domain, "updated?", libvirt_domain_is_updated, 0); rb_define_const(c_domain, "MEMORY_PARAM_UNLIMITED", LL2NUM(VIR_DOMAIN_MEMORY_PARAM_UNLIMITED)); /* Ideally we would just have the "MEM_LIVE" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_MEM_LIVE" for * backwards compatibility. */ rb_define_const(c_domain, "MEM_LIVE", INT2NUM(VIR_DOMAIN_MEM_LIVE)); rb_define_const(c_domain, "DOMAIN_MEM_LIVE", INT2NUM(VIR_DOMAIN_MEM_LIVE)); /* Ideally we would just have the "MEM_CONFIG" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_MEM_CONFIG" for * backwards compatibility. */ rb_define_const(c_domain, "MEM_CONFIG", INT2NUM(VIR_DOMAIN_MEM_CONFIG)); rb_define_const(c_domain, "DOMAIN_MEM_CONFIG", INT2NUM(VIR_DOMAIN_MEM_CONFIG)); /* Ideally we would just have the "MEM_CURRENT" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_MEM_CURRENT" for * backwards compatibility. */ rb_define_const(c_domain,"MEM_CURRENT", INT2NUM(VIR_DOMAIN_MEM_CURRENT)); rb_define_const(c_domain, "DOMAIN_MEM_CURRENT", INT2NUM(VIR_DOMAIN_MEM_CURRENT)); /* Ideally we would just have the "MEM_MAXIMUM" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_MEM_MAXIMUM" for * backwards compatibility. */ rb_define_const(c_domain, "MEM_MAXIMUM", INT2NUM(VIR_DOMAIN_MEM_MAXIMUM)); rb_define_const(c_domain, "DOMAIN_MEM_MAXIMUM", INT2NUM(VIR_DOMAIN_MEM_MAXIMUM)); rb_define_method(c_domain, "scheduler_parameters", libvirt_domain_scheduler_parameters, -1); rb_define_method(c_domain, "scheduler_parameters=", libvirt_domain_scheduler_parameters_equal, 1); rb_define_method(c_domain, "memory_parameters", libvirt_domain_memory_parameters, -1); rb_define_method(c_domain, "memory_parameters=", libvirt_domain_memory_parameters_equal, 1); rb_define_method(c_domain, "blkio_parameters", libvirt_domain_blkio_parameters, -1); rb_define_method(c_domain, "blkio_parameters=", libvirt_domain_blkio_parameters_equal, 1); /* Ideally we would just have the "RUNNING_UNKNOWN" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_RUNNING_UNKNOWN" * for backwards compatibility. */ rb_define_const(c_domain, "RUNNING_UNKNOWN", INT2NUM(VIR_DOMAIN_RUNNING_UNKNOWN)); rb_define_const(c_domain, "DOMAIN_RUNNING_UNKNOWN", INT2NUM(VIR_DOMAIN_RUNNING_UNKNOWN)); /* Ideally we would just have the "RUNNING_BOOTED" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_RUNNING_BOOTED" * for backwards compatibility. */ rb_define_const(c_domain, "RUNNING_BOOTED", INT2NUM(VIR_DOMAIN_RUNNING_BOOTED)); rb_define_const(c_domain, "DOMAIN_RUNNING_BOOTED", INT2NUM(VIR_DOMAIN_RUNNING_BOOTED)); /* Ideally we would just have the "RUNNING_MIGRATED" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_RUNNING_MIGRATED" for backwards compatibility. */ rb_define_const(c_domain, "RUNNING_MIGRATED", INT2NUM(VIR_DOMAIN_RUNNING_MIGRATED)); rb_define_const(c_domain, "DOMAIN_RUNNING_MIGRATED", INT2NUM(VIR_DOMAIN_RUNNING_MIGRATED)); /* Ideally we would just have the "RUNNING_RESTORED" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_RUNNING_RESTORED" for backwards compatibility. */ rb_define_const(c_domain, "RUNNING_RESTORED", INT2NUM(VIR_DOMAIN_RUNNING_RESTORED)); rb_define_const(c_domain, "DOMAIN_RUNNING_RESTORED", INT2NUM(VIR_DOMAIN_RUNNING_RESTORED)); /* Ideally we would just have the "RUNNING_FROM_SNAPSHOT" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_RUNNING_FROM_SNAPSHOT" for backwards compatibility. */ rb_define_const(c_domain, "RUNNING_FROM_SNAPSHOT", INT2NUM(VIR_DOMAIN_RUNNING_FROM_SNAPSHOT)); rb_define_const(c_domain, "DOMAIN_RUNNING_FROM_SNAPSHOT", INT2NUM(VIR_DOMAIN_RUNNING_FROM_SNAPSHOT)); /* Ideally we would just have the "RUNNING_UNPAUSED" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_RUNNING_UNPAUSED" for backwards compatibility. */ rb_define_const(c_domain, "RUNNING_UNPAUSED", INT2NUM(VIR_DOMAIN_RUNNING_UNPAUSED)); rb_define_const(c_domain, "DOMAIN_RUNNING_UNPAUSED", INT2NUM(VIR_DOMAIN_RUNNING_UNPAUSED)); /* Ideally we would just have the "RUNNING_MIGRATION_CANCELED" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_RUNNING_MIGRATION_CANCELED" for backwards compatibility. */ rb_define_const(c_domain, "RUNNING_MIGRATION_CANCELED", INT2NUM(VIR_DOMAIN_RUNNING_MIGRATION_CANCELED)); rb_define_const(c_domain, "DOMAIN_RUNNING_MIGRATION_CANCELED", INT2NUM(VIR_DOMAIN_RUNNING_MIGRATION_CANCELED)); /* Ideally we would just have the "RUNNING_SAVE_CANCELED" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_RUNNING_SAVE_CANCELED" for backwards compatibility. */ rb_define_const(c_domain, "RUNNING_SAVE_CANCELED", INT2NUM(VIR_DOMAIN_RUNNING_SAVE_CANCELED)); rb_define_const(c_domain, "DOMAIN_RUNNING_SAVE_CANCELED", INT2NUM(VIR_DOMAIN_RUNNING_SAVE_CANCELED)); /* Ideally we would just have the "RUNNING_WAKEUP" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_RUNNING_WAKEUP" * for backwards compatibility. */ rb_define_const(c_domain, "RUNNING_WAKEUP", INT2NUM(VIR_DOMAIN_RUNNING_WAKEUP)); rb_define_const(c_domain, "DOMAIN_RUNNING_WAKEUP", INT2NUM(VIR_DOMAIN_RUNNING_WAKEUP)); /* Ideally we would just have the "BLOCKED_UNKNOWN" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_BLOCKED_UNKNOWN" * for backwards compatibility. */ rb_define_const(c_domain, "BLOCKED_UNKNOWN", INT2NUM(VIR_DOMAIN_BLOCKED_UNKNOWN)); rb_define_const(c_domain, "DOMAIN_BLOCKED_UNKNOWN", INT2NUM(VIR_DOMAIN_BLOCKED_UNKNOWN)); /* Ideally we would just have the "PAUSED_UNKNOWN" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_PAUSED_UNKNOWN" * for backwards compatibility. */ rb_define_const(c_domain, "PAUSED_UNKNOWN", INT2NUM(VIR_DOMAIN_PAUSED_UNKNOWN)); rb_define_const(c_domain, "DOMAIN_PAUSED_UNKNOWN", INT2NUM(VIR_DOMAIN_PAUSED_UNKNOWN)); /* Ideally we would just have the "PAUSED_USER" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_PAUSED_USER" * for backwards compatibility. */ rb_define_const(c_domain, "PAUSED_USER", INT2NUM(VIR_DOMAIN_PAUSED_USER)); rb_define_const(c_domain, "DOMAIN_PAUSED_USER", INT2NUM(VIR_DOMAIN_PAUSED_USER)); /* Ideally we would just have the "PAUSED_MIGRATION" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_PAUSED_MIGRATION" for backwards compatibility. */ rb_define_const(c_domain, "PAUSED_MIGRATION", INT2NUM(VIR_DOMAIN_PAUSED_MIGRATION)); rb_define_const(c_domain, "DOMAIN_PAUSED_MIGRATION", INT2NUM(VIR_DOMAIN_PAUSED_MIGRATION)); /* Ideally we would just have the "PAUSED_SAVE" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_PAUSED_SAVE" * for backwards compatibility. */ rb_define_const(c_domain, "PAUSED_SAVE", INT2NUM(VIR_DOMAIN_PAUSED_SAVE)); rb_define_const(c_domain, "DOMAIN_PAUSED_SAVE", INT2NUM(VIR_DOMAIN_PAUSED_SAVE)); /* Ideally we would just have the "PAUSED_DUMP" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_PAUSED_DUMP" * for backwards compatibility. */ rb_define_const(c_domain, "PAUSED_DUMP", INT2NUM(VIR_DOMAIN_PAUSED_DUMP)); rb_define_const(c_domain, "DOMAIN_PAUSED_DUMP", INT2NUM(VIR_DOMAIN_PAUSED_DUMP)); /* Ideally we would just have the "PAUSED_IOERROR" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_PAUSED_IOERROR" * for backwards compatibility. */ rb_define_const(c_domain, "PAUSED_IOERROR", INT2NUM(VIR_DOMAIN_PAUSED_IOERROR)); rb_define_const(c_domain, "DOMAIN_PAUSED_IOERROR", INT2NUM(VIR_DOMAIN_PAUSED_IOERROR)); /* Ideally we would just have the "PAUSED_WATCHDOG" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_PAUSED_WATCHDOG" * for backwards compatibility. */ rb_define_const(c_domain, "PAUSED_WATCHDOG", INT2NUM(VIR_DOMAIN_PAUSED_WATCHDOG)); rb_define_const(c_domain, "DOMAIN_PAUSED_WATCHDOG", INT2NUM(VIR_DOMAIN_PAUSED_WATCHDOG)); /* Ideally we would just have the "PAUSED_FROM_SNAPSHOT" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_PAUSED_FROM_SNAPSHOT" for backwards compatibility. */ rb_define_const(c_domain, "PAUSED_FROM_SNAPSHOT", INT2NUM(VIR_DOMAIN_PAUSED_FROM_SNAPSHOT)); rb_define_const(c_domain, "DOMAIN_PAUSED_FROM_SNAPSHOT", INT2NUM(VIR_DOMAIN_PAUSED_FROM_SNAPSHOT)); /* Ideally we would just have the "PAUSED_SHUTTING_DOWN" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_PAUSED_SHUTTING_DOWN" for backwards compatibility. */ rb_define_const(c_domain, "PAUSED_SHUTTING_DOWN", INT2NUM(VIR_DOMAIN_PAUSED_SHUTTING_DOWN)); rb_define_const(c_domain, "DOMAIN_PAUSED_SHUTTING_DOWN", INT2NUM(VIR_DOMAIN_PAUSED_SHUTTING_DOWN)); /* Ideally we would just have the "PAUSED_SNAPSHOT" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_PAUSED_SNAPSHOT" * for backwards compatibility. */ rb_define_const(c_domain, "PAUSED_SNAPSHOT", INT2NUM(VIR_DOMAIN_PAUSED_SNAPSHOT)); rb_define_const(c_domain, "DOMAIN_PAUSED_SNAPSHOT", INT2NUM(VIR_DOMAIN_PAUSED_SNAPSHOT)); /* Ideally we would just have the "SHUTDOWN_UNKNOWN" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_SHUTDOWN_UNKNOWN" for backwards compatibility. */ rb_define_const(c_domain, "SHUTDOWN_UNKNOWN", INT2NUM(VIR_DOMAIN_SHUTDOWN_UNKNOWN)); rb_define_const(c_domain, "DOMAIN_SHUTDOWN_UNKNOWN", INT2NUM(VIR_DOMAIN_SHUTDOWN_UNKNOWN)); /* Ideally we would just have the "SHUTDOWN_USER" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_SHUTDOWN_USER" * for backwards compatibility. */ rb_define_const(c_domain, "SHUTDOWN_USER", INT2NUM(VIR_DOMAIN_SHUTDOWN_USER)); rb_define_const(c_domain, "DOMAIN_SHUTDOWN_USER", INT2NUM(VIR_DOMAIN_SHUTDOWN_USER)); /* Ideally we would just have the "SHUTOFF_UNKNOWN" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_SHUTOFF_UNKNOWN" * for backwards compatibility. */ rb_define_const(c_domain, "SHUTOFF_UNKNOWN", INT2NUM(VIR_DOMAIN_SHUTOFF_UNKNOWN)); rb_define_const(c_domain, "DOMAIN_SHUTOFF_UNKNOWN", INT2NUM(VIR_DOMAIN_SHUTOFF_UNKNOWN)); /* Ideally we would just have the "SHUTOFF_SHUTDOWN" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_SHUTOFF_SHUTDOWN" for backwards compatibility. */ rb_define_const(c_domain, "SHUTOFF_SHUTDOWN", INT2NUM(VIR_DOMAIN_SHUTOFF_SHUTDOWN)); rb_define_const(c_domain, "DOMAIN_SHUTOFF_SHUTDOWN", INT2NUM(VIR_DOMAIN_SHUTOFF_SHUTDOWN)); /* Ideally we would just have the "SHUTOFF_DESTROYED" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_SHUTOFF_DESTROYED" for backwards compatibility. */ rb_define_const(c_domain, "SHUTOFF_DESTROYED", INT2NUM(VIR_DOMAIN_SHUTOFF_DESTROYED)); rb_define_const(c_domain, "DOMAIN_SHUTOFF_DESTROYED", INT2NUM(VIR_DOMAIN_SHUTOFF_DESTROYED)); /* Ideally we would just have the "SHUTOFF_CRASHED" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_SHUTOFF_CRASHED" * for backwards compatibility. */ rb_define_const(c_domain, "SHUTOFF_CRASHED", INT2NUM(VIR_DOMAIN_SHUTOFF_CRASHED)); rb_define_const(c_domain, "DOMAIN_SHUTOFF_CRASHED", INT2NUM(VIR_DOMAIN_SHUTOFF_CRASHED)); /* Ideally we would just have the "SHUTOFF_MIGRATED" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_SHUTOFF_MIGRATED" for backwards compatibility. */ rb_define_const(c_domain, "SHUTOFF_MIGRATED", INT2NUM(VIR_DOMAIN_SHUTOFF_MIGRATED)); rb_define_const(c_domain, "DOMAIN_SHUTOFF_MIGRATED", INT2NUM(VIR_DOMAIN_SHUTOFF_MIGRATED)); /* Ideally we would just have the "SHUTOFF_SAVED" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_SHUTOFF_SAVED" * for backwards compatibility. */ rb_define_const(c_domain, "SHUTOFF_SAVED", INT2NUM(VIR_DOMAIN_SHUTOFF_SAVED)); rb_define_const(c_domain, "DOMAIN_SHUTOFF_SAVED", INT2NUM(VIR_DOMAIN_SHUTOFF_SAVED)); /* Ideally we would just have the "SHUTOFF_FAILED" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_SHUTOFF_FAILED" * for backwards compatibility. */ rb_define_const(c_domain, "SHUTOFF_FAILED", INT2NUM(VIR_DOMAIN_SHUTOFF_FAILED)); rb_define_const(c_domain, "DOMAIN_SHUTOFF_FAILED", INT2NUM(VIR_DOMAIN_SHUTOFF_FAILED)); /* Ideally we would just have the "SHUTOFF_FROM_SNAPSHOT" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_SHUTOFF_FROM_SNAPSHOT" for backwards compatibility. */ rb_define_const(c_domain, "SHUTOFF_FROM_SNAPSHOT", INT2NUM(VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT)); rb_define_const(c_domain, "DOMAIN_SHUTOFF_FROM_SNAPSHOT", INT2NUM(VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT)); /* Ideally we would just have the "CRASHED_UNKNOWN" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_CRASHED_UNKNOWN" * for backwards compatibility. */ rb_define_const(c_domain, "CRASHED_UNKNOWN", INT2NUM(VIR_DOMAIN_CRASHED_UNKNOWN)); rb_define_const(c_domain, "DOMAIN_CRASHED_UNKNOWN", INT2NUM(VIR_DOMAIN_CRASHED_UNKNOWN)); /* Ideally we would just have the "PMSUSPENDED_UNKNOWN" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_PMSUSPENDED_UNKNOWN" for backwards compatibility. */ rb_define_const(c_domain, "PMSUSPENDED_UNKNOWN", INT2NUM(VIR_DOMAIN_PMSUSPENDED_UNKNOWN)); rb_define_const(c_domain, "DOMAIN_PMSUSPENDED_UNKNOWN", INT2NUM(VIR_DOMAIN_PMSUSPENDED_UNKNOWN)); /* Ideally we would just have the "PMSUSPENDED_DISK_UNKNOWN" constant. * Unfortunately we screwed up long ago, and we have to leave * "DOMAIN_PMSUSPENDED_DISK_UNKNOWN" for backwards compatibility. */ rb_define_const(c_domain, "PMSUSPENDED_DISK_UNKNOWN", INT2NUM(VIR_DOMAIN_PMSUSPENDED_DISK_UNKNOWN)); rb_define_const(c_domain, "DOMAIN_PMSUSPENDED_DISK_UNKNOWN", INT2NUM(VIR_DOMAIN_PMSUSPENDED_DISK_UNKNOWN)); rb_define_const(c_domain, "RUNNING_CRASHED", INT2NUM(VIR_DOMAIN_RUNNING_CRASHED)); rb_define_const(c_domain, "NOSTATE_UNKNOWN", INT2NUM(VIR_DOMAIN_NOSTATE_UNKNOWN)); rb_define_const(c_domain, "PAUSED_CRASHED", INT2NUM(VIR_DOMAIN_PAUSED_CRASHED)); rb_define_const(c_domain, "CRASHED_PANICKED", INT2NUM(VIR_DOMAIN_CRASHED_PANICKED)); rb_define_method(c_domain, "state", libvirt_domain_state, -1); /* Ideally we would just have the "AFFECT_CURRENT" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_AFFECT_CURRENT" for * backwards compatibility. */ rb_define_const(c_domain, "AFFECT_CURRENT", INT2NUM(VIR_DOMAIN_AFFECT_CURRENT)); rb_define_const(c_domain, "DOMAIN_AFFECT_CURRENT", INT2NUM(VIR_DOMAIN_AFFECT_CURRENT)); /* Ideally we would just have the "AFFECT_LIVE" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_AFFECT_LIVE" for * backwards compatibility. */ rb_define_const(c_domain, "AFFECT_LIVE", INT2NUM(VIR_DOMAIN_AFFECT_LIVE)); rb_define_const(c_domain, "DOMAIN_AFFECT_LIVE", INT2NUM(VIR_DOMAIN_AFFECT_LIVE)); /* Ideally we would just have the "AFFECT_CONFIG" constant. Unfortunately * we screwed up long ago, and we have to leave "DOMAIN_AFFECT_CONFIG" for * backwards compatibility. */ rb_define_const(c_domain, "AFFECT_CONFIG", INT2NUM(VIR_DOMAIN_AFFECT_CONFIG)); rb_define_const(c_domain, "DOMAIN_AFFECT_CONFIG", INT2NUM(VIR_DOMAIN_AFFECT_CONFIG)); rb_define_const(c_domain, "CONSOLE_FORCE", INT2NUM(VIR_DOMAIN_CONSOLE_FORCE)); rb_define_const(c_domain, "CONSOLE_SAFE", INT2NUM(VIR_DOMAIN_CONSOLE_SAFE)); rb_define_method(c_domain, "open_console", libvirt_domain_open_console, -1); rb_define_method(c_domain, "screenshot", libvirt_domain_screenshot, -1); rb_define_method(c_domain, "inject_nmi", libvirt_domain_inject_nmi, -1); /* * Class Libvirt::Domain::ControlInfo */ c_domain_control_info = rb_define_class_under(c_domain, "ControlInfo", rb_cObject); rb_define_attr(c_domain_control_info, "state", 1, 0); rb_define_attr(c_domain_control_info, "details", 1, 0); rb_define_attr(c_domain_control_info, "stateTime", 1, 0); rb_define_const(c_domain_control_info, "CONTROL_OK", INT2NUM(VIR_DOMAIN_CONTROL_OK)); rb_define_const(c_domain_control_info, "CONTROL_JOB", INT2NUM(VIR_DOMAIN_CONTROL_JOB)); rb_define_const(c_domain_control_info, "CONTROL_OCCUPIED", INT2NUM(VIR_DOMAIN_CONTROL_OCCUPIED)); rb_define_const(c_domain_control_info, "CONTROL_ERROR", INT2NUM(VIR_DOMAIN_CONTROL_ERROR)); rb_define_method(c_domain, "control_info", libvirt_domain_control_info, -1); rb_define_method(c_domain, "migrate_max_speed", libvirt_domain_migrate_max_speed, -1); rb_define_method(c_domain, "send_key", libvirt_domain_send_key, 3); rb_define_method(c_domain, "reset", libvirt_domain_reset, -1); rb_define_method(c_domain, "hostname", libvirt_domain_hostname, -1); rb_define_const(c_domain, "METADATA_DESCRIPTION", INT2NUM(VIR_DOMAIN_METADATA_DESCRIPTION)); rb_define_const(c_domain, "METADATA_TITLE", INT2NUM(VIR_DOMAIN_METADATA_TITLE)); rb_define_const(c_domain, "METADATA_ELEMENT", INT2NUM(VIR_DOMAIN_METADATA_ELEMENT)); rb_define_method(c_domain, "metadata", libvirt_domain_metadata, -1); rb_define_method(c_domain, "metadata=", libvirt_domain_metadata_equal, 1); rb_define_const(c_domain, "PROCESS_SIGNAL_NOP", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_NOP)); rb_define_const(c_domain, "PROCESS_SIGNAL_HUP", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_HUP)); rb_define_const(c_domain, "PROCESS_SIGNAL_INT", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_INT)); rb_define_const(c_domain, "PROCESS_SIGNAL_QUIT", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_QUIT)); rb_define_const(c_domain, "PROCESS_SIGNAL_ILL", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_ILL)); rb_define_const(c_domain, "PROCESS_SIGNAL_TRAP", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_TRAP)); rb_define_const(c_domain, "PROCESS_SIGNAL_ABRT", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_ABRT)); rb_define_const(c_domain, "PROCESS_SIGNAL_BUS", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_BUS)); rb_define_const(c_domain, "PROCESS_SIGNAL_FPE", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_FPE)); rb_define_const(c_domain, "PROCESS_SIGNAL_KILL", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_KILL)); rb_define_const(c_domain, "PROCESS_SIGNAL_USR1", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_USR1)); rb_define_const(c_domain, "PROCESS_SIGNAL_SEGV", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_SEGV)); rb_define_const(c_domain, "PROCESS_SIGNAL_USR2", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_USR2)); rb_define_const(c_domain, "PROCESS_SIGNAL_PIPE", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_PIPE)); rb_define_const(c_domain, "PROCESS_SIGNAL_ALRM", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_ALRM)); rb_define_const(c_domain, "PROCESS_SIGNAL_TERM", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_TERM)); rb_define_const(c_domain, "PROCESS_SIGNAL_STKFLT", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_STKFLT)); rb_define_const(c_domain, "PROCESS_SIGNAL_CHLD", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_CHLD)); rb_define_const(c_domain, "PROCESS_SIGNAL_CONT", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_CONT)); rb_define_const(c_domain, "PROCESS_SIGNAL_STOP", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_STOP)); rb_define_const(c_domain, "PROCESS_SIGNAL_TSTP", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_TSTP)); rb_define_const(c_domain, "PROCESS_SIGNAL_TTIN", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_TTIN)); rb_define_const(c_domain, "PROCESS_SIGNAL_TTOU", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_TTOU)); rb_define_const(c_domain, "PROCESS_SIGNAL_URG", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_URG)); rb_define_const(c_domain, "PROCESS_SIGNAL_XCPU", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_XCPU)); rb_define_const(c_domain, "PROCESS_SIGNAL_XFSZ", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_XFSZ)); rb_define_const(c_domain, "PROCESS_SIGNAL_VTALRM", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_VTALRM)); rb_define_const(c_domain, "PROCESS_SIGNAL_PROF", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_PROF)); rb_define_const(c_domain, "PROCESS_SIGNAL_WINCH", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_WINCH)); rb_define_const(c_domain, "PROCESS_SIGNAL_POLL", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_POLL)); rb_define_const(c_domain, "PROCESS_SIGNAL_PWR", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_PWR)); rb_define_const(c_domain, "PROCESS_SIGNAL_SYS", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_SYS)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT0", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT0)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT1", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT1)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT2", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT2)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT3", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT3)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT4", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT4)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT5", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT5)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT6", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT6)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT7", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT7)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT8", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT8)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT9", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT9)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT10", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT10)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT11", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT11)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT12", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT12)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT13", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT13)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT14", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT14)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT15", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT15)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT16", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT16)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT17", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT17)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT18", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT18)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT19", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT19)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT20", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT20)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT21", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT21)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT22", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT22)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT23", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT23)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT24", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT24)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT25", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT25)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT26", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT26)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT27", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT27)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT28", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT28)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT29", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT29)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT30", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT30)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT31", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT31)); rb_define_const(c_domain, "PROCESS_SIGNAL_RT32", INT2NUM(VIR_DOMAIN_PROCESS_SIGNAL_RT32)); rb_define_method(c_domain, "send_process_signal", libvirt_domain_send_process_signal, -1); rb_define_const(c_domain_snapshot, "LIST_ROOTS", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)); rb_define_const(c_domain_snapshot, "LIST_DESCENDANTS", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS)); rb_define_const(c_domain_snapshot, "LIST_LEAVES", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_LEAVES)); rb_define_const(c_domain_snapshot, "LIST_NO_LEAVES", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES)); rb_define_const(c_domain_snapshot, "LIST_METADATA", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_METADATA)); rb_define_const(c_domain_snapshot, "LIST_NO_METADATA", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA)); rb_define_const(c_domain_snapshot, "LIST_INACTIVE", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE)); rb_define_const(c_domain_snapshot, "LIST_ACTIVE", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE)); rb_define_const(c_domain_snapshot, "LIST_DISK_ONLY", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY)); rb_define_const(c_domain_snapshot, "LIST_INTERNAL", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL)); rb_define_const(c_domain_snapshot, "LIST_EXTERNAL", INT2NUM(VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL)); rb_define_method(c_domain, "list_all_snapshots", libvirt_domain_list_all_snapshots, -1); rb_define_const(c_domain_snapshot, "CREATE_REDEFINE", INT2NUM(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE)); rb_define_const(c_domain_snapshot, "CREATE_CURRENT", INT2NUM(VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)); rb_define_const(c_domain_snapshot, "CREATE_NO_METADATA", INT2NUM(VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)); rb_define_const(c_domain_snapshot, "CREATE_HALT", INT2NUM(VIR_DOMAIN_SNAPSHOT_CREATE_HALT)); rb_define_const(c_domain_snapshot, "CREATE_DISK_ONLY", INT2NUM(VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY)); rb_define_const(c_domain_snapshot, "CREATE_REUSE_EXT", INT2NUM(VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT)); rb_define_const(c_domain_snapshot, "CREATE_QUIESCE", INT2NUM(VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE)); rb_define_const(c_domain_snapshot, "CREATE_ATOMIC", INT2NUM(VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC)); rb_define_const(c_domain_snapshot, "CREATE_LIVE", INT2NUM(VIR_DOMAIN_SNAPSHOT_CREATE_LIVE)); rb_define_method(c_domain_snapshot, "num_children", libvirt_domain_snapshot_num_children, -1); rb_define_method(c_domain_snapshot, "list_children_names", libvirt_domain_snapshot_list_children_names, -1); rb_define_method(c_domain_snapshot, "list_all_children", libvirt_domain_snapshot_list_all_children, -1); rb_define_method(c_domain_snapshot, "parent", libvirt_domain_snapshot_parent, -1); rb_define_method(c_domain_snapshot, "current?", libvirt_domain_snapshot_current_p, -1); rb_define_method(c_domain_snapshot, "has_metadata?", libvirt_domain_snapshot_has_metadata_p, -1); rb_define_method(c_domain, "memory_stats_period=", libvirt_domain_memory_stats_period, 1); rb_define_method(c_domain, "fstrim", libvirt_domain_fstrim, -1); rb_define_const(c_domain, "BLOCK_REBASE_SHALLOW", INT2NUM(VIR_DOMAIN_BLOCK_REBASE_SHALLOW)); rb_define_const(c_domain, "BLOCK_REBASE_REUSE_EXT", INT2NUM(VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)); rb_define_const(c_domain, "BLOCK_REBASE_COPY_RAW", INT2NUM(VIR_DOMAIN_BLOCK_REBASE_COPY_RAW)); rb_define_const(c_domain, "BLOCK_REBASE_COPY", INT2NUM(VIR_DOMAIN_BLOCK_REBASE_COPY)); rb_define_method(c_domain, "block_rebase", libvirt_domain_block_rebase, -1); rb_define_const(c_domain, "CHANNEL_FORCE", INT2NUM(VIR_DOMAIN_CHANNEL_FORCE)); rb_define_method(c_domain, "open_channel", libvirt_domain_open_channel, -1); rb_define_method(c_domain, "create_with_files", libvirt_domain_create_with_files, -1); rb_define_const(c_domain, "OPEN_GRAPHICS_SKIPAUTH", INT2NUM(VIR_DOMAIN_OPEN_GRAPHICS_SKIPAUTH)); rb_define_method(c_domain, "open_graphics", libvirt_domain_open_graphics, -1); rb_define_method(c_domain, "pmwakeup", libvirt_domain_pmwakeup, -1); rb_define_method(c_domain, "block_resize", libvirt_domain_block_resize, -1); rb_define_const(c_domain, "BLOCK_RESIZE_BYTES", INT2NUM(VIR_DOMAIN_BLOCK_RESIZE_BYTES)); rb_define_const(c_domain_snapshot, "REVERT_RUNNING", INT2NUM(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING)); rb_define_const(c_domain_snapshot, "REVERT_PAUSED", INT2NUM(VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)); rb_define_const(c_domain_snapshot, "REVERT_FORCE", INT2NUM(VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)); rb_define_method(c_domain, "pmsuspend_for_duration", libvirt_domain_pmsuspend_for_duration, -1); rb_define_method(c_domain, "migrate_compression_cache", libvirt_domain_migrate_compression_cache, -1); rb_define_method(c_domain, "migrate_compression_cache=", libvirt_domain_migrate_compression_cache_equal, 1); rb_define_const(c_domain, "DISK_ERROR_NONE", INT2NUM(VIR_DOMAIN_DISK_ERROR_NONE)); rb_define_const(c_domain, "DISK_ERROR_UNSPEC", INT2NUM(VIR_DOMAIN_DISK_ERROR_UNSPEC)); rb_define_const(c_domain, "DISK_ERROR_NO_SPACE", INT2NUM(VIR_DOMAIN_DISK_ERROR_NO_SPACE)); rb_define_method(c_domain, "disk_errors", libvirt_domain_disk_errors, -1); rb_define_method(c_domain, "emulator_pin_info", libvirt_domain_emulator_pin_info, -1); rb_define_method(c_domain, "pin_emulator", libvirt_domain_pin_emulator, -1); rb_define_method(c_domain, "security_label_list", libvirt_domain_security_label_list, 0); rb_define_const(c_domain, "KEYCODE_SET_LINUX", INT2NUM(VIR_KEYCODE_SET_LINUX)); rb_define_const(c_domain, "KEYCODE_SET_XT", INT2NUM(VIR_KEYCODE_SET_XT)); rb_define_const(c_domain, "KEYCODE_SET_ATSET1", INT2NUM(VIR_KEYCODE_SET_ATSET1)); rb_define_const(c_domain, "KEYCODE_SET_ATSET2", INT2NUM(VIR_KEYCODE_SET_ATSET2)); rb_define_const(c_domain, "KEYCODE_SET_ATSET3", INT2NUM(VIR_KEYCODE_SET_ATSET3)); rb_define_const(c_domain, "KEYCODE_SET_OSX", INT2NUM(VIR_KEYCODE_SET_OSX)); rb_define_const(c_domain, "KEYCODE_SET_XT_KBD", INT2NUM(VIR_KEYCODE_SET_XT_KBD)); rb_define_const(c_domain, "KEYCODE_SET_USB", INT2NUM(VIR_KEYCODE_SET_USB)); rb_define_const(c_domain, "KEYCODE_SET_WIN32", INT2NUM(VIR_KEYCODE_SET_WIN32)); rb_define_const(c_domain, "KEYCODE_SET_RFB", INT2NUM(VIR_KEYCODE_SET_RFB)); rb_define_method(c_domain, "job_stats", libvirt_domain_job_stats, -1); rb_define_method(c_domain, "block_iotune", libvirt_domain_block_iotune, -1); rb_define_method(c_domain, "block_iotune=", libvirt_domain_block_iotune_equal, 1); rb_define_method(c_domain, "block_commit", libvirt_domain_block_commit, -1); rb_define_method(c_domain, "block_pull", libvirt_domain_block_pull, -1); rb_define_method(c_domain, "block_job_speed=", libvirt_domain_block_job_speed_equal, 1); rb_define_const(c_domain, "BLOCK_JOB_SPEED_BANDWIDTH_BYTES", INT2NUM(VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES)); rb_define_method(c_domain, "block_job_info", libvirt_domain_block_job_info, -1); rb_define_const(c_domain, "BLOCK_JOB_INFO_BANDWIDTH_BYTES", INT2NUM(VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES)); rb_define_method(c_domain, "block_job_abort", libvirt_domain_block_job_abort, -1); rb_define_method(c_domain, "interface_parameters", libvirt_domain_interface_parameters, -1); rb_define_method(c_domain, "interface_parameters=", libvirt_domain_interface_parameters_equal, 1); rb_define_method(c_domain, "block_stats_flags", libvirt_domain_block_stats_flags, -1); rb_define_method(c_domain, "numa_parameters", libvirt_domain_numa_parameters, -1); rb_define_method(c_domain, "numa_parameters=", libvirt_domain_numa_parameters_equal, 1); rb_define_method(c_domain, "lxc_open_namespace", libvirt_domain_lxc_open_namespace, -1); rb_define_method(c_domain, "qemu_agent_command", libvirt_domain_qemu_agent_command, -1); rb_define_const(c_domain, "QEMU_AGENT_COMMAND_BLOCK", INT2NUM(VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK)); rb_define_const(c_domain, "QEMU_AGENT_COMMAND_DEFAULT", INT2NUM(VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT)); rb_define_const(c_domain, "QEMU_AGENT_COMMAND_NOWAIT", INT2NUM(VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT)); rb_define_const(c_domain, "QEMU_AGENT_COMMAND_SHUTDOWN", INT2NUM(VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN)); rb_define_const(c_domain, "QEMU_MONITOR_COMMAND_DEFAULT", INT2NUM(VIR_DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT)); rb_define_const(c_domain, "QEMU_MONITOR_COMMAND_HMP", INT2NUM(VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP)); rb_define_method(c_domain, "lxc_enter_namespace", libvirt_domain_lxc_enter_namespace, -1); rb_define_method(c_domain, "migrate3", libvirt_domain_migrate3, -1); rb_define_method(c_domain, "migrate_to_uri3", libvirt_domain_migrate_to_uri3, -1); rb_define_const(c_domain, "BLOCK_COMMIT_SHALLOW", INT2NUM(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW)); rb_define_const(c_domain, "BLOCK_COMMIT_DELETE", INT2NUM(VIR_DOMAIN_BLOCK_COMMIT_DELETE)); rb_define_const(c_domain, "BLOCK_COMMIT_ACTIVE", INT2NUM(VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)); rb_define_const(c_domain, "BLOCK_COMMIT_RELATIVE", INT2NUM(VIR_DOMAIN_BLOCK_COMMIT_RELATIVE)); rb_define_const(c_domain, "BLOCK_COMMIT_BANDWIDTH_BYTES", INT2NUM(VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)); rb_define_const(c_domain, "BLOCK_JOB_TYPE_UNKNOWN", INT2NUM(VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN)); rb_define_const(c_domain, "BLOCK_JOB_TYPE_PULL", INT2NUM(VIR_DOMAIN_BLOCK_JOB_TYPE_PULL)); rb_define_const(c_domain, "BLOCK_JOB_TYPE_COPY", INT2NUM(VIR_DOMAIN_BLOCK_JOB_TYPE_COPY)); rb_define_const(c_domain, "BLOCK_JOB_TYPE_COMMIT", INT2NUM(VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT)); rb_define_const(c_domain, "BLOCK_JOB_TYPE_ACTIVE_COMMIT", INT2NUM(VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)); rb_define_const(c_domain, "BLOCK_JOB_ABORT_ASYNC", INT2NUM(VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC)); rb_define_const(c_domain, "BLOCK_JOB_ABORT_PIVOT", INT2NUM(VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT)); rb_define_const(c_domain, "BLOCK_JOB_COMPLETED", INT2NUM(VIR_DOMAIN_BLOCK_JOB_COMPLETED)); rb_define_const(c_domain, "BLOCK_JOB_FAILED", INT2NUM(VIR_DOMAIN_BLOCK_JOB_FAILED)); rb_define_const(c_domain, "BLOCK_JOB_CANCELED", INT2NUM(VIR_DOMAIN_BLOCK_JOB_CANCELED)); rb_define_const(c_domain, "BLOCK_JOB_READY", INT2NUM(VIR_DOMAIN_BLOCK_JOB_READY)); rb_define_method(c_domain, "cpu_stats", libvirt_domain_cpu_stats, -1); rb_define_const(c_domain, "CORE_DUMP_FORMAT_RAW", INT2NUM(VIR_DOMAIN_CORE_DUMP_FORMAT_RAW)); rb_define_const(c_domain, "CORE_DUMP_FORMAT_KDUMP_ZLIB", INT2NUM(VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_ZLIB)); rb_define_const(c_domain, "CORE_DUMP_FORMAT_KDUMP_LZO", INT2NUM(VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_LZO)); rb_define_const(c_domain, "CORE_DUMP_FORMAT_KDUMP_SNAPPY", INT2NUM(VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_SNAPPY)); rb_define_method(c_domain, "time", libvirt_domain_get_time, -1); rb_define_method(c_domain, "time=", libvirt_domain_time_equal, 1); rb_define_method(c_domain, "core_dump_with_format", libvirt_domain_core_dump_with_format, -1); rb_define_method(c_domain, "fs_freeze", libvirt_domain_fs_freeze, -1); rb_define_method(c_domain, "fs_thaw", libvirt_domain_fs_thaw, -1); rb_define_method(c_domain, "fs_info", libvirt_domain_fs_info, -1); rb_define_method(c_domain, "rename", libvirt_domain_rename, -1); rb_define_method(c_domain, "user_password=", libvirt_domain_user_password_equal, 1); rb_define_const(c_domain, "PASSWORD_ENCRYPTED", INT2NUM(VIR_DOMAIN_PASSWORD_ENCRYPTED)); rb_define_const(c_domain, "TIME_SYNC", INT2NUM(VIR_DOMAIN_TIME_SYNC)); } ruby-libvirt-0.8.4/ext/libvirt/network.c0000644000175000017500000005077614641546211020436 0ustar abolognaabologna/* * network.c: virNetwork methods * * Copyright (C) 2007,2010 Red Hat Inc. * Copyright (C) 2013-2016 Chris Lalancette * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include "common.h" #include "connect.h" #include "extconf.h" static VALUE c_network; static void network_free(void *d) { ruby_libvirt_free_struct(Network, d); } static virNetworkPtr network_get(VALUE n) { ruby_libvirt_get_struct(Network, n); } VALUE ruby_libvirt_network_new(virNetworkPtr n, VALUE conn) { return ruby_libvirt_new_class(c_network, n, conn, network_free); } /* * call-seq: * net.undefine -> nil * * Call virNetworkUndefine[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkUndefine] * to undefine this network. */ static VALUE libvirt_network_undefine(VALUE n) { ruby_libvirt_generate_call_nil(virNetworkUndefine, ruby_libvirt_connect_get(n), network_get(n)); } /* * call-seq: * net.create -> nil * * Call virNetworkCreate[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreate] * to start this network. */ static VALUE libvirt_network_create(VALUE n) { ruby_libvirt_generate_call_nil(virNetworkCreate, ruby_libvirt_connect_get(n), network_get(n)); } /* * call-seq: * net.update -> nil * * Call virNetworkUpdate[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkUpdate] * to update this network. */ static VALUE libvirt_network_update(VALUE n, VALUE command, VALUE section, VALUE index, VALUE xml, VALUE flags) { ruby_libvirt_generate_call_nil(virNetworkUpdate, ruby_libvirt_connect_get(n), network_get(n), NUM2UINT(command), NUM2UINT(section), NUM2INT(index), StringValuePtr(xml), NUM2UINT(flags)); } /* * call-seq: * net.destroy -> nil * * Call virNetworkDestroy[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkDestroy] * to shutdown this network. */ static VALUE libvirt_network_destroy(VALUE n) { ruby_libvirt_generate_call_nil(virNetworkDestroy, ruby_libvirt_connect_get(n), network_get(n)); } /* * call-seq: * net.name -> String * * Call virNetworkGetName[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetName] * to retrieve the name of this network. */ static VALUE libvirt_network_name(VALUE n) { ruby_libvirt_generate_call_string(virNetworkGetName, ruby_libvirt_connect_get(n), 0, network_get(n)); } /* * call-seq: * net.uuid -> String * * Call virNetworkGetUUIDString[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetUUIDString] * to retrieve the UUID of this network. */ static VALUE libvirt_network_uuid(VALUE n) { ruby_libvirt_generate_uuid(virNetworkGetUUIDString, ruby_libvirt_connect_get(n), network_get(n)); } /* * call-seq: * net.xml_desc(flags=0) -> String * * Call virNetworkGetXMLDesc[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetXMLDesc] * to retrieve the XML for this network. */ static VALUE libvirt_network_xml_desc(int argc, VALUE *argv, VALUE n) { VALUE flags = RUBY_Qnil; rb_scan_args(argc, argv, "01", &flags); ruby_libvirt_generate_call_string(virNetworkGetXMLDesc, ruby_libvirt_connect_get(n), 1, network_get(n), ruby_libvirt_value_to_uint(flags)); } /* * call-seq: * net.bridge_name -> String * * Call virNetworkGetBridgeName[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetBridgeName] * to retrieve the bridge name for this network. */ static VALUE libvirt_network_bridge_name(VALUE n) { ruby_libvirt_generate_call_string(virNetworkGetBridgeName, ruby_libvirt_connect_get(n), 1, network_get(n)); } /* * call-seq: * net.autostart? -> [true|false] * * Call virNetworkGetAutostart[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetAutostart] * to determine if this network will be autostarted when libvirtd starts. */ static VALUE libvirt_network_autostart(VALUE n) { int r, autostart; r = virNetworkGetAutostart(network_get(n), &autostart); ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virNetworkAutostart", ruby_libvirt_connect_get(n)); return autostart ? Qtrue : Qfalse; } /* * call-seq: * net.autostart = [true|false] * * Call virNetworkSetAutostart[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkSetAutostart] * to set this network to be autostarted when libvirtd starts. */ static VALUE libvirt_network_autostart_equal(VALUE n, VALUE autostart) { if (autostart != Qtrue && autostart != Qfalse) { rb_raise(rb_eTypeError, "wrong argument type (expected TrueClass or FalseClass)"); } ruby_libvirt_generate_call_nil(virNetworkSetAutostart, ruby_libvirt_connect_get(n), network_get(n), RTEST(autostart) ? 1 : 0); } /* * call-seq: * net.free -> nil * * Call virNetworkFree[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkFree] * to free this network. The object will no longer be valid after this call. */ static VALUE libvirt_network_free(VALUE n) { ruby_libvirt_generate_call_free(Network, n); } /* * call-seq: * net.active? -> [true|false] * * Call virNetworkIsActive[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsActive] * to determine if this network is currently active. */ static VALUE libvirt_network_active_p(VALUE n) { ruby_libvirt_generate_call_truefalse(virNetworkIsActive, ruby_libvirt_connect_get(n), network_get(n)); } /* * call-seq: * net.persistent? -> [true|false] * * Call virNetworkIsPersistent[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsPersistent] * to determine if this network is persistent. */ static VALUE libvirt_network_persistent_p(VALUE n) { ruby_libvirt_generate_call_truefalse(virNetworkIsPersistent, ruby_libvirt_connect_get(n), network_get(n)); } struct leases_arg { virNetworkDHCPLeasePtr *leases; int nleases; }; static VALUE leases_wrap(VALUE arg) { struct leases_arg *e = (struct leases_arg *)arg; VALUE result, hash; virNetworkDHCPLeasePtr lease; int i; result = rb_ary_new2(e->nleases); for (i = 0; i < e->nleases; i++) { lease = e->leases[i]; hash = rb_hash_new(); rb_hash_aset(hash, rb_str_new2("iface"), rb_str_new2(lease->iface)); rb_hash_aset(hash, rb_str_new2("expirytime"), LL2NUM(lease->expirytime)); rb_hash_aset(hash, rb_str_new2("type"), INT2NUM(lease->type)); if (lease->mac) { rb_hash_aset(hash, rb_str_new2("mac"), rb_str_new2(lease->mac)); } if (lease->iaid) { rb_hash_aset(hash, rb_str_new2("iaid"), rb_str_new2(lease->iaid)); } rb_hash_aset(hash, rb_str_new2("ipaddr"), rb_str_new2(lease->ipaddr)); rb_hash_aset(hash, rb_str_new2("prefix"), UINT2NUM(lease->prefix)); if (lease->hostname) { rb_hash_aset(hash, rb_str_new2("hostname"), rb_str_new2(lease->hostname)); } if (lease->clientid) { rb_hash_aset(hash, rb_str_new2("clientid"), rb_str_new2(lease->clientid)); } rb_ary_store(result, i, hash); } return result; } /* * call-seq: * net.dhcp_leases(mac=nil, flags=0) -> Hash * * Call virNetworkGetDHCPLeases[https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetDHCPLeases] * to retrieve the leases for this network. */ static VALUE libvirt_network_get_dhcp_leases(int argc, VALUE *argv, VALUE n) { VALUE mac = RUBY_Qnil, flags = RUBY_Qnil, result; int nleases, i = 0, exception = 0; virNetworkDHCPLeasePtr *leases = NULL; struct leases_arg args; rb_scan_args(argc, argv, "02", &mac, &flags); nleases = virNetworkGetDHCPLeases(network_get(n), ruby_libvirt_get_cstring_or_null(mac), &leases, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(nleases < 0, e_Error, "virNetworkGetDHCPLeases", ruby_libvirt_connect_get(n)); args.leases = leases; args.nleases = nleases; result = rb_protect(leases_wrap, (VALUE)&args, &exception); for (i = 0; i < nleases; i++) { virNetworkDHCPLeaseFree(leases[i]); } free(leases); if (exception) { rb_jump_tag(exception); } return result; } /* * Class Libvirt::Network */ void ruby_libvirt_network_init(void) { c_network = rb_define_class_under(m_libvirt, "Network", rb_cObject); rb_undef_alloc_func(c_network); rb_define_singleton_method(c_network, "new", ruby_libvirt_new_not_allowed, -1); rb_define_attr(c_network, "connection", 1, 0); rb_define_method(c_network, "undefine", libvirt_network_undefine, 0); rb_define_method(c_network, "create", libvirt_network_create, 0); rb_define_method(c_network, "update", libvirt_network_update, 5); rb_define_method(c_network, "destroy", libvirt_network_destroy, 0); rb_define_method(c_network, "name", libvirt_network_name, 0); rb_define_method(c_network, "uuid", libvirt_network_uuid, 0); rb_define_method(c_network, "xml_desc", libvirt_network_xml_desc, -1); rb_define_method(c_network, "bridge_name", libvirt_network_bridge_name, 0); rb_define_method(c_network, "autostart", libvirt_network_autostart, 0); rb_define_method(c_network, "autostart?", libvirt_network_autostart, 0); rb_define_method(c_network, "autostart=", libvirt_network_autostart_equal, 1); rb_define_method(c_network, "free", libvirt_network_free, 0); rb_define_method(c_network, "active?", libvirt_network_active_p, 0); rb_define_method(c_network, "persistent?", libvirt_network_persistent_p, 0); /* Ideally we would just have the "UPDATE_COMMAND_NONE" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_UPDATE_COMMAND_NONE" for backwards compatibility. */ rb_define_const(c_network, "UPDATE_COMMAND_NONE", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_NONE)); rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_NONE", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_NONE)); /* Ideally we would just have the "UPDATE_COMMAND_MODIFY" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_UPDATE_COMMAND_MODIFY" for backwards compatibility. */ rb_define_const(c_network, "UPDATE_COMMAND_MODIFY", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_MODIFY)); rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_MODIFY", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_MODIFY)); /* Ideally we would just have the "UPDATE_COMMAND_ADD_LAST" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_UPDATE_COMMAND_ADD_LAST" for backwards compatibility. */ rb_define_const(c_network, "UPDATE_COMMAND_ADD_LAST", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_LAST)); rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_ADD_LAST", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_LAST)); /* Ideally we would just have the "UPDATE_COMMAND_ADD_FIRST" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_UPDATE_COMMAND_ADD_FIRST" for backwards compatibility. */ rb_define_const(c_network, "UPDATE_COMMAND_ADD_FIRST", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST)); rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_ADD_FIRST", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST)); /* Ideally we would just have the "SECTION_NONE" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_NONE" for backwards compatibility. */ rb_define_const(c_network, "SECTION_NONE", INT2NUM(VIR_NETWORK_SECTION_NONE)); rb_define_const(c_network, "NETWORK_SECTION_NONE", INT2NUM(VIR_NETWORK_SECTION_NONE)); /* Ideally we would just have the "SECTION_BRIDGE" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_BRIDGE" for backwards compatibility. */ rb_define_const(c_network, "SECTION_BRIDGE", INT2NUM(VIR_NETWORK_SECTION_BRIDGE)); rb_define_const(c_network, "NETWORK_SECTION_BRIDGE", INT2NUM(VIR_NETWORK_SECTION_BRIDGE)); /* Ideally we would just have the "SECTION_DOMAIN" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_DOMAIN" for backwards compatibility. */ rb_define_const(c_network, "SECTION_DOMAIN", INT2NUM(VIR_NETWORK_SECTION_DOMAIN)); rb_define_const(c_network, "NETWORK_SECTION_DOMAIN", INT2NUM(VIR_NETWORK_SECTION_DOMAIN)); /* Ideally we would just have the "SECTION_IP" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_IP" for backwards compatibility. */ rb_define_const(c_network, "SECTION_IP", INT2NUM(VIR_NETWORK_SECTION_IP)); rb_define_const(c_network, "NETWORK_SECTION_IP", INT2NUM(VIR_NETWORK_SECTION_IP)); /* Ideally we would just have the "SECTION_IP_DHCP_HOST" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_IP_DHCP_HOST" for backwards compatibility. */ rb_define_const(c_network, "SECTION_IP_DHCP_HOST", INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_HOST)); rb_define_const(c_network, "NETWORK_SECTION_IP_DHCP_HOST", INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_HOST)); /* Ideally we would just have the "SECTION_IP_DHCP_RANGE" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_IP_DHCP_RANGE" for backwards compatibility. */ rb_define_const(c_network, "SECTION_IP_DHCP_RANGE", INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_RANGE)); rb_define_const(c_network, "NETWORK_SECTION_IP_DHCP_RANGE", INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_RANGE)); /* Ideally we would just have the "SECTION_FORWARD" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_FORWARD" for backwards compatibility. */ rb_define_const(c_network, "SECTION_FORWARD", INT2NUM(VIR_NETWORK_SECTION_FORWARD)); rb_define_const(c_network, "NETWORK_SECTION_FORWARD", INT2NUM(VIR_NETWORK_SECTION_FORWARD)); /* Ideally we would just have the "SECTION_FORWARD_INTERFACE" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_FORWARD_INTERFACE" for backwards compatibility. */ rb_define_const(c_network, "SECTION_FORWARD_INTERFACE", INT2NUM(VIR_NETWORK_SECTION_FORWARD_INTERFACE)); rb_define_const(c_network, "NETWORK_SECTION_FORWARD_INTERFACE", INT2NUM(VIR_NETWORK_SECTION_FORWARD_INTERFACE)); /* Ideally we would just have the "SECTION_FORWARD_PF" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_FORWARD_PF" for backwards compatibility. */ rb_define_const(c_network, "SECTION_FORWARD_PF", INT2NUM(VIR_NETWORK_SECTION_FORWARD_PF)); rb_define_const(c_network, "NETWORK_SECTION_FORWARD_PF", INT2NUM(VIR_NETWORK_SECTION_FORWARD_PF)); /* Ideally we would just have the "SECTION_PORTGROUP" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_PORTGROUP" for backwards compatibility. */ rb_define_const(c_network, "SECTION_PORTGROUP", INT2NUM(VIR_NETWORK_SECTION_PORTGROUP)); rb_define_const(c_network, "NETWORK_SECTION_PORTGROUP", INT2NUM(VIR_NETWORK_SECTION_PORTGROUP)); /* Ideally we would just have the "SECTION_DNS_HOST" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_DNS_HOST" for backwards compatibility. */ rb_define_const(c_network, "SECTION_DNS_HOST", INT2NUM(VIR_NETWORK_SECTION_DNS_HOST)); rb_define_const(c_network, "NETWORK_SECTION_DNS_HOST", INT2NUM(VIR_NETWORK_SECTION_DNS_HOST)); /* Ideally we would just have the "SECTION_DNS_TXT" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_DNS_TXT" for backwards compatibility. */ rb_define_const(c_network, "SECTION_DNS_TXT", INT2NUM(VIR_NETWORK_SECTION_DNS_TXT)); rb_define_const(c_network, "NETWORK_SECTION_DNS_TXT", INT2NUM(VIR_NETWORK_SECTION_DNS_TXT)); /* Ideally we would just have the "SECTION_DNS_SRV" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_SECTION_DNS_SRV" for backwards compatibility. */ rb_define_const(c_network, "SECTION_DNS_SRV", INT2NUM(VIR_NETWORK_SECTION_DNS_SRV)); rb_define_const(c_network, "NETWORK_SECTION_DNS_SRV", INT2NUM(VIR_NETWORK_SECTION_DNS_SRV)); /* Ideally we would just have the "UPDATE_AFFECT_CURRENT" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_UPDATE_AFFECT_CURRENT" for backwards compatibility. */ rb_define_const(c_network, "UPDATE_AFFECT_CURRENT", INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CURRENT)); rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_CURRENT", INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CURRENT)); /* Ideally we would just have the "UPDATE_AFFECT_LIVE" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_UPDATE_AFFECT_LIVE" for backwards compatibility. */ rb_define_const(c_network, "UPDATE_AFFECT_LIVE", INT2NUM(VIR_NETWORK_UPDATE_AFFECT_LIVE)); rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_LIVE", INT2NUM(VIR_NETWORK_UPDATE_AFFECT_LIVE)); /* Ideally we would just have the "UPDATE_AFFECT_CONFIG" constant. * Unfortunately we screwed up long ago, and we have to * leave "NETWORK_UPDATE_AFFECT_CONFIG" for backwards compatibility. */ rb_define_const(c_network, "UPDATE_AFFECT_CONFIG", INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CONFIG)); rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_CONFIG", INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CONFIG)); rb_define_const(c_network, "XML_INACTIVE", INT2NUM(VIR_NETWORK_XML_INACTIVE)); rb_define_const(c_network, "UPDATE_COMMAND_DELETE", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_DELETE)); rb_define_method(c_network, "dhcp_leases", libvirt_network_get_dhcp_leases, -1); rb_define_const(c_network, "IP_ADDR_TYPE_IPV4", INT2NUM(VIR_IP_ADDR_TYPE_IPV4)); rb_define_const(c_network, "IP_ADDR_TYPE_IPV6", INT2NUM(VIR_IP_ADDR_TYPE_IPV6)); } ruby-libvirt-0.8.4/NEWS.rst0000644000175000017500000001670214652707410015625 0ustar abolognaabologna===================== ruby-libvirt releases ===================== 0.8.4 (2024-08-01) ================== * Explicitly disallow use of ``new`` for wrapper classes 0.8.3 (2024-05-13) ================== * Fix runtime warnings with Ruby >= 3.2 * Improve build system * Improve website 0.8.2 (2024-02-09) ================== * Fix ``StoragePool#list_all_volumes`` * Fix regression in ``Domain#attach_device`` and ``Domain#detach_device`` 0.8.1 (2024-02-08) ================== * Add missing ``virDomainUndefineFlagsValues`` constants * Require libvirt 2.0.0 * Always use pkg-config for detecting libvirt * Drop most compile-time feature checks 0.8.0 (2021-11-15) ================== * Fix default values for ``node_cpu_stats`` and ``node_memory_stats`` * Fix cpumap allocation for ``virDomainGetVcpus`` * Enforce UTF8 for strings and exceptions * Drop local ``have_const`` * Use sensible default for ``libvirt_domain_qemu_agent_command`` 0.7.1 (2018-02-18) ================== * Fix a bad bug in block_resize (Marius Rieder) * Fix up some problems pointed out by clang * Fix up the tests for small semantic differences in how libvirt works 0.7.0 (2016-09-22) ================== * Fix network lease API to allow arguments that libvirt allows * Implement ``VIRT_STORAGE_POOL_CREATE`` flags * Implement more ``VIR_STORAGE_VOL`` flags * Implement ``VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN`` * Implement ``virDomainDefineXMLFlags`` * Implement ``virDomainRename`` * Implement ``virDomainSetUserPassword`` * Implement ``VIR_DOMAIN_TIME_SYNC`` * Fix the return value from ``virStreamSourceFunc`` so volume upload works 0.6.0 (2015-11-20) ================== * Fix possible buffer overflow * Fix storage volume creation error messages * Add additional storage pool defines * Implement ``Network#dhcp_leases`` method * Implement ``Connect#node_alloc_pages`` method * Implement ``Domain#time`` method * Implement ``Connect#domain_capabilities`` method * Implement ``Domain#core_dump_with_format`` method * Implement ``Domain#fs_freeze`` method * Implement ``Domain#fs_info`` method * Implement ``Connect#node_free_pages`` method 0.5.2 (2014-01-08) ================== * Fix to make sure we don't free more entires than retrieved 0.5.1 (2013-12-15) ================== * Fixes to compile against older libvirt * Fixes to compile against ruby 1.8 0.5.0 (2013-12-09) ================== * Updated ``Network`` class, implementing almost all libvirt APIs * Updated ``Domain`` class, implementing almost all libvirt APIs * Updated ``Connection`` class, implementing almost all libvirt APIs * Updated ``DomainSnapshot`` class, implementing almost all libvirt APIs * Updated ``NodeDevice`` class, implementing almost all libvirt APIs * Updated ``Storage`` class, implementing almost all libvirt APIs * Add constants for almost all libvirt defines * Improved performance in the library by using alloca 0.4.0 (2011-07-27) ================== * Updated ``Domain`` class, implementing ``dom.memory_parameters=``, ``dom.memory_parameters``, ``dom.updated?``, ``dom.migrate2``, ``dom.migrate_to_uri2``, ``dom.migrate_set_max_speed``, ``dom.qemu_monitor_command``, ``dom.blkio_parameters``, ``dom.blkio_parameters=``, ``dom.state``, ``dom.open_console``, ``dom.screenshot`` and ``dom.inject_nmi`` * Implementation of the ``Stream`` class, which covers the libvirt ``virStream`` APIs * Add the ability to build against non-system libvirt libraries * Updated ``Error`` object, which now includes the libvirt code, component and level of the error, as well as all of the error constants from ``libvirt.h`` * Updated ``Connect`` class, implementing ``conn.sys_info``, ``conn.stream``, ``conn.interface_change_begin``, ``conn.interface_change_commit`` and ``conn.interface_change_rollback`` * Updated ``StorageVol`` class, implementing ``vol.download`` and ``vol.upload`` * Various bugfixes 0.3.0 (2010-12-12) ================== * Implementation of ``Libvirt::open_auth``, ``Libvirt::event_register_impl`` * Updated ``Connect`` class, implementing ``conn.compare_cpu``, ``conn.baseline_cpu``, ``conn.domain_event_register_any``, ``conn.domain_event_deregister_any``, ``conn.domain_event_register``, ``conn.domain_event_deregister`` and ``conn.create_domain_xml`` * Updated ``Domain`` class, implementing ``dom.get_vcpus``, ``dom.update_device``, ``dom.scheduler_type``, ``dom.scheduler_parameters``, ``dom.scheduler_parameters=``, ``dom.num_vcpus``, ``dom.vcpus_flags=`` and ``dom.qemu_monitor_command`` * Updated ``Interface`` class, implementing ``interface.free`` * Many potential memory leaks have been fixed * Many bugfixes * Documentation update of many methods, including all of the lookup methods that were missing before 0.2.0 (2010-07-01) ================== * Updated ``Storage`` class, implementing ``pool.active?``, ``pool.persistent?`` and ``pool.vol_create_xml_from`` * Updated ``Connect`` class, implementing ``conn.node_free_memory``, ``conn.node_cells_free_memory``, ``conn.node_get_security_model``, ``conn.encrypted?``, ``conn.libversion`` and ``conn.secure?`` * Updated ``Network`` class, implementing ``net.active?`` and ``net.persistent?`` * Update ``Domain`` class, implementing ``conn.domain_xml_from_native``, ``conn.domain_xml_to_native``, ``dom.migrate_to_uri``, ``dom.migrate_set_max_downtime``, ``dom.managed_save``, ``dom.has_managed_save?``, ``dom.managed_save_remove``, ``dom.security_label``, ``dom.block_stats``, ``dom.memory_stats``, ``dom.blockinfo``, ``dom.block_peek``, ``dom.memory_peek``, ``dom.active?``, ``dom.persistent?``, ``dom.snapshot_create_xml``, ``dom.num_of_snapshots``, ``dom.list_snapshots``, ``dom.lookup_snapshot_by_name``, ``dom.has_current_snapshot?``, ``dom.revert_to_snapshot``, ``dom.current_snapshot``, ``snapshot.xml_desc``, ``snapshot.delete``, ``dom.job_info`` and ``dom.abort_job`` * Implementation of the ``NodeDevice`` class * Implementation of the ``Secret`` class * Implementation of the ``NWFilter`` class * Implementation of the ``Interface`` class * Conversion of the development tree to git * New maintainer (Chris Lalancette). David Lutterkort has agreed to transfer maintainership since he is not actively involved in their development anymore 0.1.0 (2008-11-18) ================== * Add binding for ``virConnectFindStoragePoolSources`` (Chris Lalancette) * Fix ``dom_migrate`` (Chris Lalancette) * Add the ``MIGRATE_LIVE`` (``enum virDomainMigrateFlags``) flag * Slight improvements of the unit tests 0.0.7 (2008-04-15) ================== * Binding for ``virDomainMigrate`` * Fix crash caused by using ``virResetError`` * More sensible message included in exceptions 0.0.6 (2008-04-02) ================== * Fix test failure exposed by the Fedora builders 0.0.5 (2008-04-02) ================== * Explicit free methods for various objects (based on a patch by Vadim Zaliva) * Make the FLAGS argument for various calls optional, and default it to 0 (Chris Lalancette) * More finegrained exceptions on errors, containing libvirt error message (Mohammed Morsi) 0.0.4 (2008-04-01) ================== * Bindings for the libvirt storage API (requires libvirt 0.4.1) * Suppress some bindings if the underlying libvirt doesn't support it * Bindings for ``virDomainSetMemory``, ``virDomainPinVcpu`` and ``virDomainSetVcpus`` (Vadim Zaliva) 0.0.2 (2007-12-06) ================== * Add ``virNodeGetInfo`` binding * Convert Ruby API from StudlyCaps to under_score_separation, since that's the Ruby convention 0.0.1 (2007-11-19) ================== * Initial release ruby-libvirt-0.8.4/tests/0000755000175000017500000000000014652707704015461 5ustar abolognaabolognaruby-libvirt-0.8.4/tests/test_utils.rb0000644000175000017500000001563214567114130020202 0ustar abolognaabologna$FAIL = 0 $SUCCESS = 0 $SKIPPED = 0 DEFAULT_URI = "test:///default" URI = ENV['RUBY_LIBVIRT_TEST_URI'] || DEFAULT_URI $GUEST_BASE = '/var/lib/libvirt/images/rb-libvirt-test' $GUEST_DISK = $GUEST_BASE + '.qcow2' $GUEST_SAVE = $GUEST_BASE + '.save' $GUEST_UUID = "93a5c045-6457-2c09-e56f-927cdf34e17a" $GUEST_RAW_DISK = $GUEST_BASE + '.raw' # XML data for later tests $new_dom_xml = < Ruby Libvirt Tester rb-libvirt-test #{$GUEST_UUID} 1048576 1048576 2 hvm destroy restart restart EOF $NEW_INTERFACE_MAC = 'aa:bb:cc:dd:ee:ff' $new_interface_xml = < EOF $NETWORK_UUID = "04068860-d9a2-47c5-bc9d-9e047ae901da" $new_net_xml = < rb-libvirt-test #{$NETWORK_UUID} EOF $new_network_dhcp_ip = < EOF $NWFILTER_UUID = "bd339530-134c-6d07-441a-17fb90dad807" $new_nwfilter_xml = < #{$NWFILTER_UUID} EOF $SECRET_UUID = "bd339530-134c-6d07-4410-17fb90dad805" $new_secret_xml = < test secret #{$SECRET_UUID} /var/lib/libvirt/images/mail.img EOF $POOL_UUID = "33a5c045-645a-2c00-e56b-927cdf34e17a" $POOL_PATH = "/var/lib/libvirt/images/rb-libvirt-test" $new_storage_pool_xml = < rb-libvirt-test #{$POOL_UUID} #{$POOL_PATH} EOF $test_object = "unknown" def set_test_object(obj) $test_object = obj end def test_default_uri?() return URI == DEFAULT_URI end def test_sleep(s) if !test_default_uri? sleep s end end def expect_success(object, msg, func, *args) begin x = object.__send__(func, *args) if block_given? res = yield x if not res raise "block failed" end end puts_ok "#{$test_object}.#{func} #{msg} succeeded" x rescue NoMethodError puts_skipped "#{$test_object}.#{func} does not exist" rescue => e puts_fail "#{$test_object}.#{func} #{msg} expected to succeed, threw #{e.class.to_s}: #{e.to_s}" end end def expect_fail(object, errtype, errmsg, func, *args) begin object.__send__(func, *args) rescue NoMethodError puts_skipped "#{$test_object}.#{func} does not exist" rescue errtype => e puts_ok "#{$test_object}.#{func} #{errmsg} threw #{errtype.to_s}" rescue => e puts_fail "#{$test_object}.#{func} #{errmsg} expected to throw #{errtype.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}" else puts_fail "#{$test_object}.#{func} #{errmsg} expected to throw #{errtype.to_s}, but threw nothing" end end def expect_utf8_exception_msg(object, errtype, func, *args) begin object.__send__(func, *args) rescue NoMethodError puts_skipped "#{$test_object}.#{func} does not exist" rescue errtype => e if e.message.encoding.name == 'UTF-8' puts_ok "#{$test_object}.#{func} threw #{errtype.to_s} with UTF-8 encoding" else puts_fail "#{$test_object}.#{func} threw #{errtype.to_s} with #{e.message.encoding.name} encoding" end rescue => e puts_fail "#{$test_object}.#{func} expected to throw #{errtype.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}" else puts_fail "#{$test_object}.#{func} expected to throw #{errtype.to_s}, but threw nothing" end end def expect_too_many_args(object, func, *args) expect_fail(object, ArgumentError, "too many args", func, *args) end def expect_too_few_args(object, func, *args) expect_fail(object, ArgumentError, "too few args", func, *args) end def expect_invalid_arg_type(object, func, *args) expect_fail(object, TypeError, "invalid arg type", func, *args) end def puts_ok(str) puts "OK: " + str $SUCCESS = $SUCCESS + 1 end def puts_fail(str) puts "FAIL: " + str $FAIL = $FAIL + 1 end def puts_skipped(str) puts "SKIPPED: " + str $SKIPPED = $SKIPPED + 1 end def finish_tests puts "Successfully finished #{$SUCCESS} tests, failed #{$FAIL} tests, skipped #{$SKIPPED} tests" end def find_valid_iface(conn) conn.list_interfaces.each do |ifname| iface = conn.lookup_interface_by_name(ifname) if iface.mac == "00:00:00:00:00:00" next end return iface end return nil end def cleanup_test_domain(conn) # cleanup from previous runs begin olddom = conn.lookup_domain_by_name("rb-libvirt-test") rescue # in case we didn't find it, don't do anything end begin olddom.destroy rescue # in case we didn't destroy it, don't do anything end begin olddom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) rescue # in case we didn't undefine it, don't do anything end if URI != DEFAULT_URI `rm -f #{$GUEST_DISK}` `rm -f #{$GUEST_SAVE}` end end def cleanup_test_network(conn) # initial cleanup for previous run begin oldnet = conn.lookup_network_by_name("rb-libvirt-test") rescue # in case we didn't find it, don't do anything end begin oldnet.destroy rescue # in case we didn't find it, don't do anything end begin oldnet.undefine rescue # in case we didn't find it, don't do anything end end ruby-libvirt-0.8.4/tests/test_domain.rb0000644000175000017500000012722614567114130020314 0ustar abolognaabologna#!/usr/bin/ruby # Test the domain methods the bindings support. Note that this tester requires # the qemu driver to be enabled and available for use. # Note that the order of the TESTGROUPs below match the order that the # functions are defined in the ext/libvirt/domain.c file $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("domain") conn = Libvirt::open(URI) cleanup_test_domain(conn) # setup for later tests if !test_default_uri? `qemu-img create -f qcow2 #{$GUEST_DISK} 5G` `qemu-img create -f raw #{$GUEST_RAW_DISK} 5G` end new_hostdev_xml = <
EOF # start tests # TESTGROUP: dom.migrate_max_speed if !test_default_uri? newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "migrate_max_speed", 1, 2) expect_invalid_arg_type(newdom, "migrate_max_speed", 'foo') expect_invalid_arg_type(newdom, "migrate_max_speed", []) expect_invalid_arg_type(newdom, "migrate_max_speed", {}) expect_success(newdom, "no args", "migrate_max_speed") newdom.destroy end # TESTGROUP: dom.reset newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "reset", 1, 2) expect_invalid_arg_type(newdom, "reset", 'foo') expect_invalid_arg_type(newdom, "reset", []) expect_invalid_arg_type(newdom, "reset", {}) expect_success(newdom, "no args", "reset") newdom.destroy # TESTGROUP: dom.hostname newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "hostname", 1, 2) expect_invalid_arg_type(newdom, "hostname", 'foo') expect_invalid_arg_type(newdom, "hostname", []) expect_invalid_arg_type(newdom, "hostname", {}) # FIXME: spits an error "this function is not supported by the connection driver" #expect_success(newdom, "no args", "hostname") newdom.destroy # TESTGROUP: dom.metadata newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "metadata", 1, 2, 3, 4) expect_too_few_args(newdom, "metadata") expect_invalid_arg_type(newdom, "metadata", 'foo') expect_invalid_arg_type(newdom, "metadata", nil) expect_invalid_arg_type(newdom, "metadata", []) expect_invalid_arg_type(newdom, "metadata", {}) expect_invalid_arg_type(newdom, "metadata", 1, 1) expect_invalid_arg_type(newdom, "metadata", 1, 'foo', 'bar') expect_success(newdom, "no args", "metadata", Libvirt::Domain::METADATA_DESCRIPTION) {|x| x == "Ruby Libvirt Tester"} newdom.destroy # TESTGROUP: dom.metadata= newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "metadata=", 1, 2, 3, 4, 5, 6) expect_too_few_args(newdom, "metadata=") expect_too_few_args(newdom, "metadata=", [1]) expect_invalid_arg_type(newdom, "metadata=", 1) expect_invalid_arg_type(newdom, "metadata=", 'foo') expect_invalid_arg_type(newdom, "metadata=", nil) expect_invalid_arg_type(newdom, "metadata=", {}) expect_invalid_arg_type(newdom, "metadata=", ['foo', nil]) expect_invalid_arg_type(newdom, "metadata=", [nil, nil]) expect_invalid_arg_type(newdom, "metadata=", [[], nil]) expect_invalid_arg_type(newdom, "metadata=", [{}, nil]) expect_invalid_arg_type(newdom, "metadata=", [1, 1]) expect_invalid_arg_type(newdom, "metadata=", [1, []]) expect_invalid_arg_type(newdom, "metadata=", [1, {}]) expect_success(newdom, "no args", "metadata=", [Libvirt::Domain::METADATA_DESCRIPTION, 'foo']) expect_success(newdom, "no args", "metadata=", [Libvirt::Domain::METADATA_DESCRIPTION, 'foo', nil, nil, 0]) expect_success(newdom, "no args", "metadata", Libvirt::Domain::METADATA_DESCRIPTION) {|x| x == "foo"} newdom.destroy # TESTGROUP: dom.updated? newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "updated?", 1) expect_success(newdom, "no args", "updated?") newdom.destroy # TESTGROUP: dom.inject_nmi newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "inject_nmi", 1, 2) expect_invalid_arg_type(newdom, "inject_nmi", 'foo') expect_success(newdom, "no args", "inject_nmi") newdom.destroy # TESTGROUP: dom.control_info newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "control_info", 1, 2) expect_invalid_arg_type(newdom, "control_info", 'foo') expect_success(newdom, "no args", "control_info") newdom.destroy # TESTGROUP: dom.send_key newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "send_key", 1, 2, 3, 4) expect_too_few_args(newdom, "send_key") expect_too_few_args(newdom, "send_key", 1) expect_too_few_args(newdom, "send_key", 1, 2) expect_invalid_arg_type(newdom, "send_key", nil, 0, []) expect_invalid_arg_type(newdom, "send_key", nil, 0, [1]) expect_invalid_arg_type(newdom, "send_key", 'foo', 0, []) expect_invalid_arg_type(newdom, "send_key", 0, nil, []) expect_invalid_arg_type(newdom, "send_key", 0, 'foo', []) expect_invalid_arg_type(newdom, "send_key", 0, 1, nil) expect_invalid_arg_type(newdom, "send_key", 0, 1, 'foo') expect_invalid_arg_type(newdom, "send_key", 0, 1, 2) expect_invalid_arg_type(newdom, "send_key", nil, 0, [nil]) expect_invalid_arg_type(newdom, "send_key", nil, 0, ['foo']) # FIXME: this fails for reasons that are unclear to me #expect_success(newdom, "codeset, holdtime, keycodes args", "send_key", 0, 1, []) newdom.destroy # TESTGROUP: dom.migrate newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 dconn = Libvirt::open(URI) expect_too_many_args(newdom, "migrate", 1, 2, 3, 4, 5, 6) expect_too_few_args(newdom, "migrate") expect_fail(newdom, ArgumentError, "invalid connection object", "migrate", "foo") expect_invalid_arg_type(newdom, "migrate", dconn, 'foo') expect_invalid_arg_type(newdom, "migrate", dconn, 0, 1) expect_invalid_arg_type(newdom, "migrate", dconn, 0, 'foo', 1) expect_invalid_arg_type(newdom, "migrate", dconn, 0, 'foo', 'bar', 'baz') # FIXME: how can we make this work? #expect_success(newdom, "conn arg", "migrate", dconn) dconn.close newdom.destroy # TESTGROUP: dom.migrate_to_uri newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "migrate_to_uri", 1, 2, 3, 4, 5) expect_too_few_args(newdom, "migrate_to_uri") expect_invalid_arg_type(newdom, "migrate_to_uri", 1) expect_invalid_arg_type(newdom, "migrate_to_uri", URI, 'foo') expect_invalid_arg_type(newdom, "migrate_to_uri", URI, 0, 1) expect_invalid_arg_type(newdom, "migrate_to_uri", URI, 0, 'foo', 'bar') #expect_success(newdom, "URI arg", "migrate_to_uri", "qemu://remote/system") dconn.close newdom.destroy # TESTGROUP: dom.migrate_set_max_downtime newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "migrate_set_max_downtime", 1, 2, 3) expect_too_few_args(newdom, "migrate_set_max_downtime") expect_invalid_arg_type(newdom, "migrate_set_max_downtime", 'foo') expect_invalid_arg_type(newdom, "migrate_set_max_downtime", 10, 'foo') expect_fail(newdom, Libvirt::Error, "on off domain", "migrate_set_max_downtime", 10) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 #expect_fail(newdom, Libvirt::Error, "while no migration in progress", "migrate_set_max_downtime", 10) #newdom.migrate_to_uri("qemu://remote/system") #expect_success(newdom, "10 second downtime", "migrate_set_max_downtime", 10) newdom.destroy # TESTGROUP: dom.migrate2 newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 dconn = Libvirt::open(URI) expect_too_many_args(newdom, "migrate2", 1, 2, 3, 4, 5, 6, 7) expect_too_few_args(newdom, "migrate2") expect_fail(newdom, ArgumentError, "invalid connection object", "migrate2", "foo") expect_invalid_arg_type(newdom, "migrate2", dconn, 0) # FIXME: how can we make this work? #expect_success(newdom, "conn arg", "migrate2", dconn) dconn.close newdom.destroy # TESTGROUP: dom.migrate_to_uri2 newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "migrate_to_uri2", 1, 2, 3, 4, 5, 6, 7) expect_invalid_arg_type(newdom, "migrate_to_uri2", 1) expect_invalid_arg_type(newdom, "migrate_to_uri2", URI, 1) expect_invalid_arg_type(newdom, "migrate_to_uri2", URI, 'foo', 1) expect_invalid_arg_type(newdom, "migrate_to_uri2", URI, 'foo', 'bar', 'baz') expect_invalid_arg_type(newdom, "migrate_to_uri2", URI, 'foo', 'bar', 0, 1) expect_invalid_arg_type(newdom, "migrate_to_uri2", URI, 'foo', 'bar', 0, 'foo', 'baz') #expect_success(newdom, "URI arg", "migrate_to_uri2", "qemu://remote/system") dconn.close newdom.destroy # TESTGROUP: dom.migrate_set_max_speed newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "migrate_set_max_speed", 1, 2, 3) expect_too_few_args(newdom, "migrate_set_max_speed") expect_invalid_arg_type(newdom, "migrate_set_max_speed", 'foo') expect_invalid_arg_type(newdom, "migrate_set_max_speed", 5, 'foo') #expect_success(newdom, "Bandwidth arg", "migrate_set_max_speed", 5) newdom.destroy # TESTGROUP: dom.shutdown if !test_default_uri? newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "shutdown", 1, 2) expect_success(newdom, "no args", "shutdown") sleep 1 newdom.destroy end # TESTGROUP: dom.reboot newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "reboot", 1, 2) expect_invalid_arg_type(newdom, "reboot", "hello") expect_success(newdom, "no args", "reboot") test_sleep 1 expect_success(newdom, "flags arg", "reboot", 0) test_sleep 1 newdom.destroy # TESTGROUP: dom.destroy newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "destroy", 1, 2) expect_success(newdom, "no args", "destroy") # TESTGROUP: dom.suspend newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "suspend", 1) expect_success(newdom, "no args", "suspend") newdom.destroy # TESTGROUP: dom.resume newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_fail(newdom, Libvirt::Error, "already running", "resume") newdom.suspend expect_too_many_args(newdom, "resume", 1) expect_success(newdom, "no args suspended domain", "resume") newdom.destroy # TESTGROUP: dom.save if !test_default_uri? newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "save", 1, 2, 3, 4) expect_too_few_args(newdom, "save") expect_invalid_arg_type(newdom, "save", 1) expect_invalid_arg_type(newdom, "save", nil) expect_fail(newdom, Libvirt::Error, "non-existent path", "save", "/this/path/does/not/exist") expect_success(newdom, "path arg", "save", $GUEST_SAVE) `rm -f #{$GUEST_SAVE}` end # TESTGROUP: dom.managed_save if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) newdom.create test_sleep 1 expect_too_many_args(newdom, "managed_save", 1, 2) expect_invalid_arg_type(newdom, "managed_save", "hello") expect_success(newdom, "no args", "managed_save") newdom.undefine(Libvirt::Domain::UNDEFINE_MANAGED_SAVE) end # TESTGROUP: dom.has_managed_save? newdom = conn.define_domain_xml($new_dom_xml) newdom.create test_sleep 1 expect_too_many_args(newdom, "has_managed_save?", 1, 2) expect_invalid_arg_type(newdom, "has_managed_save?", "hello") if newdom.has_managed_save? puts_fail "domain.has_managed_save? reports true on a new domain" else puts_ok "domain.has_managed_save? not true on new domain" end newdom.managed_save if not newdom.has_managed_save? puts_fail "domain.has_managed_save? reports false after a managed save" else puts_ok "domain.has_managed_save? reports true after a managed save" end newdom.undefine(Libvirt::Domain::UNDEFINE_MANAGED_SAVE) # TESTGROUP: dom.managed_save_remove newdom = conn.define_domain_xml($new_dom_xml) newdom.create test_sleep 1 newdom.managed_save expect_too_many_args(newdom, "managed_save_remove", 1, 2) expect_invalid_arg_type(newdom, "managed_save_remove", "hello") if not newdom.has_managed_save? puts_fail "prior to domain.managed_save_remove, no managed save file" end expect_success(newdom, "no args", "managed_save_remove") if newdom.has_managed_save? puts_fail "after domain.managed_save_remove, managed save file still exists" else puts_ok "after domain.managed_save_remove, managed save file no longer exists" end newdom.undefine # TESTGROUP: dom.core_dump if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) newdom.create test_sleep 1 expect_too_many_args(newdom, "core_dump", 1, 2, 3) expect_too_few_args(newdom, "core_dump") expect_invalid_arg_type(newdom, "core_dump", 1, 2) expect_invalid_arg_type(newdom, "core_dump", "/path", "foo") expect_fail(newdom, Libvirt::Error, "invalid path", "core_dump", "/this/path/does/not/exist") expect_success(newdom, "live with path arg", "core_dump", "/var/lib/libvirt/images/ruby-libvirt-test.core") `rm -f /var/lib/libvirt/images/ruby-libvirt-test.core` expect_success(newdom, "crash with path arg", "core_dump", "/var/lib/libvirt/images/ruby-libvirt-test.core", Libvirt::Domain::DUMP_CRASH) expect_fail(newdom, Libvirt::Error, "of shut-off domain", "core_dump", "/var/lib/libvirt/images/ruby-libvirt-test.core", Libvirt::Domain::DUMP_CRASH) `rm -f /var/lib/libvirt/images/ruby-libvirt-test.core` newdom.undefine end # TESTGROUP: Libvirt::Domain::restore if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) newdom.create test_sleep 1 newdom.save($GUEST_SAVE) expect_too_many_args(Libvirt::Domain, "restore", 1, 2, 3) expect_too_few_args(Libvirt::Domain, "restore") expect_invalid_arg_type(Libvirt::Domain, "restore", 1, 2) expect_invalid_arg_type(Libvirt::Domain, "restore", conn, 2) expect_fail(Libvirt::Domain, Libvirt::Error, "invalid path", "restore", conn, "/this/path/does/not/exist") `touch /tmp/foo` expect_fail(Libvirt::Domain, Libvirt::Error, "invalid save file", "restore", conn, "/tmp/foo") `rm -f /tmp/foo` expect_success(Libvirt::Domain, "2 args", "restore", conn, $GUEST_SAVE) `rm -f #{$GUEST_SAVE}` newdom.destroy newdom.undefine end # TESTGROUP: dom.info newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "info", 1) expect_success(newdom, "no args", "info") {|x| x.state == Libvirt::Domain::RUNNING and x.max_mem == 1048576 and x.memory == 1048576 and x.nr_virt_cpu == 2} newdom.destroy # TESTGROUP: dom.security_label newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "security_label", 1) expect_success(newdom, "no args", "security_label") newdom.destroy # TESTGROUP: dom.block_stats newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "block_stats", 1, 2) expect_too_few_args(newdom, "block_stats") expect_invalid_arg_type(newdom, "block_stats", 1) expect_fail(newdom, Libvirt::RetrieveError, "invalid path", "block_stats", "foo") expect_success(newdom, "block device arg", "block_stats", "vda") newdom.destroy # TESTGROUP: dom.memory_stats newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "memory_stats", 1, 2) expect_invalid_arg_type(newdom, "memory_stats", "foo") expect_success(newdom, "no args", "memory_stats") newdom.destroy # TESTGROUP: dom.blockinfo newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "blockinfo", 1, 2, 3) expect_too_few_args(newdom, "blockinfo") expect_invalid_arg_type(newdom, "blockinfo", 1) expect_invalid_arg_type(newdom, "blockinfo", "foo", "bar") expect_fail(newdom, Libvirt::RetrieveError, "invalid path", "blockinfo", "foo") expect_success(newdom, "path arg", "blockinfo", $GUEST_DISK) newdom.destroy # TESTGROUP: dom.block_peek newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "block_peek", 1, 2, 3, 4, 5) expect_too_few_args(newdom, "block_peek") expect_too_few_args(newdom, "block_peek", 1) expect_too_few_args(newdom, "block_peek", 1, 2) expect_invalid_arg_type(newdom, "block_peek", 1, 2, 3) expect_invalid_arg_type(newdom, "block_peek", "foo", "bar", 3) expect_invalid_arg_type(newdom, "block_peek", "foo", 0, "bar") expect_invalid_arg_type(newdom, "block_peek", "foo", 0, 512, "baz") expect_fail(newdom, Libvirt::RetrieveError, "invalid path", "block_peek", "foo", 0, 512) # blockpeek = newdom.block_peek($GUEST_RAW_DISK, 0, 512) # # 0x51 0x46 0x49 0xfb are the first 4 bytes of a qcow2 image # if blockpeek[0].unpack('C')[0] != 0x51 or blockpeek[1].unpack('C')[0] != 0x46 or # blockpeek[2].unpack('C')[0] != 0x49 or blockpeek[3].unpack('C')[0] != 0xfb # puts_fail "domain.block_peek read did not return valid data" # else # puts_ok "domain.block_peek read valid data" # end newdom.destroy # TESTGROUP: dom.memory_peek newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "memory_peek", 1, 2, 3, 4) expect_too_few_args(newdom, "memory_peek") expect_too_few_args(newdom, "memory_peek", 1) expect_invalid_arg_type(newdom, "memory_peek", "foo", 2) expect_invalid_arg_type(newdom, "memory_peek", 0, "bar") expect_invalid_arg_type(newdom, "memory_peek", 0, 512, "baz") expect_success(newdom, "offset and size args", "memory_peek", 0, 512) newdom.destroy # TESTGROUP: dom.get_vcpus expect_too_many_args(newdom, "get_vcpus", 1) newdom = conn.define_domain_xml($new_dom_xml) expect_success(newdom, "get_vcpus on shutoff domain", "get_vcpus") {|x| x.length == 2} newdom.create test_sleep 1 expect_success(newdom, "no args", "get_vcpus") {|x| x.length == 2} newdom.destroy newdom.undefine # TESTGROUP: dom.active? expect_too_many_args(newdom, "active?", 1) newdom = conn.define_domain_xml($new_dom_xml) expect_success(newdom, "no args", "active?") {|x| x == false} newdom.create test_sleep 1 expect_success(newdom, "no args", "active?") {|x| x == true} newdom.destroy newdom.undefine # TESTGROUP: dom.persistent? newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "persistent?", 1) expect_success(newdom, "no args", "persistent?") {|x| x == false} newdom.destroy newdom = conn.define_domain_xml($new_dom_xml) expect_success(newdom, "no args", "persistent?") {|x| x == true} newdom.undefine # TESTGROUP: dom.ifinfo newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "ifinfo", 1, 2) expect_too_few_args(newdom, "ifinfo") expect_invalid_arg_type(newdom, "ifinfo", 1) expect_fail(newdom, Libvirt::RetrieveError, "invalid arg", "ifinfo", "foo") expect_success(newdom, "interface arg", "ifinfo", "rl556") newdom.destroy # TESTGROUP: dom.name newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "name", 1) expect_success(newdom, "no args", "name") {|x| x == "rb-libvirt-test"} expect_success(newdom, "is UTF-8", "name") {|x| x.encoding.name == "UTF-8"} newdom.destroy # TESTGROUP: dom.id newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "id", 1) expect_success(newdom, "no args", "id") newdom.destroy # TESTGROUP: dom.uuid newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "uuid", 1) expect_success(newdom, "no args", "uuid") {|x| x == $GUEST_UUID} newdom.destroy # TESTGROUP: dom.os_type newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "os_type", 1) if test_default_uri? expect_success(newdom, "no args", "os_type") {|x| x == "linux"} else expect_success(newdom, "no args", "os_type") {|x| x == "hvm"} end newdom.destroy # TESTGROUP: dom.max_memory newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "max_memory", 1) expect_success(newdom, "no args", "max_memory") {|x| x == 1048576} newdom.destroy # TESTGROUP: dom.max_memory= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "max_memory=", 1, 2) expect_too_few_args(newdom, "max_memory=") expect_invalid_arg_type(newdom, "max_memory=", 'foo') expect_success(newdom, "memory arg", "max_memory=", 200000) newdom.undefine # TESTGROUP: dom.memory= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "memory=", 1, 2) expect_too_many_args(newdom, "memory=", [1, 2, 3]) expect_too_few_args(newdom, "memory=") expect_too_few_args(newdom, "memory=", []) expect_invalid_arg_type(newdom, "memory=", 'foo') expect_fail(newdom, Libvirt::Error, "shutoff domain", "memory=", [2, Libvirt::Domain::AFFECT_LIVE]) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_success(newdom, "number arg", "memory=", 200000) newdom.destroy # TESTGROUP: dom.max_vcpus newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "max_vcpus", 1) expect_success(newdom, "no args", "max_vcpus") newdom.destroy # TESTGROUP: dom.vcpus= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "vcpus=", 1, 2) expect_too_many_args(newdom, "vcpus=", [0, 1, 2]) expect_too_few_args(newdom, "vcpus=") expect_too_few_args(newdom, "vcpus=", []) expect_invalid_arg_type(newdom, "vcpus=", 'foo') expect_fail(newdom, Libvirt::Error, "shutoff domain", "vcpus=", [2, Libvirt::Domain::AFFECT_LIVE]) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_success(newdom, "number arg", "vcpus=", 2) newdom.destroy # TESTGROUP: dom.pin_vcpu newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "pin_vcpu", 1, 2, 3, 4) expect_too_few_args(newdom, "pin_vcpu") expect_invalid_arg_type(newdom, "pin_vcpu", 'foo', [0]) expect_invalid_arg_type(newdom, "pin_vcpu", 0, 1) expect_success(newdom, "cpu args", "pin_vcpu", 0, [0]) newdom.destroy # TESTGROUP: dom.xml_desc newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "xml_desc", 1, 2) expect_invalid_arg_type(newdom, "xml_desc", "foo") expect_success(newdom, "no args", "xml_desc") newdom.destroy # TESTGROUP: dom.undefine newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "undefine", 1, 2) expect_success(newdom, "no args", "undefine") # TESTGROUP: dom.create newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "create", 1, 2) expect_invalid_arg_type(newdom, "create", "foo") expect_success(newdom, "no args", "create") expect_fail(newdom, Libvirt::Error, "on already running domain", "create") newdom.destroy newdom.undefine # TESTGROUP: dom.autostart? newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "autostart?", 1) expect_success(newdom, "no args", "autostart?") {|x| x == false} newdom.autostart = true expect_success(newdom, "no args", "autostart?") {|x| x == true} newdom.undefine # TESTGROUP: dom.autostart= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "autostart=", 1, 2) expect_invalid_arg_type(newdom, "autostart=", 'foo') expect_invalid_arg_type(newdom, "autostart=", nil) expect_invalid_arg_type(newdom, "autostart=", 1234) expect_success(newdom, "true arg", "autostart=", true) if not newdom.autostart? puts_fail "domain.autostart= did not set autostart to true" else puts_ok "domain.autostart= set autostart to true" end expect_success(newdom, "false arg", "autostart=", false) if newdom.autostart? puts_fail "domain.autostart= did not set autostart to false" else puts_ok "domain.autostart= set autostart to false" end newdom.undefine # TESTGROUP: dom.attach_device newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "attach_device", 1, 2, 3) expect_too_few_args(newdom, "attach_device") expect_invalid_arg_type(newdom, "attach_device", 1) expect_invalid_arg_type(newdom, "attach_device", 'foo', 'bar') expect_fail(newdom, Libvirt::Error, "invalid XML", "attach_device", "hello") expect_fail(newdom, Libvirt::Error, "shut off domain", "attach_device", new_hostdev_xml) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 #expect_success(newdom, "hostdev XML", "attach_device", new_hostdev_xml) newdom.destroy # TESTGROUP: dom.detach_device newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "detach_device", 1, 2, 3) expect_too_few_args(newdom, "detach_device") expect_invalid_arg_type(newdom, "detach_device", 1) expect_invalid_arg_type(newdom, "detach_device", 'foo', 'bar') expect_fail(newdom, Libvirt::Error, "invalid XML", "detach_device", "hello") expect_fail(newdom, Libvirt::Error, "shut off domain", "detach_device", new_hostdev_xml) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 #expect_success(newdom, "hostdev XML", "detach_device", new_hostdev_xml) newdom.destroy # TESTGROUP: dom.update_device newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "update_device", 1, 2, 3) expect_too_few_args(newdom, "update_device") expect_invalid_arg_type(newdom, "update_device", 1) expect_invalid_arg_type(newdom, "update_device", 'foo', 'bar') expect_fail(newdom, Libvirt::Error, "invalid XML", "update_device", "hello") expect_fail(newdom, Libvirt::Error, "shut off domain", "update_device", new_hostdev_xml) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 #expect_success(newdom, "hostdev XML", "update_device", new_hostdev_xml) newdom.destroy # TESTGROUP: dom.free newdom = conn.define_domain_xml($new_dom_xml) newdom.undefine expect_too_many_args(newdom, "free", 1) expect_success(newdom, "free", "free") # TESTGROUP: dom.snapshot_create_xml newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "snapshot_create_xml", 1, 2, 3) expect_too_few_args(newdom, "snapshot_create_xml") expect_invalid_arg_type(newdom, "snapshot_create_xml", 1) expect_invalid_arg_type(newdom, "snapshot_create_xml", nil) expect_invalid_arg_type(newdom, "snapshot_create_xml", 'foo', 'bar') expect_success(newdom, "simple XML arg", "snapshot_create_xml", "") snaps = newdom.num_of_snapshots if snaps != 1 puts_fail "domain.snapshot_create_xml after one snapshot has #{snaps} snapshots" else puts_ok "domain.snapshot_create_xml after one snapshot has 1 snapshot" end newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.num_of_snapshots newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "num_of_snapshots", 1, 2) expect_invalid_arg_type(newdom, "num_of_snapshots", 'foo') expect_success(newdom, "no args", "num_of_snapshots") {|x| x == 0} newdom.snapshot_create_xml("") expect_success(newdom, "no args", "num_of_snapshots") {|x| x == 1} newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.list_snapshots newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "list_snapshots", 1, 2) expect_invalid_arg_type(newdom, "list_snapshots", 'foo') expect_success(newdom, "no args", "list_snapshots") {|x| x.length == 0} newdom.snapshot_create_xml("") expect_success(newdom, "no args", "list_snapshots") {|x| x.length == 1} newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.lookup_snapshot_by_name newdom = conn.define_domain_xml($new_dom_xml) newdom.snapshot_create_xml("foo") expect_too_many_args(newdom, "lookup_snapshot_by_name", 1, 2, 3) expect_too_few_args(newdom, "lookup_snapshot_by_name") expect_invalid_arg_type(newdom, "lookup_snapshot_by_name", 1) expect_invalid_arg_type(newdom, "lookup_snapshot_by_name", 'foo', 'bar') expect_utf8_exception_msg(newdom, Libvirt::RetrieveError, "lookup_snapshot_by_name", "__non_existing_snapshot") expect_success(newdom, "name arg", "lookup_snapshot_by_name", "foo") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.has_current_snapshot? newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "has_current_snapshot?", 1, 2) expect_invalid_arg_type(newdom, "has_current_snapshot?", 'foo') expect_success(newdom, "no args", "has_current_snapshot?") {|x| x == false} newdom.snapshot_create_xml("foo") expect_success(newdom, "no args", "has_current_snapshot?") {|x| x == true} newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.revert_to_snapshot newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "revert_to_snapshot", 1, 2, 3) expect_too_few_args(newdom, "revert_to_snapshot") expect_invalid_arg_type(newdom, "revert_to_snapshot", 1) expect_invalid_arg_type(newdom, "revert_to_snapshot", nil) expect_invalid_arg_type(newdom, "revert_to_snapshot", 'foo') snap = newdom.snapshot_create_xml("foo") test_sleep 1 expect_invalid_arg_type(newdom, "revert_to_snapshot", snap, 'foo') expect_success(newdom, "snapshot arg", "revert_to_snapshot", snap) newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.current_snapshot newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "current_snapshot", 1, 2) expect_invalid_arg_type(newdom, "current_snapshot", 'foo') expect_fail(newdom, Libvirt::RetrieveError, "with no snapshots", "current_snapshot") newdom.snapshot_create_xml("foo") expect_success(newdom, "no args", "current_snapshot") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) # TESTGROUP: dom.job_info if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "job_info", 1) expect_fail(newdom, Libvirt::RetrieveError, "shutoff domain", "job_info") newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_success(newdom, "no args", "job_info") newdom.destroy end # TESTGROUP: dom.abort_job newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "abort_job", 1) expect_fail(newdom, Libvirt::Error, "not running domain", "abort_job") newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_fail(newdom, Libvirt::Error, "no active job", "abort_job") # FIXME: need to start long running job here #expect_success(newdom, "no args", "abort_job") newdom.destroy # TESTGROUP: dom.scheduler_type newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "scheduler_type", 1) expect_success(newdom, "no args", "scheduler_type") newdom.undefine # TESTGROUP: dom.scheduler_parameters newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "scheduler_parameters", 1, 1) expect_success(newdom, "no args", "scheduler_parameters") newdom.undefine # TESTGROUP: dom.scheduler_parameters= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "scheduler_parameters=", 1, 2) expect_too_few_args(newdom, "scheduler_parameters=") expect_invalid_arg_type(newdom, "scheduler_parameters=", 0) if !test_default_uri? expect_success(newdom, "cpu shares arg", "scheduler_parameters=", {"cpu_shares" => 512}) end newdom.undefine # TESTGROUP: dom.qemu_monitor_command if !test_default_uri? newdom = conn.create_domain_xml($new_dom_xml) expect_too_many_args(newdom, "qemu_monitor_command", 1, 2, 3) expect_too_few_args(newdom, "qemu_monitor_command") expect_invalid_arg_type(newdom, "qemu_monitor_command", 1) expect_invalid_arg_type(newdom, "qemu_monitor_command", "foo", "bar") expect_fail(newdom, Libvirt::RetrieveError, "invalid command", "qemu_monitor_command", "foo") expect_success(newdom, "monitor command", "qemu_monitor_command", '{"execute":"query-cpus"}') newdom.destroy end # TESTGROUP: dom.num_vcpus newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "num_vcpus", 1, 2) expect_too_few_args(newdom, "num_vcpus") expect_invalid_arg_type(newdom, "num_vcpus", 'foo') expect_fail(newdom, Libvirt::Error, "active flag on shutoff domain", "num_vcpus", Libvirt::Domain::VCPU_LIVE) expect_fail(newdom, Libvirt::Error, "live and config flags", "num_vcpus", Libvirt::Domain::VCPU_LIVE | Libvirt::Domain::VCPU_CONFIG) expect_success(newdom, "config flag", "num_vcpus", Libvirt::Domain::VCPU_CONFIG) {|x| x == 2} newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_fail(newdom, Libvirt::RetrieveError, "config flag on transient domain", "num_vcpus", Libvirt::Domain::VCPU_CONFIG) expect_success(newdom, "live flag on transient domain", "num_vcpus", Libvirt::Domain::VCPU_LIVE) newdom.destroy # TESTGROUP: dom.vcpus_flags= # dom.vcpus_flags= is deprecated in favor of dom.vcpus=, so we don't do any # tests here for it # TESTGROUP: dom.memory_parameters= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "memory_parameters=", 1, 2, 3) expect_too_many_args(newdom, "memory_parameters=", [1, 2, 3]) expect_too_few_args(newdom, "memory_parameters=") expect_too_few_args(newdom, "memory_parameters=", []) expect_invalid_arg_type(newdom, "memory_parameters=", 0) expect_invalid_arg_type(newdom, "memory_parameters=", [1, 0]) expect_invalid_arg_type(newdom, "memory_parameters=", [{}, "foo"]) expect_success(newdom, "soft and hard limit", "memory_parameters=", {"soft_limit" => 9007199254740999, "swap_hard_limit" => 9007199254740999}) newdom.undefine # TESTGROUP: dom.memory_parameters newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "memory_parameters", 1, 2) expect_success(newdom, "no args", "memory_parameters") newdom.undefine # TESTGROUP: dom.blkio_parameters= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "blkio_parameters=", 1, 2, 3) expect_too_many_args(newdom, "blkio_parameters=", [1, 2, 3]) expect_too_few_args(newdom, "blkio_parameters=") expect_too_few_args(newdom, "blkio_parameters=", []) expect_invalid_arg_type(newdom, "blkio_parameters=", 0) expect_invalid_arg_type(newdom, "blkio_parameters=", [1, 0]) expect_invalid_arg_type(newdom, "blkio_parameters=", [{}, "foo"]) expect_success(newdom, "hash", "blkio_parameters=", {"weight" => 100}) newdom.undefine # TESTGROUP: dom.blkio_parameters newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "blkio_parameters", 1, 2) expect_success(newdom, "no args", "blkio_parameters") newdom.undefine # TESTGROUP: dom.open_console newdom = conn.create_domain_xml($new_dom_xml) stream = conn.stream expect_too_many_args(newdom, "open_console", 1, 2, 3, 4) expect_too_few_args(newdom, "open_console") expect_too_few_args(newdom, "open_console", 1) expect_invalid_arg_type(newdom, "open_console", 1, stream) expect_invalid_arg_type(newdom, "open_console", "pty", 1) expect_invalid_arg_type(newdom, "open_console", "pty", stream, "wow") #expect_success(newdom, "device and stream args", "open_console", "pty", stream) newdom.destroy # TESTGROUP: dom.block_rebase newdom = conn.create_domain_xml($new_dom_xml) expect_too_many_args(newdom, "block_rebase", 1, 2, 3, 4, 5) expect_too_few_args(newdom, "block_rebase") expect_invalid_arg_type(newdom, "block_rebase", 1) expect_invalid_arg_type(newdom, "block_rebase", "foo", 1) expect_invalid_arg_type(newdom, "block_rebase", "foo", "bar", "baz") expect_invalid_arg_type(newdom, "block_rebase", "foo", "bar", 1, "boom") # FIXME: I don't know how to make block_rebase work #expect_success(newdom, "disk", "block_rebase", diskname) newdom.destroy # TESTGROUP: dom.migrate_max_downtime= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "migrate_max_downtime=", 1, 2) expect_too_many_args(newdom, "migrate_max_downtime=", [1, 2, 3]) expect_too_few_args(newdom, "migrate_max_downtime=") expect_too_few_args(newdom, "migrate_max_downtime=", []) expect_invalid_arg_type(newdom, "migrate_max_downtime=", 'foo') expect_invalid_arg_type(newdom, "migrate_max_downtime=", nil) expect_fail(newdom, Libvirt::Error, "on off domain", "migrate_max_downtime=", 10) expect_fail(newdom, Libvirt::Error, "on off domain, two args", "migrate_max_downtime=", [10, 10]) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 #expect_fail(newdom, Libvirt::Error, "while no migration in progress", "migrate_max_downtime=", 10) # FIXME: get this working #newdom.migrate_to_uri("qemu://remote/system") #expect_success(newdom, "10 second downtime", "migrate_max_downtime=", 10) newdom.destroy # TESTGROUP: dom.migrate_max_speed= newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "migrate_max_speed=", 1, 2) expect_too_many_args(newdom, "migrate_max_speed=", [1, 2, 3]) expect_too_few_args(newdom, "migrate_max_speed=") expect_too_few_args(newdom, "migrate_max_speed=", []) expect_invalid_arg_type(newdom, "migrate_max_speed=", 'foo') expect_invalid_arg_type(newdom, "migrate_max_speed=", nil) expect_invalid_arg_type(newdom, "migrate_max_speed=", ['foo', 1]) expect_invalid_arg_type(newdom, "migrate_max_speed=", [1, 'foo']) #expect_success(newdom, "Bandwidth arg", "migrate_max_speed=", 5) newdom.destroy # TESTGROUP: dom.state newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "state", 1, 2) expect_invalid_arg_type(newdom, "state", 'foo') expect_success(newdom, "no arg", "state") newdom.destroy # TESTGROUP: dom.screenshot newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 stream = conn.stream expect_too_many_args(newdom, "screenshot", 1, 2, 3, 4) expect_too_few_args(newdom, "screenshot") expect_too_few_args(newdom, "screenshot", stream) expect_invalid_arg_type(newdom, "screenshot", 1, 0) expect_invalid_arg_type(newdom, "screenshot", nil, 0) expect_invalid_arg_type(newdom, "screenshot", stream, nil) expect_invalid_arg_type(newdom, "screenshot", stream, 'foo') expect_invalid_arg_type(newdom, "screenshot", stream, 0, 'foo') expect_success(newdom, "stream and screen arg", "screenshot", stream, 0) newdom.destroy # TESTGROUP: dom.vcpus_flags= newdom = conn.define_domain_xml($new_dom_xml) expect_too_many_args(newdom, "vcpus_flags=", 1, 2) expect_too_many_args(newdom, "vcpus_flags=", [0, 1, 2]) expect_too_few_args(newdom, "vcpus_flags=") expect_too_few_args(newdom, "vcpus_flags=", []) expect_invalid_arg_type(newdom, "vcpus_flags=", 'foo') expect_fail(newdom, Libvirt::Error, "shutoff domain", "vcpus_flags=", [2, Libvirt::Domain::AFFECT_LIVE]) newdom.undefine newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_success(newdom, "number arg", "vcpus_flags=", 2) newdom.destroy # TESTGROUP: domain.list_all_snapshots newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") expect_too_many_args(newdom, "list_all_snapshots", 1, 2) expect_invalid_arg_type(newdom, "list_all_snapshots", 'foo') expect_success(newdom, "no args", "list_all_snapshots") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 # TESTGROUP: domain.open_graphics newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(newdom, "open_graphics", 1, 2, 3, 4) expect_too_few_args(newdom, "open_graphics") expect_invalid_arg_type(newdom, "open_graphics", nil) expect_invalid_arg_type(newdom, "open_graphics", 'foo') expect_invalid_arg_type(newdom, "open_graphics", []) expect_invalid_arg_type(newdom, "open_graphics", {}) expect_invalid_arg_type(newdom, "open_graphics", 4, 'foo') expect_invalid_arg_type(newdom, "open_graphics", 4, []) expect_invalid_arg_type(newdom, "open_graphics", 4, {}) expect_invalid_arg_type(newdom, "open_graphics", 4, 0, 'foo') expect_invalid_arg_type(newdom, "open_graphics", 4, 0, []) expect_invalid_arg_type(newdom, "open_graphics", 4, 0, {}) #expect_success(newdom, "fd arg", "open_graphics", fd) set_test_object("snapshot") # TESTGROUP: snapshot.xml_desc newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") expect_too_many_args(snap, "xml_desc", 1, 2) expect_invalid_arg_type(snap, "xml_desc", 'foo') expect_success(newdom, "no args", "xml_desc") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 # TESTGROUP: snapshot.delete if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") expect_too_many_args(snap, "delete", 1, 2) expect_invalid_arg_type(snap, "delete", 'foo') expect_success(snap, "no args", "delete") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 end # TESTGROUP: snapshot.name if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") expect_too_many_args(snap, "name", 1) expect_success(snap, "no args", "name") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 end # TESTGROUP: snapshot.num_children if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") expect_too_many_args(snap, "num_children", 1, 2) expect_success(snap, "no args, no children", "num_children") {|x| x == 0} newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 end # TESTGROUP: snapshot.list_children_names if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") expect_too_many_args(snap, "list_children_names", 1, 2) expect_success(snap, "no args, no children", "num_children") {|x| x == 0} newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 end # TESTGROUP: snapshot.free if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") expect_too_many_args(snap, "free", 1) expect_success(snap, "no args", "free") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 end # TESTGROUP: snapshot.has_metadata? if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") expect_too_many_args(snap, "has_metadata?", 1, 2) expect_invalid_arg_type(snap, "has_metadata?", "foo") expect_success(snap, "no args", "has_metadata?") {|x| x == true} newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 end # TESTGROUP: snapshot.list_children_names if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("snap") snap2 = newdom.snapshot_create_xml("snap2") expect_too_many_args(snap, "list_children_names", 1, 2) expect_invalid_arg_type(snap, "list_children_names", "foo") expect_invalid_arg_type(snap, "list_children_names", []) expect_invalid_arg_type(snap, "list_children_names", {}) expect_success(snap, "no args", "list_children_names") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 end # TESTGROUP: snapshot.list_all_children if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") expect_too_many_args(snap, "list_all_children", 1, 2) expect_invalid_arg_type(snap, "list_all_children", "foo") expect_invalid_arg_type(snap, "list_all_children", []) expect_invalid_arg_type(snap, "list_all_children", {}) expect_success(snap, "no args", "list_all_children") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 end # TESTGROUP: snapshot.parent if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") test_sleep 1 snap2 = newdom.snapshot_create_xml("") expect_too_many_args(snap2, "parent", 1, 2) expect_invalid_arg_type(snap2, "parent", "foo") expect_invalid_arg_type(snap2, "parent", []) expect_invalid_arg_type(snap2, "parent", {}) expect_success(snap2, "no args", "parent") expect_success(snap, "no args", "parent") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 end # TESTGROUP: snapshot.current? if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) snap = newdom.snapshot_create_xml("") expect_too_many_args(snap, "current?", 1, 2) expect_invalid_arg_type(snap, "current?", "foo") expect_invalid_arg_type(snap, "current?", []) expect_invalid_arg_type(snap, "current?", {}) expect_success(snap, "no args", "current?") newdom.undefine(Libvirt::Domain::UNDEFINE_SNAPSHOTS_METADATA) test_sleep 1 end # END TESTS conn.close finish_tests ruby-libvirt-0.8.4/tests/test_storage.rb0000644000175000017500000003734414567114130020512 0ustar abolognaabologna#!/usr/bin/ruby # Test the storage methods the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("storage_pool") conn = Libvirt::open(URI) begin oldpool = conn.lookup_storage_pool_by_name("rb-libvirt-test") oldpool.destroy oldpool.undefine rescue # in case we didn't find it, don't do anything end # test setup if !test_default_uri? `rm -rf #{$POOL_PATH}; mkdir -p #{$POOL_PATH} ; echo $?` end new_storage_vol_xml = < test.img 0 1 /tmp/rb-libvirt-test/test.img EOF new_storage_vol_xml_2 = < test2.img 0 5 /tmp/rb-libvirt-test/test2.img EOF # TESTGROUP: vol.pool newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newvol, "pool", 1) expect_success(newvol, "no args", "pool") newvol.delete newpool.destroy # TESTGROUP: pool.build newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "build", 1, 2) expect_invalid_arg_type(newpool, "build", 'foo') expect_success(newpool, "no args", "build") newpool.undefine # TESTGROUP: pool.undefine newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "undefine", 1) expect_success(newpool, "no args", "undefine") # TESTGROUP: pool.create newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "create", 1, 2) expect_invalid_arg_type(newpool, "create", 'foo') expect_success(newpool, "no args", "create") newpool.destroy newpool.undefine # TESTGROUP: pool.destroy newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "destroy", 1) expect_success(newpool, "no args", "destroy") # TESTGROUP: pool.delete newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "delete", 1, 2) expect_invalid_arg_type(newpool, "delete", 'foo') expect_success(newpool, "no args", "delete") if !test_default_uri? `mkdir -p /tmp/rb-libvirt-test` end newpool.undefine if !test_default_uri? `mkdir -p #{$POOL_PATH}` end # TESTGROUP: pool.refresh newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "refresh", 1, 2) expect_invalid_arg_type(newpool, "refresh", 'foo') expect_success(newpool, "no args", "refresh") newpool.destroy # TESTGROUP: pool.name newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "name", 1) expect_success(newpool, "no args", "name") {|x| x == "rb-libvirt-test"} newpool.destroy # TESTGROUP: pool.uuid newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "uuid", 1) expect_success(newpool, "no args", "uuid") {|x| x == $POOL_UUID} newpool.destroy # TESTGROUP: pool.info newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "info", 1) expect_success(newpool, "no args", "info") newpool.destroy # TESTGROUP: pool.xml_desc newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "xml_desc", 1, 2) expect_invalid_arg_type(newpool, "xml_desc", "foo") expect_success(newpool, "no args", "xml_desc") newpool.destroy # TESTGROUP: pool.autostart? newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "autostart?", 1) expect_success(newpool, "no args", "autostart?") {|x| x == false} newpool.autostart = true expect_success(newpool, "no args", "autostart?") {|x| x == true} newpool.undefine # TESTGROUP: pool.autostart= newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "autostart=", 1, 2) expect_invalid_arg_type(newpool, "autostart=", 'foo') expect_invalid_arg_type(newpool, "autostart=", nil) expect_invalid_arg_type(newpool, "autostart=", 1234) expect_success(newpool, "no args", "autostart=", true) if not newpool.autostart? puts_fail "storage_pool.autostart= did not set autostart to true" else puts_ok "storage_pool.autostart= set autostart to true" end expect_success(newpool, "no args", "autostart=", false) if newpool.autostart? puts_fail "storage_pool.autostart= did not set autostart to false" else puts_ok "storage_pool.autostart= set autostart to false" end newpool.undefine # TESTGROUP: pool.num_of_volumes newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "num_of_volumes", 1) expect_success(newpool, "no args", "num_of_volumes") {|x| x == 0} newpool.destroy # TESTGROUP: pool.list_volumes newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "list_volumes", 1) expect_success(newpool, "no args", "list_volumes") newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_success(newpool, "no args", "list_volumes") newvol.delete newpool.destroy # TESTGROUP: pool.free newpool = conn.define_storage_pool_xml($new_storage_pool_xml) newpool.undefine expect_too_many_args(newpool, "free", 1) expect_success(newpool, "no args", "free") # TESTGROUP: pool.lookup_volume_by_name newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newpool, "lookup_volume_by_name", 1, 2) expect_too_few_args(newpool, "lookup_volume_by_name") expect_invalid_arg_type(newpool, "lookup_volume_by_name", 1); expect_invalid_arg_type(newpool, "lookup_volume_by_name", nil); expect_fail(newpool, Libvirt::RetrieveError, "non-existent name arg", "lookup_volume_by_name", "foobarbazsucker") expect_success(newpool, "name arg", "lookup_volume_by_name", "test.img") newvol.delete newpool.destroy # TESTGROUP: pool.lookup_volume_by_key newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newpool, "lookup_volume_by_key", 1, 2) expect_too_few_args(newpool, "lookup_volume_by_key") expect_invalid_arg_type(newpool, "lookup_volume_by_key", 1); expect_invalid_arg_type(newpool, "lookup_volume_by_key", nil); expect_fail(newpool, Libvirt::RetrieveError, "non-existent key arg", "lookup_volume_by_key", "foobarbazsucker") expect_success(newpool, "name arg", "lookup_volume_by_key", newvol.key) newvol.delete newpool.destroy # TESTGROUP: pool.lookup_volume_by_path newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newpool, "lookup_volume_by_path", 1, 2) expect_too_few_args(newpool, "lookup_volume_by_path") expect_invalid_arg_type(newpool, "lookup_volume_by_path", 1); expect_invalid_arg_type(newpool, "lookup_volume_by_path", nil); expect_fail(newpool, Libvirt::RetrieveError, "non-existent path arg", "lookup_volume_by_path", "foobarbazsucker") expect_success(newpool, "name arg", "lookup_volume_by_path", newvol.path) newvol.delete newpool.destroy # TESTGROUP: pool.create_volume_xml newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "create_volume_xml", new_storage_vol_xml, 0, 1) expect_too_few_args(newpool, "create_volume_xml") expect_invalid_arg_type(newpool, "create_volume_xml", nil) expect_invalid_arg_type(newpool, "create_volume_xml", 1) expect_invalid_arg_type(newpool, "create_volume_xml", new_storage_vol_xml, "foo") expect_fail(newpool, Libvirt::Error, "invalid xml", "create_volume_xml", "hello") expect_success(newpool, "storage volume XML", "create_volume_xml", new_storage_vol_xml) expect_fail(newpool, Libvirt::Error, "already existing domain", "create_volume_xml", new_storage_vol_xml) newvol.delete newpool.destroy # TESTGROUP: pool.create_volume_xml_from newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newpool, "create_volume_xml_from", new_storage_vol_xml_2, 0, 1, 2) expect_too_few_args(newpool, "create_volume_xml_from") expect_invalid_arg_type(newpool, "create_volume_xml_from", 1, 2) expect_invalid_arg_type(newpool, "create_volume_xml_from", "foo", 2) expect_invalid_arg_type(newpool, "create_volume_xml_from", "foo", newvol, "bar") expect_fail(newpool, Libvirt::Error, "invalid xml", "create_volume_xml_from", "hello", newvol) newvol2 = expect_success(newpool, "storage volume XML", "create_volume_xml_from", new_storage_vol_xml_2, newvol) expect_fail(newpool, Libvirt::Error, "already existing domain", "create_volume_xml_from", new_storage_vol_xml_2, newvol) newvol2.delete newvol.delete newpool.destroy # TESTGROUP: pool.active? newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(newpool, "active?", 1) expect_success(newpool, "no args", "active?") {|x| x == true} newpool.destroy newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_success(newpool, "no args", "active?") {|x| x == false} newpool.create expect_success(newpool, "no args", "active?") {|x| x == true} newpool.destroy newpool.undefine # TESTGROUP: pool.persistent? newpool = conn.create_storage_pool_xml($new_storage_pool_xml) test_sleep 1 expect_too_many_args(newpool, "persistent?", 1) expect_success(newpool, "no args", "persistent?") {|x| x == false} newpool.destroy newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_success(newpool, "no args", "persistent?") {|x| x == true} newpool.undefine # TESTGROUP: newpool = conn.create_storage_pool_xml($new_storage_pool_xml) test_sleep 1 expect_too_many_args(newpool, "list_all_volumes", 1, 2) expect_invalid_arg_type(newpool, "list_all_volumes", 'foo') expect_invalid_arg_type(newpool, "list_all_volumes", []) expect_invalid_arg_type(newpool, "list_all_volumes", {}) expect_success(newpool, "no args", "list_all_volumes") newpool.destroy set_test_object("storage_volume") # TESTGROUP: vol.name newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newvol, "name", 1) expect_success(newvol, "no args", "name") newvol.delete newpool.destroy # TESTGROUP: vol.key newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newvol, "key", 1) expect_success(newvol, "no args", "key") newvol.delete newpool.destroy # TESTGROUP: vol.delete newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newvol, "delete", 1, 2) expect_invalid_arg_type(newvol, "delete", 'foo') expect_success(newvol, "no args", "delete") newpool.destroy # TESTGROUP: vol.wipe if !test_default_uri? newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newvol, "wipe", 1, 2) expect_invalid_arg_type(newvol, "wipe", 'foo') expect_success(newvol, "no args", "wipe") newvol.delete newpool.destroy end # TESTGROUP: vol.info newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newvol, "info", 1) expect_success(newvol, "no args", "info") newvol.delete newpool.destroy # TESTGROUP: vol.xml_desc newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newvol, "xml_desc", 1, 2) expect_invalid_arg_type(newvol, "xml_desc", "foo") expect_success(newvol, "no args", "xml_desc") newvol.delete newpool.destroy # TESTGROUP: vol.path newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newvol, "path", 1) expect_success(newvol, "no args", "path") newvol.delete newpool.destroy # TESTGROUP: vol.free newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) newvol.delete expect_too_many_args(newvol, "free", 1) expect_success(newvol, "no args", "free") newpool.destroy # TESTGROUP: vol.download if !test_default_uri? newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) stream = conn.stream expect_too_many_args(newvol, "download", 1, 2, 3, 4, 5) expect_too_few_args(newvol, "download") expect_too_few_args(newvol, "download", 1) expect_too_few_args(newvol, "download", 1, 2) expect_invalid_arg_type(newvol, "download", nil, 1, 1) expect_invalid_arg_type(newvol, "download", 'foo', 1, 1) expect_invalid_arg_type(newvol, "download", 1, 1, 1) expect_invalid_arg_type(newvol, "download", [], 1, 1) expect_invalid_arg_type(newvol, "download", {}, 1, 1) expect_invalid_arg_type(newvol, "download", stream, nil, 1) expect_invalid_arg_type(newvol, "download", stream, 'foo', 1) expect_invalid_arg_type(newvol, "download", stream, [], 1) expect_invalid_arg_type(newvol, "download", stream, {}, 1) expect_invalid_arg_type(newvol, "download", stream, 1, nil) expect_invalid_arg_type(newvol, "download", stream, 1, 'foo') expect_invalid_arg_type(newvol, "download", stream, 1, []) expect_invalid_arg_type(newvol, "download", stream, 1, {}) expect_invalid_arg_type(newvol, "download", stream, 1, 1, 'foo') expect_invalid_arg_type(newvol, "download", stream, 1, 1, []) expect_invalid_arg_type(newvol, "download", stream, 1, 1, {}) expect_success(newvol, "stream, offset, and length args", "download", stream, 0, 10) newvol.delete newpool.destroy end # TESTGROUP: vol.upload if !test_default_uri? newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) stream = conn.stream expect_too_many_args(newvol, "upload", 1, 2, 3, 4, 5) expect_too_few_args(newvol, "upload") expect_too_few_args(newvol, "upload", 1) expect_too_few_args(newvol, "upload", 1, 2) expect_invalid_arg_type(newvol, "upload", nil, 1, 1) expect_invalid_arg_type(newvol, "upload", 'foo', 1, 1) expect_invalid_arg_type(newvol, "upload", 1, 1, 1) expect_invalid_arg_type(newvol, "upload", [], 1, 1) expect_invalid_arg_type(newvol, "upload", {}, 1, 1) expect_invalid_arg_type(newvol, "upload", stream, nil, 1) expect_invalid_arg_type(newvol, "upload", stream, 'foo', 1) expect_invalid_arg_type(newvol, "upload", stream, [], 1) expect_invalid_arg_type(newvol, "upload", stream, {}, 1) expect_invalid_arg_type(newvol, "upload", stream, 1, nil) expect_invalid_arg_type(newvol, "upload", stream, 1, 'foo') expect_invalid_arg_type(newvol, "upload", stream, 1, []) expect_invalid_arg_type(newvol, "upload", stream, 1, {}) expect_invalid_arg_type(newvol, "upload", stream, 1, 1, 'foo') expect_invalid_arg_type(newvol, "upload", stream, 1, 1, []) expect_invalid_arg_type(newvol, "upload", stream, 1, 1, {}) expect_success(newvol, "stream, offset, and length args", "upload", stream, 0, 10) newvol.delete newpool.destroy end # TESTGROUP: vol.upload if !test_default_uri? newpool = conn.create_storage_pool_xml($new_storage_pool_xml) newvol = newpool.create_volume_xml(new_storage_vol_xml) expect_too_many_args(newvol, "wipe_pattern", 1, 2, 3) expect_too_few_args(newvol, "wipe_pattern") expect_invalid_arg_type(newvol, "wipe_pattern", nil) expect_invalid_arg_type(newvol, "wipe_pattern", 'foo') expect_invalid_arg_type(newvol, "wipe_pattern", []) expect_invalid_arg_type(newvol, "wipe_pattern", {}) expect_invalid_arg_type(newvol, "wipe_pattern", 0, 'foo') expect_invalid_arg_type(newvol, "wipe_pattern", 0, []) expect_invalid_arg_type(newvol, "wipe_pattern", 0, {}) expect_success(newvol, "alg arg", "wipe_pattern", Libvirt::StorageVol::WIPE_ALG_ZERO) newvol.delete newpool.destroy end # END TESTS conn.close finish_tests ruby-libvirt-0.8.4/tests/test_interface.rb0000644000175000017500000000444614567114130021003 0ustar abolognaabologna#!/usr/bin/ruby # Test the interface methods the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("interface") conn = Libvirt::open(URI) # test setup if !test_default_uri? begin `rm -f /etc/sysconfig/network-scripts/ifcfg-rb-libvirt-test` `brctl delbr rb-libvirt-test >& /dev/null` rescue end end # TESTGROUP: iface.undefine newiface = conn.define_interface_xml($new_interface_xml) expect_too_many_args(newiface, "undefine", 1) expect_success(newiface, "no args", "undefine") # TESTGROUP: iface.create newiface = conn.define_interface_xml($new_interface_xml) expect_too_many_args(newiface, "create", 1, 2) expect_invalid_arg_type(newiface, "create", 'foo') #expect_success(newiface, "no args", "create") #expect_fail(newiface, Libvirt::Error, "on already running interface", "create") #newiface.destroy newiface.undefine # TESTGROUP: iface.destroy newiface = conn.define_interface_xml($new_interface_xml) expect_too_many_args(newiface, "destroy", 1, 2) expect_invalid_arg_type(newiface, "destroy", 'foo') #expect_success(newiface, "no args", "destroy") newiface.undefine # TESTGROUP: iface.active? newiface = conn.define_interface_xml($new_interface_xml) expect_too_many_args(newiface, "active?", 1) expect_success(newiface, "no args", "active?") {|x| x == false} #newiface.create #expect_success(newiface, "no args", "active?") {|x| x == true} #newiface.destroy newiface.undefine # TESTGROUP: iface.name newiface = conn.define_interface_xml($new_interface_xml) expect_too_many_args(newiface, "name", 1) expect_success(newiface, "no args", "name") {|x| x == "rb-libvirt-test"} newiface.undefine # TESTGROUP: iface.mac testiface = find_valid_iface(conn) if not testiface.nil? expect_too_many_args(testiface, "mac", 1) expect_success(testiface, "no args", "mac") end # TESTGROUP: iface.xml_desc testiface = find_valid_iface(conn) if not testiface.nil? expect_too_many_args(testiface, "xml_desc", 1, 2) expect_invalid_arg_type(testiface, "xml_desc", "foo") expect_success(testiface, "no args", "xml_desc") end # TESTGROUP: iface.free newiface = conn.define_interface_xml($new_interface_xml) newiface.undefine expect_too_many_args(newiface, "free", 1) expect_success(newiface, "no args", "free") # END TESTS conn.close finish_tests ruby-libvirt-0.8.4/tests/test_nodedevice.rb0000644000175000017500000000476414567114130021153 0ustar abolognaabologna#!/usr/bin/ruby # Test the nodedevice methods the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("nodedevice") conn = Libvirt::open(URI) # TESTGROUP: nodedevice.name testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(testnode, "name", 1) expect_success(testnode, "no args", "name") # TESTGROUP: nodedevice.parent testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(testnode, "parent", 1) expect_success(testnode, "no args", "parent") # TESTGROUP: nodedevice.num_of_caps testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(testnode, "num_of_caps", 1) expect_success(testnode, "no args", "num_of_caps") # TESTGROUP: nodedevice.list_caps testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(testnode, "list_caps", 1) expect_success(testnode, "no args", "list_caps") # TESTGROUP: nodedevice.xml_desc testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(testnode, "xml_desc", 1, 2) expect_invalid_arg_type(testnode, "xml_desc", 'foo') expect_success(testnode, "no args", "xml_desc") # TESTGROUP: nodedevice.detach testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(testnode, "detach", 1, 2, 3) expect_invalid_arg_type(testnode, "detach", 1) expect_invalid_arg_type(testnode, "detach", []) expect_invalid_arg_type(testnode, "detach", {}) expect_invalid_arg_type(testnode, "detach", nil, 'foo') expect_invalid_arg_type(testnode, "detach", nil, []) expect_invalid_arg_type(testnode, "detach", nil, {}) #expect_success(testnode, "no args", "detach") # TESTGROUP: nodedevice.reattach testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(testnode, "reattach", 1) #expect_success(testnode, "no args", "reattach") # TESTGROUP: nodedevice.reset testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(testnode, "reset", 1) #expect_success(testnode, "no args", "reset") # TESTGROUP: nodedevice.destroy testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(testnode, "destroy", 1) #expect_success(testnode, "no args", "destroy") # TESTGROUP: nodedevice.free testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(testnode, "free", 1) expect_success(testnode, "no args", "free") # END TESTS conn.close finish_tests ruby-libvirt-0.8.4/tests/test_network.rb0000644000175000017500000000772314567114130020535 0ustar abolognaabologna#!/usr/bin/ruby # Test the network methods the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("network") conn = Libvirt::open(URI) cleanup_test_network(conn) # TESTGROUP: net.undefine newnet = conn.define_network_xml($new_net_xml) expect_too_many_args(newnet, "undefine", 1) expect_success(newnet, "no args", "undefine") # TESTGROUP: net.create newnet = conn.define_network_xml($new_net_xml) expect_too_many_args(newnet, "create", 1) expect_success(newnet, "no args", "create") expect_fail(newnet, Libvirt::Error, "on already running network", "create") newnet.destroy newnet.undefine # TESTGROUP: net.update newnet = conn.create_network_xml($new_net_xml) expect_too_few_args(newnet, "update", 1) command = Libvirt::Network::NETWORK_UPDATE_COMMAND_ADD_LAST section = Libvirt::Network::NETWORK_SECTION_IP_DHCP_HOST flags = Libvirt::Network::NETWORK_UPDATE_AFFECT_CURRENT expect_success(newnet, "dhcp ip", "update", command, section, -1, $new_network_dhcp_ip, flags) newnet.destroy # TESTGROUP: net.destroy newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(newnet, "destroy", 1) expect_success(newnet, "no args", "destroy") # TESTGROUP: net.name newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(newnet, "name", 1) expect_success(newnet, "no args", "name") {|x| x == "rb-libvirt-test"} newnet.destroy # TESTGROUP: net.uuid newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(newnet, "uuid", 1) expect_success(newnet, "no args", "uuid") {|x| x == $NETWORK_UUID} newnet.destroy # TESTGROUP: net.xml_desc newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(newnet, "xml_desc", 1, 2) expect_invalid_arg_type(newnet, "xml_desc", "foo") expect_success(newnet, "no args", "xml_desc") newnet.destroy # TESTGROUP: net.bridge_name newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(newnet, "bridge_name", 1) expect_success(newnet, "no args", "bridge_name") {|x| x == "rubybr0"} newnet.destroy # TESTGROUP: net.autostart? newnet = conn.define_network_xml($new_net_xml) expect_too_many_args(newnet, "autostart?", 1) expect_success(newnet, "no args", "autostart?") {|x| x == false} newnet.autostart = true expect_success(newnet, "no args", "autostart?") {|x| x == true} newnet.undefine # TESTGROUP: net.autostart= newnet = conn.define_network_xml($new_net_xml) expect_too_many_args(newnet, "autostart=", 1, 2) expect_invalid_arg_type(newnet, "autostart=", 'foo') expect_invalid_arg_type(newnet, "autostart=", nil) expect_invalid_arg_type(newnet, "autostart=", 1234) expect_success(newnet, "boolean arg", "autostart=", true) if not newnet.autostart? puts_fail "network.autostart= did not set autostart to true" else puts_ok "network.autostart= set autostart to true" end expect_success(newnet, "boolean arg", "autostart=", false) if newnet.autostart? puts_fail "network.autostart= did not set autostart to false" else puts_ok "network.autostart= set autostart to false" end newnet.undefine # TESTGROUP: net.free newnet = conn.define_network_xml($new_net_xml) newnet.undefine expect_too_many_args(newnet, "free", 1) expect_success(newnet, "no args", "free") # TESTGROUP: net.active? newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(newnet, "active?", 1) expect_success(newnet, "no args", "active?") {|x| x == true} newnet.destroy newnet = conn.define_network_xml($new_net_xml) expect_success(newnet, "no args", "active?") {|x| x == false} newnet.create expect_success(newnet, "no args", "active?") {|x| x == true} newnet.destroy newnet.undefine # TESTGROUP: net.persistent? newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(newnet, "persistent?", 1) expect_success(newnet, "no args", "persistent?") {|x| x == false} newnet.destroy newnet = conn.define_network_xml($new_net_xml) expect_success(newnet, "no args", "persistent?") {|x| x == true} newnet.undefine # END TESTS conn.close finish_tests ruby-libvirt-0.8.4/tests/test_conn.rb0000644000175000017500000007626714567114130020012 0ustar abolognaabologna#!/usr/bin/ruby # Test the conn methods the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("connect") conn = Libvirt::open(URI) cleanup_test_domain(conn) cleanup_test_network(conn) # test setup if !test_default_uri? begin `rm -f /etc/sysconfig/network-scripts/ifcfg-rb-libvirt-test` `brctl delbr rb-libvirt-test >& /dev/null` rescue end `qemu-img create -f qcow2 #{$GUEST_DISK} 5G` `rm -rf #{$POOL_PATH}; mkdir #{$POOL_PATH} ; echo $?` end cpu_xml = < x86_64 athlon EOF # TESTGROUP: conn.close conn2 = Libvirt::open(URI) expect_too_many_args(conn2, "close", 1) expect_success(conn2, "no args", "close") # TESTGROUP: conn.closed? conn2 = Libvirt::open(URI) expect_too_many_args(conn2, "closed?", 1) expect_success(conn2, "no args", "closed?") {|x| x == false } conn2.close expect_success(conn2, "no args", "closed?") {|x| x == true } # TESTGROUP: conn.type expect_too_many_args(conn, "type", 1) if test_default_uri? expect_success(conn, "no args", "type") {|x| x == "TEST"} else expect_success(conn, "no args", "type") {|x| x == "QEMU"} end # TESTGROUP: conn.version expect_too_many_args(conn, "version", 1) expect_success(conn, "no args", "version") # TESTGROUP: conn.libversion expect_too_many_args(conn, "libversion", 1) expect_success(conn, "no args", "libversion") # TESTGROUP: conn.hostname expect_too_many_args(conn, "hostname", 1) expect_success(conn, "no args", "hostname") # TESTGROUP: conn.uri expect_too_many_args(conn, "uri", 1) expect_success(conn, "no args", "uri") {|x| x == URI } # TESTGROUP: conn.max_vcpus expect_too_many_args(conn, "max_vcpus", 'kvm', 1) if !test_default_uri? expect_fail(conn, Libvirt::RetrieveError, "invalid arg", "max_vcpus", "foo") end expect_success(conn, "no args", "max_vcpus") expect_success(conn, "nil arg", "max_vcpus") expect_success(conn, "kvm arg", "max_vcpus") expect_success(conn, "qemu arg", "max_vcpus") # TESTGROUP: conn.node_get_info expect_too_many_args(conn, "node_get_info", 1) expect_success(conn, "no args", "node_get_info") # TESTGROUP: conn.node_free_memory expect_too_many_args(conn, "node_free_memory", 1) expect_success(conn, "no args", "node_free_memory") # TESTGROUP: conn.node_cells_free_memory expect_too_many_args(conn, "node_cells_free_memory", 1, 2, 3) expect_invalid_arg_type(conn, "node_cells_free_memory", 'start') expect_invalid_arg_type(conn, "node_cells_free_memory", 0, 'end') expect_success(conn, "no args", "node_cells_free_memory") expect_success(conn, "start cell", "node_cells_free_memory", 0) expect_success(conn, "start cell and max cells", "node_cells_free_memory", 0, 1) # TESTGROUP: conn.node_get_security_model expect_too_many_args(conn, "node_get_security_model", 1) expect_success(conn, "no args", "node_get_security_model") # TESTGROUP: conn.encrypted? expect_too_many_args(conn, "encrypted?", 1) expect_success(conn, "no args", "encrypted?") # TESTGROUP: conn.secure? expect_too_many_args(conn, "secure?", 1) expect_success(conn, "no args", "secure?") {|x| x == true} # TESTGROUP: conn.capabilities expect_too_many_args(conn, "capabilities", 1) expect_success(conn, "no args", "capabilities") # TESTGROUP: conn.compare_cpu if !test_default_uri? expect_too_many_args(conn, "compare_cpu", 1, 2, 3) expect_too_few_args(conn, "compare_cpu") expect_invalid_arg_type(conn, "compare_cpu", 1) expect_invalid_arg_type(conn, "compare_cpu", "hello", 'bar') expect_fail(conn, Libvirt::RetrieveError, "invalid XML", "compare_cpu", "hello") expect_success(conn, "CPU XML", "compare_cpu", cpu_xml) end # TESTGROUP: conn.baseline_cpu expect_too_many_args(conn, "baseline_cpu", 1, 2, 3) expect_too_few_args(conn, "baseline_cpu") expect_invalid_arg_type(conn, "baseline_cpu", 1) expect_invalid_arg_type(conn, "baseline_cpu", [cpu_xml], "foo") expect_fail(conn, ArgumentError, "empty array", "baseline_cpu", []) expect_success(conn, "CPU XML", "baseline_cpu", [cpu_xml]) # TESTGROUP: conn.domain_event_register_any dom_event_callback_proc = lambda {|connect, dom, event, detail, opaque| } # def dom_event_callback_symbol(conn, dom, event, detail, opaque) # end expect_too_many_args(conn, "domain_event_register_any", 1, 2, 3, 4, 5) expect_too_few_args(conn, "domain_event_register_any") expect_too_few_args(conn, "domain_event_register_any", 1) expect_invalid_arg_type(conn, "domain_event_register_any", "hello", 1) expect_invalid_arg_type(conn, "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, 1) expect_invalid_arg_type(conn, "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, 1) expect_fail(conn, ArgumentError, "invalid event ID", "domain_event_register_any", 456789, dom_event_callback_proc) # callbackID = expect_success(conn, "eventID and proc", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc) # conn.domain_event_deregister_any(callbackID) # callbackID = expect_success(conn, "eventID and symbol", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, :dom_event_callback_symbol) # conn.domain_event_deregister_any(callbackID) # callbackID = expect_success(conn, "eventID, proc, nil domain", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, nil) # conn.domain_event_deregister_any(callbackID) # callbackID = expect_success(conn, "eventID, proc, nil domain, opaque", "domain_event_register_any", Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc, nil, "opaque user data") # conn.domain_event_deregister_any(callbackID) # # TESTGROUP: conn.domain_event_deregister_any # dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque| # } # callbackID = conn.domain_event_register_any(Libvirt::Connect::DOMAIN_EVENT_ID_LIFECYCLE, dom_event_callback_proc) expect_too_many_args(conn, "domain_event_deregister_any", 1, 2) expect_too_few_args(conn, "domain_event_deregister_any") expect_invalid_arg_type(conn, "domain_event_deregister_any", "hello") # expect_success(conn, "callbackID", "domain_event_deregister_any", callbackID) # TESTGROUP: conn.domain_event_register # dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque| # } # def dom_event_callback_symbol(conn, dom, event, detail, opaque) # end expect_too_many_args(conn, "domain_event_register", 1, 2, 3) expect_too_few_args(conn, "domain_event_register") expect_invalid_arg_type(conn, "domain_event_register", "hello") # expect_success(conn, "proc", "domain_event_register", dom_event_callback_proc) # conn.domain_event_deregister # expect_success(conn, "symbol", "domain_event_register", :dom_event_callback_symbol) # conn.domain_event_deregister # expect_success(conn, "proc and opaque", "domain_event_register", dom_event_callback_proc, "opaque user data") # conn.domain_event_deregister # # TESTGROUP: conn.domain_event_deregister # dom_event_callback_proc = lambda {|conn, dom, event, detail, opaque| # } # conn.domain_event_register(dom_event_callback_proc) expect_too_many_args(conn, "domain_event_deregister", 1) # expect_success(conn, "no args", "domain_event_deregister") # TESTGROUP: conn.num_of_domains expect_too_many_args(conn, "num_of_domains", 1) expect_success(conn, "no args", "num_of_domains") # TESTGROUP: conn.list_domains expect_too_many_args(conn, "list_domains", 1) expect_success(conn, "no args", "list_domains") newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_success(conn, "no args", "list_domains") newdom.destroy # TESTGROUP: conn.num_of_defined_domains expect_too_many_args(conn, "num_of_defined_domains", 1) expect_success(conn, "no args", "num_of_defined_domains") # TESTGROUP: conn.list_defined_domains expect_too_many_args(conn, "list_defined_domains", 1) expect_success(conn, "no args", "list_defined_domains") # TESTGROUP: conn.create_domain_linux expect_too_many_args(conn, "create_domain_linux", $new_dom_xml, 0, 1) expect_too_few_args(conn, "create_domain_linux") expect_invalid_arg_type(conn, "create_domain_linux", nil) expect_invalid_arg_type(conn, "create_domain_linux", 1) expect_invalid_arg_type(conn, "create_domain_linux", $new_dom_xml, "foo") expect_fail(conn, Libvirt::Error, "invalid xml", "create_domain_linux", "hello") newdom = expect_success(conn, "domain xml", "create_domain_linux", $new_dom_xml) {|x| x.class == Libvirt::Domain} test_sleep 1 expect_fail(conn, Libvirt::Error, "already existing domain", "create_domain_linux", $new_dom_xml) newdom.destroy # TESTGROUP: conn.create_domain_xml expect_too_many_args(conn, "create_domain_xml", $new_dom_xml, 0, 1) expect_too_few_args(conn, "create_domain_xml") expect_invalid_arg_type(conn, "create_domain_xml", nil) expect_invalid_arg_type(conn, "create_domain_xml", 1) expect_invalid_arg_type(conn, "create_domain_xml", $new_dom_xml, "foo") expect_fail(conn, Libvirt::Error, "invalid xml", "create_domain_xml", "hello") newdom = expect_success(conn, "domain xml", "create_domain_xml", $new_dom_xml) {|x| x.class == Libvirt::Domain} test_sleep 1 expect_fail(conn, Libvirt::Error, "already existing domain", "create_domain_xml", $new_dom_xml) newdom.destroy # TESTGROUP: conn.lookup_domain_by_name newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(conn, "lookup_domain_by_name", 1, 2) expect_too_few_args(conn, "lookup_domain_by_name") expect_invalid_arg_type(conn, "lookup_domain_by_name", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_domain_by_name", "foobarbazsucker") expect_success(conn, "name arg for running domain", "lookup_domain_by_name", "rb-libvirt-test") {|x| x.name == "rb-libvirt-test"} newdom.destroy newdom = conn.define_domain_xml($new_dom_xml) expect_success(conn, "name arg for defined domain", "lookup_domain_by_name", "rb-libvirt-test") {|x| x.name == "rb-libvirt-test"} newdom.undefine # TESTGROUP: conn.lookup_domain_by_id newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(conn, "lookup_domain_by_id", 1, 2) expect_too_few_args(conn, "lookup_domain_by_id") expect_invalid_arg_type(conn, "lookup_domain_by_id", "foo") expect_fail(conn, Libvirt::Error, "with negative value", "lookup_domain_by_id", -1) expect_success(conn, "id arg for running domain", "lookup_domain_by_id", newdom.id) newdom.destroy # TESTGROUP: conn.lookup_domain_by_uuid newdom = conn.create_domain_xml($new_dom_xml) test_sleep 1 expect_too_many_args(conn, "lookup_domain_by_uuid", 1, 2) expect_too_few_args(conn, "lookup_domain_by_uuid") expect_invalid_arg_type(conn, "lookup_domain_by_uuid", 1) expect_fail(conn, Libvirt::RetrieveError, "invalid UUID", "lookup_domain_by_uuid", "abcd") expect_success(conn, "UUID arg for running domain", "lookup_domain_by_uuid", newdom.uuid) {|x| x.uuid == $GUEST_UUID} newdom.destroy newdom = conn.define_domain_xml($new_dom_xml) expect_success(conn, "UUID arg for defined domain", "lookup_domain_by_uuid", newdom.uuid) {|x| x.uuid == $GUEST_UUID} newdom.undefine # TESTGROUP: conn.define_domain_xml expect_too_many_args(conn, "define_domain_xml", 1, 2, 3) expect_too_few_args(conn, "define_domain_xml") expect_invalid_arg_type(conn, "define_domain_xml", 1) expect_invalid_arg_type(conn, "define_domain_xml", nil) expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_domain_xml", "hello") newdom = expect_success(conn, "domain xml arg", "define_domain_xml", $new_dom_xml) newdom.undefine # TESTGROUP: conn.num_of_interfaces expect_too_many_args(conn, "num_of_interfaces", 1) expect_success(conn, "no args", "num_of_interfaces") # TESTGROUP: conn.list_interfaces expect_too_many_args(conn, "list_interfaces", 1) expect_success(conn, "no args", "list_interfaces") # TESTGROUP: conn.num_of_defined_interfaces expect_too_many_args(conn, "num_of_defined_interfaces", 1) expect_success(conn, "no args", "num_of_defined_interfaces") # TESTGROUP: conn.list_defined_interfaces expect_too_many_args(conn, "list_defined_interfaces", 1) expect_success(conn, "no args", "list_defined_interfaces") # TESTGROUP: conn.lookup_interface_by_name newiface = conn.define_interface_xml($new_interface_xml) expect_too_many_args(conn, "lookup_interface_by_name", 1, 2) expect_too_few_args(conn, "lookup_interface_by_name") expect_invalid_arg_type(conn, "lookup_interface_by_name", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_interface_by_name", "foobarbazsucker") expect_success(conn, "name arg", "lookup_interface_by_name", "rb-libvirt-test") expect_success(conn, "name arg", "lookup_interface_by_name", "rb-libvirt-test") newiface.undefine # TESTGROUP: conn.lookup_interface_by_mac newiface = conn.define_interface_xml($new_interface_xml) expect_too_many_args(conn, "lookup_interface_by_mac", 1, 2) expect_too_few_args(conn, "lookup_interface_by_mac") expect_invalid_arg_type(conn, "lookup_interface_by_mac", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent mac arg", "lookup_interface_by_mac", "foobarbazsucker") # FIXME: we can't look up an interface by MAC address on an inactive interface, # but we also can't start up the interface without a /etc/sysconfig file. #expect_success(conn, "mac arg", "lookup_interface_by_mac", $NEW_INTERFACE_MAC) {|x| x.mac == $NEW_INTERFACE_MAC} newiface.undefine # TESTGROUP: conn.define_interface_xml expect_too_many_args(conn, "define_interface_xml", 1, 2, 3) expect_too_few_args(conn, "define_interface_xml") expect_invalid_arg_type(conn, "define_interface_xml", 1) expect_invalid_arg_type(conn, "define_interface_xml", nil) expect_invalid_arg_type(conn, "define_interface_xml", "hello", 'foo') expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_interface_xml", "hello") expect_success(conn, "interface XML", "define_interface_xml", $new_interface_xml) newiface.undefine # TESTGROUP: conn.num_of_networks expect_too_many_args(conn, "num_of_networks", 1) expect_success(conn, "no args", "num_of_networks") # TESTGROUP: conn.list_networks expect_too_many_args(conn, "list_networks", 1) expect_success(conn, "no args", "list_networks") # TESTGROUP: conn.num_of_defined_networks expect_too_many_args(conn, "num_of_defined_networks", 1) expect_success(conn, "no args", "num_of_defined_networks") # TESTGROUP: conn.list_defined_networks expect_too_many_args(conn, "list_defined_networks", 1) expect_success(conn, "no args", "list_defined_networks") # TESTGROUP: conn.lookup_network_by_name newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(conn, "lookup_network_by_name", 1, 2) expect_too_few_args(conn, "lookup_network_by_name") expect_invalid_arg_type(conn, "lookup_network_by_name", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_network_by_name", "foobarbazsucker") expect_success(conn, "name arg", "lookup_network_by_name", "rb-libvirt-test") newnet.destroy newnet = conn.define_network_xml($new_net_xml) expect_success(conn, "name arg", "lookup_network_by_name", "rb-libvirt-test") newnet.undefine # TESTGROUP: conn.lookup_network_by_uuid newnet = conn.create_network_xml($new_net_xml) expect_too_many_args(conn, "lookup_network_by_uuid", 1, 2) expect_too_few_args(conn, "lookup_network_by_uuid") expect_invalid_arg_type(conn, "lookup_network_by_uuid", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent uuid arg", "lookup_network_by_uuid", "foobarbazsucker") expect_success(conn, "uuid arg", "lookup_network_by_uuid", $NETWORK_UUID) newnet.destroy newnet = conn.define_network_xml($new_net_xml) expect_success(conn, "uuid arg", "lookup_network_by_uuid", $NETWORK_UUID) newnet.undefine # TESTGROUP: conn.create_network_xml expect_too_many_args(conn, "create_network_xml", $new_net_xml, 0) expect_too_few_args(conn, "create_network_xml") expect_invalid_arg_type(conn, "create_network_xml", nil) expect_invalid_arg_type(conn, "create_network_xml", 1) expect_fail(conn, Libvirt::Error, "invalid xml", "create_network_xml", "hello") newnet = expect_success(conn, "network XML", "create_network_xml", $new_net_xml) expect_fail(conn, Libvirt::Error, "already existing network", "create_network_xml", $new_net_xml) newnet.destroy # TESTGROUP: conn.define_network_xml expect_too_many_args(conn, "define_network_xml", 1, 2) expect_too_few_args(conn, "define_network_xml") expect_invalid_arg_type(conn, "define_network_xml", 1) expect_invalid_arg_type(conn, "define_network_xml", nil) expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_network_xml", "hello") newnet = expect_success(conn, "network XML", "define_network_xml", $new_net_xml) newnet.undefine # TESTGROUP: conn.num_of_nodedevices expect_too_many_args(conn, "num_of_nodedevices", 1, 2, 3) expect_invalid_arg_type(conn, "num_of_nodedevices", 1) expect_invalid_arg_type(conn, "num_of_nodedevices", 'foo', 'bar') expect_success(conn, "no args", "num_of_nodedevices") # TESTGROUP: conn.list_nodedevices expect_too_many_args(conn, "list_nodedevices", 1, 2, 3) expect_invalid_arg_type(conn, "list_nodedevices", 1) expect_invalid_arg_type(conn, "list_nodedevices", 'foo', 'bar') expect_success(conn, "no args", "list_nodedevices") # TESTGROUP: conn.lookup_nodedevice_by_name testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) expect_too_many_args(conn, "lookup_nodedevice_by_name", 1, 2) expect_too_few_args(conn, "lookup_nodedevice_by_name") expect_invalid_arg_type(conn, "lookup_nodedevice_by_name", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_nodedevice_by_name", "foobarbazsucker") expect_success(conn, "name arg", "lookup_nodedevice_by_name", testnode.name) # TESTGROUP: conn.create_nodedevice_xml expect_too_many_args(conn, "create_nodedevice_xml", 1, 2, 3) expect_too_few_args(conn, "create_nodedevice_xml") expect_invalid_arg_type(conn, "create_nodedevice_xml", 1) expect_invalid_arg_type(conn, "create_nodedevice_xml", "foo", 'bar') expect_fail(conn, Libvirt::Error, "invalid XML", "create_nodedevice_xml", "hello") #expect_success(conn, "nodedevice XML", "create_nodedevice_xml", "") # TESTGROUP: conn.num_of_nwfilters if !test_default_uri? expect_too_many_args(conn, "num_of_nwfilters", 1) expect_success(conn, "no args", "num_of_nwfilters") end # TESTGROUP: conn.list_nwfilters if !test_default_uri? expect_too_many_args(conn, "list_nwfilters", 1) expect_success(conn, "no args", "list_nwfilters") end # TESTGROUP: conn.lookup_nwfilter_by_name if !test_default_uri? newnw = conn.define_nwfilter_xml($new_nwfilter_xml) expect_too_many_args(conn, "lookup_nwfilter_by_name", 1, 2) expect_too_few_args(conn, "lookup_nwfilter_by_name") expect_invalid_arg_type(conn, "lookup_nwfilter_by_name", 1) expect_success(conn, "name arg", "lookup_nwfilter_by_name", "rb-libvirt-test") newnw.undefine end # TESTGROUP: conn.lookup_nwfilter_by_uuid if !test_default_uri? newnw = conn.define_nwfilter_xml($new_nwfilter_xml) expect_too_many_args(conn, "lookup_nwfilter_by_uuid", 1, 2) expect_too_few_args(conn, "lookup_nwfilter_by_uuid") expect_invalid_arg_type(conn, "lookup_nwfilter_by_uuid", 1) expect_success(conn, "uuid arg", "lookup_nwfilter_by_uuid", $NWFILTER_UUID) {|x| x.uuid == $NWFILTER_UUID} newnw.undefine end # TESTGROUP: conn.define_nwfilter_xml if !test_default_uri? expect_too_many_args(conn, "define_nwfilter_xml", 1, 2) expect_too_few_args(conn, "define_nwfilter_xml") expect_invalid_arg_type(conn, "define_nwfilter_xml", 1) expect_invalid_arg_type(conn, "define_nwfilter_xml", nil) expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_nwfilter_xml", "hello") newnw = expect_success(conn, "nwfilter XML", "define_nwfilter_xml", $new_nwfilter_xml) newnw.undefine end # TESTGROUP: conn.num_of_secrets if !test_default_uri? expect_too_many_args(conn, "num_of_secrets", 1) expect_success(conn, "no args", "num_of_secrets") end # TESTGROUP: conn.list_secrets if !test_default_uri? expect_too_many_args(conn, "list_secrets", 1) expect_success(conn, "no args", "list_secrets") end # TESTGROUP: conn.lookup_secret_by_uuid if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(conn, "lookup_secret_by_uuid", 1, 2) expect_too_few_args(conn, "lookup_secret_by_uuid") expect_invalid_arg_type(conn, "lookup_secret_by_uuid", 1) expect_success(conn, "uuid arg", "lookup_secret_by_uuid", $SECRET_UUID) {|x| x.uuid == $SECRET_UUID} newsecret.undefine end # TESTGROUP: conn.lookup_secret_by_usage if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(conn, "lookup_secret_by_usage", 1, 2, 3) expect_too_few_args(conn, "lookup_secret_by_usage") expect_invalid_arg_type(conn, "lookup_secret_by_usage", 'foo', 1) expect_invalid_arg_type(conn, "lookup_secret_by_usage", 1, 2) expect_fail(conn, Libvirt::RetrieveError, "invalid secret", "lookup_secret_by_usage", Libvirt::Secret::USAGE_TYPE_VOLUME, "foo") expect_success(conn, "usage type and key", "lookup_secret_by_usage", Libvirt::Secret::USAGE_TYPE_VOLUME, "/var/lib/libvirt/images/mail.img") newsecret.undefine end # TESTGROUP: conn.define_secret_xml if !test_default_uri? expect_too_many_args(conn, "define_secret_xml", 1, 2, 3) expect_too_few_args(conn, "define_secret_xml") expect_invalid_arg_type(conn, "define_secret_xml", 1) expect_invalid_arg_type(conn, "define_secret_xml", nil) expect_invalid_arg_type(conn, "define_secret_xml", "hello", 'foo') expect_fail(conn, Libvirt::DefinitionError, "invalid XML", "define_secret_xml", "hello") expect_success(conn, "secret XML", "define_secret_xml", $new_secret_xml) newsecret.undefine end # TESTGROUP: conn.list_storage_pools expect_too_many_args(conn, "list_storage_pools", 1) expect_success(conn, "no args", "list_storage_pools") # TESTGROUP: conn.num_of_storage_pools expect_too_many_args(conn, "num_of_storage_pools", 1) expect_success(conn, "no args", "num_of_storage_pools") # TESTGROUP: conn.list_defined_storage_pools expect_too_many_args(conn, "list_defined_storage_pools", 1) expect_success(conn, "no args", "list_defined_storage_pools") # TESTGROUP: conn.num_of_defined_storage_pools expect_too_many_args(conn, "num_of_defined_storage_pools", 1) expect_success(conn, "no args", "num_of_defined_storage_pools") # TESTGROUP: conn.lookup_storage_pool_by_name newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(conn, "lookup_storage_pool_by_name", 1, 2) expect_too_few_args(conn, "lookup_storage_pool_by_name") expect_invalid_arg_type(conn, "lookup_storage_pool_by_name", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent name arg", "lookup_storage_pool_by_name", "foobarbazsucker") expect_success(conn, "name arg", "lookup_storage_pool_by_name", "rb-libvirt-test") newpool.destroy newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_success(conn, "name arg", "lookup_storage_pool_by_name", "rb-libvirt-test") newpool.undefine # TESTGROUP: conn.lookup_storage_pool_by_uuid newpool = conn.create_storage_pool_xml($new_storage_pool_xml) expect_too_many_args(conn, "lookup_storage_pool_by_uuid", 1, 2) expect_too_few_args(conn, "lookup_storage_pool_by_uuid") expect_invalid_arg_type(conn, "lookup_storage_pool_by_uuid", 1) expect_fail(conn, Libvirt::RetrieveError, "non-existent uuid arg", "lookup_storage_pool_by_uuid", "foobarbazsucker") expect_success(conn, "uuid arg", "lookup_storage_pool_by_uuid", $POOL_UUID) newpool.destroy newpool = conn.define_storage_pool_xml($new_storage_pool_xml) expect_success(conn, "uuid arg", "lookup_storage_pool_by_uuid", $POOL_UUID) newpool.undefine # TESTGROUP: conn.create_storage_pool_xml expect_too_many_args(conn, "create_storage_pool_xml", $new_storage_pool_xml, 0, 1) expect_too_few_args(conn, "create_storage_pool_xml") expect_invalid_arg_type(conn, "create_storage_pool_xml", nil) expect_invalid_arg_type(conn, "create_storage_pool_xml", 1) expect_invalid_arg_type(conn, "create_storage_pool_xml", $new_storage_pool_xml, "foo") expect_fail(conn, Libvirt::Error, "invalid xml", "create_storage_pool_xml", "hello") expect_success(conn, "storage pool XML", "create_storage_pool_xml", $new_storage_pool_xml) expect_fail(conn, Libvirt::Error, "already existing domain", "create_storage_pool_xml", $new_storage_pool_xml) newpool.destroy # TESTGROUP: conn.define_storage_pool_xml expect_too_many_args(conn, "define_storage_pool_xml", $new_storage_pool_xml, 0, 1) expect_too_few_args(conn, "define_storage_pool_xml") expect_invalid_arg_type(conn, "define_storage_pool_xml", nil) expect_invalid_arg_type(conn, "define_storage_pool_xml", 1) expect_invalid_arg_type(conn, "define_storage_pool_xml", $new_storage_pool_xml, "foo") expect_fail(conn, Libvirt::Error, "invalid xml", "define_storage_pool_xml", "hello") expect_success(conn, "storage pool XML", "define_storage_pool_xml", $new_storage_pool_xml) newpool.undefine # TESTGROUP: conn.discover_storage_pool_sources expect_too_many_args(conn, "discover_storage_pool_sources", 1, 2, 3, 4) expect_too_few_args(conn, "discover_storage_pool_sources") expect_invalid_arg_type(conn, "discover_storage_pool_sources", 1) expect_invalid_arg_type(conn, "discover_storage_pool_sources", "foo", 1) expect_invalid_arg_type(conn, "discover_storage_pool_sources", "foo", "bar", "baz") expect_fail(conn, Libvirt::Error, "invalid pool type", "discover_storage_pool_sources", "foo") expect_success(conn, "pool type", "discover_storage_pool_sources", "logical") # TESTGROUP: conn.sys_info expect_too_many_args(conn, "sys_info", 1, 2) expect_invalid_arg_type(conn, "sys_info", "foo") expect_success(conn, "system info", "sys_info") # TESTGROUP: conn.interface_change_begin expect_too_many_args(conn, "interface_change_begin", 1, 2) expect_invalid_arg_type(conn, "interface_change_begin", 'hello') expect_success(conn, "interface change begin", "interface_change_begin") conn.interface_change_rollback # TESTGROUP: conn.interface_change_commit expect_too_many_args(conn, "interface_change_commit", 1, 2) expect_invalid_arg_type(conn, "interface_change_commit", 'foo') # FIXME: libvirt throws an error on commit with no changes. What changes can # we do here? #expect_success(conn, "interface change commit", "interface_change_commit") # TESTGROUP: conn.interface_change_rollback conn.interface_change_begin expect_too_many_args(conn, "interface_change_rollback", 1, 2) expect_invalid_arg_type(conn, "interface_change_rollback", 'foo') expect_success(conn, "interface change rollback", "interface_change_rollback") # TESTGROUP: conn.node_cpu_stats expect_too_many_args(conn, "node_cpu_stats", 1, 2, 3) expect_invalid_arg_type(conn, "node_cpu_stats", 'foo') expect_invalid_arg_type(conn, "node_cpu_stats", 1, 'bar') expect_success(conn, "node cpu stats", "node_cpu_stats") # TESTGROUP: conn.node_memory_stats if !test_default_uri? expect_too_many_args(conn, "node_memory_stats", 1, 2, 3) expect_invalid_arg_type(conn, "node_memory_stats", 'foo') expect_invalid_arg_type(conn, "node_memory_stats", 1, 'bar') expect_success(conn, "node memory status", "node_memory_stats") end # TESTGROUP: conn.save_image_xml_desc if !test_default_uri? newdom = conn.define_domain_xml($new_dom_xml) newdom.create test_sleep 1 newdom.save($GUEST_SAVE) expect_too_many_args(conn, "save_image_xml_desc", 1, 2, 3) expect_too_few_args(conn, "save_image_xml_desc") expect_invalid_arg_type(conn, "save_image_xml_desc", nil) expect_invalid_arg_type(conn, "save_image_xml_desc", 1) expect_invalid_arg_type(conn, "save_image_xml_desc", 'foo', 'bar') expect_success(conn, "save image path", "save_image_xml_desc", $GUEST_SAVE) `rm -f #{$GUEST_SAVE}` end # TESTGROUP: conn.define_save_image_xml expect_too_many_args(conn, "define_save_image_xml", 1, 2, 3, 4) expect_too_few_args(conn, "define_save_image_xml") expect_too_few_args(conn, "define_save_image_xml", 'foo') expect_invalid_arg_type(conn, "define_save_image_xml", nil, 'foo') expect_invalid_arg_type(conn, "define_save_image_xml", 1, 'foo') expect_invalid_arg_type(conn, "define_save_image_xml", 'foo', nil) expect_invalid_arg_type(conn, "define_save_image_xml", 'foo', 1) expect_invalid_arg_type(conn, "define_save_image_xml", 'foo', 'bar', 'baz') # TESTGROUP: conn.alive? expect_too_many_args(conn, "alive?", 1) expect_success(conn, "alive connection", "alive?") {|x| x == true} # TESTGROUP: conn.list_all_nwfilters if !test_default_uri? expect_too_many_args(conn, "list_all_nwfilters", 1, 2) expect_invalid_arg_type(conn, "list_all_nwfilters", "foo") expect_success(conn, "no args", "list_all_nwfilters") end # TESTGROUP: conn.list_all_storage_pools expect_too_many_args(conn, "list_all_storage_pools", 1, 2) expect_invalid_arg_type(conn, "list_all_storage_pools", "foo") expect_success(conn, "no args", "list_all_storage_pools") # TESTGROUP: conn.list_all_nodedevices expect_too_many_args(conn, "list_all_nodedevices", 1, 2) expect_invalid_arg_type(conn, "list_all_nodedevices", "foo") expect_success(conn, "no args", "list_all_nodedevices") # TESTGROUP: conn.list_all_secrets if !test_default_uri? expect_too_many_args(conn, "list_all_secrets", 1, 2) expect_invalid_arg_type(conn, "list_all_secrets", "foo") expect_success(conn, "no args", "list_all_secrets") end # TESTGROUP: conn.list_all_interfaces expect_too_many_args(conn, "list_all_interfaces", 1, 2) expect_invalid_arg_type(conn, "list_all_interfaces", "foo") expect_success(conn, "no args", "list_all_interfaces") # TESTGROUP: conn.list_all_networks expect_too_many_args(conn, "list_all_networks", 1, 2) expect_invalid_arg_type(conn, "list_all_networks", "foo") expect_success(conn, "no args", "list_all_networks") # TESTGROUP: conn.list_all_domains expect_too_many_args(conn, "list_all_domains", 1, 2) expect_invalid_arg_type(conn, "list_all_domains", "foo") expect_success(conn, "no args", "list_all_domains") # TESTGROUP: conn.set_keepalive expect_too_many_args(conn, "set_keepalive", 1, 2, 3, 4) expect_too_few_args(conn, "set_keepalive") expect_too_few_args(conn, "set_keepalive", 1) expect_invalid_arg_type(conn, "set_keepalive", 'foo', 0) expect_invalid_arg_type(conn, "set_keepalive", 0, 'foo') # FIXME: somehow we need an event loop implementation for this to work #expect_success(conn, "interval and count", "set_keepalive", 1, 10) # TESTGROUP: conn.node_suspend_for_duration expect_too_many_args(conn, "node_suspend_for_duration", 1, 2, 3, 4) expect_too_few_args(conn, "node_suspend_for_duration") expect_too_few_args(conn, "node_suspend_for_duration", 1) expect_invalid_arg_type(conn, "node_suspend_for_duration", 'foo', 1) expect_invalid_arg_type(conn, "node_suspend_for_duration", 1, 'foo') expect_invalid_arg_type(conn, "node_suspend_for_duration", 1, 2, 'foo') # TESTGROUP: conn.node_memory_parameters if !test_default_uri? expect_too_many_args(conn, "node_memory_parameters", 1, 2) expect_invalid_arg_type(conn, "node_memory_parameters", 'foo') expect_success(conn, "no args", "node_memory_parameters") end # TESTGROUP: conn.node_memory_paramters= expect_too_many_args(conn, "node_memory_parameters=", 1, 2) expect_invalid_arg_type(conn, "node_memory_parameters=", nil) expect_invalid_arg_type(conn, "node_memory_parameters=", ['foo', 0]) expect_invalid_arg_type(conn, "node_memory_parameters=", [{}, 'foo']) # TESTGROUP: conn.keepalive= expect_too_many_args(conn, "keepalive=", 1, 2) expect_too_few_args(conn, "keepalive=", []) expect_too_few_args(conn, "keepalive=", [1]) expect_invalid_arg_type(conn, "keepalive=", 1) expect_invalid_arg_type(conn, "keepalive=", ['foo', 1]) expect_invalid_arg_type(conn, "keepalive=", [1, 'foo']) # FIXME: somehow we need an event loop implementation for this to work #expect_success(conn, "interval and count", "keepalive=", 1, 10) # END TESTS conn.close finish_tests ruby-libvirt-0.8.4/tests/test_nwfilter.rb0000644000175000017500000000260014567114130020663 0ustar abolognaabologna#!/usr/bin/ruby # Test the nwfilter methods the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("nwfilter") conn = Libvirt::open(URI) # TESTGROUP: nwfilter.undefine if !test_default_uri? newnw = conn.define_nwfilter_xml($new_nwfilter_xml) expect_too_many_args(newnw, "undefine", 1) expect_success(newnw, "no args", "undefine") end # TESTGROUP: nwfilter.name if !test_default_uri? newnw = conn.define_nwfilter_xml($new_nwfilter_xml) expect_too_many_args(newnw, "name", 1) expect_success(newnw, "no args", "name") {|x| x == "rb-libvirt-test"} newnw.undefine end # TESTGROUP: nwfilter.uuid if !test_default_uri? newnw = conn.define_nwfilter_xml($new_nwfilter_xml) expect_too_many_args(newnw, "uuid", 1) expect_success(newnw, "no args", "uuid") {|x| x == $NWFILTER_UUID} newnw.undefine end # TESTGROUP: nwfilter.xml_desc if !test_default_uri? newnw = conn.define_nwfilter_xml($new_nwfilter_xml) expect_too_many_args(newnw, "xml_desc", 1, 2) expect_invalid_arg_type(newnw, "xml_desc", "foo") expect_success(newnw, "no args", "xml_desc") newnw.undefine end # TESTGROUP: nwfilter.free if !test_default_uri? newnw = conn.define_nwfilter_xml($new_nwfilter_xml) newnw.undefine expect_too_many_args(newnw, "free", 1) expect_success(newnw, "no args", "free") end # END TESTS conn.close finish_tests ruby-libvirt-0.8.4/tests/test_stream.rb0000644000175000017500000001156014567114130020331 0ustar abolognaabologna#!/usr/bin/ruby # Test the stream methods the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("stream") conn = Libvirt::open(URI) # TESTGROUP: stream.send st = conn.stream expect_too_many_args(st, "send", 1, 2) expect_too_few_args(st, "send") expect_invalid_arg_type(st, "send", 1) expect_invalid_arg_type(st, "send", nil) expect_invalid_arg_type(st, "send", []) expect_invalid_arg_type(st, "send", {}) # FIXME: we need to setup a proper stream for this to work #expect_success(st, "buffer arg", "send", buffer) st.free # TESTGROUP: stream.recv st = conn.stream expect_too_many_args(st, "recv", 1, 2) expect_too_few_args(st, "recv") expect_invalid_arg_type(st, "recv", nil) expect_invalid_arg_type(st, "recv", 'foo') expect_invalid_arg_type(st, "recv", []) expect_invalid_arg_type(st, "recv", {}) # FIXME: we need to setup a proper stream for this to work #expect_success(st, "bytes arg", "recv", 12) st.free # TESTGROUP: stream.sendall st = conn.stream # equivalent to expect_too_many_args begin st.sendall(1, 2) {|x,y| x = y} rescue NoMethodError puts_skipped "#{$test_object}.sendall does not exist" rescue ArgumentError => e puts_ok "#{$test_object}.sendall too many args threw #{ArgumentError.to_s}" rescue => e puts_fail "#{$test_object}.sendall too many args expected to throw #{ArgumentError.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}" else puts_fail "#{$test_object}.sendall too many args expected to throw #{ArgumentError.to_s}, but threw nothing" end expect_fail(st, RuntimeError, "no block given", "sendall") # FIXME: we need to setup a proper stream for this to work #st.sendall {|opaque,nbytes| return opaque} st.free # TESTGROUP: stream.recvall st = conn.stream # equivalent to expect_too_many_args begin st.recvall(1, 2) {|x,y| x = y} rescue NoMethodError puts_skipped "#{$test_object}.recvall does not exist" rescue ArgumentError => e puts_ok "#{$test_object}.recvall too many args threw #{ArgumentError.to_s}" rescue => e puts_fail "#{$test_object}.recvall too many args expected to throw #{ArgumentError.to_s}, but instead threw #{e.class.to_s}: #{e.to_s}" else puts_fail "#{$test_object}.recvall too many args expected to throw #{ArgumentError.to_s}, but threw nothing" end expect_fail(st, RuntimeError, "no block given", "recvall") # FIXME: we need to setup a proper stream for this to work #st.recvall {|data,opaque| return opaque} st.free # TESTGROUP: stream.event_add_callback st_event_callback_proc = lambda {|stream,events,opaque| } st = conn.stream expect_too_many_args(st, "event_add_callback", 1, 2, 3, 4) expect_too_few_args(st, "event_add_callback") expect_too_few_args(st, "event_add_callback", 1) expect_invalid_arg_type(st, "event_add_callback", nil, st_event_callback_proc) expect_invalid_arg_type(st, "event_add_callback", 'foo', st_event_callback_proc) expect_invalid_arg_type(st, "event_add_callback", [], st_event_callback_proc) expect_invalid_arg_type(st, "event_add_callback", {}, st_event_callback_proc) expect_invalid_arg_type(st, "event_add_callback", 1, nil) expect_invalid_arg_type(st, "event_add_callback", 1, 'foo') expect_invalid_arg_type(st, "event_add_callback", 1, 1) expect_invalid_arg_type(st, "event_add_callback", 1, []) expect_invalid_arg_type(st, "event_add_callback", 1, {}) # FIXME: I get "this function is not support by the connection driver" #expect_success(st, "events and callback arg", "event_add_callback", Libvirt::Stream::EVENT_READABLE, st_event_callback_proc) #st.event_remove_callback st.free # TESTGROUP: stream.event_update_callback st = conn.stream expect_too_many_args(st, "event_update_callback", 1, 2) expect_too_few_args(st, "event_update_callback") expect_invalid_arg_type(st, "event_update_callback", nil) expect_invalid_arg_type(st, "event_update_callback", 'foo') expect_invalid_arg_type(st, "event_update_callback", []) expect_invalid_arg_type(st, "event_update_callback", {}) # FIXME: we would need to get st.event_add_callback working to get this working #expect_success(st, "events arg", "event_update_callback", Libvirt::Stream::EVENT_WRITABLE) st.free # TESTGROUP: stream.remove_callback st = conn.stream expect_too_many_args(st, "event_remove_callback", 1) # FIXME: we would need to get st.event_add_callback working to get this working #expect_success(st, "no arg", "event_remove_callback") st.free # TESTGROUP: stream.finish st = conn.stream expect_too_many_args(st, "finish", 1) # FIXME: I get "this function is not support by the connection driver" #expect_success(st, "no arg", "finish") st.free # TESTGROUP: stream.abort st = conn.stream expect_too_many_args(st, "abort", 1) # FIXME: I get "this function is not support by the connection driver" #expect_success(st, "no arg", "abort") st.free # TESTGROUP: stream.abort st = conn.stream expect_too_many_args(st, "free", 1) expect_success(st, "no arg", "free") # END TESTS conn.close finish_tests ruby-libvirt-0.8.4/tests/test_open.rb0000644000175000017500000002502614567114130020001 0ustar abolognaabologna#!/usr/bin/ruby # Test the open calls that the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("Libvirt") def expect_connect_error(func, args) expect_fail(Libvirt, Libvirt::ConnectionError, "invalid driver", func, *args) end # TESTGROUP: Libvirt::version expect_too_many_args(Libvirt, "version", "test", 1) expect_invalid_arg_type(Libvirt, "version", 1) expect_success(Libvirt, "no args", "version") {|x| x.class == Array and x.length == 2} expect_success(Libvirt, "nil arg", "version", nil) {|x| x.class == Array and x.length == 2} expect_success(Libvirt, "Test arg", "version", "Test") {|x| x.class == Array and x.length == 2} # TESTGROUP: Libvirt::open if !test_default_uri? expect_too_many_args(Libvirt, "open", URI, 1) expect_connect_error("open", "foo:///system") conn = expect_success(Libvirt, "no args", "open") {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, URI, "open", URI) {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "nil arg", "open", nil) {|x| x.class == Libvirt::Connect } conn.close end # TESTGROUP: Libvirt::open_read_only if !test_default_uri? expect_too_many_args(Libvirt, "open_read_only", URI, 1) expect_connect_error("open_read_only", "foo:///system") conn = expect_success(Libvirt, "no args", "open_read_only") {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, URI, "open_read_only", URI) {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "nil arg", "open_read_only", nil) {|x| x.class == Libvirt::Connect } conn.close end # TESTGROUP: Libvirt::open_auth if !test_default_uri? expect_too_many_args(Libvirt, "open_auth", URI, [], "hello there", 1, 2) expect_connect_error("open_auth", "foo:///system") expect_invalid_arg_type(Libvirt, "open_auth", 1) expect_invalid_arg_type(Libvirt, "open_auth", URI, [], "hello", "foo") conn = expect_success(Libvirt, "no args", "open_auth") {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "uri arg", "open_auth", URI) {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "uri and empty cred args", "open_auth", URI, []) {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "uri and full cred args", "open_auth", URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]) {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "uri, full cred, and user args", "open_auth", URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello") {|x| x.class == Libvirt::Connect } conn.close # equivalent to expect_invalid_arg_type begin conn = Libvirt::open_auth(URI, {}) do |cred| end rescue TypeError => e puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}" else puts_fail "#{$test_object}.open_auth invalid arg type expected to throw #{TypeError.to_s}, but threw nothing" end # equivalent to expect_invalid_arg_type begin conn = Libvirt::open_auth(URI, 1) do |cred| end rescue TypeError => e puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}" else puts_fail "#{$test_object}.open_auth invalid arg type expected to throw #{TypeError.to_s}, but threw nothing" end # equivalent to expect_invalid_arg_type begin conn = Libvirt::open_auth(URI, 'foo') do |cred| end rescue TypeError => e puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}" else puts_fail "#{$test_object}.open_auth invalid arg type expected to throw #{TypeError.to_s}, but threw nothing" end # equivalent to "expect_success" begin conn = Libvirt::open_auth(URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello") do |cred| if not cred["userdata"].nil? puts "userdata is #{cred["userdata"]}" end if cred["type"] == Libvirt::CRED_AUTHNAME print "#{cred['prompt']}: " res = gets # strip off the \n res = res[0..-2] elsif cred["type"] == Libvirt::CRED_PASSPHRASE print "#{cred['prompt']}: " res = gets res = res[0..-2] else raise "Unsupported credential #{cred['type']}" end res end puts_ok "Libvirt.open_auth uri, creds, userdata, auth block succeeded" conn.close rescue NoMethodError puts_skipped "Libvirt.open_auth does not exist" rescue => e puts_fail "Libvirt.open_auth uri, creds, userdata, auth block expected to succeed, threw #{e.class.to_s}: #{e.to_s}" end # equivalent to "expect_success" begin conn = Libvirt::open_auth(URI) do |cred| end puts_ok "Libvirt.open_auth uri, succeeded" conn.close rescue NoMethodError puts_skipped "Libvirt.open_auth does not exist" rescue => e puts_fail "Libvirt.open_auth uri expected to succeed, threw #{e.class.to_s}: #{e.to_s}" end # equivalent to "expect_success" begin conn = Libvirt::open_auth(URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello", Libvirt::CONNECT_RO) do |cred| if not cred["userdata"].nil? puts "userdata is #{cred["userdata"]}" end if cred["type"] == Libvirt::CRED_AUTHNAME print "#{cred['prompt']}: " res = gets # strip off the \n res = res[0..-2] elsif cred["type"] == Libvirt::CRED_PASSPHRASE print "#{cred['prompt']}: " res = gets res = res[0..-2] else raise "Unsupported credential #{cred['type']}" end res end puts_ok "Libvirt.open_auth uri, creds, userdata, R/O flag, auth block succeeded" conn.close rescue NoMethodError puts_skipped "Libvirt.open_auth does not exist" rescue => e puts_fail "Libvirt.open_auth uri, creds, userdata, R/O flag, auth block expected to succeed, threw #{e.class.to_s}: #{e.to_s}" end end # TESTGROUP: Libvirt::event_invoke_handle_callback if !test_default_uri? conn = Libvirt::open(URI) expect_too_many_args(Libvirt, "event_invoke_handle_callback", 1, 2, 3, 4, 5) expect_too_few_args(Libvirt, "event_invoke_handle_callback") expect_too_few_args(Libvirt, "event_invoke_handle_callback", 1) expect_too_few_args(Libvirt, "event_invoke_handle_callback", 1, 2) expect_too_few_args(Libvirt, "event_invoke_handle_callback", 1, 2, 3) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, 1) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, []) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, nil) # this is a bit bizarre; I am constructing a bogus hash to pass as the 4th # parameter to event_invoke_handle_callback. In a real situation, I would # have been given this hash from libvirt earlier, and just pass it on. I # don't want all of that complexity here, though, so I create the bogus hash. # One caveat; the data inside the hash *must* be of type T_DATA, so I pass in # a fake conn object just to appease the type checker (so I can test out the # other arguments properly) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", "hello", 1, 1, { "libvirt_cb" => conn, "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, "hello", 1, { "libvirt_cb" => conn, "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, 1, "hello", { "libvirt_cb" => conn, "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, 1, 1, { "libvirt_cb" => "hello", "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, 1, 1, { "libvirt_cb" => conn, "opaque" => "hello" }) conn.close end # TESTGROUP: Libvirt::event_invoke_timeout_callback if !test_default_uri? conn = Libvirt::open(URI) expect_too_many_args(Libvirt, "event_invoke_timeout_callback", 1, 2, 3) expect_too_few_args(Libvirt, "event_invoke_timeout_callback") expect_too_few_args(Libvirt, "event_invoke_timeout_callback", 1) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", 1) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", []) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", nil) # this is a bit bizarre; I am constructing a bogus hash to pass as the 4th # parameter to event_invoke_handle_callback. In a real situation, I would # have been given this hash from libvirt earlier, and just pass it on. I # don't want all of that complexity here, though, so I create the bogus hash. # One caveat; the data inside the hash *must* be of type T_DATA, so I pass in # a fake conn object just to appease the type checker (so I can test out the # other arguments properly) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", "hello", { "libvirt_cb" => conn, "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", 1, { "libvirt_cb" => "hello", "opaque" => conn }) expect_invalid_arg_type(Libvirt, "event_invoke_timeout_callback", 1, { "libvirt_cb" => conn, "opaque" => "hello" }) conn.close end # TESTGROUP: Libvirt::event_register_impl if !test_default_uri? expect_too_many_args(Libvirt, "event_register_impl", 1, 2, 3, 4, 5, 6, 7) expect_invalid_arg_type(Libvirt, "event_register_impl", 1) # symbol callbacks def virEventAddHandleImpl(fd, events, opaque) end def virEventUpdateHandleImpl(watch, event) end def virEventRemoveHandleImpl(handleID) end def virEventAddTimerImpl(interval, opaque) end def virEventUpdateTimerImpl(timer, timeout) end def virEventRemoveTimerImpl(timerID) end # proc callbacks virEventAddHandleProc = lambda {|fd, events, opaque| } virEventUpdateHandleProc = lambda {|watch, event| } virEventRemoveHandleProc = lambda {|handleID| } virEventAddTimerProc = lambda {|interval, opaque| } virEventUpdateTimerProc = lambda {|timer, timeout| } virEventRemoveTimerProc = lambda {|timerID| } expect_success(Libvirt, "all Symbol callbacks", "event_register_impl", :virEventAddHandleImpl, :virEventUpdateHandleImpl, :virEventRemoveHandleImpl, :virEventAddTimerImpl, :virEventUpdateTimerImpl, :virEventRemoveTimerImpl) expect_success(Libvirt, "unregister all callbacks", "event_register_impl", nil, nil, nil, nil, nil, nil) expect_success(Libvirt, "all Proc callbacks", "event_register_impl", virEventAddHandleProc, virEventUpdateHandleProc, virEventRemoveHandleProc, virEventAddTimerProc, virEventUpdateTimerProc, virEventRemoveTimerProc) expect_success(Libvirt, "unregister all callbacks", "event_register_impl") end # END TESTS finish_tests ruby-libvirt-0.8.4/tests/test_secret.rb0000644000175000017500000000646214567114130020330 0ustar abolognaabologna#!/usr/bin/ruby # Test the secret methods the bindings support $: << File.dirname(__FILE__) require 'libvirt' require 'test_utils.rb' set_test_object("secret") conn = Libvirt::open(URI) # TESTGROUP: secret.uuid if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(newsecret, "uuid", 1) expect_success(newsecret, "no args", "uuid") {|x| x == $SECRET_UUID} newsecret.undefine end # TESTGROUP: secret.usagetype if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(newsecret, "usagetype", 1) expect_success(newsecret, "no args", "usagetype") {|x| x == Libvirt::Secret::USAGE_TYPE_VOLUME} newsecret.undefine end # TESTGROUP: secret.usageid if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(newsecret, "usageid", 1) expect_success(newsecret, "no args", "usageid") newsecret.undefine end # TESTGROUP: secret.xml_desc if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(newsecret, "xml_desc", 1, 2) expect_invalid_arg_type(newsecret, "xml_desc", "foo") expect_success(newsecret, "no args", "xml_desc") newsecret.undefine end # TESTGROUP: secret.set_value if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(newsecret, "set_value", 1, 2, 3) expect_too_few_args(newsecret, "set_value") expect_invalid_arg_type(newsecret, "set_value", 1) expect_invalid_arg_type(newsecret, "set_value", "foo", "bar") expect_success(newsecret, "value arg", "set_value", "foo") newsecret.undefine end # TESTGROUP: secret.value= if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(newsecret, "value=", 1, 2) expect_too_few_args(newsecret, "value=") expect_invalid_arg_type(newsecret, "value=", {}) expect_invalid_arg_type(newsecret, "value=", nil) expect_invalid_arg_type(newsecret, "value=", 1) expect_invalid_arg_type(newsecret, "value=", [1, 1]) expect_invalid_arg_type(newsecret, "value=", [nil, 1]) expect_invalid_arg_type(newsecret, "value=", [[], 1]) expect_invalid_arg_type(newsecret, "value=", [{}, 1]) expect_invalid_arg_type(newsecret, "value=", ['foo', nil]) expect_invalid_arg_type(newsecret, "value=", ['foo', 'foo']) expect_invalid_arg_type(newsecret, "value=", ['foo', []]) expect_invalid_arg_type(newsecret, "value=", ['foo', {}]) expect_success(newsecret, "value arg", "value=", "foo") newsecret.undefine end # TESTGROUP: secret.get_value if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) newsecret.set_value("foo") expect_too_many_args(newsecret, "get_value", 1, 2) expect_invalid_arg_type(newsecret, "get_value", 'foo') expect_success(newsecret, "no args", "get_value") {|x| x == 'foo'} newsecret.undefine end # TESTGROUP: secret.undefine if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) expect_too_many_args(newsecret, "undefine", 1) expect_success(newsecret, "no args", "undefine") end # TESTGROUP: secret.free if !test_default_uri? newsecret = conn.define_secret_xml($new_secret_xml) newsecret.undefine expect_too_many_args(newsecret, "free", 1) expect_success(newsecret, "no args", "free") end # END TESTS conn.close finish_tests ruby-libvirt-0.8.4/COPYING0000644000175000017500000006365514557177263015376 0ustar abolognaabologna GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. ^L Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. ^L GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. ^L Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. ^L 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. ^L 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. ^L 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. ^L 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS ^L How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ruby-libvirt-0.8.4/lib/0000755000175000017500000000000014652707704015065 5ustar abolognaabolognaruby-libvirt-0.8.4/lib/libvirt.rb0000644000175000017500000000136214565713204017062 0ustar abolognaabologna# # libvirt.rb: main module for the ruby-libvirt bindings # # Copyright (C) 2007 Red Hat, Inc. # # Distributed under the GNU Lesser General Public License v2.1 or later. # See COPYING for details # # David Lutterkort require '_libvirt' module Libvirt # A version in Libvirt's representation class Version attr_reader :version, :type def initialize(type, version) @type = type @version = version end def major version / 1000000 end def minor version % 1000000 / 1000 end def release version % 1000 end def to_s "#{major}.#{minor}.#{release}" end end end ruby-libvirt-0.8.4/doc/0000755000175000017500000000000014652707704015064 5ustar abolognaabolognaruby-libvirt-0.8.4/doc/main.rdoc0000644000175000017500000000215714575777023016673 0ustar abolognaabologna= Ruby bindings for libvirt The module Libvirt provides bindings to libvirt[https://libvirt.org] The various *Ptr types in Libvirt map loosely to the following Ruby classes: [virConnectPtr] Libvirt::Connect [virNodeInfoPtr] Libvirt::Connect::Nodeinfo [virSecurityModelPtr] Libvirt::Connect::NodeSecurityModel [virDomainPtr] Libvirt::Domain [virDomainInfoPtr] Libvirt::Domain::Info [virDomainInterfaceStatsPtr] Libvirt::Domain::InterfaceInfo [virSecurityLabelPtr] Libvirt::Domain::SecurityLabel [virDomainBlockStatsPtr] Libvirt::Domain::BlockStats [virDomainMemoryStatPtr] Libvirt::Domain::MemoryStats [virDomainBlockInfoPtr] Libvirt::Domain::BlockInfo [virDomainSnapshotPtr] Libvirt::Domain::Snapshot [virDomainJobInfoPtr] Libvirt::Domain::JobInfo [virNetworkPtr] Libvirt::Network [virNWFilterPtr] Libvirt::NWFilter [virNodeDevicePtr] Libvirt::NodeDevice [virStoragePoolPtr] Libvirt::StoragePool [virStoragePoolInfoPtr] Libvirt::StoragePoolInfo [virStorageVolPtr] Libvirt::StorageVol [virStorageVolInfoPtr] Libvirt::StorageVolInfo [virSecretPtr] Libvirt::Secret [virInterfacePtr] Libvirt::Interface [virStreamPtr] Libvirt::Stream ruby-libvirt-0.8.4/Rakefile0000644000175000017500000001051714652707410015762 0ustar abolognaabologna# -*- ruby -*- # Rakefile: build ruby libvirt bindings # # Copyright (C) 2007,2010 Red Hat, Inc. # Copyright (C) 2013,2014 Chris Lalancette # # Distributed under the GNU Lesser General Public License v2.1 or later. # See COPYING for details # # David Lutterkort # Rakefile for ruby-rpm -*- ruby -*- require 'rake/clean' require 'rake/testtask' require 'rdoc/task' require 'rubygems/package_task' PKG_NAME='ruby-libvirt' PKG_VERSION='0.8.4' EXT_DIR = "ext/libvirt" EXTCONF = "#{EXT_DIR}/extconf.rb" MAKEFILE = "#{EXT_DIR}/Makefile" LIBVIRT_MODULE = "#{EXT_DIR}/_libvirt.so" SPEC_FILE = "#{PKG_NAME}.spec" SRC_FILES = FileList[ "#{EXT_DIR}/_libvirt.c", "#{EXT_DIR}/common.c", "#{EXT_DIR}/common.h", "#{EXT_DIR}/connect.c", "#{EXT_DIR}/connect.h", "#{EXT_DIR}/domain.c", "#{EXT_DIR}/domain.h", "#{EXT_DIR}/interface.c", "#{EXT_DIR}/interface.h", "#{EXT_DIR}/network.c", "#{EXT_DIR}/network.h", "#{EXT_DIR}/nodedevice.c", "#{EXT_DIR}/nodedevice.h", "#{EXT_DIR}/nwfilter.c", "#{EXT_DIR}/nwfilter.h", "#{EXT_DIR}/secret.c", "#{EXT_DIR}/secret.h", "#{EXT_DIR}/storage.c", "#{EXT_DIR}/storage.h", "#{EXT_DIR}/stream.c", "#{EXT_DIR}/stream.h", ] LIB_FILES = FileList[ "lib/libvirt.rb", ] GEN_FILES = FileList[ MAKEFILE, "#{EXT_DIR}/extconf.h", ] # # Additional files for clean/clobber # CLEAN.include [ "#{EXT_DIR}/*.o", LIBVIRT_MODULE ] CLOBBER.include [ "#{EXT_DIR}/mkmf.log" ] + GEN_FILES # # Build locally # task :default => :build file MAKEFILE => EXTCONF do |t| Dir::chdir(File::dirname(EXTCONF)) do sh "ruby #{File::basename(EXTCONF)}" end end file LIBVIRT_MODULE => SRC_FILES + [ MAKEFILE ] do |t| Dir::chdir(File::dirname(EXTCONF)) do sh "make" end end desc "Build the native library" task :build => LIBVIRT_MODULE # # Test tasks # TEST_FILES = FileList[ "tests/test_conn.rb", "tests/test_domain.rb", "tests/test_interface.rb", "tests/test_network.rb", "tests/test_nodedevice.rb", "tests/test_nwfilter.rb", "tests/test_open.rb", "tests/test_secret.rb", "tests/test_storage.rb", "tests/test_stream.rb", "tests/test_utils.rb", ] Rake::TestTask.new(:test) do |t| t.test_files = TEST_FILES t.libs << EXT_DIR end task :test => :build # # Documentation tasks # RDOC_MAIN = "doc/main.rdoc" RDOC_FILES = FileList[ RDOC_MAIN ] + SRC_FILES + LIB_FILES RDoc::Task.new do |rd| rd.main = RDOC_MAIN rd.rdoc_dir = "doc/site/api" rd.rdoc_files.include(RDOC_FILES) end RDoc::Task.new(:ri) do |rd| rd.main = RDOC_MAIN rd.rdoc_dir = "doc/ri" rd.options << "--ri-system" rd.rdoc_files.include(RDOC_FILES) end # # Package tasks # PKG_FILES = FileList[ "Rakefile", "COPYING", "README.rst", "NEWS.rst", EXTCONF, RDOC_MAIN, ] + SRC_FILES + LIB_FILES + TEST_FILES SPEC = Gem::Specification.new do |s| s.name = PKG_NAME s.version = PKG_VERSION s.files = PKG_FILES s.extensions = EXTCONF s.required_ruby_version = ">= 1.8.1" s.summary = "Ruby bindings for libvirt" s.description = <<~EOF ruby-libvirt allows applications written in Ruby to use the libvirt API. EOF s.authors = ["David Lutterkort", "Chris Lalancette"] s.license = "LGPL-2.1-or-later" s.email = "devel@lists.libvirt.org" s.homepage = "https://ruby.libvirt.org/" s.metadata = { "source_code_uri" => "https://gitlab.com/libvirt/libvirt-ruby", "bug_tracker_uri" => "https://gitlab.com/libvirt/libvirt-ruby/-/issues", "documentation_uri" => "https://ruby.libvirt.org/api/index.html", } end Gem::PackageTask.new(SPEC) do |pkg| pkg.need_tar = true pkg.need_zip = true end desc "Build (S)RPM for #{PKG_NAME}" task :rpm => [ :package ] do |t| pkg_dir = File::expand_path("pkg") sed = [ "sed", "-e", "'s/@VERSION@/#{PKG_VERSION}/'", "#{SPEC_FILE}.in", ">#{pkg_dir}/#{SPEC_FILE}", ] sh sed.join(" ") rpmbuild = [ "rpmbuild", "--clean", "--define", "'_topdir #{pkg_dir}'", "--define", "'_sourcedir #{pkg_dir}'", "--define", "'_srcrpmdir #{pkg_dir}'", "--define", "'_rpmdir #{pkg_dir}'", "--define", "'_builddir #{pkg_dir}'", "-ba", "#{pkg_dir}/#{SPEC_FILE}", ] sh rpmbuild.join(" ") end ruby-libvirt-0.8.4/README.rst0000644000175000017500000000133614575777023016016 0ustar abolognaabologna============ ruby-libvirt ============ Ruby bindings for `libvirt `__. Usage ===== Add ``require 'libvirt'`` to your program, then call ``Libvirt::open`` or ``Libvirt::open_read_only`` to obtain a connection. See ``examples/*.rb`` and ``tests/*.rb`` for more examples. Hacking ======= On a Fedora machine, run :: $ yum install libvirt-devel ruby-devel rubygem-rake followed by :: $ rake build To run code against the bindings without having to install them first, ``$RUBYLIB`` needs to be set appropriately. For example: :: $ export RUBYLIB="lib:ext/libvirt" $ ruby -rlibvirt -e 'puts Libvirt::version[0]' Contributing ============ See `CONTRIBUTING.rst `__.