Commit 87316114 authored by Katerina Koukiou's avatar Katerina Koukiou

Introduce Network Interface

Signed-off-by: default avatarKaterina Koukiou <kkoukiou@redhat.com>
parent 5c18fde2
......@@ -20,7 +20,8 @@ polkit_DATA = $(polkit_files:.rules.in=.rules)
interfaces_files = \
org.libvirt.Connect.xml \
org.libvirt.Domain.xml
org.libvirt.Domain.xml \
org.libvirt.Network.xml
interfacesdir = $(DBUS_INTERFACES_DIR)
interfaces_DATA = $(interfaces_files)
......
<!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/network">
<interface name="org.libvirt.Network">
</interface>
</node>
......@@ -8,7 +8,8 @@ DAEMON_SOURCES = \
util.c util.h \
domain.c domain.h \
events.c events.h \
gdbus.c gdbus.h
gdbus.c gdbus.h \
network.c network.h
EXTRA_DIST = \
$(DAEMON_SOURCES)
......
#include "connect.h"
#include "domain.h"
#include "events.h"
#include "network.h"
#include "util.h"
#include <glib/gprintf.h>
......@@ -303,6 +304,7 @@ virtDBusConnectFree(virtDBusConnect *connect)
virtDBusConnectClose(connect, TRUE);
g_free(connect->domainPath);
g_free(connect->networkPath);
g_free(connect);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusConnect, virtDBusConnectFree);
......@@ -345,6 +347,10 @@ virtDBusConnectNew(virtDBusConnect **connectp,
if (error && *error)
return;
virtDBusNetworkRegister(connect, error);
if (error && *error)
return;
*connectp = connect;
connect = NULL;
}
......
......@@ -13,6 +13,7 @@ struct virtDBusConnect {
const gchar *uri;
const gchar *connectPath;
gchar *domainPath;
gchar *networkPath;
virConnectPtr connection;
GMutex lock;
......
#include "network.h"
#include "util.h"
#include <libvirt/libvirt.h>
static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = {
{ 0 }
};
static virtDBusGDBusMethodTable virtDBusNetworkMethodTable[] = {
{ 0 }
};
static gchar **
virtDBusNetworkEnumerate(gpointer userData)
{
virtDBusConnect *connect = userData;
g_autoptr(virNetworkPtr) networks = NULL;
gint num = 0;
gchar **ret = NULL;
if (!virtDBusConnectOpen(connect, NULL))
return NULL;
num = virConnectListAllNetworks(connect->connection, &networks, 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] = virtDBusUtilBusPathForVirNetwork(networks[i],
connect->networkPath);
}
return ret;
}
static GDBusInterfaceInfo *interfaceInfo = NULL;
void
virtDBusNetworkRegister(virtDBusConnect *connect,
GError **error)
{
connect->networkPath = g_strdup_printf("%s/network", connect->connectPath);
if (!interfaceInfo) {
interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_NETWORK_INTERFACE,
error);
if (!interfaceInfo)
return;
}
virtDBusGDBusRegisterSubtree(connect->bus,
connect->networkPath,
interfaceInfo,
virtDBusNetworkEnumerate,
virtDBusNetworkMethodTable,
virtDBusNetworkPropertyTable,
connect);
}
#pragma once
#include "connect.h"
#define VIRT_DBUS_NETWORK_INTERFACE "org.libvirt.Network"
void
virtDBusNetworkRegister(virtDBusConnect *connect,
GError **error);
......@@ -151,3 +151,36 @@ virtDBusUtilEnumFromString(const gchar *const *types,
return -1;
}
virNetworkPtr
virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
const gchar *path,
const gchar *networkPath)
{
g_autofree gchar *name = NULL;
gsize prefixLen = strlen(networkPath) + 1;
name = virtDBusUtilDecodeUUID(path+prefixLen);
return virNetworkLookupByUUIDString(connection, name);
}
gchar *
virtDBusUtilBusPathForVirNetwork(virNetworkPtr network,
const gchar *networkPath)
{
gchar uuid[VIR_UUID_STRING_BUFLEN] = "";
g_autofree gchar *newUuid = NULL;
virNetworkGetUUIDString(network, uuid);
newUuid = virtDBusUtilEncodeUUID(uuid);
return g_strdup_printf("%s/%s", networkPath, newUuid);
}
void
virtDBusUtilVirNetworkListFree(virNetworkPtr *networks)
{
for (gint i = 0; networks[i] != NULL; i += 1)
virNetworkFree(networks[i]);
g_free(networks);
}
......@@ -65,3 +65,18 @@ virtDBusUtilEnumToString(const gchar *const *types,
#define VIRT_DBUS_ENUM_DECL(name) \
const gchar *name ##TypeToString(gint type) G_GNUC_PURE; \
gint name ##TypeFromString(const gchar *type) G_GNUC_PURE;
virNetworkPtr
virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
const gchar *path,
const gchar *networkPath);
gchar *
virtDBusUtilBusPathForVirNetwork(virNetworkPtr network,
const gchar *networkPath);
void
virtDBusUtilVirNetworkListFree(virNetworkPtr *networks);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetwork, virNetworkFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkPtr, virtDBusUtilVirNetworkListFree);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment