From: "Zeeshan Ali (Khattak)" <zeeshanak(a)gnome.org>
---
libvirt-gobject/libvirt-gobject-domain.c | 63 ++++++++++++++++++++++++++++++
libvirt-gobject/libvirt-gobject-domain.h | 3 +
libvirt-gobject/libvirt-gobject.sym | 1 +
3 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c
b/libvirt-gobject/libvirt-gobject-domain.c
index 1fa27bd..a198715 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -449,6 +449,69 @@ GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom,
return conf;
}
+/**
+ * gvir_domain_set_config:
+ * @domain: the domain
+ * @conf: the new configuration for the domain
+ * @err: (allow-none): Place-holder for error or NULL
+ *
+ * Resets configuration of an existing domain.
+ *
+ * Note: If domain is already running, the new configuration will not take
+ * affect until domain reboots.
+ *
+ * Returns: TRUE on success, FALSE if an error occurred.
+ */
+gboolean gvir_domain_set_config(GVirDomain *domain,
+ GVirConfigDomain *conf,
+ GError **err)
+{
+ const gchar *xml;
+ virConnectPtr conn;
+ virDomainPtr handle;
+ gchar uuid[VIR_UUID_STRING_BUFLEN];
+ GVirDomainPrivate *priv = domain->priv;
+
+ g_return_val_if_fail(GVIR_IS_DOMAIN (domain), FALSE);
+ g_return_val_if_fail(GVIR_IS_CONFIG_DOMAIN (conf), FALSE);
+ g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+ xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+ g_return_val_if_fail(xml != NULL, FALSE);
+
+ if ((conn = virDomainGetConnect(priv->handle)) == NULL) {
+ if (err != NULL)
+ *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
+ 0,
+ "Failed to get domain connection");
+ return FALSE;
+ }
+
+ handle = virDomainDefineXML(conn, xml);
+
+ if (handle == NULL) {
+ if (err != NULL)
+ *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
+ 0,
+ "Failed to set "
+ "domain configuration");
+ return FALSE;
+ }
+
+ virDomainGetUUIDString(priv->handle, uuid);
+
+ if (strcmp (uuid, priv->uuid) != 0) {
+ if (err != NULL)
+ *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
+ 0,
+ "Failed to set "
+ "domain configuration");
+ return FALSE;
+ }
+
+ return TRUE;
+}
/**
* gvir_domain_get_info:
diff --git a/libvirt-gobject/libvirt-gobject-domain.h
b/libvirt-gobject/libvirt-gobject-domain.h
index 94bd53e..0479de8 100644
--- a/libvirt-gobject/libvirt-gobject-domain.h
+++ b/libvirt-gobject/libvirt-gobject-domain.h
@@ -123,6 +123,9 @@ GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom,
GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom,
guint64 flags,
GError **err);
+gboolean gvir_domain_set_config(GVirDomain *domain,
+ GVirConfigDomain *conf,
+ GError **err);
gchar *gvir_domain_screenshot(GVirDomain *dom,
GVirStream *stream,
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index 164b6b8..46c53f9 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -53,6 +53,7 @@ LIBVIRT_GOBJECT_0.0.1 {
gvir_domain_shutdown;
gvir_domain_reboot;
gvir_domain_get_config;
+ gvir_domain_set_config;
gvir_domain_get_info;
gvir_domain_screenshot;
--
1.7.7.1