[libvirt] [dbus PATCH 00/10] *** Use API calls supporting flags ***

* Replace all API calls to support flags where possible. * Replace libvirt-dbus API method names to follow naming of libvirt API. * Change type of virtDBusDomainGetVcpus from property to method. Katerina Koukiou (10): virtDBusDomainGetVcpus: Should be implemented as method and not as property GetVcpus API method: Renamed to GetVcpusFlags virtDBusDomainShutdown: Use virDomainShutdownFlags instead of virDomainShutdown Shutdown API method: Renamed to ShutdownFlags virtDBusDomainCreate: Use virDomainCreateWithFlags instead of virDomainCreate Create API method: Renamed to CreateWithFlags virtDBusDomainUndefine: Use virDomainUndefineFlags instead of virDomainUndefine Undefine API method: Renamed to UndefineFlags virtDBusDomainDestroy: Use virDomainDestroyFlags instead of virDomainDestroy Destroy API method: Renamed to DestroyFlags data/org.libvirt.Domain.xml | 21 +++++-- src/domain.c | 134 +++++++++++++++++++++++++------------------- test/test_domain.py | 22 +++++--- 3 files changed, 106 insertions(+), 71 deletions(-) -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 5 ++++- src/domain.c | 51 ++++++++++++++++++++++++++------------------- test/test_domain.py | 3 ++- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 48bf40f..1ecf826 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -6,12 +6,15 @@ <property name="Name" type="s" access="read"/> <property name="UUID" type="s" access="read"/> <property name="Id" type="u" access="read"/> - <property name="Vcpus" type="u" access="read"/> <property name="OSType" type="s" access="read"/> <property name="Active" type="b" access="read"/> <property name="Persistent" type="b" access="read"/> <property name="State" type="s" access="read"/> <property name="Autostart" type="b" access="read"/> + <method name="GetVcpus"> + <arg name="flags" type="u" direction="in"/> + <arg name="vcpus" type="u" direction="out"/> + </method> <method name="GetXMLDesc"> <arg name="flags" type="u" direction="in"/> <arg name="xml" type="s" direction="out"/> diff --git a/src/domain.c b/src/domain.c index e4404c1..09b3440 100644 --- a/src/domain.c +++ b/src/domain.c @@ -86,27 +86,6 @@ virtDBusDomainGetId(const gchar *objectPath, *value = g_variant_new("u", id); } -static void -virtDBusDomainGetVcpus(const gchar *objectPath, - gpointer userData, - GVariant **value, - GError **error) -{ - virtDBusConnect *connect = userData; - g_autoptr(virDomain) domain = NULL; - gint vcpus; - - domain = virtDBusDomainGetVirDomain(connect, objectPath, error); - if (!domain) - return; - - vcpus = virDomainGetVcpusFlags(domain, VIR_DOMAIN_VCPU_CURRENT); - if (vcpus < 0) - return virtDBusUtilSetLastVirtError(error); - - *value = g_variant_new("u", vcpus); -} - static void virtDBusDomainGetOsType(const gchar *objectPath, gpointer userData, @@ -239,6 +218,34 @@ virtDBusDomainGetAutostart(const gchar *objectPath, *value = g_variant_new("b", !!autostart); } +static void +virtDBusDomainGetVcpus(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(virDomain) domain = NULL; + gint vcpus; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + domain = virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + vcpus = virDomainGetVcpusFlags(domain, flags); + if (vcpus < 0) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("(u)", vcpus); +} + static void virtDBusDomainGetXMLDesc(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -435,7 +442,6 @@ static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = { { "Name", virtDBusDomainGetName, NULL }, { "UUID", virtDBusDomainGetUUID, NULL }, { "Id", virtDBusDomainGetId, NULL }, - { "Vcpus", virtDBusDomainGetVcpus, NULL }, { "OSType", virtDBusDomainGetOsType, NULL }, { "Active", virtDBusDomainGetActive, NULL }, { "Persistent", virtDBusDomainGetPersistent, NULL }, @@ -445,6 +451,7 @@ static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = { }; static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { + { "GetVcpus", virtDBusDomainGetVcpus }, { "GetXMLDesc", virtDBusDomainGetXMLDesc }, { "GetStats", virtDBusDomainGetStats }, { "Shutdown", virtDBusDomainShutdown }, diff --git a/test/test_domain.py b/test/test_domain.py index 1bf9c1b..22039dc 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -17,7 +17,6 @@ class TestDomain(libvirttest.BaseTestClass): assert isinstance(props['Name'], dbus.String) assert isinstance(props['UUID'], dbus.String) assert isinstance(props['Id'], dbus.UInt32) - assert isinstance(props['Vcpus'], dbus.UInt32) assert isinstance(props['OSType'], dbus.String) assert isinstance(props['Active'], dbus.Boolean) assert isinstance(props['Persistent'], dbus.Boolean) @@ -29,6 +28,8 @@ class TestDomain(libvirttest.BaseTestClass): xml = domain.GetXMLDesc(0) assert isinstance(xml, dbus.String) + vcpus = domain.GetVcpus(0) + assert isinstance(vcpus, dbus.UInt32) domain.Reboot(0) domain.Shutdown() -- 2.15.0

Same for internal virtDBusDomainGetVcpus: Renamed to virtDBusDomainGetVcpusFlags Following naming from libvirt API. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 2 +- src/domain.c | 17 ++++++++--------- test/test_domain.py | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 1ecf826..46cc8a7 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -11,7 +11,7 @@ <property name="Persistent" type="b" access="read"/> <property name="State" type="s" access="read"/> <property name="Autostart" type="b" access="read"/> - <method name="GetVcpus"> + <method name="GetVcpusFlags"> <arg name="flags" type="u" direction="in"/> <arg name="vcpus" type="u" direction="out"/> </method> diff --git a/src/domain.c b/src/domain.c index 09b3440..333b5e8 100644 --- a/src/domain.c +++ b/src/domain.c @@ -219,14 +219,13 @@ virtDBusDomainGetAutostart(const gchar *objectPath, } static void -virtDBusDomainGetVcpus(GVariant *inArgs, - GUnixFDList *inFDs G_GNUC_UNUSED, - const gchar *objectPath, - gpointer userData, - GVariant **outArgs, - GUnixFDList **outFDs G_GNUC_UNUSED, - GError **error) - +virtDBusDomainGetVcpusFlags(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(virDomain) domain = NULL; @@ -451,7 +450,7 @@ static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = { }; static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { - { "GetVcpus", virtDBusDomainGetVcpus }, + { "GetVcpusFlags", virtDBusDomainGetVcpusFlags }, { "GetXMLDesc", virtDBusDomainGetXMLDesc }, { "GetStats", virtDBusDomainGetStats }, { "Shutdown", virtDBusDomainShutdown }, diff --git a/test/test_domain.py b/test/test_domain.py index 22039dc..c7f9ca2 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -28,7 +28,7 @@ class TestDomain(libvirttest.BaseTestClass): xml = domain.GetXMLDesc(0) assert isinstance(xml, dbus.String) - vcpus = domain.GetVcpus(0) + vcpus = domain.GetVcpusFlags(0) assert isinstance(vcpus, dbus.UInt32) domain.Reboot(0) -- 2.15.0

On Fri, Mar 23, 2018 at 03:16:59PM +0100, Katerina Koukiou wrote:
Same for internal virtDBusDomainGetVcpus: Renamed to virtDBusDomainGetVcpusFlags
Following naming from libvirt API.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 2 +- src/domain.c | 17 ++++++++--------- test/test_domain.py | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 1ecf826..46cc8a7 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -11,7 +11,7 @@ <property name="Persistent" type="b" access="read"/> <property name="State" type="s" access="read"/> <property name="Autostart" type="b" access="read"/> - <method name="GetVcpus"> + <method name="GetVcpusFlags">
We only added Flags as a suffix in our C apis because we have no other way to fix it without breaking ABI compat. In some language bindings, however, we didn't preserve that naming, instead just adding 'flags' as an optional parameter. DBus doesn't have optional params, but since this is a green-field API, we don't have a backcompat problem to worry about. IOW, I suggest *not* adding "Flags" as a suffix to any of the DBus method names, even if you ultimately call a libvirt API named with a "Flags" suffix.
<arg name="flags" type="u" direction="in"/> <arg name="vcpus" type="u" direction="out"/> </method> diff --git a/src/domain.c b/src/domain.c index 09b3440..333b5e8 100644 --- a/src/domain.c +++ b/src/domain.c @@ -219,14 +219,13 @@ virtDBusDomainGetAutostart(const gchar *objectPath, }
static void -virtDBusDomainGetVcpus(GVariant *inArgs, - GUnixFDList *inFDs G_GNUC_UNUSED, - const gchar *objectPath, - gpointer userData, - GVariant **outArgs, - GUnixFDList **outFDs G_GNUC_UNUSED, - GError **error) - +virtDBusDomainGetVcpusFlags(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(virDomain) domain = NULL; @@ -451,7 +450,7 @@ static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = { };
static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { - { "GetVcpus", virtDBusDomainGetVcpus }, + { "GetVcpusFlags", virtDBusDomainGetVcpusFlags }, { "GetXMLDesc", virtDBusDomainGetXMLDesc }, { "GetStats", virtDBusDomainGetStats }, { "Shutdown", virtDBusDomainShutdown }, diff --git a/test/test_domain.py b/test/test_domain.py index 22039dc..c7f9ca2 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -28,7 +28,7 @@ class TestDomain(libvirttest.BaseTestClass):
xml = domain.GetXMLDesc(0) assert isinstance(xml, dbus.String) - vcpus = domain.GetVcpus(0) + vcpus = domain.GetVcpusFlags(0) assert isinstance(vcpus, dbus.UInt32)
domain.Reboot(0) -- 2.15.0
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Fri, Mar 23, 2018 at 02:25:25PM +0000, Daniel P. Berrangé wrote:
On Fri, Mar 23, 2018 at 03:16:59PM +0100, Katerina Koukiou wrote:
Same for internal virtDBusDomainGetVcpus: Renamed to virtDBusDomainGetVcpusFlags
Following naming from libvirt API.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 2 +- src/domain.c | 17 ++++++++--------- test/test_domain.py | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 1ecf826..46cc8a7 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -11,7 +11,7 @@ <property name="Persistent" type="b" access="read"/> <property name="State" type="s" access="read"/> <property name="Autostart" type="b" access="read"/> - <method name="GetVcpus"> + <method name="GetVcpusFlags">
We only added Flags as a suffix in our C apis because we have no other way to fix it without breaking ABI compat.
In some language bindings, however, we didn't preserve that naming, instead just adding 'flags' as an optional parameter.
DBus doesn't have optional params, but since this is a green-field API, we don't have a backcompat problem to worry about.
IOW, I suggest *not* adding "Flags" as a suffix to any of the DBus method names, even if you ultimately call a libvirt API named with a "Flags" suffix.
I was thinking about not following the names exactly but on the other hand it may leads into a confusion especially when we have the non-flags version of the same API. I personally don't like the API names and I would gladly remove the suffix from the D-Bus API names, but it may lead into a confusion about which libvirt API is used under the hood. Sure, the API takes flags so it will be probably the flags version, but we as libvirt developers know this fact, on the other hand users might not realize that. If we decide not to follow the libvirt API names, we should probably somehow document which libvirt API is used. Pavel

On Fri, Mar 23, 2018 at 03:43:45PM +0100, Pavel Hrdina wrote:
On Fri, Mar 23, 2018 at 02:25:25PM +0000, Daniel P. Berrangé wrote:
On Fri, Mar 23, 2018 at 03:16:59PM +0100, Katerina Koukiou wrote:
Same for internal virtDBusDomainGetVcpus: Renamed to virtDBusDomainGetVcpusFlags
Following naming from libvirt API.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 2 +- src/domain.c | 17 ++++++++--------- test/test_domain.py | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 1ecf826..46cc8a7 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -11,7 +11,7 @@ <property name="Persistent" type="b" access="read"/> <property name="State" type="s" access="read"/> <property name="Autostart" type="b" access="read"/> - <method name="GetVcpus"> + <method name="GetVcpusFlags">
We only added Flags as a suffix in our C apis because we have no other way to fix it without breaking ABI compat.
In some language bindings, however, we didn't preserve that naming, instead just adding 'flags' as an optional parameter.
DBus doesn't have optional params, but since this is a green-field API, we don't have a backcompat problem to worry about.
IOW, I suggest *not* adding "Flags" as a suffix to any of the DBus method names, even if you ultimately call a libvirt API named with a "Flags" suffix.
I was thinking about not following the names exactly but on the other hand it may leads into a confusion especially when we have the non-flags version of the same API.
I personally don't like the API names and I would gladly remove the suffix from the D-Bus API names, but it may lead into a confusion about which libvirt API is used under the hood. Sure, the API takes flags so it will be probably the flags version, but we as libvirt developers know this fact, on the other hand users might not realize that.
If we decide not to follow the libvirt API names, we should probably somehow document which libvirt API is used.
In the Go binding I did this in the embedded API docs via link to the C API docs // See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainAttachDevice func (d *Domain) AttachDevice(xml string) error { cXml := C.CString(xml) defer C.free(unsafe.Pointer(cXml)) result := C.virDomainAttachDevice(d.ptr, cXml) if result == -1 { return GetLastError() } return nil } IIRC, the dbus introspection XML has something for docs comments where you could do the same. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Right, as seen here [1], "documentation can also be added as annotation elements in the XML". I 'll repost, thanks. [1] https://dbus.freedesktop.org/doc/dbus-api-design.html#documentation On Fri, Mar 23, 2018 at 3:51 PM, Daniel P. Berrangé <berrange@redhat.com> wrote:
On Fri, Mar 23, 2018 at 03:43:45PM +0100, Pavel Hrdina wrote:
On Fri, Mar 23, 2018 at 02:25:25PM +0000, Daniel P. Berrangé wrote:
On Fri, Mar 23, 2018 at 03:16:59PM +0100, Katerina Koukiou wrote:
Same for internal virtDBusDomainGetVcpus: Renamed to virtDBusDomainGetVcpusFlags
Following naming from libvirt API.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 2 +- src/domain.c | 17 ++++++++--------- test/test_domain.py | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 1ecf826..46cc8a7 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -11,7 +11,7 @@ <property name="Persistent" type="b" access="read"/> <property name="State" type="s" access="read"/> <property name="Autostart" type="b" access="read"/> - <method name="GetVcpus"> + <method name="GetVcpusFlags">
We only added Flags as a suffix in our C apis because we have no other way to fix it without breaking ABI compat.
In some language bindings, however, we didn't preserve that naming, instead just adding 'flags' as an optional parameter.
DBus doesn't have optional params, but since this is a green-field API, we don't have a backcompat problem to worry about.
IOW, I suggest *not* adding "Flags" as a suffix to any of the DBus method names, even if you ultimately call a libvirt API named with a "Flags" suffix.
I was thinking about not following the names exactly but on the other hand it may leads into a confusion especially when we have the non-flags version of the same API.
I personally don't like the API names and I would gladly remove the suffix from the D-Bus API names, but it may lead into a confusion about which libvirt API is used under the hood. Sure, the API takes flags so it will be probably the flags version, but we as libvirt developers know this fact, on the other hand users might not realize that.
If we decide not to follow the libvirt API names, we should probably somehow document which libvirt API is used.
In the Go binding I did this in the embedded API docs via link to the C API docs
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainAttachDevice func (d *Domain) AttachDevice(xml string) error { cXml := C.CString(xml) defer C.free(unsafe.Pointer(cXml)) result := C.virDomainAttachDevice(d.ptr, cXml) if result == -1 { return GetLastError() } return nil }
IIRC, the dbus introspection XML has something for docs comments where you could do the same.
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 4 +++- src/domain.c | 5 ++++- test/test_domain.py | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 46cc8a7..28f5609 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -24,7 +24,9 @@ <arg name="flags" type="u" direction="in"/> <arg name="records" type="a{sv}" direction="out"/> </method> - <method name="Shutdown"/> + <method name="Shutdown"> + <arg name="flags" type="u" direction="in"/> + </method> <method name="Destroy"/> <method name="Reboot"> <arg name="flags" type="u" direction="in"/> diff --git a/src/domain.c b/src/domain.c index 333b5e8..b6e72db 100644 --- a/src/domain.c +++ b/src/domain.c @@ -320,12 +320,15 @@ virtDBusDomainShutdown(GVariant *inArgs G_GNUC_UNUSED, { virtDBusConnect *connect = userData; g_autoptr(virDomain) domain = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); domain = virtDBusDomainGetVirDomain(connect, objectPath, error); if (!domain) return; - if (virDomainShutdown(domain) < 0) + if (virDomainShutdownFlags(domain, flags) < 0) virtDBusUtilSetLastVirtError(error); } diff --git a/test/test_domain.py b/test/test_domain.py index c7f9ca2..0c5ee45 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -32,7 +32,7 @@ class TestDomain(libvirttest.BaseTestClass): assert isinstance(vcpus, dbus.UInt32) domain.Reboot(0) - domain.Shutdown() + domain.Shutdown(0) domain.Create() domain.Destroy() domain.Undefine() @@ -46,7 +46,7 @@ class TestDomain(libvirttest.BaseTestClass): self.connect.connect_to_signal('DomainStopped', domain_stopped) obj, domain = self.domain() - domain.Shutdown() + domain.Shutdown(0) state = obj.Get('org.libvirt.Domain', 'State', dbus_interface=dbus.PROPERTIES_IFACE) assert state == 'shutoff' @@ -62,7 +62,7 @@ class TestDomain(libvirttest.BaseTestClass): self.connect.connect_to_signal('DomainUndefined', domain_undefined) _, domain = self.domain() - domain.Shutdown() + domain.Shutdown(0) domain.Undefine() self.main_loop() -- 2.15.0

Same for internal virtDBusDomainShutdown: Renamed to virtDBusDomainShutdownFlags Following naming from libvirt API. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 2 +- src/domain.c | 16 ++++++++-------- test/test_domain.py | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 28f5609..94a0e40 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -24,7 +24,7 @@ <arg name="flags" type="u" direction="in"/> <arg name="records" type="a{sv}" direction="out"/> </method> - <method name="Shutdown"> + <method name="ShutdownFlags"> <arg name="flags" type="u" direction="in"/> </method> <method name="Destroy"/> diff --git a/src/domain.c b/src/domain.c index b6e72db..d6da98d 100644 --- a/src/domain.c +++ b/src/domain.c @@ -310,13 +310,13 @@ virtDBusDomainGetStats(GVariant *inArgs, } static void -virtDBusDomainShutdown(GVariant *inArgs G_GNUC_UNUSED, - GUnixFDList *inFDs G_GNUC_UNUSED, - const gchar *objectPath G_GNUC_UNUSED, - gpointer userData, - GVariant **outArgs G_GNUC_UNUSED, - GUnixFDList **outFDs G_GNUC_UNUSED, - GError **error) +virtDBusDomainShutdownFlags(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) { virtDBusConnect *connect = userData; g_autoptr(virDomain) domain = NULL; @@ -456,7 +456,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { { "GetVcpusFlags", virtDBusDomainGetVcpusFlags }, { "GetXMLDesc", virtDBusDomainGetXMLDesc }, { "GetStats", virtDBusDomainGetStats }, - { "Shutdown", virtDBusDomainShutdown }, + { "ShutdownFlags", virtDBusDomainShutdownFlags }, { "Destroy", virtDBusDomainDestroy }, { "Reboot", virtDBusDomainReboot }, { "Reset", virtDBusDomainReset }, diff --git a/test/test_domain.py b/test/test_domain.py index 0c5ee45..c0ffc3f 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -32,7 +32,7 @@ class TestDomain(libvirttest.BaseTestClass): assert isinstance(vcpus, dbus.UInt32) domain.Reboot(0) - domain.Shutdown(0) + domain.ShutdownFlags(0) domain.Create() domain.Destroy() domain.Undefine() @@ -46,7 +46,7 @@ class TestDomain(libvirttest.BaseTestClass): self.connect.connect_to_signal('DomainStopped', domain_stopped) obj, domain = self.domain() - domain.Shutdown(0) + domain.ShutdownFlags(0) state = obj.Get('org.libvirt.Domain', 'State', dbus_interface=dbus.PROPERTIES_IFACE) assert state == 'shutoff' @@ -62,7 +62,7 @@ class TestDomain(libvirttest.BaseTestClass): self.connect.connect_to_signal('DomainUndefined', domain_undefined) _, domain = self.domain() - domain.Shutdown(0) + domain.ShutdownFlags(0) domain.Undefine() self.main_loop() -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 4 +++- src/domain.c | 5 ++++- test/test_domain.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 94a0e40..0f6743d 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -34,7 +34,9 @@ <method name="Reset"> <arg name="flags" type="u" direction="in"/> </method> - <method name="Create"/> + <method name="Create"> + <arg name="flags" type="u" direction="in"/> + </method> <method name="Undefine"/> <signal name="DeviceAdded"> <arg name="device" type="s"/> diff --git a/src/domain.c b/src/domain.c index d6da98d..fee7f47 100644 --- a/src/domain.c +++ b/src/domain.c @@ -411,12 +411,15 @@ virtDBusDomainCreate(GVariant *inArgs G_GNUC_UNUSED, { virtDBusConnect *connect = userData; g_autoptr(virDomain) domain = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); domain = virtDBusDomainGetVirDomain(connect, objectPath, error); if (!domain) return; - if (virDomainCreate(domain) < 0) + if (virDomainCreateWithFlags(domain, flags) < 0) virtDBusUtilSetLastVirtError(error); } diff --git a/test/test_domain.py b/test/test_domain.py index c0ffc3f..ae722fd 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -33,7 +33,7 @@ class TestDomain(libvirttest.BaseTestClass): domain.Reboot(0) domain.ShutdownFlags(0) - domain.Create() + domain.Create(0) domain.Destroy() domain.Undefine() -- 2.15.0

Same for internal virtDBusDomainCreate: Renamed to virtDBusDomainCreatewithFlags Following naming from libvirt API. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 2 +- src/domain.c | 16 ++++++++-------- test/test_domain.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 0f6743d..3afee78 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -34,7 +34,7 @@ <method name="Reset"> <arg name="flags" type="u" direction="in"/> </method> - <method name="Create"> + <method name="CreateWithFlags"> <arg name="flags" type="u" direction="in"/> </method> <method name="Undefine"/> diff --git a/src/domain.c b/src/domain.c index fee7f47..6b1779a 100644 --- a/src/domain.c +++ b/src/domain.c @@ -401,13 +401,13 @@ virtDBusDomainReset(GVariant *inArgs, } static void -virtDBusDomainCreate(GVariant *inArgs G_GNUC_UNUSED, - GUnixFDList *inFDs G_GNUC_UNUSED, - const gchar *objectPath G_GNUC_UNUSED, - gpointer userData, - GVariant **outArgs G_GNUC_UNUSED, - GUnixFDList **outFDs G_GNUC_UNUSED, - GError **error) +virtDBusDomainCreateWithFlags(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) { virtDBusConnect *connect = userData; g_autoptr(virDomain) domain = NULL; @@ -463,7 +463,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { { "Destroy", virtDBusDomainDestroy }, { "Reboot", virtDBusDomainReboot }, { "Reset", virtDBusDomainReset }, - { "Create", virtDBusDomainCreate }, + { "CreateWithFlags", virtDBusDomainCreateWithFlags }, { "Undefine", virtDBusDomainUndefine }, { NULL, NULL } }; diff --git a/test/test_domain.py b/test/test_domain.py index ae722fd..bf0f149 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -33,7 +33,7 @@ class TestDomain(libvirttest.BaseTestClass): domain.Reboot(0) domain.ShutdownFlags(0) - domain.Create(0) + domain.CreateWithFlags(0) domain.Destroy() domain.Undefine() -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 4 +++- src/domain.c | 5 ++++- test/test_domain.py | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 3afee78..05d0c9c 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -37,7 +37,9 @@ <method name="CreateWithFlags"> <arg name="flags" type="u" direction="in"/> </method> - <method name="Undefine"/> + <method name="Undefine"> + <arg name="flags" type="u" direction="in"/> + </method> <signal name="DeviceAdded"> <arg name="device" type="s"/> </signal> diff --git a/src/domain.c b/src/domain.c index 6b1779a..635af6a 100644 --- a/src/domain.c +++ b/src/domain.c @@ -434,12 +434,15 @@ virtDBusDomainUndefine(GVariant *inArgs G_GNUC_UNUSED, { virtDBusConnect *connect = userData; g_autoptr(virDomain) domain = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); domain = virtDBusDomainGetVirDomain(connect, objectPath, error); if (!domain) return; - if (virDomainUndefine(domain) < 0) + if (virDomainUndefineFlags(domain, flags) < 0) virtDBusUtilSetLastVirtError(error); } diff --git a/test/test_domain.py b/test/test_domain.py index bf0f149..cad1da5 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -35,7 +35,7 @@ class TestDomain(libvirttest.BaseTestClass): domain.ShutdownFlags(0) domain.CreateWithFlags(0) domain.Destroy() - domain.Undefine() + domain.Undefine(0) def test_shutdown(self): def domain_stopped(name, path): @@ -63,7 +63,7 @@ class TestDomain(libvirttest.BaseTestClass): _, domain = self.domain() domain.ShutdownFlags(0) - domain.Undefine() + domain.Undefine(0) self.main_loop() -- 2.15.0

Same for internal virtDBusDomainUndefine: Renamed to virtDBusDomainUndefineFlags Following naming from libvirt API Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 2 +- src/domain.c | 16 ++++++++-------- test/test_domain.py | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 05d0c9c..4b1a650 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -37,7 +37,7 @@ <method name="CreateWithFlags"> <arg name="flags" type="u" direction="in"/> </method> - <method name="Undefine"> + <method name="UndefineFlags"> <arg name="flags" type="u" direction="in"/> </method> <signal name="DeviceAdded"> diff --git a/src/domain.c b/src/domain.c index 635af6a..cc4e692 100644 --- a/src/domain.c +++ b/src/domain.c @@ -424,13 +424,13 @@ virtDBusDomainCreateWithFlags(GVariant *inArgs G_GNUC_UNUSED, } static void -virtDBusDomainUndefine(GVariant *inArgs G_GNUC_UNUSED, - GUnixFDList *inFDs G_GNUC_UNUSED, - const gchar *objectPath G_GNUC_UNUSED, - gpointer userData, - GVariant **outArgs G_GNUC_UNUSED, - GUnixFDList **outFDs G_GNUC_UNUSED, - GError **error) +virtDBusDomainUndefineFlags(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) { virtDBusConnect *connect = userData; g_autoptr(virDomain) domain = NULL; @@ -467,7 +467,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { { "Reboot", virtDBusDomainReboot }, { "Reset", virtDBusDomainReset }, { "CreateWithFlags", virtDBusDomainCreateWithFlags }, - { "Undefine", virtDBusDomainUndefine }, + { "UndefineFlags", virtDBusDomainUndefineFlags }, { NULL, NULL } }; diff --git a/test/test_domain.py b/test/test_domain.py index cad1da5..e3f32ca 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -35,7 +35,7 @@ class TestDomain(libvirttest.BaseTestClass): domain.ShutdownFlags(0) domain.CreateWithFlags(0) domain.Destroy() - domain.Undefine(0) + domain.UndefineFlags(0) def test_shutdown(self): def domain_stopped(name, path): @@ -63,7 +63,7 @@ class TestDomain(libvirttest.BaseTestClass): _, domain = self.domain() domain.ShutdownFlags(0) - domain.Undefine(0) + domain.UndefineFlags(0) self.main_loop() -- 2.15.0

We need to catch Exceptions when testing this API call, since virDomainDestroyFlags will be supported in test-driver in 4.2.0 libvirt release. Better version checks for unsupported API calls need to be done in all tests, but it's not relevant to this commit. When virConnectGetVersion will be supported we can move to better implementation, and python logging should be used to provide proper warnings for skipped tests. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 4 +++- src/domain.c | 5 ++++- test/test_domain.py | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 4b1a650..dcaca5e 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -27,7 +27,9 @@ <method name="ShutdownFlags"> <arg name="flags" type="u" direction="in"/> </method> - <method name="Destroy"/> + <method name="Destroy"> + <arg name="flags" type="u" direction="in"/> + </method> <method name="Reboot"> <arg name="flags" type="u" direction="in"/> </method> diff --git a/src/domain.c b/src/domain.c index cc4e692..9e13862 100644 --- a/src/domain.c +++ b/src/domain.c @@ -343,12 +343,15 @@ virtDBusDomainDestroy(GVariant *inArgs G_GNUC_UNUSED, { virtDBusConnect *connect = userData; g_autoptr(virDomain) domain = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); domain = virtDBusDomainGetVirDomain(connect, objectPath, error); if (!domain) return; - if (virDomainDestroy(domain) < 0) + if (virDomainDestroyFlags(domain, flags) < 0) virtDBusUtilSetLastVirtError(error); } diff --git a/test/test_domain.py b/test/test_domain.py index e3f32ca..409633a 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -3,6 +3,7 @@ import dbus import libvirttest +DBUS_EXCEPTION_MISSING_FUNCTION = 'this function is not supported by the connection driver' class TestDomain(libvirttest.BaseTestClass): def domain(self): @@ -34,7 +35,11 @@ class TestDomain(libvirttest.BaseTestClass): domain.Reboot(0) domain.ShutdownFlags(0) domain.CreateWithFlags(0) - domain.Destroy() + try: + domain.Destroy(0) + except dbus.exceptions.DBusException as e: + if not any(DBUS_EXCEPTION_MISSING_FUNCTION in arg for arg in e.args): + raise e domain.UndefineFlags(0) def test_shutdown(self): -- 2.15.0

Same for internal virtDBusDomainDestroy: Renamed to virtDBusDomainDestroyFlags Following naming from libvirt API. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 2 +- src/domain.c | 16 ++++++++-------- test/test_domain.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index dcaca5e..3278133 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -27,7 +27,7 @@ <method name="ShutdownFlags"> <arg name="flags" type="u" direction="in"/> </method> - <method name="Destroy"> + <method name="DestroyFlags"> <arg name="flags" type="u" direction="in"/> </method> <method name="Reboot"> diff --git a/src/domain.c b/src/domain.c index 9e13862..aa2e081 100644 --- a/src/domain.c +++ b/src/domain.c @@ -333,13 +333,13 @@ virtDBusDomainShutdownFlags(GVariant *inArgs G_GNUC_UNUSED, } static void -virtDBusDomainDestroy(GVariant *inArgs G_GNUC_UNUSED, - GUnixFDList *inFDs G_GNUC_UNUSED, - const gchar *objectPath G_GNUC_UNUSED, - gpointer userData, - GVariant **outArgs G_GNUC_UNUSED, - GUnixFDList **outFDs G_GNUC_UNUSED, - GError **error) +virtDBusDomainDestroyFlags(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) { virtDBusConnect *connect = userData; g_autoptr(virDomain) domain = NULL; @@ -466,7 +466,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { { "GetXMLDesc", virtDBusDomainGetXMLDesc }, { "GetStats", virtDBusDomainGetStats }, { "ShutdownFlags", virtDBusDomainShutdownFlags }, - { "Destroy", virtDBusDomainDestroy }, + { "DestroyFlags", virtDBusDomainDestroyFlags }, { "Reboot", virtDBusDomainReboot }, { "Reset", virtDBusDomainReset }, { "CreateWithFlags", virtDBusDomainCreateWithFlags }, diff --git a/test/test_domain.py b/test/test_domain.py index 409633a..410f82f 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -36,7 +36,7 @@ class TestDomain(libvirttest.BaseTestClass): domain.ShutdownFlags(0) domain.CreateWithFlags(0) try: - domain.Destroy(0) + domain.DestroyFlags(0) except dbus.exceptions.DBusException as e: if not any(DBUS_EXCEPTION_MISSING_FUNCTION in arg for arg in e.args): raise e -- 2.15.0
participants (3)
-
Daniel P. Berrangé
-
Katerina Koukiou
-
Pavel Hrdina