[libvirt] [dbus PATCH 00/15] Implement Interface APIs

https://libvirt.org/html/libvirt-libvirt-interface.html The following functions have been implemented: - virConnectListAllInterfaces (connect method) - virInterfaceChangeBegin (connect method) - virInterfaceChangeCommit (connect method) - virInterfaceChangeRollback (connect method) - virInterfaceCreate (interface method) - virInterfaceDefineXML (connect method) - virInterfaceDestroy (interface method) - virInterfaceGetMACString (property) - virInterfaceGetName (property) - virInterfaceGetXMLDesc (interface method) - virInterfaceIsActive (property) - virInterfaceLookupByMACString (connect method) - virInterfaceLookupByName (connect method) - virInterfaceUndefine (interface method) Anya Harter (15): Introduce Interface Interface Implement Name property for Interface Interface Implement MACString property for Interface Interface Implement Active property for Interface Interface Implement ListInterfaces method for Connect Interface Implement InterfaceDefineXML method for Connect Interface Implement InterfaceChangeBegin method for Connect Interface Implement InterfaceChangeCommit method for Connect Interface Implement InterfaceChangeRollback method for Connect Interface Implement InterfaceLookupByName method for Connect Interface Implement InterfaceLookupByMACString method for Connect Interface Implement Create method for Interface Interface Implement Destroy method for Interface Interface Implement Undefine method for Interface Interface Implement GetXMLDesc method for Interface Interface data/Makefile.am | 1 + data/org.libvirt.Connect.xml | 40 ++++++ data/org.libvirt.Interface.xml | 41 ++++++ src/Makefile.am | 2 + src/connect.c | 198 ++++++++++++++++++++++++++ src/connect.h | 1 + src/interface.c | 249 +++++++++++++++++++++++++++++++++ src/interface.h | 9 ++ src/util.c | 35 +++++ src/util.h | 15 ++ 10 files changed, 591 insertions(+) create mode 100644 data/org.libvirt.Interface.xml create mode 100644 src/interface.c create mode 100644 src/interface.h -- 2.17.1

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/Makefile.am | 1 + data/org.libvirt.Interface.xml | 7 +++ src/Makefile.am | 2 + src/connect.c | 6 +++ src/connect.h | 1 + src/interface.c | 86 ++++++++++++++++++++++++++++++++++ src/interface.h | 9 ++++ src/util.c | 35 ++++++++++++++ src/util.h | 15 ++++++ 9 files changed, 162 insertions(+) create mode 100644 data/org.libvirt.Interface.xml create mode 100644 src/interface.c create mode 100644 src/interface.h diff --git a/data/Makefile.am b/data/Makefile.am index 7b523da..35a0bbd 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -33,6 +33,7 @@ polkit_DATA = \ interfaces_files = \ org.libvirt.Connect.xml \ org.libvirt.Domain.xml \ + org.libvirt.Interface.xml \ org.libvirt.Network.xml \ org.libvirt.NodeDevice.xml \ org.libvirt.NWFilter.xml \ diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml new file mode 100644 index 0000000..93fa32f --- /dev/null +++ b/data/org.libvirt.Interface.xml @@ -0,0 +1,7 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> + +<node name="/org/libvirt/interface"> + <interface name="org.libvirt.Interface"> + </interface> +</node> diff --git a/src/Makefile.am b/src/Makefile.am index b5bf129..d0e8f0d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,6 +41,8 @@ libvirt_dbus_SOURCES = \ events.h \ gdbus.c \ gdbus.h \ + interface.c \ + interface.h \ main.c \ network.c \ network.h \ diff --git a/src/connect.c b/src/connect.c index 9ebceaa..b10533a 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1,6 +1,7 @@ #include "connect.h" #include "domain.h" #include "events.h" +#include "interface.h" #include "network.h" #include "nodedev.h" #include "nwfilter.h" @@ -1810,6 +1811,7 @@ virtDBusConnectFree(virtDBusConnect *connect) g_free(connect->nodeDevPath); g_free(connect->domainPath); + g_free(connect->interfacePath); g_free(connect->networkPath); g_free(connect->nwfilterPath); g_free(connect->secretPath); @@ -1869,6 +1871,10 @@ virtDBusConnectNew(virtDBusConnect **connectp, if (error && *error) return; + virtDBusInterfaceRegister(connect, error); + if (error && *error) + return; + virtDBusNetworkRegister(connect, error); if (error && *error) return; diff --git a/src/connect.h b/src/connect.h index b81b6a8..f755534 100644 --- a/src/connect.h +++ b/src/connect.h @@ -14,6 +14,7 @@ struct virtDBusConnect { const gchar *connectPath; gchar *nodeDevPath; gchar *domainPath; + gchar *interfacePath; gchar *networkPath; gchar *nwfilterPath; gchar *secretPath; diff --git a/src/interface.c b/src/interface.c new file mode 100644 index 0000000..6dbc702 --- /dev/null +++ b/src/interface.c @@ -0,0 +1,86 @@ +#include "interface.h" +#include "util.h" + +#include <libvirt/libvirt.h> + +static virInterfacePtr +virtDBusInterfaceGetVirInterface(virtDBusConnect *connect, + const gchar *objectPath, + GError **error) +{ + virInterfacePtr interface; + + if (virtDBusConnectOpen(connect, error) < 0) + return NULL; + + interface = virtDBusUtilVirInterfaceFromBusPath(connect->connection, + objectPath, + connect->interfacePath); + if (!interface) { + virtDBusUtilSetLastVirtError(error); + return NULL; + } + + return interface; +} + +static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] = { + { 0 } +}; + +static gchar ** +virtDBusInterfaceEnumerate(gpointer userData) +{ + virtDBusConnect *connect = userData; + g_autoptr(virInterfacePtr) interfaces = NULL; + gint num = 0; + gchar **ret = NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + num = virConnectListAllInterfaces(connect->connection, &interfaces, 0); + if (num < 0) + return NULL; + + if (num == 0) + return NULL; + + ret = g_new0(gchar *, num + 1); + + for (gint i = 0; i < num; i++) { + ret[i] = virtDBusUtilBusPathForVirInterface(interfaces[i], + connect->interfacePath); + } + + return ret; +} + +static GDBusInterfaceInfo *interfaceInfo; + +void +virtDBusInterfaceRegister(virtDBusConnect *connect, + GError **error) +{ + connect->interfacePath = g_strdup_printf("%s/interface", + connect->connectPath); + + if (!interfaceInfo) { + interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_INTERFACE_INTERFACE, + error); + if (!interfaceInfo) + return; + } + + virtDBusGDBusRegisterSubtree(connect->bus, + connect->interfacePath, + interfaceInfo, + virtDBusInterfaceEnumerate, + virtDBusInterfaceMethodTable, + virtDBusInterfacePropertyTable, + connect); +} diff --git a/src/interface.h b/src/interface.h new file mode 100644 index 0000000..8e5ee0a --- /dev/null +++ b/src/interface.h @@ -0,0 +1,9 @@ +#pragma once + +#include "connect.h" + +#define VIRT_DBUS_INTERFACE_INTERFACE "org.libvirt.Interface" + +void +virtDBusInterfaceRegister(virtDBusConnect *connect, + GError **error); diff --git a/src/util.c b/src/util.c index 8c822f2..9e11285 100644 --- a/src/util.c +++ b/src/util.c @@ -278,6 +278,41 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains) g_free(domains); } +virInterfacePtr +virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *interfacePath) +{ + g_autofree gchar *macstr = NULL; + gsize prefixLen = strlen(interfacePath) + 1; + + macstr = virtDBusUtilDecodeStr(path + prefixLen); + + return virInterfaceLookupByMACString(connection, macstr); +} + +gchar * +virtDBusUtilBusPathForVirInterface(virInterfacePtr interface, + const gchar *interfacePath) +{ + const gchar *macstr = NULL; + g_autofree const gchar *encodedMACStr = NULL; + + macstr = virInterfaceGetMACString(interface); + encodedMACStr = virtDBusUtilEncodeStr(macstr); + + return g_strdup_printf("%s/%s", interfacePath, encodedMACStr); +} + +void +virtDBusUtilVirInterfaceListFree(virInterfacePtr *interfaces) +{ + for (gint i = 0; interfaces[i] != NULL; i++) + virInterfaceFree(interfaces[i]); + + g_free(interfaces); +} + virNetworkPtr virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection, const gchar *path, diff --git a/src/util.h b/src/util.h index a688a3d..b05c2fc 100644 --- a/src/util.h +++ b/src/util.h @@ -65,6 +65,21 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtilVirDomainListFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainStatsRecordPtr, virDomainStatsRecordListFree); +virInterfacePtr +virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *interfacePath); + +gchar * +virtDBusUtilBusPathForVirInterface(virInterfacePtr interface, + const gchar *interfacePath); + +void +virtDBusUtilVirInterfaceListFree(virInterfacePtr *interfaces); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterface, virInterfaceFree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterfacePtr, virtDBusUtilVirInterfaceListFree); + virNetworkPtr virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection, const gchar *path, -- 2.17.1

On Fri, Jul 06, 2018 at 05:36:41PM -0400, Anya Harter wrote:
Signed-off-by: Anya Harter <aharter@redhat.com> --- data/Makefile.am | 1 + data/org.libvirt.Interface.xml | 7 +++ src/Makefile.am | 2 + src/connect.c | 6 +++ src/connect.h | 1 + src/interface.c | 86 ++++++++++++++++++++++++++++++++++ src/interface.h | 9 ++++ src/util.c | 35 ++++++++++++++ src/util.h | 15 ++++++ 9 files changed, 162 insertions(+) create mode 100644 data/org.libvirt.Interface.xml create mode 100644 src/interface.c create mode 100644 src/interface.h
[...]
diff --git a/src/interface.c b/src/interface.c new file mode 100644 index 0000000..6dbc702 --- /dev/null +++ b/src/interface.c @@ -0,0 +1,86 @@ +#include "interface.h" +#include "util.h" + +#include <libvirt/libvirt.h> + +static virInterfacePtr +virtDBusInterfaceGetVirInterface(virtDBusConnect *connect, + const gchar *objectPath, + GError **error) +{
This function needs to be introduced in patch that uses it. It's a static function and compilation fails for this commit. Every commit should be able to compile in order not to break "git bisect". You can easily try to do that by calling: git rebase -x "make && make check" origin/master This will rebase current branch on top of origin master and call "make && make check" for every commit that is applied on top of master. git rebase -i -x "make && make check" origin/master In interactive mode you can review what is going to happen.
+ virInterfacePtr interface; + + if (virtDBusConnectOpen(connect, error) < 0) + return NULL; + + interface = virtDBusUtilVirInterfaceFromBusPath(connect->connection, + objectPath, + connect->interfacePath); + if (!interface) { + virtDBusUtilSetLastVirtError(error); + return NULL; + } + + return interface; +} + +static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] = { + { 0 } +}; + +static gchar ** +virtDBusInterfaceEnumerate(gpointer userData) +{ + virtDBusConnect *connect = userData; + g_autoptr(virInterfacePtr) interfaces = NULL; + gint num = 0; + gchar **ret = NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + num = virConnectListAllInterfaces(connect->connection, &interfaces, 0); + if (num < 0) + return NULL; + + if (num == 0) + return NULL; + + ret = g_new0(gchar *, num + 1); + + for (gint i = 0; i < num; i++) { + ret[i] = virtDBusUtilBusPathForVirInterface(interfaces[i], + connect->interfacePath); + } + + return ret; +} + +static GDBusInterfaceInfo *interfaceInfo; + +void +virtDBusInterfaceRegister(virtDBusConnect *connect, + GError **error)
Indentation is off. Otherwise it looks good. Pavel

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Interface.xml | 5 +++++ src/interface.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml index 93fa32f..ad7c326 100644 --- a/data/org.libvirt.Interface.xml +++ b/data/org.libvirt.Interface.xml @@ -3,5 +3,10 @@ <node name="/org/libvirt/interface"> <interface name="org.libvirt.Interface"> + <property name="Name" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetName"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> </interface> </node> diff --git a/src/interface.c b/src/interface.c index 6dbc702..733ce44 100644 --- a/src/interface.c +++ b/src/interface.c @@ -24,7 +24,29 @@ virtDBusInterfaceGetVirInterface(virtDBusConnect *connect, return interface; } +static void +virtDBusInterfaceGetName(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virInterface) interface = NULL; + const gchar *name; + + interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error); + if (!interface) + return; + + name = virInterfaceGetName(interface); + if (!name) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", name); +} + static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { + { "Name", virtDBusInterfaceGetName, NULL }, { 0 } }; -- 2.17.1

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Interface.xml | 5 +++++ src/interface.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml index ad7c326..e6d9f2a 100644 --- a/data/org.libvirt.Interface.xml +++ b/data/org.libvirt.Interface.xml @@ -8,5 +8,10 @@ value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetName"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <property name="MACString" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetMACString"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> </interface> </node> diff --git a/src/interface.c b/src/interface.c index 733ce44..2b62304 100644 --- a/src/interface.c +++ b/src/interface.c @@ -45,7 +45,29 @@ virtDBusInterfaceGetName(const gchar *objectPath, *value = g_variant_new("s", name); } +static void +virtDBusInterfaceGetMACString(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virInterface) interface = NULL; + const gchar *mac; + + interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error); + if (!interface) + return; + + mac = virInterfaceGetMACString(interface); + if (!mac) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", mac); +} + static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { + { "MACString", virtDBusInterfaceGetMACString, NULL }, { "Name", virtDBusInterfaceGetName, NULL }, { 0 } }; -- 2.17.1

On Fri, Jul 06, 2018 at 05:36:43PM -0400, Anya Harter wrote:
Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Interface.xml | 5 +++++ src/interface.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+)
diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml index ad7c326..e6d9f2a 100644 --- a/data/org.libvirt.Interface.xml +++ b/data/org.libvirt.Interface.xml @@ -8,5 +8,10 @@ value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetName"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <property name="MACString" type="s" access="read">
I would use only "MAC" like we do with UUIDString. Pavel

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Interface.xml | 4 ++++ src/interface.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml index e6d9f2a..f50bc37 100644 --- a/data/org.libvirt.Interface.xml +++ b/data/org.libvirt.Interface.xml @@ -13,5 +13,9 @@ value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetMACString"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <property name="Active" type="b" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceIsActive"/> + </property> </interface> </node> diff --git a/src/interface.c b/src/interface.c index 2b62304..b73e116 100644 --- a/src/interface.c +++ b/src/interface.c @@ -66,7 +66,29 @@ virtDBusInterfaceGetMACString(const gchar *objectPath, *value = g_variant_new("s", mac); } +static void +virtDBusInterfaceGetActive(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virInterface) interface = NULL; + gint active; + + interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error); + if (!interface) + return; + + active = virInterfaceIsActive(interface); + if (active < 0) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("b", !!active); +} + static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { + { "Active", virtDBusInterfaceGetActive, NULL }, { "MACString", virtDBusInterfaceGetMACString, NULL }, { "Name", virtDBusInterfaceGetName, NULL }, { 0 } -- 2.17.1

On Fri, Jul 06, 2018 at 05:36:44PM -0400, Anya Harter wrote:
Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Interface.xml | 4 ++++ src/interface.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+)
diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml index e6d9f2a..f50bc37 100644 --- a/data/org.libvirt.Interface.xml +++ b/data/org.libvirt.Interface.xml @@ -13,5 +13,9 @@ value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetMACString"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <property name="Active" type="b" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceIsActive"/> + </property>
There is no "org.freedesktop.DBus.Property.EmitsChangedSignal" annotation and the default value is "true". We need to change the default value so there needs to be <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/> at the same level as <property ...> elements. For example you can check "data/org.libvirt.Domain.xml". Otherwise looks good. Pavel

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 7014a09..0604841 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -154,6 +154,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="domains" type="ao" direction="out"/> </method> + <method name="ListInterfaces"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectListAllInterfaces"/> + <arg name="flags" type="u" direction="in"/> + <arg name="interfaces" type="ao" direction="out"/> + </method> <method name="ListNetworks"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListAllNetworks"/> diff --git a/src/connect.c b/src/connect.c index b10533a..a3d002e 100644 --- a/src/connect.c +++ b/src/connect.c @@ -772,6 +772,43 @@ virtDBusConnectListDomains(GVariant *inArgs, *outArgs = g_variant_new_tuple(&gdomains, 1); } +static void +virtDBusConnectListInterfaces(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(virInterfacePtr) interfaces = NULL; + guint flags; + GVariantBuilder builder; + GVariant *ginterfaces; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virConnectListAllInterfaces(connect->connection, &interfaces, flags) < 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ao")); + + for (gint i = 0; interfaces[i]; i++) { + g_autofree gchar *path = NULL; + path = virtDBusUtilBusPathForVirInterface(interfaces[i], + connect->interfacePath); + + g_variant_builder_add(&builder, "o", path); + } + + ginterfaces = g_variant_builder_end(&builder); + *outArgs = g_variant_new_tuple(&ginterfaces, 1); +} + static void virtDBusConnectListNetworks(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1767,6 +1804,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "GetDomainCapabilities", virtDBusConnectGetDomainCapabilities }, { "GetSysinfo", virtDBusConnectGetSysinfo }, { "ListDomains", virtDBusConnectListDomains }, + { "ListInterfaces", virtDBusConnectListInterfaces }, { "ListNetworks", virtDBusConnectListNetworks }, { "ListNodeDevices", virtDBusConnectListNodeDevices }, { "ListNWFilters", virtDBusConnectListNWFilters }, -- 2.17.1

On Fri, Jul 06, 2018 at 05:36:45PM -0400, Anya Harter wrote:
Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
[...]
diff --git a/src/connect.c b/src/connect.c index b10533a..a3d002e 100644 --- a/src/connect.c +++ b/src/connect.c @@ -772,6 +772,43 @@ virtDBusConnectListDomains(GVariant *inArgs, *outArgs = g_variant_new_tuple(&gdomains, 1); }
+static void +virtDBusConnectListInterfaces(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(virInterfacePtr) interfaces = NULL; + guint flags; + GVariantBuilder builder; + GVariant *ginterfaces; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virConnectListAllInterfaces(connect->connection, &interfaces, flags) < 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ao")); + + for (gint i = 0; interfaces[i]; i++) { + g_autofree gchar *path = NULL; + path = virtDBusUtilBusPathForVirInterface(interfaces[i], + connect->interfacePath);
Indentation is off. Pavel

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 0604841..791e1f5 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -148,6 +148,13 @@ <arg name="flags" type="u" direction="in"/> <arg name="sysinfo" type="s" direction="out"/> </method> + <method name="InterfaceDefineXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDefineXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="flags" type="u" 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#virConnectListAllDomains"/> diff --git a/src/connect.c b/src/connect.c index a3d002e..8c39d52 100644 --- a/src/connect.c +++ b/src/connect.c @@ -735,6 +735,35 @@ virtDBusConnectGetSysinfo(GVariant *inArgs, *outArgs = g_variant_new("(s)", sysinfo); } +static void +virtDBusConnectInterfaceDefineXML(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 *xml; + guint flags; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + interface = virInterfaceDefineXML(connect->connection, xml, flags); + 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, @@ -1803,6 +1832,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "GetCPUModelNames", virtDBusConnectGetCPUModelNames }, { "GetDomainCapabilities", virtDBusConnectGetDomainCapabilities }, { "GetSysinfo", virtDBusConnectGetSysinfo }, + { "InterfaceDefineXML", virtDBusConnectInterfaceDefineXML }, { "ListDomains", virtDBusConnectListDomains }, { "ListInterfaces", virtDBusConnectListInterfaces }, { "ListNetworks", virtDBusConnectListNetworks }, -- 2.17.1

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Connect.xml | 5 +++++ src/connect.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 791e1f5..604afea 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -148,6 +148,11 @@ <arg name="flags" type="u" direction="in"/> <arg name="sysinfo" type="s" direction="out"/> </method> + <method name="InterfaceChangeBegin"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeBegin"/> + <arg name="flags" type="u" direction="in"/> + </method> <method name="InterfaceDefineXML"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDefineXML"/> diff --git a/src/connect.c b/src/connect.c index 8c39d52..7cf2d66 100644 --- a/src/connect.c +++ b/src/connect.c @@ -735,6 +735,27 @@ virtDBusConnectGetSysinfo(GVariant *inArgs, *outArgs = g_variant_new("(s)", sysinfo); } +static void +virtDBusConnectInterfaceChangeBegin(GVariant *inArgs, + 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; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virInterfaceChangeBegin(connect->connection, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static void virtDBusConnectInterfaceDefineXML(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1832,6 +1853,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "GetCPUModelNames", virtDBusConnectGetCPUModelNames }, { "GetDomainCapabilities", virtDBusConnectGetDomainCapabilities }, { "GetSysinfo", virtDBusConnectGetSysinfo }, + { "InterfaceChangeBegin", virtDBusConnectInterfaceChangeBegin }, { "InterfaceDefineXML", virtDBusConnectInterfaceDefineXML }, { "ListDomains", virtDBusConnectListDomains }, { "ListInterfaces", virtDBusConnectListInterfaces }, -- 2.17.1

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Connect.xml | 5 +++++ src/connect.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 604afea..8c88cc8 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -153,6 +153,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeBegin"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="InterfaceChangeCommit"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeCommit"/> + <arg name="flags" type="u" direction="in"/> + </method> <method name="InterfaceDefineXML"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDefineXML"/> diff --git a/src/connect.c b/src/connect.c index 7cf2d66..dadfd96 100644 --- a/src/connect.c +++ b/src/connect.c @@ -756,6 +756,27 @@ virtDBusConnectInterfaceChangeBegin(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusConnectInterfaceChangeCommit(GVariant *inArgs, + 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; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virInterfaceChangeCommit(connect->connection, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static void virtDBusConnectInterfaceDefineXML(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1854,6 +1875,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "GetDomainCapabilities", virtDBusConnectGetDomainCapabilities }, { "GetSysinfo", virtDBusConnectGetSysinfo }, { "InterfaceChangeBegin", virtDBusConnectInterfaceChangeBegin }, + { "InterfaceChangeCommit", virtDBusConnectInterfaceChangeCommit }, { "InterfaceDefineXML", virtDBusConnectInterfaceDefineXML }, { "ListDomains", virtDBusConnectListDomains }, { "ListInterfaces", virtDBusConnectListInterfaces }, -- 2.17.1

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Connect.xml | 5 +++++ src/connect.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 8c88cc8..7c97117 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -158,6 +158,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeCommit"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="InterfaceChangeRollback"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeRollback"/> + <arg name="flags" type="u" direction="in"/> + </method> <method name="InterfaceDefineXML"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDefineXML"/> diff --git a/src/connect.c b/src/connect.c index dadfd96..563535c 100644 --- a/src/connect.c +++ b/src/connect.c @@ -777,6 +777,27 @@ virtDBusConnectInterfaceChangeCommit(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusConnectInterfaceChangeRollback(GVariant *inArgs, + 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; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virInterfaceChangeRollback(connect->connection, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static void virtDBusConnectInterfaceDefineXML(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1876,6 +1897,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "GetSysinfo", virtDBusConnectGetSysinfo }, { "InterfaceChangeBegin", virtDBusConnectInterfaceChangeBegin }, { "InterfaceChangeCommit", virtDBusConnectInterfaceChangeCommit }, + { "InterfaceChangeRollback", virtDBusConnectInterfaceChangeRollback }, { "InterfaceDefineXML", virtDBusConnectInterfaceDefineXML }, { "ListDomains", virtDBusConnectListDomains }, { "ListInterfaces", virtDBusConnectListInterfaces }, -- 2.17.1

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 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#virInterfaceLookupByName"/> + <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#virConnectListAllDomains"/> diff --git a/src/connect.c b/src/connect.c index 563535c..51a6ba0 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 }, -- 2.17.1

On Fri, Jul 06, 2018 at 05:36:50PM -0400, Anya Harter wrote:
Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)
[...]
diff --git a/src/connect.c b/src/connect.c index 563535c..51a6ba0 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);
The format string needs to be "(&s)", the explanation is in the following patch. Pavel

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index f99e205..535d225 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="InterfaceLookupByMACString"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceLookupByMACString"/> + <arg name="macstr" type="s" 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#virInterfaceLookupByName"/> diff --git a/src/connect.c b/src/connect.c index 51a6ba0..f611965 100644 --- a/src/connect.c +++ b/src/connect.c @@ -827,6 +827,34 @@ virtDBusConnectInterfaceDefineXML(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusConnectInterfaceLookupByMACString(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 *macstr; + + g_variant_get(inArgs, "(s)", &macstr); + + if (!virtDBusConnectOpen(connect, NULL)) + return; + + interface = virInterfaceLookupByMACString(connect->connection, macstr); + if (!interface) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirInterface(interface, connect->interfacePath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusConnectInterfaceLookupByName(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1927,6 +1955,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "InterfaceChangeCommit", virtDBusConnectInterfaceChangeCommit }, { "InterfaceChangeRollback", virtDBusConnectInterfaceChangeRollback }, { "InterfaceDefineXML", virtDBusConnectInterfaceDefineXML }, + { "InterfaceLookupByMACString", virtDBusConnectInterfaceLookupByMACString }, { "InterfaceLookupByName", virtDBusConnectInterfaceLookupByName }, { "ListDomains", virtDBusConnectListDomains }, { "ListInterfaces", virtDBusConnectListInterfaces }, -- 2.17.1

On Fri, Jul 06, 2018 at 05:36:51PM -0400, Anya Harter wrote:
Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index f99e205..535d225 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="InterfaceLookupByMACString">
Same here, I would use only "InterfaceLookupByMAC".
+ <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceLookupByMACString"/> + <arg name="macstr" type="s" 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#virInterfaceLookupByName"/> diff --git a/src/connect.c b/src/connect.c index 51a6ba0..f611965 100644 --- a/src/connect.c +++ b/src/connect.c @@ -827,6 +827,34 @@ virtDBusConnectInterfaceDefineXML(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); }
+static void +virtDBusConnectInterfaceLookupByMACString(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 *macstr; + + g_variant_get(inArgs, "(s)", &macstr);
The format string needs to be "(&s)" otherwise we would have to free @macstr. The "&" means that we will get only the pointer to the memory, without it we will get a new copy of the memory. Pavel

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Interface.xml | 5 +++++ src/interface.c | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml index f50bc37..f62346a 100644 --- a/data/org.libvirt.Interface.xml +++ b/data/org.libvirt.Interface.xml @@ -17,5 +17,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceIsActive"/> </property> + <method name="Create"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceCreate"/> + <arg name="flags" type="u" direction="in"/> + </method> </interface> </node> diff --git a/src/interface.c b/src/interface.c index b73e116..dec980a 100644 --- a/src/interface.c +++ b/src/interface.c @@ -87,6 +87,29 @@ virtDBusInterfaceGetActive(const gchar *objectPath, *value = g_variant_new("b", !!active); } +static void +virtDBusInterfaceCreate(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virInterface) interface = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error); + if (!interface) + return; + + if (virInterfaceCreate(interface, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { { "Active", virtDBusInterfaceGetActive, NULL }, { "MACString", virtDBusInterfaceGetMACString, NULL }, @@ -95,6 +118,7 @@ static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { }; static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] = { + { "Create", virtDBusInterfaceCreate }, { 0 } }; -- 2.17.1

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Interface.xml | 5 +++++ src/interface.c | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml index f62346a..16caba1 100644 --- a/data/org.libvirt.Interface.xml +++ b/data/org.libvirt.Interface.xml @@ -22,5 +22,10 @@ value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceCreate"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="Destroy"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDestroy"/> + <arg name="flags" type="u" direction="in"/> + </method> </interface> </node> diff --git a/src/interface.c b/src/interface.c index dec980a..54a4c6b 100644 --- a/src/interface.c +++ b/src/interface.c @@ -110,6 +110,29 @@ virtDBusInterfaceCreate(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusInterfaceDestroy(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virInterface) interface = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error); + if (!interface) + return; + + if (virInterfaceDestroy(interface, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { { "Active", virtDBusInterfaceGetActive, NULL }, { "MACString", virtDBusInterfaceGetMACString, NULL }, @@ -119,6 +142,7 @@ static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] = { { "Create", virtDBusInterfaceCreate }, + { "Destroy", virtDBusInterfaceDestroy }, { 0 } }; -- 2.17.1

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Interface.xml | 4 ++++ src/interface.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml index 16caba1..5ca366c 100644 --- a/data/org.libvirt.Interface.xml +++ b/data/org.libvirt.Interface.xml @@ -27,5 +27,9 @@ value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDestroy"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="Undefine"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceUndefine"/> + </method> </interface> </node> diff --git a/src/interface.c b/src/interface.c index 54a4c6b..07e1aba 100644 --- a/src/interface.c +++ b/src/interface.c @@ -133,6 +133,26 @@ virtDBusInterfaceDestroy(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusInterfaceUndefine(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virInterface) interface = NULL; + + interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error); + if (!interface) + return; + + if (virInterfaceUndefine(interface) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { { "Active", virtDBusInterfaceGetActive, NULL }, { "MACString", virtDBusInterfaceGetMACString, NULL }, @@ -143,6 +163,7 @@ static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] = { { "Create", virtDBusInterfaceCreate }, { "Destroy", virtDBusInterfaceDestroy }, + { "Undefine", virtDBusInterfaceUndefine }, { 0 } }; -- 2.17.1

Signed-off-by: Anya Harter <aharter@redhat.com> --- data/org.libvirt.Interface.xml | 6 ++++++ src/interface.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml index 5ca366c..efe59e3 100644 --- a/data/org.libvirt.Interface.xml +++ b/data/org.libvirt.Interface.xml @@ -27,6 +27,12 @@ value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDestroy"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="GetXMLDesc"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetXMLDesc"/> + <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-interface.html#virInterfaceUndefine"/> diff --git a/src/interface.c b/src/interface.c index 07e1aba..83dbdbe 100644 --- a/src/interface.c +++ b/src/interface.c @@ -133,6 +133,33 @@ virtDBusInterfaceDestroy(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusInterfaceGetXMLDesc(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(virInterface) interface = NULL; + g_autofree gchar *xml = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error); + if (!interface) + return; + + xml = virInterfaceGetXMLDesc(interface, flags); + if (!xml) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("(s)", xml); +} + static void virtDBusInterfaceUndefine(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -163,6 +190,7 @@ static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = { static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] = { { "Create", virtDBusInterfaceCreate }, { "Destroy", virtDBusInterfaceDestroy }, + { "GetXMLDesc", virtDBusInterfaceGetXMLDesc }, { "Undefine", virtDBusInterfaceUndefine }, { 0 } }; -- 2.17.1

On Fri, Jul 06, 2018 at 05:36:40PM -0400, Anya Harter wrote:
https://libvirt.org/html/libvirt-libvirt-interface.html
The following functions have been implemented:
- virConnectListAllInterfaces (connect method) - virInterfaceChangeBegin (connect method) - virInterfaceChangeCommit (connect method) - virInterfaceChangeRollback (connect method) - virInterfaceCreate (interface method) - virInterfaceDefineXML (connect method) - virInterfaceDestroy (interface method) - virInterfaceGetMACString (property) - virInterfaceGetName (property) - virInterfaceGetXMLDesc (interface method) - virInterfaceIsActive (property) - virInterfaceLookupByMACString (connect method) - virInterfaceLookupByName (connect method) - virInterfaceUndefine (interface method)
Nice work, there are some minor issues that needs to be fixed but otherwise it looks good. Only tests are missing but we already discussed that on IRC and it will require DefineXML & Create APIs because test driver doesn't have virConnectListAllInterfaces() implemented which is used to get some interface to work with and there is no CreateXML API to create temporary interface like we do for NodeDevices. We usually introduce test case together with the new API and in this case it would require to change the order of patches to introduce DefineXML and Create API before introducing tests. Pavel
participants (2)
-
Anya Harter
-
Pavel Hrdina