Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ test/test_connect.py | 11 +++++++++++ 3 files changed, 46 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index ac06875..2901ba5 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -56,5 +56,11 @@ <arg name="flags" type="u" direction="in"/> <arg name="networks" type="ao" direction="out"/> </method> + <method name="NetworkLookupByName"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName"/> + <arg name="name" type="s" direction="in"/> + <arg name="network" type="o" direction="out"/> + </method> </interface> </node> diff --git a/src/connect.c b/src/connect.c index 13fdd20..a17e15c 100644 --- a/src/connect.c +++ b/src/connect.c @@ -320,6 +320,34 @@ virtDBusConnectListNetworks(GVariant *inArgs, *outArgs = g_variant_new_tuple(&gnetworks, 1); } +static void +virtDBusNetworkLookupByName(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNetwork) network = NULL; + g_autofree gchar *path = NULL; + const gchar *name; + + g_variant_get(inArgs, "(s)", &name); + + if (!virtDBusConnectOpen(connect, NULL)) + return; + + network = virNetworkLookupByName(connect->connection, name); + if (!network) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirNetwork(network, connect->networkPath); + + *outArgs = g_variant_new("(o)", path); +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Version", virtDBusConnectGetVersion, NULL }, { 0 } @@ -333,6 +361,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "DomainLookupByName", virtDBusDomainLookupByName }, { "DomainLookupByUUID", virtDBusDomainLookupByUUID }, { "ListNetworks", virtDBusConnectListNetworks }, + { "NetworkLookupByName", virtDBusNetworkLookupByName }, { 0 } }; diff --git a/test/test_connect.py b/test/test_connect.py index 5df7a5b..5f82259 100755 --- a/test/test_connect.py +++ b/test/test_connect.py @@ -74,6 +74,17 @@ class TestConnect(libvirttest.BaseTestClass): props = obj.GetAll('org.libvirt.Connect', dbus_interface=dbus.PROPERTIES_IFACE) assert isinstance(props[property_name], expected_type) + @pytest.mark.parametrize("lookup_method_name,lookup_item", [ + ("NetworkLookupByName", 'Name'), + ]) + def test_connect_network_lookup_by_property(self, lookup_method_name, lookup_item): + """Parameterized test for all NetworkLookupBy* API calls of Connect interface + """ + original_path, obj = self.test_network() + prop = obj.Get('org.libvirt.Network', lookup_item, dbus_interface=dbus.PROPERTIES_IFACE) + path = getattr(self.connect, lookup_method_name)(prop) + assert original_path == path + if __name__ == '__main__': libvirttest.run() -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list