[dbus PATCH 04/14] Implement NodeDeviceCreateXML method for Connect Interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
---
 data/org.libvirt.Connect.xml |  7 +++++++
 src/connect.c                | 30 ++++++++++++++++++++++++++++++
 tests/libvirttest.py         |  3 +++
 tests/test_connect.py        | 14 ++++++++++++++
 tests/xmldata.py             | 16 ++++++++++++++++
 5 files changed, 70 insertions(+)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 3828832..d8b0d9e 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -208,6 +208,13 @@
       <arg name="uuid" type="s" direction="in"/>
       <arg name="network" type="o" direction="out"/>
     </method>
+    <method name="NodeDeviceCreateXML">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceCreateXML"/>
+      <arg name="xml" type="s" direction="in"/>
+      <arg name="flags" type="u" direction="in"/>
+      <arg name="dev" type="o" direction="out"/>
+    </method>
     <method name="NWFilterDefineXML">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterDefineXML"/>
diff --git a/src/connect.c b/src/connect.c
index 1c27768..5e146a6 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -1069,6 +1069,35 @@ virtDBusConnectNetworkLookupByUUID(GVariant *inArgs,
     *outArgs = g_variant_new("(o)", path);
 }
 
+static void
+virtDBusConnectNodeDeviceCreateXML(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(virNodeDevice) dev = NULL;
+    g_autofree gchar *path = NULL;
+    gchar *xml;
+    guint flags;
+
+    g_variant_get(inArgs, "(&su)", &xml, &flags);
+
+    if (!virtDBusConnectOpen(connect, error))
+        return;
+
+    dev = virNodeDeviceCreateXML(connect->connection, xml, flags);
+    if (!dev)
+        return virtDBusUtilSetLastVirtError(error);
+
+    path = virtDBusUtilBusPathForVirNodeDevice(dev, connect->devPath);
+
+    *outArgs = g_variant_new("(o)", path);
+}
+
 static void
 virtDBusConnectNWFilterDefineXML(GVariant *inArgs,
                                  GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -1687,6 +1716,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "NetworkDefineXML", virtDBusConnectNetworkDefineXML },
     { "NetworkLookupByName", virtDBusConnectNetworkLookupByName },
     { "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID },
+    { "NodeDeviceCreateXML", virtDBusConnectNodeDeviceCreateXML },
     { "NWFilterDefineXML", virtDBusConnectNWFilterDefineXML },
     { "NWFilterLookupByName", virtDBusConnectNWFilterLookupByName },
     { "NWFilterLookupByUUID", virtDBusConnectNWFilterLookupByUUID },
diff --git a/tests/libvirttest.py b/tests/libvirttest.py
index 6d1a9d0..6b6cb4c 100644
--- a/tests/libvirttest.py
+++ b/tests/libvirttest.py
@@ -217,6 +217,9 @@ class NetworkEvent(IntEnum):
     STARTED = 2
     STOPPED = 3
 
+class NodeDeviceEvent(IntEnum):
+    CREATED = 0
+    DELETED = 1
 
 class StoragePoolBuildFlags(IntEnum):
     NEW = 0
diff --git a/tests/test_connect.py b/tests/test_connect.py
index 57b385e..e532016 100755
--- a/tests/test_connect.py
+++ b/tests/test_connect.py
@@ -155,6 +155,20 @@ class TestConnect(libvirttest.BaseTestClass):
         path = getattr(self.connect, lookup_method_name)(prop)
         assert original_path == path
 
+    def test_connect_node_device_create_xml(self):
+        def node_device_created(path, event, _detail):
+            if event != libvirttest.NodeDeviceEvent.CREATED:
+                return
+            assert isinstance(path, dbus.ObjectPath)
+            self.loop.quit()
+
+        self.connect.connect_to_signal('NodeDeviceEvent', node_device_created)
+
+        path = self.connect.NodeDeviceCreateXML(xmldata.minimal_node_device_xml, 0)
+        assert isinstance(path, dbus.ObjectPath)
+
+        self.main_loop()
+
     def test_connect_node_get_cpu_stats(self):
         stats = self.connect.NodeGetCPUStats(0, 0)
         assert isinstance(stats, dbus.Dictionary)
diff --git a/tests/xmldata.py b/tests/xmldata.py
index 926bd2c..25bb089 100644
--- a/tests/xmldata.py
+++ b/tests/xmldata.py
@@ -26,6 +26,22 @@ minimal_network_xml = '''
 </network>
 '''
 
+minimal_node_device_xml = '''
+<device>
+  <name>scsi_host22</name>
+  <parent>scsi_host2</parent>
+  <capability type='scsi_host'>
+    <host>22</host>
+    <unique_id>22</unique_id>
+    <capability type='fc_host'>
+      <wwnn>2000000098765432</wwnn>
+      <wwpn>1000000098765432</wwpn>
+      <fabric_wwn>2000000098769876</fabric_wwn>
+    </capability>
+  </capability>
+</device>
+'''
+
 minimal_storage_pool_xml = '''
 <pool type='dir'>
   <name>foo</name>
-- 
2.15.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux