protected void SaveConfig(Host host) { string secretuuid = ""; try { Dictionary<string, string> powerONConfig = new Dictionary<string, string>(); if (newMode == "DRAC" || newMode == "iLO") { powerONConfig.Add("power_on_ip", ip); powerONConfig.Add("power_on_user", user); secretuuid = Secret.CreateSecret(Session, password); powerONConfig.Add("power_on_password_secret", secretuuid); } else if (newMode != "wake-on-lan" && newMode != "") { foreach (KeyValuePair<string, string> pair in customConfig) { if (pair.Key == "power_on_password_secret") { secretuuid = Secret.CreateSecret(Session, pair.Value); powerONConfig.Add(pair.Key, secretuuid); } else powerONConfig.Add(pair.Key, pair.Value); } } else if (string.IsNullOrEmpty(newMode)) { // We don't want this bit to alter the function of the main action so... try { Pool pool = Core.Helpers.GetPool(this.Connection); if (null != pool) { if (WlbServerState.GetState(pool) == XenAdmin.Wlb.WlbServerState.ServerState.Enabled) { //Tell WLB to not allow this host to be powered down automatically, since we cannot turn it back on WlbHostConfiguration hostConfig = new WlbHostConfiguration(host.uuid); hostConfig.ParticipatesInPowerManagement = false; //Use the existing SendWlbConfig action, as it wraps the config functionality // as well as the RBAC checks. SendWlbConfigurationAction wlbAction = new SendWlbConfigurationAction(pool, hostConfig.ToDictionary(), SendWlbConfigurationKind.SetHostConfiguration); wlbAction.RunExternal(Session); } } } catch (Exception) { //Do nothing on failure. } } Host.set_power_on_mode(Session, host.opaque_ref, newMode, powerONConfig); } catch (Exception e) { if (!string.IsNullOrEmpty(secretuuid)) { string secretRef = Secret.get_by_uuid(Session, secretuuid); Secret.destroy(Session, secretRef); } throw e; } }
/// <summary> /// Attempts to set the LastPowerOnSucceeded flag in the WLB Host configuration /// </summary> /// <param name="successful">bool </param> private void UpdateHostLastPowerOnSucceeded(bool succeeded, XenAPI.Host host) { try { //Helpers.SetOtherConfig(this.Host.Connection.Session, this.Host, "LastPowerOnsucceeded", successful.ToString()); WlbHostConfiguration hostConfig = new WlbHostConfiguration(host.uuid); hostConfig.LastPowerOnSucceeded = succeeded; if (!succeeded) { hostConfig.ParticipatesInPowerManagement = false; } XenAPI.Pool pool = Helpers.GetPoolOfOne(host.Connection); if (null != pool) { SendWlbConfigurationAction action = new SendWlbConfigurationAction(pool, hostConfig.ToDictionary(), SendWlbConfigurationKind.SetHostConfiguration); action.RunExternal(Session); } else { throw new Exception("Could not find host's pool."); } } catch (Exception ex) { log.Error("Unable to set the host's LastPowerOnSucceeded status.", ex); } }