Exemple #1
0
        private bool HasHostChanged(Host host, Host.PowerOnMode activeMode)
        {
            if (activeMode == null)
            {
                return(false);
            }

            if (host.power_on_mode != activeMode.ToString())
            {
                return(true);
            }

            var customConfig = activeMode.Config;

            if (host.power_on_config.Count != customConfig.Count)
            {
                return(true);
            }

            foreach (var kvp in host.power_on_config)
            {
                if (!customConfig.ContainsKey(kvp.Key) || kvp.Value != customConfig[kvp.Key])
                {
                    return(true);
                }
            }

            return(false);
        }
        private void SaveConfig(Host host, Host.PowerOnMode mode)
        {
            var    newMode    = mode.ToString();
            var    config     = mode.Config;
            string secretuuid = "";


            if (newMode == "iLO" && Helpers.StockholmOrGreater(Connection))
            {
                //the UI should have already prevented us from getting here, but be defensive
                newMode = "";
                config  = new Dictionary <string, string>();
            }

            try
            {
                if (newMode == "DRAC" || newMode == "iLO" || newMode != "wake-on-lan" && newMode != "")
                {
                    if (config.ContainsKey("power_on_password_secret"))
                    {
                        secretuuid = Secret.CreateSecret(Session, config["power_on_password_secret"]);
                        config["power_on_password_secret"] = secretuuid;
                    }
                }
                else if (string.IsNullOrEmpty(newMode))
                {
                    //if WLB is on, we need to exclude the host from WLB power management,
                    //since we cannot turn it back on if it is powered down automatically

                    try
                    {
                        Pool pool = Helpers.GetPool(Connection);
                        if (pool != null && WlbServerState.GetState(pool) == WlbServerState.ServerState.Enabled)
                        {
                            var hostConfig = new WlbHostConfiguration(host.uuid)
                            {
                                ParticipatesInPowerManagement = false
                            };

                            var wlbAction = new SendWlbConfigurationAction(pool, hostConfig.ToDictionary(),
                                                                           SendWlbConfigurationKind.SetHostConfiguration);
                            wlbAction.RunExternal(Session);
                        }
                    }
                    catch
                    {
                        //Do nothing on failure.
                    }
                }

                Host.set_power_on_mode(Session, host.opaque_ref, newMode, config);
            }
            catch
            {
                if (!string.IsNullOrEmpty(secretuuid))
                {
                    string secretRef = Secret.get_by_uuid(Session, secretuuid);
                    Secret.destroy(Session, secretRef);
                }

                throw;
            }
        }