[libvirt-glib] Ability to create new domains

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>

---
 libvirt-gobject/libvirt-gobject-connection.c |   38 ++++++++++++++++++++++++++
 libvirt-gobject/libvirt-gobject-connection.h |    3 ++
 libvirt-gobject/libvirt-gobject.sym          |    1 +
 3 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 32f749c..072484e 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -720,3 +720,41 @@ GVirStream *gvir_connection_get_stream(GVirConnection *self,
 
     return klass->stream_new(self, st);
 }
+
+/**
+ * gvir_connection_create_domain:
+ * @conn: the connection on which to create the dmain
+ * @conf: the configuration for the new domain
+ * Returns: (transfer full): the newly created domain
+ */
+GVirDomain *gvir_connection_create_domain(GVirConnection *conn,
+                                          GVirConfigDomain *conf,
+                                          GError **err)
+{
+    const gchar *xml;
+    virDomainPtr handle;
+    GVirConnectionPrivate *priv = conn->priv;
+
+    xml = gvir_config_object_get_doc(GVIR_CONFIG_OBJECT(conf));
+
+    g_return_val_if_fail(xml != NULL, NULL);
+
+    if (!(handle = virDomainDefineXML(priv->conn, xml))) {
+        *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR,
+                                      0,
+                                      "Failed to create domain");
+        return NULL;
+    }
+
+    GVirDomain *domain;
+
+    domain = GVIR_DOMAIN(g_object_new(GVIR_TYPE_DOMAIN,
+                                       "handle", handle,
+                                       NULL));
+
+    g_hash_table_insert(priv->domains,
+                        g_strdup(gvir_domain_get_uuid(domain)),
+                        domain);
+
+    return domain;
+}
diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h
index 0172d02..c453bed 100644
--- a/libvirt-gobject/libvirt-gobject-connection.h
+++ b/libvirt-gobject/libvirt-gobject-connection.h
@@ -107,6 +107,9 @@ GVirDomain *gvir_connection_find_domain_by_id(GVirConnection *conn,
 GVirDomain *gvir_connection_find_domain_by_name(GVirConnection *conn,
                                                 const gchar *name);
 
+GVirDomain *gvir_connection_create_domain(GVirConnection *conn,
+                                          GVirConfigDomain *conf,
+                                          GError **err);
 
 #if 0
 GList *gvir_connection_get_interfaces(GVirConnection *conn);
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index a68db4b..eae40a2 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -18,6 +18,7 @@ LIBVIRT_GOBJECT_0.0.1 {
 	gvir_connection_get_domain;
 	gvir_connection_find_domain_by_id;
 	gvir_connection_find_domain_by_name;
+	gvir_connection_create_domain;
 
 	gvir_domain_get_type;
 	gvir_domain_handle_get_type;
-- 
1.7.6.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]