xenadmin/XenModel/Actions/CallHome/SaveCallHomeSettingsAction.cs
Mihaela Stoica d366c57f55 CP-12890: Allow user to specify XenServer credentials to use for Health Check
- added new fields to the Health Check Settings dialog (XenServer credentials)
- these credentials are saved as xapi secrets, and on un-enroll they are being removed
- removed the Authenticate button; the authentication is now done on pressing the OK button
- the Health Check Settings dialog is displayed on "Enroll now" and "Edit Health Check settings"
- display the "Last Successful Upload" on the Health Check Overview dialog
- use uniform format when converting time to string and string to time

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
2015-07-06 17:02:55 +01:00

36 lines
1.8 KiB
C#

using System.Collections.Generic;
using XenAPI;
namespace XenAdmin.Actions
{
public class SaveCallHomeSettingsAction : PureAsyncAction
{
private readonly Pool pool;
CallHomeSettings callHomeSettings;
private string authenticationToken;
private string username;
private string password;
public SaveCallHomeSettingsAction(Pool pool, CallHomeSettings callHomeSettings, string authenticationToken, string userName, string passWord, bool suppressHistory)
: base(pool.Connection, Messages.ACTION_SAVE_CALLHOME_SETTINGS, string.Format(Messages.ACTION_SAVING_CALLHOME_SETTINGS, pool.Name), suppressHistory)
{
this.pool = pool;
this.callHomeSettings = callHomeSettings;
this.authenticationToken = authenticationToken;
this.username = callHomeSettings.Status == CallHomeStatus.Enabled ? userName : null;
this.password = callHomeSettings.Status == CallHomeStatus.Enabled ? passWord : null;
}
protected override void Run()
{
Dictionary<string, string> newConfig = callHomeSettings.ToDictionary(pool.health_check_config);
if (!string.IsNullOrEmpty(authenticationToken))
CallHomeAuthenticationAction.SetSecretInfo(Connection, newConfig, CallHomeSettings.UPLOAD_TOKEN_SECRET, authenticationToken);
CallHomeAuthenticationAction.SetSecretInfo(Connection, newConfig, CallHomeSettings.UPLOAD_CREDENTIAL_USER_SECRET, username);
CallHomeAuthenticationAction.SetSecretInfo(Connection, newConfig, CallHomeSettings.UPLOAD_CREDENTIAL_PASSWORD_SECRET, password);
Pool.set_health_check_config(Connection.Session, pool.opaque_ref, newConfig);
}
}
}