[gnome-boxes] libvirt-machine-properties: Mark recommended resources



commit 7da90d4f6395da4e179a57d248e4a4c90d95642e
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Feb 6 00:54:28 2013 +0200

    libvirt-machine-properties: Mark recommended resources
    
    Mark recommended RAM and storage when known.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688333

 src/libvirt-machine-properties.vala |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 1cd00c3..3e79da7 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -124,8 +124,9 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
             break;
 
         case PropertiesPage.SYSTEM:
-            add_ram_property (ref list);
-            add_storage_property (ref list);
+            var ram_property = add_ram_property (ref list);
+            var storage_property = add_storage_property (ref list);
+            mark_recommended_resources.begin (ram_property, storage_property);
 
             var button = new Gtk.Button.with_label (_("Troubleshooting log"));
             button.halign = Gtk.Align.START;
@@ -347,6 +348,33 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
         } catch (GLib.Error e) {}
     }
 
+    private async void mark_recommended_resources (SizeProperty? ram_property, SizeProperty? 
storage_property) {
+        if (ram_property == null && storage_property == null)
+            return;
+
+        var os_id = VMConfigurator.get_os_id (machine.domain_config);
+        if (os_id == null)
+            return;
+
+        var os_db = MediaManager.get_instance ().os_db;
+        Osinfo.Os os;
+        try {
+            os = yield os_db.get_os_by_id (os_id);
+        } catch (OSDatabaseError error) {
+            warning ("Failed to find OS with ID '%s': %s", os_id, error.message);
+            return;
+        }
+
+        var architecture = machine.domain_config.get_os ().get_arch ();
+        var resources = os_db.get_recommended_resources_for_os (os, architecture);
+        if (resources != null) {
+            if (ram_property != null)
+                ram_property.recommended = resources.ram;
+            if (storage_property != null)
+                storage_property.recommended = resources.storage;
+        }
+    }
+
     private SizeProperty? add_ram_property (ref List<Boxes.Property> list) {
         try {
             var max_ram = machine.connection.get_node_info ().memory;



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