private void InitialiseMessagesFromErrorKey(string errorKey, out string shortMessage, out string longMessage)
        {
            longMessage = Messages.PROBLEM_PREPARE_TO_UPGRADE;

            if (string.IsNullOrEmpty(errorKey))
            {
                shortMessage = string.Format(Messages.INSTALL_FILES_CANNOT_BE_FOUND, ServerName);
                return;
            }

            if (errorKey.StartsWith("REPO_SERVER_ERROR_"))
            {
                errorKey = "REPO_SERVER_ERROR_5XX";
            }

            var friendlyError = FriendlyNameManager.GetFriendlyName($"PREPARE_HOST_UPGRADE_{errorKey}");

            if (string.IsNullOrEmpty(friendlyError))
            {
                shortMessage = string.Format(Messages.INSTALL_FILES_CANNOT_BE_FOUND, ServerName);
                return;
            }

            shortMessage = $"{ServerName}: {friendlyError}";
        }
Ejemplo n.º 2
0
Archivo: SR.cs Proyecto: 00mjk/xenadmin
        private string I18N(string field_name, string field_value, bool with_host)
        {
            if (!other_config.ContainsKey("i18n-key"))
            {
                return(field_value);
            }

            string i18n_key = other_config["i18n-key"];

            string original_value_key = "i18n-original-value-" + field_name;
            string original_value     =
                other_config.ContainsKey(original_value_key) ? other_config[original_value_key] : "";

            if (original_value != field_value)
            {
                return(field_value);
            }

            string hostname = with_host ? GetHostName() : null;

            if (hostname == null)
            {
                string pattern = FriendlyNameManager.GetFriendlyName(string.Format("SR.{0}-{1}", field_name, i18n_key));
                return(pattern == null ? field_value : pattern);
            }
            else
            {
                string pattern = FriendlyNameManager.GetFriendlyName(string.Format("SR.{0}-{1}-host", field_name, i18n_key));
                return(pattern == null ? field_value : string.Format(pattern, hostname));
            }
        }
Ejemplo n.º 3
0
 private static string GetErrorMessageFromResources(string errCode)
 {
     if (errCode == null)
     {
         return(null);
     }
     return(FriendlyNameManager.GetFriendlyName("Message.name-" + errCode));
 }
Ejemplo n.º 4
0
        private string extractMultipathCurrentState(string body, string format)
        {
            /* message body format - if this changes you need to alter this method
             *
             * Unhealthy paths:
             * [20090511T16:29:22Z] host=foo; host-name=bar; pbd=whiz; scsi_id=pop; current=1; max=2
             * [20090511T16:29:22Z] host=foo; host-name=bar; pbd=whiz; scsi_id=pop; current=1; max=2
             * ....
             * Events received during the last 120 seconds:
             * [20090511T16:29:22Z] host=foo; host-name=bar; pbd=whiz; scsi_id=pop; current=1; max=2
             * [20090511T16:29:22Z] host=foo; host-name=bar; pbd=whiz; scsi_id=pop; current=1; max=2
             * ...
             */
            string[]      lines        = Message.body.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
            List <string> currentState = new List <string>();

            if (lines[0] == "Events received during the last 120 seconds:")
            {
                // current state is healthy, past errors have been resolved.
                if (Helpers.IsPool(Message.Connection))
                {
                    return(string.Format(FriendlyNameManager.GetFriendlyName("Message.body-multipath_periodic_alert_healthy"),
                                         Helpers.GetName(XenObject)));
                }
                else
                {
                    return(string.Format(FriendlyNameManager.GetFriendlyName("Message.body-multipath_periodic_alert_healthy_standalone"),
                                         Helpers.GetName(XenObject)));
                }
            }
            // Skip "unhealthy paths" line
            int lineIndex = 1;

            while (lineIndex < lines.Length && lines[lineIndex].StartsWith("["))
            {
                //record all lines that describe the current state
                currentState.Add(lines[lineIndex]);
                lineIndex++;
            }
            if (currentState.Count == 1)
            {
                // Only one host currently unhealthy, describe it's specific min/max paths
                Match m = multipathRegex.Match(currentState[0]);
                if (m.Success)
                {
                    return(string.Format(format, Message.Connection.Cache.Find_By_Uuid <Host>(m.Groups[1].Value),
                                         m.Groups[2].Value,
                                         m.Groups[3].Value));
                }
                return("");
            }
            else
            {
                // Several hosts in pool unhealthy, list their names as a summary
                var output = string.Join(", ",
                                         FindHostUuids(currentState)
                                         .Select(s => string.Format("'{0}'", Message.Connection.Cache.Find_By_Uuid <Host>(s)))
                                         );
                return(string.Format(FriendlyNameManager.GetFriendlyName("Message.body-multipath_periodic_alert_summary"),
                                     Helpers.GetName(XenObject),
                                     output));
            }
        }
Ejemplo n.º 5
0
Archivo: SR.cs Proyecto: 00mjk/xenadmin
 /// <summary>
 /// A friendly (internationalized) name for the SR type.
 /// </summary>
 public static string GetFriendlyTypeName(SRTypes srType)
 {
     return(FriendlyNameManager.GetFriendlyName(string.Format("Label-SR.SRTypes-{0}", srType.ToString())));
 }
Ejemplo n.º 6
0
        static PropertyAccessors()
        {
            foreach (vm_power_state p in Enum.GetValues(typeof(vm_power_state)))
            {
                VM_power_state_i18n[FriendlyNameManager.GetFriendlyName(string.Format("Label-VM.power_state-{0}", p.ToString()))] = p;
            }
            foreach (SR.SRTypes type in Enum.GetValues(typeof(SR.SRTypes)))
            {
                SRType_i18n[SR.getFriendlyTypeName(type)] = type;
            }

            VirtualisationStatus_i18n[Messages.VIRTUALIZATION_STATE_VM_NOT_OPTIMIZED] = VM.VirtualisationStatus.NOT_INSTALLED;
            VirtualisationStatus_i18n[Messages.OUT_OF_DATE] = VM.VirtualisationStatus.PV_DRIVERS_OUT_OF_DATE;
            VirtualisationStatus_i18n[Messages.UNKNOWN]     = VM.VirtualisationStatus.UNKNOWN;
            VirtualisationStatus_i18n[Messages.VIRTUALIZATION_STATE_VM_IO_OPTIMIZED_ONLY] = VM.VirtualisationStatus.IO_DRIVERS_INSTALLED;
            VirtualisationStatus_i18n[Messages.VIRTUALIZATION_STATE_VM_MANAGEMENT_AGENT_INSTALLED_ONLY] = VM.VirtualisationStatus.MANAGEMENT_INSTALLED;
            VirtualisationStatus_i18n[Messages.VIRTUALIZATION_STATE_VM_OPTIMIZED] = VM.VirtualisationStatus.IO_DRIVERS_INSTALLED | VM.VirtualisationStatus.MANAGEMENT_INSTALLED;

            ObjectTypes_i18n[Messages.VMS] = ObjectTypes.VM;
            ObjectTypes_i18n[Messages.XENSERVER_TEMPLATES] = ObjectTypes.DefaultTemplate;
            ObjectTypes_i18n[Messages.CUSTOM_TEMPLATES]    = ObjectTypes.UserTemplate;
            ObjectTypes_i18n[Messages.POOLS]   = ObjectTypes.Pool;
            ObjectTypes_i18n[Messages.SERVERS] = ObjectTypes.Server;
            ObjectTypes_i18n[Messages.DISCONNECTED_SERVERS] = ObjectTypes.DisconnectedServer;
            ObjectTypes_i18n[Messages.LOCAL_SRS]            = ObjectTypes.LocalSR;
            ObjectTypes_i18n[Messages.REMOTE_SRS]           = ObjectTypes.RemoteSR;
            ObjectTypes_i18n[Messages.NETWORKS]             = ObjectTypes.Network;
            ObjectTypes_i18n[Messages.SNAPSHOTS]            = ObjectTypes.Snapshot;
            ObjectTypes_i18n[Messages.VIRTUAL_DISKS]        = ObjectTypes.VDI;
            ObjectTypes_i18n[Messages.FOLDERS]      = ObjectTypes.Folder;
            ObjectTypes_i18n[Messages.VM_APPLIANCE] = ObjectTypes.Appliance;


            foreach (VM.HA_Restart_Priority p in VM.GetAvailableRestartPriorities(null)) //CA-57600 - From Boston onwards, the HA restart priorities list contains Restart instead of AlwaysRestartHighPriority and AlwaysRestart
            {
                HARestartPriority_i18n[Helpers.RestartPriorityI18n(p)] = p;
            }

            // This one is used for grouping and filtering i18n
            PropertyNames_i18n[PropertyNames.description]           = Messages.DESCRIPTION;
            PropertyNames_i18n[PropertyNames.host]                  = Messages.SERVER;
            PropertyNames_i18n[PropertyNames.label]                 = Messages.NAME;
            PropertyNames_i18n[PropertyNames.uuid]                  = Messages.UUID;
            PropertyNames_i18n[PropertyNames.networks]              = Messages.NETWORK;
            PropertyNames_i18n[PropertyNames.os_name]               = Messages.OPERATING_SYSTEM;
            PropertyNames_i18n[PropertyNames.pool]                  = Messages.POOL;
            PropertyNames_i18n[PropertyNames.power_state]           = Messages.POWER_STATE;
            PropertyNames_i18n[PropertyNames.start_time]            = Messages.START_TIME;
            PropertyNames_i18n[PropertyNames.storage]               = Messages.SR;
            PropertyNames_i18n[PropertyNames.disks]                 = Messages.VIRTUAL_DISK;
            PropertyNames_i18n[PropertyNames.type]                  = Messages.TYPE;
            PropertyNames_i18n[PropertyNames.virtualisation_status] = Messages.TOOLS_STATUS;
            PropertyNames_i18n[PropertyNames.ha_restart_priority]   = Messages.HA_RESTART_PRIORITY;
            PropertyNames_i18n[PropertyNames.appliance]             = Messages.VM_APPLIANCE;
            PropertyNames_i18n[PropertyNames.tags]                  = Messages.TAGS;
            PropertyNames_i18n[PropertyNames.shared]                = Messages.SHARED;
            PropertyNames_i18n[PropertyNames.ha_enabled]            = Messages.HA;
            PropertyNames_i18n[PropertyNames.isNotFullyUpgraded]    = Messages.POOL_VERSIONS_LINK_TEXT_SHORT;
            PropertyNames_i18n[PropertyNames.ip_address]            = Messages.ADDRESS;
            PropertyNames_i18n[PropertyNames.vm]                         = Messages.VM;
            PropertyNames_i18n[PropertyNames.dockervm]                   = "Docker VM";
            PropertyNames_i18n[PropertyNames.read_caching_enabled]       = Messages.VM_READ_CACHING_ENABLED_SEARCH;
            PropertyNames_i18n_false[PropertyNames.read_caching_enabled] = Messages.VM_READ_CACHING_DISABLED_SEARCH;
            PropertyNames_i18n[PropertyNames.memory]                     = Messages.MEMORY;
            PropertyNames_i18n[PropertyNames.sr_type]                    = Messages.STORAGE_TYPE;
            PropertyNames_i18n[PropertyNames.folder]                     = Messages.PARENT_FOLDER;
            PropertyNames_i18n[PropertyNames.folders]                    = Messages.ANCESTOR_FOLDERS;
            PropertyNames_i18n[PropertyNames.has_custom_fields]          = Messages.HAS_CUSTOM_FIELDS;
            PropertyNames_i18n[PropertyNames.in_any_appliance]           = Messages.IN_ANY_APPLIANCE;
            PropertyNames_i18n[PropertyNames.vendor_device_state]        = Messages.WINDOWS_UPDATE_CAPABLE;
            PropertyNames_i18n_false[PropertyNames.vendor_device_state]  = Messages.WINDOWS_UPDATE_CAPABLE_NOT;

            VM_power_state_images[vm_power_state.Halted]    = Icons.PowerStateHalted;
            VM_power_state_images[vm_power_state.Paused]    = Icons.PowerStateSuspended;
            VM_power_state_images[vm_power_state.Running]   = Icons.PowerStateRunning;
            VM_power_state_images[vm_power_state.Suspended] = Icons.PowerStateSuspended;
            VM_power_state_images[vm_power_state.unknown]   = Icons.PowerStateUnknown;

            ObjectTypes_images[ObjectTypes.DefaultTemplate]                = Icons.Template;
            ObjectTypes_images[ObjectTypes.UserTemplate]                   = Icons.TemplateUser;
            ObjectTypes_images[ObjectTypes.Pool]                           = Icons.Pool;
            ObjectTypes_images[ObjectTypes.Server]                         = Icons.Host;
            ObjectTypes_images[ObjectTypes.DisconnectedServer]             = Icons.HostDisconnected;
            ObjectTypes_images[ObjectTypes.LocalSR]                        = Icons.Storage;
            ObjectTypes_images[ObjectTypes.RemoteSR]                       = Icons.Storage;
            ObjectTypes_images[ObjectTypes.LocalSR | ObjectTypes.RemoteSR] = Icons.Storage;
            ObjectTypes_images[ObjectTypes.VM]        = Icons.VM;
            ObjectTypes_images[ObjectTypes.Network]   = Icons.Network;
            ObjectTypes_images[ObjectTypes.Snapshot]  = Icons.Snapshot;
            ObjectTypes_images[ObjectTypes.VDI]       = Icons.VDI;
            ObjectTypes_images[ObjectTypes.Folder]    = Icons.Folder;
            ObjectTypes_images[ObjectTypes.Appliance] = Icons.VmAppliance;

            property_types.Add(PropertyNames.pool, typeof(Pool));
            property_types.Add(PropertyNames.host, typeof(Host));
            property_types.Add(PropertyNames.os_name, typeof(string));
            property_types.Add(PropertyNames.power_state, typeof(vm_power_state));
            property_types.Add(PropertyNames.virtualisation_status, typeof(VM.VirtualisationStatus));
            property_types.Add(PropertyNames.type, typeof(ObjectTypes));
            property_types.Add(PropertyNames.networks, typeof(XenAPI.Network));
            property_types.Add(PropertyNames.storage, typeof(SR));
            property_types.Add(PropertyNames.ha_restart_priority, typeof(VM.HA_Restart_Priority));
            property_types.Add(PropertyNames.read_caching_enabled, typeof(bool));
            property_types.Add(PropertyNames.appliance, typeof(VM_appliance));
            property_types.Add(PropertyNames.tags, typeof(string));
            property_types.Add(PropertyNames.has_custom_fields, typeof(bool));
            property_types.Add(PropertyNames.ip_address, typeof(ComparableAddress));
            property_types.Add(PropertyNames.vm, typeof(VM));
            property_types.Add(PropertyNames.sr_type, typeof(SR.SRTypes));
            property_types.Add(PropertyNames.folder, typeof(Folder));
            property_types.Add(PropertyNames.folders, typeof(Folder));
            property_types.Add(PropertyNames.in_any_appliance, typeof(bool));
            property_types.Add(PropertyNames.disks, typeof(VDI));

            properties[PropertyNames.os_name]               = o => o is VM vm && vm.is_a_real_vm() ? vm.GetOSName() : null;
            properties[PropertyNames.power_state]           = o => o is VM vm && vm.is_a_real_vm() ? (IComparable)vm.power_state : null;
            properties[PropertyNames.vendor_device_state]   = o => o is VM vm && vm.is_a_real_vm() ? (bool?)vm.WindowsUpdateCapable() : null;
            properties[PropertyNames.virtualisation_status] = o => o is VM vm && vm.is_a_real_vm() ? (IComparable)vm.GetVirtualisationStatus(out _) : null;
            properties[PropertyNames.start_time]            = o => o is VM vm && vm.is_a_real_vm() ? (DateTime?)vm.GetStartTime() : null;
            properties[PropertyNames.read_caching_enabled]  = o => o is VM vm && vm.is_a_real_vm() ? (bool?)vm.ReadCachingEnabled() : null;

            properties[PropertyNames.label]    = Helpers.GetName;
            properties[PropertyNames.pool]     = o => o == null ? null : Helpers.GetPool(o.Connection);
            properties[PropertyNames.host]     = HostProperty;
            properties[PropertyNames.vm]       = VMProperty;
            properties[PropertyNames.dockervm] = o => o is DockerContainer dc ? new ComparableList <VM> {
                dc.Parent
            } : new ComparableList <VM>();
            properties[PropertyNames.networks] = NetworksProperty;
            properties[PropertyNames.storage]  = StorageProperty;
            properties[PropertyNames.disks]    = DisksProperty;

            properties[PropertyNames.has_custom_fields] = delegate(IXenObject o)
            {
                // this needs to be tidied up so that CustomFields calls don't require the event thread.

                bool ret = false;
                InvokeHelper.Invoke(delegate { ret = CustomFieldsManager.HasCustomFields(o); });
                return(ret);
            };

            properties[PropertyNames.memory] = o =>
            {
                if (o is VM vm && vm.is_a_real_vm() && vm.Connection != null)
                {
                    var metrics = vm.Connection.Resolve(vm.metrics);
                    if (metrics != null)
                    {
                        return(metrics.memory_actual);
                    }
                }
                return(null);
            };

            properties[PropertyNames.ha_restart_priority] = delegate(IXenObject o)
            {
                if (o is VM vm && vm.is_a_real_vm())
                {
                    Pool pool = Helpers.GetPool(vm.Connection);
                    if (pool != null && pool.ha_enabled)
                    {
                        return(vm.HaPriorityIsRestart() ? VM.HA_Restart_Priority.Restart : vm.HARestartPriority());
                    }

                    // CA-57600 - From Boston onwards, the HA_restart_priority enum contains Restart instead of
                    // AlwaysRestartHighPriority and AlwaysRestart. When searching in a pre-Boston pool for VMs
                    // with HA_restart_priority.Restart, the search will return VMs with HA_restart_priority
                    // AlwaysRestartHighPriority or AlwaysRestart
                }
                return(null);
            };

            properties[PropertyNames.appliance] = delegate(IXenObject o)
            {
                if (o is VM_appliance app)
                {
                    return(app);
                }

                if (o is VM vm && vm.is_a_real_vm() && vm.Connection != null)
                {
                    return(vm.Connection.Resolve(vm.appliance));
                }

                return(null);
            };

            properties[PropertyNames.in_any_appliance] = delegate(IXenObject o)
            {
                if (o is VM_appliance)
                {
                    return(true);
                }
                if (o is VM vm && vm.is_a_real_vm() && vm.Connection != null)
                {
                    return(vm.Connection.Resolve(vm.appliance) != null);
                }
                return(null);
            };

            properties[PropertyNames.connection_hostname] = ConnectionHostnameProperty;
            properties[PropertyNames.cpuText]             = CPUTextProperty;
            properties[PropertyNames.cpuValue]            = CPUValueProperty;
            properties[PropertyNames.description]         = DescriptionProperty;
            properties[PropertyNames.diskText]            = DiskTextProperty;
            properties[PropertyNames.folder]             = Folders.GetFolder;
            properties[PropertyNames.folders]            = Folders.GetAncestorFolders;
            properties[PropertyNames.haText]             = HATextProperty;
            properties[PropertyNames.ha_enabled]         = o => o is Pool pool ? (IComparable)pool.ha_enabled : null;
            properties[PropertyNames.isNotFullyUpgraded] = o => o is Pool pool ? (IComparable) !pool.IsPoolFullyUpgraded() : null;
            properties[PropertyNames.ip_address]         = IPAddressProperty;
            properties[PropertyNames.license]            = LicenseProperty;
            properties[PropertyNames.memoryText]         = MemoryTextProperty;
            properties[PropertyNames.memoryValue]        = MemoryValueProperty;
            properties[PropertyNames.memoryRank]         = MemoryRankProperty;
            properties[PropertyNames.networkText]        = NetworkTextProperty;
            properties[PropertyNames.shared]             = SharedProperty;
            properties[PropertyNames.size]    = o => o is VDI vdi ? (IComparable)vdi.virtual_size : null;
            properties[PropertyNames.sr_type] = o => o is SR sr ? (IComparable)sr.GetSRType(false) : null;
            properties[PropertyNames.tags]    = Tags.GetTagList;
            properties[PropertyNames.type]    = TypeProperty;
            properties[PropertyNames.uptime]  = UptimeProperty;
            properties[PropertyNames.uuid]    = UUIDProperty;

            column_sort_by[ColumnNames.name]    = PropertyNames.label;
            column_sort_by[ColumnNames.cpu]     = PropertyNames.cpuValue;
            column_sort_by[ColumnNames.memory]  = PropertyNames.memoryValue;
            column_sort_by[ColumnNames.disks]   = PropertyNames.diskText;
            column_sort_by[ColumnNames.network] = PropertyNames.networkText;
            column_sort_by[ColumnNames.ha]      = PropertyNames.haText;
            column_sort_by[ColumnNames.ip]      = PropertyNames.ip_address;
            column_sort_by[ColumnNames.uptime]  = PropertyNames.uptime;
        }
Ejemplo n.º 7
0
 public static string FriendlyAction(string type)
 {
     return(FriendlyNameManager.GetFriendlyName(string.Format("Message.action-{0}", type.ToLowerInvariant())));
 }
Ejemplo n.º 8
0
 private static string GetFriendlyName(string propertyName)
 {
     return(FriendlyNameManager.GetFriendlyName(string.Format("Label-{0}", propertyName)));
 }
Ejemplo n.º 9
0
 public string FriendlyDescription()
 {
     return(FriendlyNameManager.GetFriendlyName(String.Format("Role.{0}.Description", this.name_label.ToLowerInvariant())));
 }
Ejemplo n.º 10
0
 public static string FriendlyName(string role)
 {
     return(FriendlyNameManager.GetFriendlyName(string.Format("Role.{0}.NameLabel", role.ToLowerInvariant())));
 }
Ejemplo n.º 11
0
 public static string FriendlyHelp(string type)
 {
     return FriendlyNameManager.GetFriendlyName(string.Format("Message.help-{0}", type.ToLowerInvariant()));
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Extracts a key value pair list of information on the subject
        /// </summary>
        /// <param name="subject"></param>
        /// <returns></returns>
        public static List <KeyValuePair <String, String> > ExtractKvpInfo(Subject subject)
        {
            List <KeyValuePair <String, String> > kvpList = new List <KeyValuePair <string, string> >();
            Dictionary <string, string>           info    = new Dictionary <string, string>(subject.other_config);

            // Trim undesirable entries
            info.Remove("subject-gid");
            info.Remove("subject-uid");
            info.Remove("subject-sid");
            info.Remove("subject-is-group");
            info.Remove("subject-gecos");
            info.Remove("subject-upn");

            if (info.Count == 0)
            {
                return(kvpList);
            }

            string s;

            // Try and extract the important info as headers. No need for a label, just put the value as the key of the kvp
            if (info.TryGetValue("subject-displayname", out s))
            {
                kvpList.Add(new KeyValuePair <string, string>(s, ""));
                info.Remove("subject-displayname");
            }
            if (info.TryGetValue("subject-name", out s))
            {
                kvpList.Add(new KeyValuePair <string, string>(s, ""));
                info.Remove("subject-name");
            }

            // Add a double blank entry which is drawn as a vertical space and then add remaining kvps
            kvpList.Add(new KeyValuePair <string, string>("", ""));
            foreach (KeyValuePair <string, string> kvp in info)
            {
                // Try to localise the property key name
                string keyText, valueText;
                keyText = FriendlyNameManager.GetFriendlyName(string.Format("AD.PropertyKey-{0}", kvp.Key));
                if (keyText == null)
                {
                    keyText = kvp.Key;
                }

                if (kvp.Value == "true")
                {
                    valueText = Messages.YES;
                }
                else if (kvp.Value == "false")
                {
                    valueText = Messages.NO;
                }
                else
                {
                    valueText = kvp.Value;
                }

                keyText += Messages.GENERAL_PAGE_KVP_SEPARATOR;
                kvpList.Add(new KeyValuePair <string, string>(keyText, valueText));
            }
            return(kvpList);
        }