Converting ENUMS to str can be user friendly though it can be problematic in matters of backward compatibility. In particular when some ENUM in libvirt API will introduce a new constant, libvirt-dbus will fail with: size of array ‘_GStaticAssertCompileTimeAssertion_5’ is negative So using ints is preferable to avoid the previous issue. Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- data/org.libvirt.Network.xml | 6 ++-- src/network.c | 66 +++----------------------------------------- tests/test_network.py | 2 +- 3 files changed, 8 insertions(+), 66 deletions(-) diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml index cf05062..e8c1506 100644 --- a/data/org.libvirt.Network.xml +++ b/data/org.libvirt.Network.xml @@ -43,7 +43,7 @@ Empty string will be returned in output for NULL variables."/> <arg name="mac" type="s" direction="in"/> <arg name="flags" type="u" direction="in"/> - <arg name="leases" type="a(stssssuss)" direction="out"/> + <arg name="leases" type="a(stusssuss)" direction="out"/> </method> <method name="GetXMLDesc"> <annotation name="org.gtk.GDBus.DocString" @@ -58,8 +58,8 @@ <method name="Update"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkUpdate"/> - <arg name="command" type="s" direction="in"/> - <arg name="section" type="s" direction="in"/> + <arg name="command" type="u" direction="in"/> + <arg name="section" type="u" direction="in"/> <arg name="parentIndex" type="i" direction="in"/> <arg name="xml" type="s" direction="in"/> <arg name="flags" type="u" direction="in"/> diff --git a/src/network.c b/src/network.c index 4d00dfe..256940f 100644 --- a/src/network.c +++ b/src/network.c @@ -3,38 +3,6 @@ #include <libvirt/libvirt.h> -VIRT_DBUS_ENUM_DECL(virtDBusNetworkIPAddr) -VIRT_DBUS_ENUM_IMPL(virtDBusNetworkIPAddr, - VIR_IP_ADDR_TYPE_LAST, - "ipv4", - "ipv6") - -VIRT_DBUS_ENUM_DECL(virtDBusNetworkUpdateCommand) -VIRT_DBUS_ENUM_IMPL(virtDBusNetworkUpdateCommand, - VIR_NETWORK_UPDATE_COMMAND_LAST, - "none", - "modify", - "delete", - "add-last", - "add-first") - -VIRT_DBUS_ENUM_DECL(virtDBusNetworkUpdateSection) -VIRT_DBUS_ENUM_IMPL(virtDBusNetworkUpdateSection, - VIR_NETWORK_SECTION_LAST, - "none", - "bridge", - "domain", - "ip", - "ip-dhcp-host", - "ip-dhcp-range", - "forward", - "forward-interface", - "forward-pf", - "portgroup", - "dns-host", - "dns-txt", - "dns-srv") - static void virtDBusNetworkDHCPLeaseListFree(virNetworkDHCPLeasePtr *leases) { @@ -284,20 +252,11 @@ virtDBusNetworkGetDHCPLeases(GVariant *inArgs, g_variant_builder_init(&builder, G_VARIANT_TYPE("a(stssssuss)")); for (gint i = 0; i < nleases; i++) { - const gchar *typeStr; - virNetworkDHCPLeasePtr lease = leases[i]; - typeStr = virtDBusNetworkIPAddrTypeToString(lease->type); - if (!typeStr) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't format virIPAddrType '%d' to string.", lease->type); - return; - } - - g_variant_builder_add(&builder, "(stssssuss)", + g_variant_builder_add(&builder, "(stusssuss)", lease->iface, lease->expirytime, - typeStr, lease->mac, + lease->type, lease->mac, lease->iaid ? lease->iaid : "" , lease->ipaddr, lease->prefix, lease->hostname ? lease->hostname : "", @@ -366,33 +325,16 @@ virtDBusNetworkUpdate(GVariant *inArgs, { virtDBusConnect *connect = userData; g_autoptr(virNetwork) network = NULL; - const gchar *commandStr; gint command; - const gchar *sectionStr; gint section; gint parentIndex; const gchar *xml; guint flags; - g_variant_get(inArgs, "(&s&si&su)", - &commandStr, §ionStr, + g_variant_get(inArgs, "(uui&su)", + &command, §ion, &parentIndex, &xml, &flags); - command = virtDBusNetworkUpdateCommandTypeFromString(commandStr); - if (command < 0) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't get valid virNetworkUpdateCommand from string '%s'.", - commandStr); - return; - } - section = virtDBusNetworkUpdateSectionTypeFromString(sectionStr); - if (section < 0) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't get valid virNetworkUpdateSection from string '%s'.", - sectionStr); - return; - } - network = virtDBusNetworkGetVirNetwork(connect, objectPath, error); if (!network) return; diff --git a/tests/test_network.py b/tests/test_network.py index 2c1bd21..1340d95 100755 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -80,7 +80,7 @@ class TestNetwork(libvirttest.BaseTestClass): self.main_loop() @pytest.mark.parametrize("command, section, parentIndex, xml_str, flags", [ - ('add-first', 'ip-dhcp-host', 0, ip_dhcp_host_xml, 0), + ('4', '4', 0, ip_dhcp_host_xml, 0), # add-first, ip-dhcp-host ]) def test_network_update(self, command, section, parentIndex, xml_str, flags): _, test_network = self.test_network() -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list