[libvirt] [dbus PATCH 0/9] Add more properties and methods for Network

Katerina Koukiou (9): tests: Rename minimal_xml to minimal_domain_xml Add Domain prefix to CreateXML method, test and related functions. Add Domain prefix to DefineXML method, tests and related functions. Implement NetworkCreateXML method for Connect interface Implement NetworkDefineXML method for Connect interface Implement GetXMLDesc method for Network Interface. Implement Active property for Network Interface. Implement Persistent property for Network Interface. Implement Setter for Autostart property of Network Interface. data/org.libvirt.Connect.xml | 16 +++++++- data/org.libvirt.Network.xml | 19 ++++++++- src/connect.c | 90 ++++++++++++++++++++++++++++++++++-------- src/network.c | 94 +++++++++++++++++++++++++++++++++++++++++++- test/test_connect.py | 48 +++++++++++++++++++--- test/test_network.py | 15 +++++++ 6 files changed, 256 insertions(+), 26 deletions(-) -- 2.15.0

Needed so as to keep consistent naming when we 'll introduce XML for other entities. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- test/test_connect.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_connect.py b/test/test_connect.py index 79402b8..5436a29 100755 --- a/test/test_connect.py +++ b/test/test_connect.py @@ -6,7 +6,7 @@ import pytest class TestConnect(libvirttest.BaseTestClass): - minimal_xml = ''' + minimal_domain_xml = ''' <domain type="test"> <name>foo</name> <memory>1024</memory> @@ -35,7 +35,7 @@ class TestConnect(libvirttest.BaseTestClass): self.connect.connect_to_signal('DomainEvent', domain_started, arg1='Started') - path = self.connect.CreateXML(self.minimal_xml, 0) + path = self.connect.CreateXML(self.minimal_domain_xml, 0) assert isinstance(path, dbus.ObjectPath) self.main_loop() @@ -47,7 +47,7 @@ class TestConnect(libvirttest.BaseTestClass): self.connect.connect_to_signal('DomainEvent', domain_defined, arg1='Defined') - path = self.connect.DefineXML(self.minimal_xml) + path = self.connect.DefineXML(self.minimal_domain_xml) assert isinstance(path, dbus.ObjectPath) self.main_loop() -- 2.15.0

On Fri, Apr 06, 2018 at 01:20:26PM +0200, Katerina Koukiou wrote:
Needed so as to keep consistent naming when we 'll introduce XML
s/we 'll/we'll/
for other entities.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- test/test_connect.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

This method is domain specific and should be clear from the naming, so that we can later define *CreateXML methods for other entities. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 2 +- src/connect.c | 16 ++++++++-------- test/test_connect.py | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 6aa07f6..c29076d 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -13,7 +13,7 @@ <arg name="flags" type="u" direction="in"/> <arg name="domains" type="ao" direction="out"/> </method> - <method name="CreateXML"> + <method name="DomainCreateXML"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateXML"/> <arg name="xml" type="s" direction="in"/> diff --git a/src/connect.c b/src/connect.c index 85c85ee..3715d25 100644 --- a/src/connect.c +++ b/src/connect.c @@ -150,13 +150,13 @@ virtDBusConnectListDomains(GVariant *inArgs, } static void -virtDBusConnectCreateXML(GVariant *inArgs, - GUnixFDList *inFDs G_GNUC_UNUSED, - const gchar *objectPath G_GNUC_UNUSED, - gpointer userData, - GVariant **outArgs, - GUnixFDList **outFDs G_GNUC_UNUSED, - GError **error) +virtDBusConnectDomainCreateXML(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(virDomain) domain = NULL; @@ -393,7 +393,7 @@ static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "ListDomains", virtDBusConnectListDomains }, - { "CreateXML", virtDBusConnectCreateXML }, + { "DomainCreateXML", virtDBusConnectDomainCreateXML }, { "DefineXML", virtDBusConnectDefineXML }, { "DomainLookupByID", virtDBusDomainLookupByID }, { "DomainLookupByName", virtDBusDomainLookupByName }, diff --git a/test/test_connect.py b/test/test_connect.py index 5436a29..2b2031d 100755 --- a/test/test_connect.py +++ b/test/test_connect.py @@ -28,14 +28,14 @@ class TestConnect(libvirttest.BaseTestClass): # ensure the path exists by calling Introspect on it domain.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE) - def test_create(self): + def test_connect_domain_create_xml(self): def domain_started(path, _event): assert isinstance(path, dbus.ObjectPath) self.loop.quit() self.connect.connect_to_signal('DomainEvent', domain_started, arg1='Started') - path = self.connect.CreateXML(self.minimal_domain_xml, 0) + path = self.connect.DomainCreateXML(self.minimal_domain_xml, 0) assert isinstance(path, dbus.ObjectPath) self.main_loop() -- 2.15.0

On Fri, Apr 06, 2018 at 01:20:27PM +0200, Katerina Koukiou wrote: In the $subject s/, test and related functions.// we don't end the subject with period and the part after comma can be removed.
This method is domain specific and should be clear from the naming, so that we can later define *CreateXML methods for other entities.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 2 +- src/connect.c | 16 ++++++++-------- test/test_connect.py | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

This method is domain specific and should be clear from the naming, so that we can later define *DefineXML methods for other entities. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 2 +- src/connect.c | 16 ++++++++-------- test/test_connect.py | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index c29076d..715aeef 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -20,7 +20,7 @@ <arg name="flags" type="u" direction="in"/> <arg name="domain" type="o" direction="out"/> </method> - <method name="DefineXML"> + <method name="DomainDefineXML"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDefineXML"/> <arg name="xml" type="s" direction="in"/> diff --git a/src/connect.c b/src/connect.c index 3715d25..9931c8f 100644 --- a/src/connect.c +++ b/src/connect.c @@ -179,13 +179,13 @@ virtDBusConnectDomainCreateXML(GVariant *inArgs, } static void -virtDBusConnectDefineXML(GVariant *inArgs, - GUnixFDList *inFDs G_GNUC_UNUSED, - const gchar *objectPath G_GNUC_UNUSED, - gpointer userData, - GVariant **outArgs, - GUnixFDList **outFDs G_GNUC_UNUSED, - GError **error) +virtDBusConnectDomainDefineXML(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(virDomain) domain = NULL; @@ -394,7 +394,7 @@ static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "ListDomains", virtDBusConnectListDomains }, { "DomainCreateXML", virtDBusConnectDomainCreateXML }, - { "DefineXML", virtDBusConnectDefineXML }, + { "DomainDefineXML", virtDBusConnectDomainDefineXML }, { "DomainLookupByID", virtDBusDomainLookupByID }, { "DomainLookupByName", virtDBusDomainLookupByName }, { "DomainLookupByUUID", virtDBusDomainLookupByUUID }, diff --git a/test/test_connect.py b/test/test_connect.py index 2b2031d..394f812 100755 --- a/test/test_connect.py +++ b/test/test_connect.py @@ -40,14 +40,14 @@ class TestConnect(libvirttest.BaseTestClass): self.main_loop() - def test_define(self): + def test_comnect_domain_define_xml(self): def domain_defined(path, _event): assert isinstance(path, dbus.ObjectPath) self.loop.quit() self.connect.connect_to_signal('DomainEvent', domain_defined, arg1='Defined') - path = self.connect.DefineXML(self.minimal_domain_xml) + path = self.connect.DomainDefineXML(self.minimal_domain_xml) assert isinstance(path, dbus.ObjectPath) self.main_loop() -- 2.15.0

On Fri, Apr 06, 2018 at 01:20:28PM +0200, Katerina Koukiou wrote: Same comment for the $subject as in the previous patch.
This method is domain specific and should be clear from the naming, so that we can later define *DefineXML methods for other entities.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 2 +- src/connect.c | 16 ++++++++-------- test/test_connect.py | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ test/test_connect.py | 26 ++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 715aeef..5f5c5fe 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -50,6 +50,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="networks" type="ao" direction="out"/> </method> + <method name="NetworkCreateXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreateXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="network" type="o" direction="out"/> + </method> <method name="NetworkLookupByName"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName"/> diff --git a/src/connect.c b/src/connect.c index 9931c8f..759b9fb 100644 --- a/src/connect.c +++ b/src/connect.c @@ -330,6 +330,34 @@ virtDBusConnectListNetworks(GVariant *inArgs, *outArgs = g_variant_new_tuple(&gnetworks, 1); } +static void +virtDBusConnectNetworkCreateXML(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; + gchar *xml; + + g_variant_get(inArgs, "(&s)", &xml); + + if (!virtDBusConnectOpen(connect, error)) + return; + + network = virNetworkCreateXML(connect->connection, xml); + if (!network) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirNetwork(network, connect->domainPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusNetworkLookupByName(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -399,6 +427,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "DomainLookupByName", virtDBusDomainLookupByName }, { "DomainLookupByUUID", virtDBusDomainLookupByUUID }, { "ListNetworks", virtDBusConnectListNetworks }, + { "NetworkCreateXML", virtDBusConnectNetworkCreateXML }, { "NetworkLookupByName", virtDBusNetworkLookupByName }, { "NetworkLookupByUUID", virtDBusNetworkLookupByUUID }, { 0 } diff --git a/test/test_connect.py b/test/test_connect.py index 394f812..e3b493b 100755 --- a/test/test_connect.py +++ b/test/test_connect.py @@ -16,6 +16,20 @@ class TestConnect(libvirttest.BaseTestClass): </domain> ''' + minimal_network_xml = ''' + <network> + <name>bar</name> + <uuid>004b96e12d78c30f5aa5f03c87d21e69</uuid> + <bridge name='brdefault'/> + <forward dev='eth0'/> + <ip address='192.168.122.1' netmask='255.255.255.0'> + <dhcp> + <range start='192.168.122.128' end='192.168.122.253'/> + </dhcp> + </ip> + </network> + ''' + def test_list_domains(self): domains = self.connect.ListDomains(0) assert isinstance(domains, dbus.Array) @@ -86,6 +100,18 @@ class TestConnect(libvirttest.BaseTestClass): # ensure the path exists by calling Introspect on it network.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE) + def test_connect_network_create_xml(self): + def network_started(path, _event): + assert isinstance(path, dbus.ObjectPath) + self.loop.quit() + + self.connect.connect_to_signal('NetworkEvent', network_started, arg1='Started') + + path = self.connect.NetworkCreateXML(self.minimal_network_xml) + assert isinstance(path, dbus.ObjectPath) + + self.main_loop() + @pytest.mark.parametrize("lookup_method_name,lookup_item", [ ("NetworkLookupByName", 'Name'), ("NetworkLookupByUUID", 'UUID'), -- 2.15.0

On Fri, Apr 06, 2018 at 01:20:29PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ test/test_connect.py | 26 ++++++++++++++++++++++++++ 3 files changed, 61 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 715aeef..5f5c5fe 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -50,6 +50,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="networks" type="ao" direction="out"/> </method> + <method name="NetworkCreateXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreateXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="network" type="o" direction="out"/> + </method> <method name="NetworkLookupByName"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName"/> diff --git a/src/connect.c b/src/connect.c index 9931c8f..759b9fb 100644 --- a/src/connect.c +++ b/src/connect.c @@ -330,6 +330,34 @@ virtDBusConnectListNetworks(GVariant *inArgs, *outArgs = g_variant_new_tuple(&gnetworks, 1); }
+static void +virtDBusConnectNetworkCreateXML(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; + gchar *xml;
This can be const gchar *xml. Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ test/test_connect.py | 12 ++++++++++++ 3 files changed, 47 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 5f5c5fe..e36b7f6 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -56,6 +56,12 @@ <arg name="xml" type="s" direction="in"/> <arg name="network" type="o" direction="out"/> </method> + <method name="NetworkDefineXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkDefineXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="network" type="o" direction="out"/> + </method> <method name="NetworkLookupByName"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName"/> diff --git a/src/connect.c b/src/connect.c index 759b9fb..3a0e969 100644 --- a/src/connect.c +++ b/src/connect.c @@ -358,6 +358,34 @@ virtDBusConnectNetworkCreateXML(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusConnectNetworkDefineXML(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; + gchar *xml; + + g_variant_get(inArgs, "(&s)", &xml); + + if (!virtDBusConnectOpen(connect, error)) + return; + + network = virNetworkDefineXML(connect->connection, xml); + if (!network) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirNetwork(network, connect->networkPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusNetworkLookupByName(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -428,6 +456,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "DomainLookupByUUID", virtDBusDomainLookupByUUID }, { "ListNetworks", virtDBusConnectListNetworks }, { "NetworkCreateXML", virtDBusConnectNetworkCreateXML }, + { "NetworkDefineXML", virtDBusConnectNetworkDefineXML }, { "NetworkLookupByName", virtDBusNetworkLookupByName }, { "NetworkLookupByUUID", virtDBusNetworkLookupByUUID }, { 0 } diff --git a/test/test_connect.py b/test/test_connect.py index e3b493b..c411eeb 100755 --- a/test/test_connect.py +++ b/test/test_connect.py @@ -112,6 +112,18 @@ class TestConnect(libvirttest.BaseTestClass): self.main_loop() + def test_connect_network_define_xml(self): + def network_defined(path, _event): + assert isinstance(path, dbus.ObjectPath) + self.loop.quit() + + self.connect.connect_to_signal('NetworkEvent', network_defined, arg1='Defined') + + path = self.connect.NetworkDefineXML(self.minimal_network_xml) + assert isinstance(path, dbus.ObjectPath) + + self.main_loop() + @pytest.mark.parametrize("lookup_method_name,lookup_item", [ ("NetworkLookupByName", 'Name'), ("NetworkLookupByUUID", 'UUID'), -- 2.15.0

On Fri, Apr 06, 2018 at 01:20:30PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ test/test_connect.py | 12 ++++++++++++ 3 files changed, 47 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 5f5c5fe..e36b7f6 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -56,6 +56,12 @@ <arg name="xml" type="s" direction="in"/> <arg name="network" type="o" direction="out"/> </method> + <method name="NetworkDefineXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkDefineXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="network" type="o" direction="out"/> + </method> <method name="NetworkLookupByName"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName"/> diff --git a/src/connect.c b/src/connect.c index 759b9fb..3a0e969 100644 --- a/src/connect.c +++ b/src/connect.c @@ -358,6 +358,34 @@ virtDBusConnectNetworkCreateXML(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); }
+static void +virtDBusConnectNetworkDefineXML(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; + gchar *xml;
const gchar *xml; Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Network.xml | 6 ++++++ src/network.c | 28 ++++++++++++++++++++++++++++ test/test_network.py | 5 +++++ 3 files changed, 39 insertions(+) diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml index 46198fe..456217a 100644 --- a/data/org.libvirt.Network.xml +++ b/data/org.libvirt.Network.xml @@ -27,6 +27,12 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkDestroy"/> </method> + <method name="GetXMLDesc"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetXMLDesc"/> + <arg name="flags" type="u" direction="in"/> + <arg name="xml" type="s" direction="out"/> + </method> <method name="Undefine"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkUndefine"/> diff --git a/src/network.c b/src/network.c index bb385d3..bd9e86a 100644 --- a/src/network.c +++ b/src/network.c @@ -147,6 +147,33 @@ virtDBusNetworkDestroy(GVariant *inArgs G_GNUC_UNUSED, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusNetworkGetXMLDesc(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNetwork) network = NULL; + g_autofree gchar *xml = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + network = virtDBusNetworkGetVirNetwork(connect, objectPath, error); + if (!network) + return; + + xml = virNetworkGetXMLDesc(network, flags); + if (!xml) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("(s)", xml); +} + static void virtDBusNetworkUndefine(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -178,6 +205,7 @@ static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = { static virtDBusGDBusMethodTable virtDBusNetworkMethodTable[] = { { "Create", virtDBusNetworkCreate }, { "Destroy", virtDBusNetworkDestroy }, + { "GetXMLDesc", virtDBusNetworkGetXMLDesc }, { "Undefine", virtDBusNetworkUndefine }, { 0 } }; diff --git a/test/test_network.py b/test/test_network.py index 8ec54ad..397fc0c 100755 --- a/test/test_network.py +++ b/test/test_network.py @@ -44,6 +44,11 @@ class TestNetwork(libvirttest.BaseTestClass): self.main_loop() + def test_network_get_xml_description(self): + _,test_network = self.test_network() + interface_obj = dbus.Interface(test_network, 'org.libvirt.Network') + assert isinstance(interface_obj.GetXMLDesc(0), dbus.String) + def test_network_undefine(self): def domain_undefined(path, _event): assert isinstance(path, dbus.ObjectPath) -- 2.15.0

On Fri, Apr 06, 2018 at 01:20:31PM +0200, Katerina Koukiou wrote: In $subject remove the period.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Network.xml | 6 ++++++ src/network.c | 28 ++++++++++++++++++++++++++++ test/test_network.py | 5 +++++ 3 files changed, 39 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Network.xml | 4 ++++ src/network.c | 22 ++++++++++++++++++++++ test/test_network.py | 1 + 3 files changed, 27 insertions(+) diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml index 456217a..cadf0a8 100644 --- a/data/org.libvirt.Network.xml +++ b/data/org.libvirt.Network.xml @@ -3,6 +3,10 @@ <node name="/org/libvirt/network"> <interface name="org.libvirt.Network"> + <property name="Active" type="b" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsActive"/> + </property> <property name="Autostart" type="b" access="read"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetAutostart"/> diff --git a/src/network.c b/src/network.c index bd9e86a..7f0091a 100644 --- a/src/network.c +++ b/src/network.c @@ -24,6 +24,27 @@ virtDBusNetworkGetVirNetwork(virtDBusConnect *connect, return network; } +static void +virtDBusNetworkGetActive(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNetwork) network = NULL; + gint active; + + network = virtDBusNetworkGetVirNetwork(connect, objectPath, error); + if (!network) + return; + + active = virNetworkIsActive(network); + if (active < 0) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("b", !!active); +} + static void virtDBusNetworkGetAutostart(const gchar *objectPath, gpointer userData, @@ -195,6 +216,7 @@ virtDBusNetworkUndefine(GVariant *inArgs G_GNUC_UNUSED, } static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = { + { "Active", virtDBusNetworkGetActive, NULL }, { "Autostart", virtDBusNetworkGetAutostart, NULL }, { "BridgeName", virtDBusNetworkGetBridgeName, NULL }, { "Name", virtDBusNetworkGetName, NULL }, diff --git a/test/test_network.py b/test/test_network.py index 397fc0c..4180cc8 100755 --- a/test/test_network.py +++ b/test/test_network.py @@ -12,6 +12,7 @@ class TestNetwork(libvirttest.BaseTestClass): """ _, obj = self.test_network() props = obj.GetAll('org.libvirt.Network', dbus_interface=dbus.PROPERTIES_IFACE) + assert isinstance(props['Active'], dbus.Boolean) assert isinstance(props['Autostart'], dbus.Boolean) assert isinstance(props['BridgeName'], dbus.String) assert isinstance(props['Name'], dbus.String) -- 2.15.0

On Fri, Apr 06, 2018 at 01:20:32PM +0200, Katerina Koukiou wrote: In $subject remove the period.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Network.xml | 4 ++++ src/network.c | 22 ++++++++++++++++++++++ test/test_network.py | 1 + 3 files changed, 27 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Network.xml | 4 ++++ src/network.c | 22 ++++++++++++++++++++++ test/test_network.py | 1 + 3 files changed, 27 insertions(+) diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml index cadf0a8..863f4d2 100644 --- a/data/org.libvirt.Network.xml +++ b/data/org.libvirt.Network.xml @@ -19,6 +19,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetName"/> </property> + <property name="Persistent" type="b" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsPersistent"/> + </property> <property name="UUID" type="s" access="read"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetUUIDString"/> diff --git a/src/network.c b/src/network.c index 7f0091a..5ca1379 100644 --- a/src/network.c +++ b/src/network.c @@ -108,6 +108,27 @@ virtDBusNetworkGetName(const gchar *objectPath, *value = g_variant_new("s", name); } +static void +virtDBusNetworkGetPersistent(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNetwork) network = NULL; + gint persistent; + + network = virtDBusNetworkGetVirNetwork(connect, objectPath, error); + if (!network) + return; + + persistent = virNetworkIsPersistent(network); + if (persistent < 0) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("b", !!persistent); +} + static void virtDBusNetworkGetUUID(const gchar *objectPath, gpointer userData, @@ -220,6 +241,7 @@ static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = { { "Autostart", virtDBusNetworkGetAutostart, NULL }, { "BridgeName", virtDBusNetworkGetBridgeName, NULL }, { "Name", virtDBusNetworkGetName, NULL }, + { "Persistent", virtDBusNetworkGetPersistent, NULL }, { "UUID", virtDBusNetworkGetUUID, NULL }, { 0 } }; diff --git a/test/test_network.py b/test/test_network.py index 4180cc8..a5987e5 100755 --- a/test/test_network.py +++ b/test/test_network.py @@ -16,6 +16,7 @@ class TestNetwork(libvirttest.BaseTestClass): assert isinstance(props['Autostart'], dbus.Boolean) assert isinstance(props['BridgeName'], dbus.String) assert isinstance(props['Name'], dbus.String) + assert isinstance(props['Persistent'], dbus.Boolean) assert isinstance(props['UUID'], dbus.String) def test_network_create(self): -- 2.15.0

On Fri, Apr 06, 2018 at 01:20:33PM +0200, Katerina Koukiou wrote: In $subject remove the period.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Network.xml | 4 ++++ src/network.c | 22 ++++++++++++++++++++++ test/test_network.py | 1 + 3 files changed, 27 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Network.xml | 5 +++-- src/network.c | 22 +++++++++++++++++++++- test/test_network.py | 8 ++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml index 863f4d2..1d89ae3 100644 --- a/data/org.libvirt.Network.xml +++ b/data/org.libvirt.Network.xml @@ -7,9 +7,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsActive"/> </property> - <property name="Autostart" type="b" access="read"> + <property name="Autostart" type="b" access="readwrite"> <annotation name="org.gtk.GDBus.DocString" - value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetAutostart"/> + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetAutostart and + https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkSetAutostart"/> </property> <property name="BridgeName" type="s" access="read"> <annotation name="org.gtk.GDBus.DocString" diff --git a/src/network.c b/src/network.c index 5ca1379..1448777 100644 --- a/src/network.c +++ b/src/network.c @@ -149,6 +149,26 @@ virtDBusNetworkGetUUID(const gchar *objectPath, *value = g_variant_new("s", uuid); } +static void +virtDBusNetworkSetAutostart(GVariant *value, + const gchar *objectPath, + gpointer userData, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNetwork) network = NULL; + gboolean autostart; + + g_variant_get(value, "b", &autostart); + + network = virtDBusNetworkGetVirNetwork(connect, objectPath, error); + if (!network) + return; + + if (virNetworkSetAutostart(network, autostart) < 0) + return virtDBusUtilSetLastVirtError(error); +} + static void virtDBusNetworkCreate(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -238,7 +258,7 @@ virtDBusNetworkUndefine(GVariant *inArgs G_GNUC_UNUSED, static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = { { "Active", virtDBusNetworkGetActive, NULL }, - { "Autostart", virtDBusNetworkGetAutostart, NULL }, + { "Autostart", virtDBusNetworkGetAutostart, virtDBusNetworkSetAutostart }, { "BridgeName", virtDBusNetworkGetBridgeName, NULL }, { "Name", virtDBusNetworkGetName, NULL }, { "Persistent", virtDBusNetworkGetPersistent, NULL }, diff --git a/test/test_network.py b/test/test_network.py index a5987e5..0dda923 100755 --- a/test/test_network.py +++ b/test/test_network.py @@ -19,6 +19,14 @@ class TestNetwork(libvirttest.BaseTestClass): assert isinstance(props['Persistent'], dbus.Boolean) assert isinstance(props['UUID'], dbus.String) + def test_network_autostart(self): + _,test_network = self.test_network() + interface_obj = dbus.Interface(test_network, 'org.libvirt.Network') + autostart_expected = True + interface_obj.Set('org.libvirt.Network', 'Autostart', autostart_expected, dbus_interface=dbus.PROPERTIES_IFACE) + autostart_current = interface_obj.Get('org.libvirt.Network', 'Autostart', dbus_interface=dbus.PROPERTIES_IFACE) + assert autostart_current == dbus.Boolean(autostart_expected) + def test_network_create(self): def domain_started(path, _event): assert isinstance(path, dbus.ObjectPath) -- 2.15.0

On Fri, Apr 06, 2018 at 01:20:34PM +0200, Katerina Koukiou wrote: In $subject remove the period.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Network.xml | 5 +++-- src/network.c | 22 +++++++++++++++++++++- test/test_network.py | 8 ++++++++ 3 files changed, 32 insertions(+), 3 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

On Fri, 2018-04-06 at 13:20 +0200, Katerina Koukiou wrote:
Katerina Koukiou (9): tests: Rename minimal_xml to minimal_domain_xml Add Domain prefix to CreateXML method, test and related functions.
I broke tests with this, and I didn't realize because of the known issue with non propagating Exceptions from handlers. Will fix and repost.
Add Domain prefix to DefineXML method, tests and related functions. Implement NetworkCreateXML method for Connect interface Implement NetworkDefineXML method for Connect interface Implement GetXMLDesc method for Network Interface. Implement Active property for Network Interface. Implement Persistent property for Network Interface. Implement Setter for Autostart property of Network Interface.
data/org.libvirt.Connect.xml | 16 +++++++- data/org.libvirt.Network.xml | 19 ++++++++- src/connect.c | 90 ++++++++++++++++++++++++++++++++++-------- src/network.c | 94 +++++++++++++++++++++++++++++++++++++++++++- test/test_connect.py | 48 +++++++++++++++++++--- test/test_network.py | 15 +++++++ 6 files changed, 256 insertions(+), 26 deletions(-)
participants (2)
-
Katerina Koukiou
-
Pavel Hrdina