private void Populate() { labelHostName.Text = Host.Name(); // initialize cacheSize SetupCacheSizeSpinner(OrigPvsCacheStorage == null ? DEFAULT_CACHE_SIZE_GB : (decimal)Util.ToGB(OrigPvsCacheStorage.size, 1, RoundingBehaviour.Nearest), MIN_CACHE_SIZE_GB, MAX_CACHE_SIZE_GB); origCacheSizeGb = numericUpDownCacheSize.Value; PopulateCacheSrCombobox(); ReadOnly = OrigPvsCacheStorage != null && OrigPvsCacheStorage.IsInUse(); comboBoxCacheSr.Enabled = numericUpDownCacheSize.Enabled = !ReadOnly; }
private void Populate() { labelHostName.Text = Host.Name(); // initialize cacheSize SetupCacheSizeSpinner(OrigPvsCacheStorage == null ? DEFAULT_CACHE_SIZE_GB : (decimal)Util.ToGB(OrigPvsCacheStorage.size, 1, RoundingBehaviour.Nearest), MIN_CACHE_SIZE_GB, MAX_CACHE_SIZE_GB); origCacheSizeGb = numericUpDownCacheSize.Value; comboBoxCacheSr.Items.Clear(); // add the "Not configured" item first var notConfiguredItem = new SrComboBoxItem(null, Messages.PVS_CACHE_NOT_CONFIGURED); comboBoxCacheSr.Items.Add(notConfiguredItem); // add Memory SR; if no memory SR found, add a placeholder (we will create the memory SR in ConfigurePvsCacheAction) var memorySrs = Host.Connection.Cache.SRs.Where(s => s.GetSRType(false) == SR.SRTypes.tmpfs && s.CanBeSeenFrom(Host)).ToList(); SR memorySr = null; if (memorySrs.Count == 0) { // create a placeholder for the memory SR memorySr = new SR { type = SR.SRTypes.tmpfs.ToString(), name_label = Messages.PVS_CACHE_MEMORY_SR_NAME, shared = false, opaque_ref = Helper.NullOpaqueRef }; } else { if (OrigPvsCacheStorage != null) { memorySr = memorySrs.FirstOrDefault(sr => sr.opaque_ref == OrigPvsCacheStorage.SR.opaque_ref); } if (memorySr == null) { memorySr = memorySrs.First(); } } var enabled = Host.dom0_memory_extra() >= MIN_CACHE_SIZE_GB * Util.BINARY_GIGA; var label = enabled ? Messages.PVS_CACHE_MEMORY_ONLY : Messages.PVS_CACHE_MEMORY_ONLY_DISABLED; var memorySrItem = new SrComboBoxItem(memorySr, label, enabled); comboBoxCacheSr.Items.Add(memorySrItem); if (OrigPvsCacheStorage != null && memorySr.opaque_ref == OrigPvsCacheStorage.SR.opaque_ref) { comboBoxCacheSr.SelectedItem = memorySrItem; } // add all suitable SRs var availableSRs = Host.Connection.Cache.SRs.Where(s => s.CanBeSeenFrom(Host) && SrIsSuitableForPvsCache(s)).ToList(); availableSRs.Sort(); foreach (var sr in availableSRs) { var newItem = new SrComboBoxItem(sr, sr.Name()); comboBoxCacheSr.Items.Add(newItem); if (OrigPvsCacheStorage != null && sr.opaque_ref == OrigPvsCacheStorage.SR.opaque_ref) { comboBoxCacheSr.SelectedItem = newItem; } } if (comboBoxCacheSr.SelectedItem == null) { comboBoxCacheSr.SelectedItem = notConfiguredItem; } ReadOnly = OrigPvsCacheStorage != null && OrigPvsCacheStorage.IsInUse(); comboBoxCacheSr.Enabled = numericUpDownCacheSize.Enabled = !ReadOnly; }