From 5abe4e109cf770e1caf720281baf4c37a9e512a1 Mon Sep 17 00:00:00 2001 From: Gabor Apati-Nagy Date: Wed, 14 Jan 2015 16:20:36 +0000 Subject: [PATCH] CA-84876: Show more infrastructure information for objects Instead of showing just the name, this code is showing name with location information in title for all objects that appear in the tree view. (A new property (NameWithLocation) with a getter accessor defined in IXenObject and has been implemented as virtual in XenObject and overridden at several child classes.) Signed-off-by: Gabor Apati-Nagy --- XenAdmin/MainWindow.cs | 18 +----- XenModel/Messages.Designer.cs | 81 ++++++++++++++++++------ XenModel/Messages.resx | 23 +++++-- XenModel/XenAPI-Extensions/Host.cs | 9 +++ XenModel/XenAPI-Extensions/IXenObject.cs | 1 + XenModel/XenAPI-Extensions/Pool.cs | 8 +++ XenModel/XenAPI-Extensions/SR.cs | 22 +++++++ XenModel/XenAPI-Extensions/VDI.cs | 16 ++++- XenModel/XenAPI-Extensions/VM.cs | 45 +++++++++++++ XenModel/XenAPI-Extensions/XenObject.cs | 23 +++++++ 10 files changed, 206 insertions(+), 40 deletions(-) diff --git a/XenAdmin/MainWindow.cs b/XenAdmin/MainWindow.cs index 21a3d4da5..3bda0f3d6 100644 --- a/XenAdmin/MainWindow.cs +++ b/XenAdmin/MainWindow.cs @@ -2622,7 +2622,7 @@ namespace XenAdmin else if (!SearchMode && SelectionManager.Selection.ContainsOneItemOfType()) { IXenObject xenObject = SelectionManager.Selection[0].XenObject; - TitleLabel.Text = GetTitleLabel(xenObject); + TitleLabel.Text = xenObject.NameWithLocation; TitleIcon.Image = Images.GetImage16For(xenObject); // When in folder view only show the logged in label if it is clear to which connection the object belongs (most likely pools and hosts) @@ -2677,22 +2677,6 @@ namespace XenAdmin pluginMenuItemStartIndexes[viewToolStripMenuItem] = viewToolStripMenuItem.DropDownItems.IndexOf(toolStripSeparator24) + 1; } - string GetTitleLabel(IXenObject xenObject) - { - string name = Helpers.GetName(xenObject); - VM vm = xenObject as VM; - if (vm != null && vm.is_a_real_vm) - { - Host server = vm.Home(); - if (server != null) - return string.Format(Messages.VM_ON_SERVER, name, server); - Pool pool = Helpers.GetPool(vm.Connection); - if (pool != null) - return string.Format(Messages.VM_IN_POOL, name, pool); - } - return name; - } - void navigationPane_DragDropCommandActivated(string cmdText) { SetStatusBar(null, cmdText); diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index e91e289b2..f32637a61 100644 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -16949,6 +16949,15 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to in '{0}'. + /// + public static string IN_POOL { + get { + return ResourceManager.GetString("IN_POOL", resourceCulture); + } + } + /// /// Looks up a localized string similar to In progress. /// @@ -20486,6 +20495,15 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to {0} {1}. + /// + public static string NAME_WITH_LOCATION { + get { + return ResourceManager.GetString("NAME_WITH_LOCATION", resourceCulture); + } + } + /// /// Looks up a localized string similar to Select the SR to reattach or create a new SR. /// @@ -23402,6 +23420,24 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to {0} in '{1}'. + /// + public static string OBJECT_IN_POOL { + get { + return ResourceManager.GetString("OBJECT_IN_POOL", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} on '{1}'. + /// + public static string OBJECT_ON_SERVER { + get { + return ResourceManager.GetString("OBJECT_ON_SERVER", resourceCulture); + } + } + /// /// Looks up a localized string similar to Objects with tag '{0}'. /// @@ -23493,6 +23529,15 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to on '{0}'. + /// + public static string ON_SERVER { + get { + return ResourceManager.GetString("ON_SERVER", resourceCulture); + } + } + /// /// Looks up a localized string similar to 1 VM selected. /// @@ -28052,6 +28097,15 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to {0} (snapshot of '{1}' {2}). + /// + public static string SNAPSHOT_OF_TITLE { + get { + return ResourceManager.GetString("SNAPSHOT_OF_TITLE", resourceCulture); + } + } + /// /// Looks up a localized string similar to Snapshots require XenServer 5.5 or later. /// @@ -32105,6 +32159,15 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to {0} on '{1}' {2}. + /// + public static string VDI_ON_SR_TITLE { + get { + return ResourceManager.GetString("VDI_ON_SR_TITLE", resourceCulture); + } + } + /// /// Looks up a localized string similar to Vendor. /// @@ -32519,15 +32582,6 @@ namespace XenAdmin { } } - /// - /// Looks up a localized string similar to {0} in '{1}'. - /// - public static string VM_IN_POOL { - get { - return ResourceManager.GetString("VM_IN_POOL", resourceCulture); - } - } - /// /// Looks up a localized string similar to Memory and/or VCPU changes will take effect when you restart the VM.. /// @@ -32627,15 +32681,6 @@ namespace XenAdmin { } } - /// - /// Looks up a localized string similar to {0} on '{1}'. - /// - public static string VM_ON_SERVER { - get { - return ResourceManager.GetString("VM_ON_SERVER", resourceCulture); - } - } - /// /// Looks up a localized string similar to This VM is paused.. /// diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 107819ef8..f77e8d250 100644 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -11271,8 +11271,8 @@ To learn more about the XenServer Dynamic Workload Balancing feature or to start VM General Properties - - {0} in '{1}' + + in '{0}' Memory and/or VCPU changes will take effect when you restart the VM. @@ -11307,8 +11307,8 @@ To learn more about the XenServer Dynamic Workload Balancing feature or to start This VM is not suspended. - - {0} on '{1}' + + on '{0}' This VM is paused. @@ -12252,4 +12252,19 @@ You will need to navigate to the Console on each of the selected VMs to complete You are here + + {0} (snapshot of '{1}' {2}) + + + {0} {1} + + + {0} in '{1}' + + + {0} on '{1}' + + + {0} on '{1}' {2} + \ No newline at end of file diff --git a/XenModel/XenAPI-Extensions/Host.cs b/XenModel/XenAPI-Extensions/Host.cs index 9270c52d6..24454ee8d 100644 --- a/XenModel/XenAPI-Extensions/Host.cs +++ b/XenModel/XenAPI-Extensions/Host.cs @@ -1324,6 +1324,15 @@ namespace XenAPI get { return license_params.ContainsKey("grace"); } } + internal override string LocationString + { + get + { + //for standalone hosts we do not show redundant location info + return Helpers.GetPool(Connection) == null ? string.Empty : base.LocationString; + } + } + #region Supplemental Packs // From http://scale.uk.xensource.com/confluence/display/engp/Supplemental+Pack+product+design+notes#SupplementalPackproductdesignnotes-XenAPI: diff --git a/XenModel/XenAPI-Extensions/IXenObject.cs b/XenModel/XenAPI-Extensions/IXenObject.cs index b8ee93560..662cb46a4 100644 --- a/XenModel/XenAPI-Extensions/IXenObject.cs +++ b/XenModel/XenAPI-Extensions/IXenObject.cs @@ -65,5 +65,6 @@ namespace XenAPI string SaveChanges(Session session, IXenObject beforeObject); string Description { get; } + string NameWithLocation { get; } } } diff --git a/XenModel/XenAPI-Extensions/Pool.cs b/XenModel/XenAPI-Extensions/Pool.cs index 48b18b686..aafe2e336 100644 --- a/XenModel/XenAPI-Extensions/Pool.cs +++ b/XenModel/XenAPI-Extensions/Pool.cs @@ -69,6 +69,14 @@ namespace XenAPI } } + internal override string LocationString + { + get + { + return string.Empty; + } + } + public List GetHAHeartbeatSRs() { List result = new List(); diff --git a/XenModel/XenAPI-Extensions/SR.cs b/XenModel/XenAPI-Extensions/SR.cs index beb35893f..ff94ad6bf 100644 --- a/XenModel/XenAPI-Extensions/SR.cs +++ b/XenModel/XenAPI-Extensions/SR.cs @@ -760,6 +760,28 @@ namespace XenAPI } } + public override string NameWithLocation + { + get + { + //return only the Name for local SRs + if (Connection != null && !shared) + { + return Name; + } + + return base.NameWithLocation; + } + } + + internal override string LocationString + { + get + { + return Home != null ? Home.LocationString : base.LocationString; + } + } + private bool CheckMultipathString(String status) { int current; diff --git a/XenModel/XenAPI-Extensions/VDI.cs b/XenModel/XenAPI-Extensions/VDI.cs index 47f1a5387..3664fceb1 100644 --- a/XenModel/XenAPI-Extensions/VDI.cs +++ b/XenModel/XenAPI-Extensions/VDI.cs @@ -201,7 +201,21 @@ namespace XenAPI return Util.DiskSizeString(virtual_size); } } - + + public override string NameWithLocation + { + get + { + if (Connection != null) + { + var srOfVdi = Connection.Resolve(SR); + return string.Format(Messages.VDI_ON_SR_TITLE, Name, srOfVdi.Name, srOfVdi.LocationString); + } + + return base.NameWithLocation; + } + } + #region IEquatable Members /// diff --git a/XenModel/XenAPI-Extensions/VM.cs b/XenModel/XenAPI-Extensions/VM.cs index e8a0d8e5d..16c5b35a3 100644 --- a/XenModel/XenAPI-Extensions/VM.cs +++ b/XenModel/XenAPI-Extensions/VM.cs @@ -1086,6 +1086,51 @@ namespace XenAPI } } + public override string NameWithLocation + { + get + { + if (this.Connection != null) + { + if (this.is_a_real_vm) + { + return base.NameWithLocation; + } + else if (this.is_a_snapshot) + { + var snapshotOf = this.Connection.Resolve(this.snapshot_of); + return string.Format(Messages.SNAPSHOT_OF_TITLE, Name, snapshotOf.Name, LocationString); + } + else if (this.is_a_template) + { + if (Helpers.IsPool(Connection)) + return string.Format(Messages.OBJECT_IN_POOL, Name, Connection.Name); + + return string.Format(Messages.OBJECT_ON_SERVER, Name, Connection.Name); + } + } + + return NameWithLocation; + } + } + + internal override string LocationString + { + get + { + Host server = this.Home(); + if (server != null) + return string.Format(Messages.ON_SERVER, server); + + Pool pool = Helpers.GetPool(this.Connection); + if (pool != null) + return string.Format(Messages.IN_POOL, pool); + + return string.Empty; + } + } + + public static List GetAvailableRestartPriorities(IXenConnection connection) { var restartPriorities = new List(); diff --git a/XenModel/XenAPI-Extensions/XenObject.cs b/XenModel/XenAPI-Extensions/XenObject.cs index d96f57e81..3082579a8 100644 --- a/XenModel/XenAPI-Extensions/XenObject.cs +++ b/XenModel/XenAPI-Extensions/XenObject.cs @@ -34,6 +34,7 @@ using System.Collections.Generic; using System.Reflection; using XenAdmin.Core; using XenAdmin.Network; +using XenAdmin; namespace XenAPI { @@ -267,5 +268,27 @@ namespace XenAPI { get { return ""; } } + + public virtual string NameWithLocation + { + get + { + return string.Format(Messages.NAME_WITH_LOCATION, Name, LocationString); + } + } + + internal virtual string LocationString + { + get + { + if (Connection == null) + return string.Empty; + + if (Helpers.IsPool(Connection)) + return string.Format(Messages.IN_POOL, Connection.Name); + + return string.Format(Messages.ON_SERVER, Connection.Name); + } + } } }