On Thu, Sep 13, 2012 at 04:04:31PM +0200, Michal Privoznik wrote:
Users can choose between minimum and recommended values
for VCPU count and amount of RAM. Moreover, recommended
values should inherit defaults from the minimum.
---
examples/virtxml.c | 12 ++++
libvirt-designer/libvirt-designer-domain.c | 91 ++++++++++++++++++++++++++++
libvirt-designer/libvirt-designer-domain.h | 8 +++
libvirt-designer/libvirt-designer.sym | 1 +
4 files changed, 112 insertions(+), 0 deletions(-)
diff --git a/examples/virtxml.c b/examples/virtxml.c
index cfe25ff..2908667 100644
--- a/examples/virtxml.c
+++ b/examples/virtxml.c
@@ -496,6 +496,7 @@ main(int argc, char *argv[])
static char *platform_str = NULL;
static char *arch_str = NULL;
static char *connect_uri = NULL;
+ static char *resources = NULL;
GOptionContext *context;
static GOptionEntry entries[] =
@@ -516,6 +517,8 @@ main(int argc, char *argv[])
"add disk to domain with PATH being source and FORMAT its format",
"PATH[,FORMAT]"},
{"interface", 'i', 0, G_OPTION_ARG_CALLBACK, add_iface_str,
"add interface with NETWORK source. Possible ARGs: mac,
link={up,down}", "NETWORK[,ARG=VAL]"},
+ {"resources", 'r', 0, G_OPTION_ARG_STRING, &resources,
+ "Set minimal or recommended values for cpu count and RAM amount",
"{minimal|recommended}"},
{NULL}
};
@@ -572,6 +575,15 @@ main(int argc, char *argv[])
CHECK_ERROR;
}
+ if (resources) {
+ gvir_designer_domain_setup_resources(domain, resources, &error);
+ CHECK_ERROR;
+ } else {
+ gvir_designer_domain_setup_resources(domain,
+
GVIR_DESIGNER_DOMAIN_RESOURCES_RECOMMENDED,
+ NULL);
+ }
+
g_list_foreach(disk_str_list, add_disk, domain);
g_list_foreach(iface_str_list, add_iface, domain);
diff --git a/libvirt-designer/libvirt-designer-domain.c
b/libvirt-designer/libvirt-designer-domain.c
index 194fdf5..de4582c 100644
--- a/libvirt-designer/libvirt-designer-domain.c
+++ b/libvirt-designer/libvirt-designer-domain.c
@@ -1033,3 +1033,94 @@ gvir_designer_domain_add_interface_network(GVirDesignerDomain
*design,
return ret;
}
+
+
+static void
+gvir_designer_domain_get_resources(OsinfoResourcesList *res_list,
+ const gchar *design_arch,
+ gint *design_n_cpus,
+ gint64 *design_ram)
+{
+ GList *elem_list, *elem_iterator;
+
+ if (!res_list)
+ return;
+
+ elem_list = osinfo_list_get_elements(OSINFO_LIST(res_list));
+ for (elem_iterator = elem_list; elem_iterator; elem_iterator =
elem_iterator->next) {
+ OsinfoResources *res = OSINFO_RESOURCES(elem_iterator->data);
+ const char *arch = osinfo_resources_get_architecture(res);
+ gint n_cpus = -1;
+ gint64 ram = -1;
+
+ if (g_str_equal(arch, "all") ||
+ g_str_equal(arch, design_arch)) {
+ n_cpus = osinfo_resources_get_n_cpus(res);
+ ram = osinfo_resources_get_ram(res);
extra space after '='
+ if (n_cpus > 0) {
+ *design_n_cpus = n_cpus;
+ }
+ if (ram > 0) {
+ /* libosinfo returns RAM in B, libvirt-gconfig takes it in KB */
+ *design_ram = ram / 1024;
+ }
+ break;
+ }
+ }
+}
+
+
+/**
+ * gvir_designer_domain_setup_resources:
+ * @design: (transfer none): the domain designer intance
instance
+ * @req: (transfer none): requirements to set
+ *
+ * Set minimal or recommended resources on @design.
+ *
+ * Returns: (transfer none): TRUE when successfully set, FALSE otherwise.
+ */
+gboolean gvir_designer_domain_setup_resources(GVirDesignerDomain *design,
+ const gchar *req,
I think an enum would be better than a string based API. If we go with a
string, can you explicitly mention the valid values in the api doc?
Christophe