Signed-off-by: Anya Harter <aharter(a)redhat.com>
---
data/org.libvirt.Connect.xml | 6 ++++++
src/connect.c | 29 +++++++++++++++++++++++++++++
tests/test_connect.py | 12 ++++++++++++
3 files changed, 47 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 7c97117..f99e205 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -170,6 +170,12 @@
<arg name="flags" type="u" direction="in"/>
<arg name="interface" type="o"
direction="out"/>
</method>
+ <method name="InterfaceLookupByName">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceLooku...
+ <arg name="name" type="s" direction="in"/>
+ <arg name="interface" type="o"
direction="out"/>
+ </method>
<method name="ListDomains">
<annotation name="org.gtk.GDBus.DocString"
value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListAllDom...
diff --git a/src/connect.c b/src/connect.c
index ebcfa38..ae64d59 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -827,6 +827,34 @@ virtDBusConnectInterfaceDefineXML(GVariant *inArgs,
*outArgs = g_variant_new("(o)", path);
}
+static void
+virtDBusConnectInterfaceLookupByName(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(virInterface) interface = NULL;
+ g_autofree gchar *path = NULL;
+ const gchar *name;
+
+ g_variant_get(inArgs, "(&s)", &name);
+
+ if (!virtDBusConnectOpen(connect, NULL))
+ return;
+
+ interface = virInterfaceLookupByName(connect->connection, name);
+ if (!interface)
+ return virtDBusUtilSetLastVirtError(error);
+
+ path = virtDBusUtilBusPathForVirInterface(interface, connect->interfacePath);
+
+ *outArgs = g_variant_new("(o)", path);
+}
+
static void
virtDBusConnectListDomains(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -1899,6 +1927,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
{ "InterfaceChangeCommit", virtDBusConnectInterfaceChangeCommit },
{ "InterfaceChangeRollback", virtDBusConnectInterfaceChangeRollback },
{ "InterfaceDefineXML", virtDBusConnectInterfaceDefineXML },
+ { "InterfaceLookupByName", virtDBusConnectInterfaceLookupByName },
{ "ListDomains", virtDBusConnectListDomains },
{ "ListInterfaces", virtDBusConnectListInterfaces },
{ "ListNetworks", virtDBusConnectListNetworks },
diff --git a/tests/test_connect.py b/tests/test_connect.py
index d21b366..7e33b2a 100755
--- a/tests/test_connect.py
+++ b/tests/test_connect.py
@@ -88,6 +88,18 @@ class TestConnect(libvirttest.BaseTestClass):
path = self.connect.InterfaceDefineXML(xmldata.minimal_interface_xml, 0)
assert isinstance(path, dbus.ObjectPath)
+ @pytest.mark.parametrize("lookup_method_name,lookup_item", [
+ ("InterfaceLookupByName", 'Name'),
+ ])
+ def test_connect_interface_lookup_by_property(self, lookup_method_name,
lookup_item):
+ """Parameterized test for all InterfaceLookupBy* API calls of
Connect interface
+ """
+ original_path,_ = self.interface_create()
+ obj = self.bus.get_object('org.libvirt', original_path)
+ prop = obj.Get('org.libvirt.Interface', lookup_item,
dbus_interface=dbus.PROPERTIES_IFACE)
+ path = getattr(self.connect, lookup_method_name)(prop)
+ assert original_path == path
+
def test_connect_list_networks(self):
networks = self.connect.ListNetworks(0)
assert isinstance(networks, dbus.Array)
--
2.17.1