From f1c02cdc4ee28308ebfb43a6f944c7a4b840b8b0 Mon Sep 17 00:00:00 2001 From: Cheng Zhang Date: Mon, 4 Aug 2014 17:38:49 +0800 Subject: [PATCH] CP-9370:Add network type and more error message for resource list report feature Signed-off-by: Cheng Zhang --- .../GUIActions/ExportResourceReportAction.cs | 55 ++++++++++---- XenAdmin/ReportViewer/resource_report.rdlc | 74 ++++++++++++++++--- XenModel/Messages.Designer.cs | 18 +++++ XenModel/Messages.ja.resx | 6 ++ XenModel/Messages.resx | 6 ++ XenModel/Messages.zh-CN.resx | 6 ++ XenModel/XenSearch/PropertyAccessorHelper.cs | 22 ++++++ 7 files changed, 161 insertions(+), 26 deletions(-) diff --git a/XenAdmin/Actions/GUIActions/ExportResourceReportAction.cs b/XenAdmin/Actions/GUIActions/ExportResourceReportAction.cs index 999f824bf..34804a932 100755 --- a/XenAdmin/Actions/GUIActions/ExportResourceReportAction.cs +++ b/XenAdmin/Actions/GUIActions/ExportResourceReportAction.cs @@ -127,15 +127,23 @@ namespace XenAdmin.Actions { log.Warn(string.Format("Export of Pool {0} failed", this.Connection.Cache.Pools[0].Name), _exception); log.DebugFormat("Progress of the action until exception: {0}", PercentComplete); - try + + if (_exception is IOException) { - File.Delete(_filename); + this.Description = string.Format(Messages.ACTION_EXPORT_DESCRIPTION_FAILED_OF_OPEN_FILE, _filename); } - catch (Exception e) + else { - log.Warn(string.Format("deleting file {0} failed", _filename), e); + try + { + File.Delete(_filename); + } + catch (Exception e) + { + log.Warn(string.Format("deleting file {0} failed", _filename), e); + } + this.Description = Messages.ACTION_EXPORT_DESCRIPTION_FAILED; } - this.Description = Messages.ACTION_EXPORT_DESCRIPTION_FAILED; throw new Exception(Description); } else @@ -254,13 +262,14 @@ namespace XenAdmin.Actions private class NetworkInfo { public NetworkInfo(string name, string networkVlanID, string networkLinkStatus, - string NetworkMac, string NetworkMtu) + string NetworkMac, string NetworkMtu, string Type) { _name = name; _vlanID = networkVlanID; _linkStatus = networkLinkStatus; _mac = NetworkMac; _mtu = NetworkMtu; + _networkType = Type; } public virtual string Name { @@ -282,11 +291,16 @@ namespace XenAdmin.Actions { get { return _mtu; } } + public virtual string NetworkType + { + get { return _networkType; } + } private string _name; private string _vlanID; private string _linkStatus; private string _mac; private string _mtu; + private string _networkType; } private class VMInfo @@ -586,7 +600,7 @@ namespace XenAdmin.Actions throw new CancelledException(); string cpu_usage = PropertyAccessorHelper.hostCpuUsageStringByMetric(host, MetricUpdater); - string usage = PropertyAccessorHelper.hostMemoryUsageStringByMetric(host, MetricUpdater); + string usage = PropertyAccessorHelper.hostMemoryUsagePercentageStringByMetric(host, MetricUpdater); string network_usage = PropertyAccessorHelper.hostNetworkUsageStringByMetric(host, MetricUpdater); HostInfo buf = new HostInfo(host.name_label, host.address, host.uuid, cpu_usage, @@ -606,7 +620,7 @@ namespace XenAdmin.Actions { if (Cancelling) throw new CancelledException(); - + if (network.other_config.ContainsKey("is_guest_installer_network")) { if (network.other_config["is_guest_installer_network"].ToLower() == "true") @@ -617,12 +631,23 @@ namespace XenAdmin.Actions } List pifs = network.Connection.ResolveAll(network.PIFs); - + string type; + if (Cancelling) + throw new CancelledException(); + if (network.IsBond) + type = Messages.BOND; + else if (network.IsVLAN) + type = Messages.NETWORKPANEL_VLAN; + else if (pifs.Count != 0 && pifs[0].IsTunnelAccessPIF) + type = Messages.CHIN; + else + type = Messages.HYPHEN; + NetworkInfo buf; if (pifs.Count != 0) - buf = new NetworkInfo(network.Name, Helpers.VlanString(pifs[0]), network.LinkStatusString, pifs[0].MAC, network.MTU.ToString()); + buf = new NetworkInfo(network.Name, Helpers.VlanString(pifs[0]), network.LinkStatusString, pifs[0].MAC, network.MTU.ToString(), type); else - buf = new NetworkInfo(network.Name, Messages.HYPHEN, network.LinkStatusString, Messages.HYPHEN, network.MTU.ToString()); + buf = new NetworkInfo(network.Name, Messages.HYPHEN, network.LinkStatusString, Messages.HYPHEN, network.MTU.ToString(), type); m_Networks.Add(buf); @@ -738,7 +763,7 @@ namespace XenAdmin.Actions if (vbd != null && !vbd.IsCDROM && !vbd.IsFloppyDrive && vbd.bootable) { VDI vdi = vm.Connection.Resolve(vbd.VDI); - srInfo += vdi.name_label + ":" + vbd.Name + ":" + vdi.SizeText + ";"; + srInfo += vdi.name_label + ":" + vdi.SizeText + ";"; } } if (srInfo.Length == 0) @@ -754,7 +779,7 @@ namespace XenAdmin.Actions default_template_name = vm.other_config["base_template_name"]; VMInfo buf = new VMInfo(vm.Name, vm.uuid, PropertyAccessorHelper.vmCpuUsageStringByMetric(vm, MetricUpdater), - PropertyAccessorHelper.vmMemoryUsageStringByMetric(vm, MetricUpdater), srInfo, Convert.ToString(vm.VIFs.Count), + PropertyAccessorHelper.vmMemoryUsagePercentageStringByMetric(vm, MetricUpdater), srInfo, Convert.ToString(vm.VIFs.Count), Convert.ToString(addresses), MacInfo, OSinfo, Convert.ToString(vm.power_state), Convert.ToString(vm.RunningTime), running_on, default_template_name, vm.Description); @@ -841,8 +866,6 @@ namespace XenAdmin.Actions fs = new FileStream(_filename, FileMode.Create); fs.Write(bytes, 0, bytes.Length); - - PercentComplete = 100; if (fs != null) fs.Close(); @@ -1074,8 +1097,8 @@ namespace XenAdmin.Actions { FileStream fs = null; List items = new List(); - fs = new FileStream(_filename, FileMode.Create); + //pool information part items.Add(Messages.POOL + ":" + Connection.Cache.Pools[0].Name); ComposeCSVRow(ref fs, ref items); diff --git a/XenAdmin/ReportViewer/resource_report.rdlc b/XenAdmin/ReportViewer/resource_report.rdlc index 001f269ec..55371cf87 100755 --- a/XenAdmin/ReportViewer/resource_report.rdlc +++ b/XenAdmin/ReportViewer/resource_report.rdlc @@ -110,6 +110,10 @@ VlanID System.String + + NetworkType + System.String + DummyDataSource @@ -2515,7 +2519,7 @@ 4 Report_NetworkInfo 5.25cm - 15cm + 20.75cm
@@ -2541,7 +2545,7 @@ 2pt 2pt - 4 + 5 true =Fields!Name.Value @@ -2568,7 +2572,7 @@ 2pt 2pt - 3 + 4 true =Fields!LinkStatus.Value @@ -2595,7 +2599,7 @@ 2pt 2pt - 2 + 3 true =Fields!MAC.Value @@ -2622,7 +2626,7 @@ 2pt 2pt - 1 + 2 true =Fields!MTU.Value @@ -2642,11 +2646,30 @@ 2pt 2pt + 1 true =Fields!VlanID.Value + + + + NetworkType + + true + =Fields!NetworkType.Value + + + 0.66667cm @@ -2684,7 +2707,7 @@ 2pt 2pt - 9 + 11 true =Code.GetLabel("LBL_HOSTNAME") @@ -2706,7 +2729,7 @@ 2pt 2pt - 8 + 10 true =Code.GetLabel("LBL_LINKSTATUS") @@ -2734,7 +2757,7 @@ 2pt 2pt - 7 + 9 true =Code.GetLabel("LBL_MAC") @@ -2763,7 +2786,7 @@ 2pt 2pt - 6 + 8 true =Code.GetLabel("LBL_MTU") @@ -2792,12 +2815,40 @@ 2pt 2pt - 5 + 7 true =Code.GetLabel("LBL_VLAN") + + + + textbox39 + + 6 + true + =Code.GetLabel("LBL_STORAGETYPE") + + + 0.66667cm @@ -2819,6 +2870,9 @@ 3cm + + 5.75cm + 1.33334cm diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index c77079abb..fdba5a123 100644 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -780,6 +780,15 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to Export failed due to open destination file {0} failed. + /// + public static string ACTION_EXPORT_DESCRIPTION_FAILED_OF_OPEN_FILE { + get { + return ResourceManager.GetString("ACTION_EXPORT_DESCRIPTION_FAILED_OF_OPEN_FILE", resourceCulture); + } + } + /// /// Looks up a localized string similar to Export failed due to a header checksum mismatch. Please retry the export.. /// @@ -4989,6 +4998,15 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to Bond. + /// + public static string BOND { + get { + return ResourceManager.GetString("BOND", resourceCulture); + } + } + /// /// Looks up a localized string similar to Create Bond. /// diff --git a/XenModel/Messages.ja.resx b/XenModel/Messages.ja.resx index be28e5480..f5893fef5 100644 --- a/XenModel/Messages.ja.resx +++ b/XenModel/Messages.ja.resx @@ -357,6 +357,9 @@ エクスポートに失敗しました + + Export failed due to open destination file {0} failed + ヘッダーのチェックサムが一致しないため、エクスポートに失敗しました。もう一度エクスポートしてください。 @@ -1761,6 +1764,9 @@ CPU 使用率が {3} を超えるとアラートが送信されます。 BIOS 文字列のコピー + + Bond + ボンディングの作成 diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 4a93084b0..ceff829cc 100644 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -357,6 +357,9 @@ Export failed + + Export failed due to open destination file {0} failed + Export failed due to a header checksum mismatch. Please retry the export. @@ -1818,6 +1821,9 @@ This is a potentially dangerous operation and is not allowed. BIOS strings copied + + Bond + Create Bond diff --git a/XenModel/Messages.zh-CN.resx b/XenModel/Messages.zh-CN.resx index 65c28f87b..01f784033 100644 --- a/XenModel/Messages.zh-CN.resx +++ b/XenModel/Messages.zh-CN.resx @@ -357,6 +357,9 @@ 导出失败 + + 导出操作因源文件 {0} 打开失败 + 导出操作因标头校验和不匹配而失败。请重新尝试导出。 @@ -1761,6 +1764,9 @@ XenServer 可以重新启动服务器并将服务器的 CPU 级别降至池中 已复制 BIOS 字符串 + + 绑定 + 创建绑定 diff --git a/XenModel/XenSearch/PropertyAccessorHelper.cs b/XenModel/XenSearch/PropertyAccessorHelper.cs index e765d0ef4..ad68939fd 100644 --- a/XenModel/XenSearch/PropertyAccessorHelper.cs +++ b/XenModel/XenSearch/PropertyAccessorHelper.cs @@ -109,6 +109,17 @@ namespace XenAdmin.XenSearch return String.Format(Messages.QUERY_MEMORY_USAGE, Util.MemorySizeStringWithoutUnits((total - (free * Util.BINARY_KILO))), Util.MemorySizeString(total)); } + public static string vmMemoryUsagePercentageStringByMetric(VM vm, MetricUpdater MetricUpdater) + { + double free = MetricUpdater.GetValue(vm, "memory_internal_free"); + double total = MetricUpdater.GetValue(vm, "memory"); + + if (total == 0 || Double.IsNaN(total) || Double.IsNaN(free)) + return Messages.HYPHEN; + + return String.Format(Messages.QUERY_MEMORY_PERCENT, ((total - (free * Util.BINARY_KILO))/total * 100.0).ToString("0."), Util.MemorySizeString(total)); + } + public static int vmMemoryUsageRank(VM vm) { double free = MetricUpdater.GetValue(vm, "memory_internal_free"); @@ -221,6 +232,17 @@ namespace XenAdmin.XenSearch return String.Format(Messages.QUERY_MEMORY_USAGE, Util.MemorySizeStringWithoutUnits((total - free) * Util.BINARY_KILO), Util.MemorySizeString(total * Util.BINARY_KILO)); } + public static string hostMemoryUsagePercentageStringByMetric(Host host, MetricUpdater MetricUpdater) + { + double free = MetricUpdater.GetValue(host, "memory_free_kib"); + double total = MetricUpdater.GetValue(host, "memory_total_kib"); + + if (total == 0 || Double.IsNaN(total) || Double.IsNaN(free)) + return Messages.HYPHEN; + + return String.Format(Messages.QUERY_MEMORY_PERCENT, ((total - free) / total * 100.0).ToString("0."), Util.MemorySizeString(total * Util.BINARY_KILO)); + } + public static string hostMemoryUsageString(Host host) { return hostMemoryUsageStringByMetric(host, MetricUpdater);