[libvirt-glib 22/23] Add GVirConfigDomain::memory

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

 



---
 libvirt-gconfig/libvirt-gconfig-domain.c   |   29 +++++++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain.h   |    2 +
 libvirt-gconfig/libvirt-gconfig-object.c   |   32 ++++++++++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-object.h   |    5 ++++
 libvirt-gconfig/libvirt-gconfig.sym        |    2 +
 libvirt-gconfig/tests/test-domain-create.c |    3 ++
 libvirt-gconfig/tests/test-domain-parse.c  |    3 ++
 libvirt-gconfig/tests/test-domain.xml      |    1 +
 8 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index 039e551..71bfb55 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -44,6 +44,7 @@ G_DEFINE_TYPE(GVirConfigDomain, gvir_config_domain, GVIR_TYPE_CONFIG_OBJECT);
 enum {
     PROP_0,
     PROP_NAME,
+    PROP_MEMORY,
 };
 
 static void gvir_config_domain_get_property(GObject *object,
@@ -57,6 +58,9 @@ static void gvir_config_domain_get_property(GObject *object,
     case PROP_NAME:
         g_value_take_string(value, gvir_config_domain_get_name(domain));
         break;
+    case PROP_MEMORY:
+        g_value_set_uint64(value, gvir_config_domain_get_memory(domain));
+        break;
 
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@@ -74,6 +78,9 @@ static void gvir_config_domain_set_property(GObject *object,
     case PROP_NAME:
         gvir_config_domain_set_name(domain, g_value_get_string(value));
         break;
+    case PROP_MEMORY:
+        gvir_config_domain_set_memory(domain, g_value_get_uint64(value));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     }
@@ -97,6 +104,15 @@ static void gvir_config_domain_class_init(GVirConfigDomainClass *klass)
                                                         NULL,
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_STATIC_STRINGS));
+    g_object_class_install_property(object_class,
+                                    PROP_MEMORY,
+                                    g_param_spec_uint64("memory",
+                                                        "Memory",
+                                                        "Maximum Guest Memory (in kilobytes)",
+                                                        0, G_MAXUINT64,
+                                                        0,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_STATIC_STRINGS));
 }
 
 
@@ -150,3 +166,16 @@ void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name)
                                         "name", name);
     g_object_notify(G_OBJECT(domain), "name");
 }
+
+guint64 gvir_config_domain_get_memory(GVirConfigDomain *domain)
+{
+    return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(domain),
+                                                      "memory");
+}
+
+void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory)
+{
+    gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(domain),
+                                               "memory", memory);
+    g_object_notify(G_OBJECT(domain), "memory");
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h
index b5ae050..03169b2 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain.h
@@ -64,6 +64,8 @@ GVirConfigDomain *gvir_config_domain_new(void);
 
 char *gvir_config_domain_get_name(GVirConfigDomain *domain);
 void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name);
+guint64 gvir_config_domain_get_memory(GVirConfigDomain *domain);
+void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory);
 
 G_END_DECLS
 
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index 679c3f9..0de4abf 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -322,3 +322,35 @@ void gvir_config_object_set_node_content(GVirConfigObject *object,
     }
 }
 
+/* FIXME: how to notify of errors/node not found? */
+guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object,
+                                                   const char *node_name)
+{
+    xmlNodePtr node;
+    xmlChar *str;
+    guint64 value;
+
+    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object));
+    if (node == NULL)
+        return 0;
+
+    str = gvir_config_xml_get_child_element_content(node, node_name);
+    if (!str)
+        return 0;
+
+    value = g_ascii_strtoull((char *)str, NULL, 0);
+    xmlFree(str);
+
+    return value;
+}
+
+
+void gvir_config_object_set_node_content_uint64(GVirConfigObject *object,
+                                                const char *node_name,
+                                                guint64 value)
+{
+    char *str;
+    str = g_strdup_printf("%"G_GUINT64_FORMAT, value);
+    gvir_config_object_set_node_content(object, node_name, str);
+    g_free(str);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-object.h b/libvirt-gconfig/libvirt-gconfig-object.h
index ab99279..c203798 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.h
+++ b/libvirt-gconfig/libvirt-gconfig-object.h
@@ -68,9 +68,14 @@ const gchar *gvir_config_object_get_schema(GVirConfigObject *config);
 xmlNodePtr gvir_config_object_get_xml_node(GVirConfigObject *config);
 char *gvir_config_object_get_node_content(GVirConfigObject *object,
                                           const char *node_name);
+guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object,
+                                                   const char *node_name);
 void gvir_config_object_set_node_content(GVirConfigObject *object,
                                          const char *node_name,
                                          const char *value);
+void gvir_config_object_set_node_content_uint64(GVirConfigObject *object,
+                                                const char *node_name,
+                                                guint64 value);
 
 /* FIXME: move to a libvirt-gconfig-helpers.h file? */
 xmlNodePtr gvir_config_object_parse(const char *xml, const char *root_node, GError **err);
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index b67d152..7acb95d 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -6,6 +6,8 @@ LIBVIRT_GOBJECT_0.0.1 {
 	gvir_config_domain_get_type;
 	gvir_config_domain_new;
 	gvir_config_domain_new_from_xml;
+	gvir_config_domain_get_memory;
+	gvir_config_domain_set_memory;
 	gvir_config_domain_get_name;
 	gvir_config_domain_set_name;
 
diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c
index a742dd7..fe0063c 100644
--- a/libvirt-gconfig/tests/test-domain-create.c
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -44,6 +44,9 @@ int main(void)
     g_assert(strcmp(name, "foo") == 0);
     g_free(name);
 
+    gvir_config_domain_set_memory(domain, 1234);
+    g_assert(gvir_config_domain_get_memory(domain) == 1234);
+
     xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain));
     g_print("%s\n", xml);
     g_free(xml);
diff --git a/libvirt-gconfig/tests/test-domain-parse.c b/libvirt-gconfig/tests/test-domain-parse.c
index 545e733..7521d20 100644
--- a/libvirt-gconfig/tests/test-domain-parse.c
+++ b/libvirt-gconfig/tests/test-domain-parse.c
@@ -66,6 +66,9 @@ int main(int argc, char **argv)
     g_assert(name != NULL);
     g_assert(strcmp(name, "foo") == 0);
     g_free(name);
+
+    g_assert(gvir_config_domain_get_memory(domain) == 987654321);
+
     g_free(xml);
 
     xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain));
diff --git a/libvirt-gconfig/tests/test-domain.xml b/libvirt-gconfig/tests/test-domain.xml
index 08a926e..d887e95 100644
--- a/libvirt-gconfig/tests/test-domain.xml
+++ b/libvirt-gconfig/tests/test-domain.xml
@@ -2,4 +2,5 @@
   <name>foo</name>
   <uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid>
   <description>Some human readable description</description>
+ <memory>987654321</memory>
 </domain>
-- 
1.7.6.4

--
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]