Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- 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 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list