Hi Chris, I use ruby-libvirt for Vagrant and Vagrant-kvm project. A virNetworkUpdate method with libvirt ruby binding is essential in order to support network configuration among multi VMs in Vagrant. Please find an attachment that is trying to support virNetworkUpdate. https://github.com/miurahr/ruby-libvirt/tree/virNetworkUpdate -- Hiroshi Miura
>From 7dae1312e844e62ad057300845a4a56c7f212d13 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura <miurahr@xxxxxxxxx> Date: Sat, 10 Aug 2013 13:55:56 +0900 Subject: [PATCH] support virNetworkUpdate Signed-off-by: Hiroshi Miura <miurahr@xxxxxxxxx> --- NEWS | 3 +++ README | 24 +----------------------- Rakefile | 2 +- ext/libvirt/extconf.rb | 22 ++++++++++++++++++++++ ext/libvirt/network.c | 37 +++++++++++++++++++++++++++++++++++++ tests/test_network.rb | 13 +++++++++++++ tests/test_utils.rb | 4 ++++ 7 files changed, 81 insertions(+), 24 deletions(-) diff --git a/NEWS b/NEWS index c26c071..f4a5bd3 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +2013-08-10 0.5.0 + * Update Network class, implementing network_update + 2011-07-27 0.4.0 * Updated Domain class, implementing dom.memory_parameters=, dom.memory_parameters, dom.updated?, dom.migrate2, dom.migrate_to_uri2, diff --git a/README b/README index f7f1790..7cda384 100644 --- a/README +++ b/README @@ -27,7 +27,7 @@ toplevel of your source checkout): Notes ----- -As of March 17, 2013, the ruby-libvirt bindings support all of the libvirt +As of August 10, 2013, the ruby-libvirt bindings support all of the libvirt APIs up to libvirt commit hash eebbb232e65e555b7d358ca752c23d2bacaf4edf with the following exceptions: @@ -163,28 +163,6 @@ with the following exceptions: - VIR_CONNECT_LIST_NETWORKS_TRANSIENT - VIR_CONNECT_LIST_NETWORKS_AUTOSTART - VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART -- VIR_NETWORK_UPDATE_COMMAND_NONE -- VIR_NETWORK_UPDATE_COMMAND_MODIFY -- VIR_NETWORK_UPDATE_COMMAND_DELETE -- VIR_NETWORK_UPDATE_COMMAND_ADD_LAST -- VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST -- VIR_NETWORK_SECTION_NONE -- VIR_NETWORK_SECTION_BRIDGE -- VIR_NETWORK_SECTION_DOMAIN -- VIR_NETWORK_SECTION_IP -- VIR_NETWORK_SECTION_IP_DHCP_HOST -- VIR_NETWORK_SECTION_IP_DHCP_RANGE -- VIR_NETWORK_SECTION_FORWARD -- VIR_NETWORK_SECTION_FORWARD_INTERFACE -- VIR_NETWORK_SECTION_FORWARD_PF -- VIR_NETWORK_SECTION_PORTGROUP -- VIR_NETWORK_SECTION_DNS_HOST -- VIR_NETWORK_SECTION_DNS_TXT -- VIR_NETWORK_SECTION_DNS_SRV -- VIR_NETWORK_UPDATE_AFFECT_CURRENT -- VIR_NETWORK_UPDATE_AFFECT_LIVE -- VIR_NETWORK_UPDATE_AFFECT_CONFIG -- virNetworkUpdate - VIR_CONNECT_LIST_INTERFACES_INACTIVE - VIR_CONNECT_LIST_INTERFACES_ACTIVE - virConnectListAllInterfaces diff --git a/Rakefile b/Rakefile index 2aef612..c8d9756 100644 --- a/Rakefile +++ b/Rakefile @@ -16,7 +16,7 @@ require 'rubygems/package_task' require 'rbconfig' PKG_NAME='ruby-libvirt' -PKG_VERSION='0.4.0' +PKG_VERSION='0.5.0' EXT_CONF='ext/libvirt/extconf.rb' MAKEFILE="ext/libvirt/Makefile" diff --git a/ext/libvirt/extconf.rb b/ext/libvirt/extconf.rb index 8c33e72..714d039 100644 --- a/ext/libvirt/extconf.rb +++ b/ext/libvirt/extconf.rb @@ -156,6 +156,7 @@ libvirt_funcs = [ 'virStorageVolWipe', 'virDomainSaveFlags', 'virDomainSaveImageGetXMLDesc', 'virDomainSendKey', + 'virNetworkUpdate', ] libvirt_consts = [ 'VIR_MIGRATE_LIVE', @@ -224,6 +225,27 @@ libvirt_consts = [ 'VIR_MIGRATE_LIVE', 'VIR_DOMAIN_SAVE_BYPASS_CACHE', 'VIR_DOMAIN_SAVE_RUNNING', 'VIR_DOMAIN_SAVE_PAUSED', + 'VIR_NETWORK_UPDATE_COMMAND_NONE', + 'VIR_NETWORK_UPDATE_COMMAND_MODIFY', + 'VIR_NETWORK_UPDATE_COMMAND_DELETE', + 'VIR_NETWORK_UPDATE_COMMAND_ADD_LAST', + 'VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST', + 'VIR_NETWORK_SECTION_NONE', + 'VIR_NETWORK_SECTION_BRIDGE', + 'VIR_NETWORK_SECTION_DOMAIN', + 'VIR_NETWORK_SECTION_IP', + 'VIR_NETWORK_SECTION_IP_DHCP_HOST', + 'VIR_NETWORK_SECTION_IP_DHCP_RANGE', + 'VIR_NETWORK_SECTION_FORWARD', + 'VIR_NETWORK_SECTION_FORWARD_INTERFACE', + 'VIR_NETWORK_SECTION_FORWARD_PF', + 'VIR_NETWORK_SECTION_PORTGROUP', + 'VIR_NETWORK_SECTION_DNS_HOST', + 'VIR_NETWORK_SECTION_DNS_TXT', + 'VIR_NETWORK_SECTION_DNS_SRV', + 'VIR_NETWORK_UPDATE_AFFECT_CURRENT', + 'VIR_NETWORK_UPDATE_AFFECT_LIVE', + 'VIR_NETWORK_UPDATE_AFFECT_CONFIG', ] have_libvirt_types(libvirt_types) diff --git a/ext/libvirt/network.c b/ext/libvirt/network.c index 75eefce..fbbd45a 100644 --- a/ext/libvirt/network.c +++ b/ext/libvirt/network.c @@ -64,6 +64,20 @@ static VALUE libvirt_netw_create(VALUE s) { /* * call-seq: + * net.update -> nil + * + * Call +virNetworkUpdate+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkUpdate] + * to update this network. + */ +static VALUE libvirt_netw_update(VALUE s, VALUE command, VALUE section, + VALUE index, VALUE xml, VALUE flags) { + + gen_call_void(virNetworkUpdate, conn(s), network_get(s), + NUM2UINT(command), NUM2UINT(section), NUM2INT(index), + StringValuePtr(xml), NUM2UINT(flags)); +} +/* + * call-seq: * net.destroy -> nil * * Call +virNetworkDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkDestroy] @@ -216,6 +230,7 @@ void init_network() rb_define_method(c_network, "undefine", libvirt_netw_undefine, 0); rb_define_method(c_network, "create", libvirt_netw_create, 0); + rb_define_method(c_network, "update", libvirt_netw_update, 5); rb_define_method(c_network, "destroy", libvirt_netw_destroy, 0); rb_define_method(c_network, "name", libvirt_netw_name, 0); rb_define_method(c_network, "uuid", libvirt_netw_uuid, 0); @@ -231,5 +246,27 @@ void init_network() #if HAVE_VIRNETWORKISPERSISTENT rb_define_method(c_network, "persistent?", libvirt_netw_persistent_p, 0); #endif +#if HAVE_CONST_VIR_NETWORK_UPDATE_COMMAND_NONE + rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_NONE", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_NONE)); + rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_MODIFY", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_MODIFY)); + rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_ADD_LAST", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_LAST)); + rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_ADD_FIRST", INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST)); + rb_define_const(c_network, "NETWORK_SECTION_NONE", INT2NUM(VIR_NETWORK_SECTION_NONE)); + rb_define_const(c_network, "NETWORK_SECTION_BRIDGE", INT2NUM(VIR_NETWORK_SECTION_BRIDGE)); + rb_define_const(c_network, "NETWORK_SECTION_DOMAIN", INT2NUM(VIR_NETWORK_SECTION_DOMAIN)); + rb_define_const(c_network, "NETWORK_SECTION_IP", INT2NUM(VIR_NETWORK_SECTION_IP)); + rb_define_const(c_network, "NETWORK_SECTION_IP_DHCP_HOST", INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_HOST)); + rb_define_const(c_network, "NETWORK_SECTION_IP_DHCP_RANGE", INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_RANGE)); + rb_define_const(c_network, "NETWORK_SECTION_FORWARD", INT2NUM(VIR_NETWORK_SECTION_FORWARD)); + rb_define_const(c_network, "NETWORK_SECTION_FORWARD_INTERFACE", INT2NUM(VIR_NETWORK_SECTION_FORWARD_INTERFACE)); + rb_define_const(c_network, "NETWORK_SECTION_FORWARD_PF", INT2NUM(VIR_NETWORK_SECTION_FORWARD_PF)); + rb_define_const(c_network, "NETWORK_SECTION_PORTGROUP", INT2NUM(VIR_NETWORK_SECTION_PORTGROUP)); + rb_define_const(c_network, "NETWORK_SECTION_DNS_HOST", INT2NUM(VIR_NETWORK_SECTION_DNS_HOST)); + rb_define_const(c_network, "NETWORK_SECTION_DNS_TXT", INT2NUM(VIR_NETWORK_SECTION_DNS_TXT)); + rb_define_const(c_network, "NETWORK_SECTION_DNS_SRV", INT2NUM(VIR_NETWORK_SECTION_DNS_SRV)); + rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_CURRENT", INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CURRENT)); + rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_LIVE", INT2NUM(VIR_NETWORK_UPDATE_AFFECT_LIVE)); + rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_CONFIG", INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CONFIG)); +#endif #endif } diff --git a/tests/test_network.rb b/tests/test_network.rb index dbe6a0e..c7f9b3f 100644 --- a/tests/test_network.rb +++ b/tests/test_network.rb @@ -37,6 +37,19 @@ 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, "update dhcp ip", "update", + command, section, -1, $new_network_dhcp_ip, flags) + +newnet.destroy + # TESTGROUP: net.destroy newnet = conn.create_network_xml($new_net_xml) diff --git a/tests/test_utils.rb b/tests/test_utils.rb index cc0c856..778c843 100644 --- a/tests/test_utils.rb +++ b/tests/test_utils.rb @@ -79,6 +79,10 @@ $new_net_xml = <<EOF </network> EOF +$new_network_dhcp_ip = <<EOF +<host mac='00:11:22:33:44:55' ip='192.168.134.5'/> +EOF + $NWFILTER_UUID = "bd339530-134c-6d07-441a-17fb90dad807" $new_nwfilter_xml = <<EOF <filter name='ruby-libvirt-tester' chain='ipv4'> -- 1.7.9.5
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list