2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-09-14 18:03:26 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAPI;
|
2020-09-14 18:03:26 +02:00
|
|
|
|
using XenAdmin.Actions;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Dialogs;
|
2020-09-14 18:03:26 +02:00
|
|
|
|
using XenAdmin.Network;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Wizards;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Commands
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2020-09-14 18:03:26 +02:00
|
|
|
|
/// IF HA is not enabled, it launches the HA wizard, otherwise the HA config dialog
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// </summary>
|
2020-09-14 18:03:26 +02:00
|
|
|
|
internal class HAConfigureCommand : HACommand
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-07-18 01:35:11 +02:00
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
private RbacMethodList HA_PERMISSION_CHECKS = new RbacMethodList(
|
|
|
|
|
"pool.set_ha_host_failures_to_tolerate",
|
|
|
|
|
"pool.sync_database",
|
|
|
|
|
"vm.set_ha_restart_priority",
|
|
|
|
|
"pool.ha_compute_hypothetical_max_host_failures_to_tolerate"
|
|
|
|
|
);
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of this Command. The parameter-less constructor is required if
|
|
|
|
|
/// this Command is to be attached to a ToolStrip menu item or button. It should not be used in any other scenario.
|
|
|
|
|
/// </summary>
|
2020-09-14 18:03:26 +02:00
|
|
|
|
public HAConfigureCommand()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
public HAConfigureCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: base(mainWindow, selection)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
public HAConfigureCommand(IMainWindow mainWindow, IXenConnection connection)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: base(mainWindow, Helpers.GetPoolOfOne(connection))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
public HAConfigureCommand(IMainWindow mainWindow, Pool pool)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: base(mainWindow, pool)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Execute(IXenConnection connection)
|
|
|
|
|
{
|
|
|
|
|
if (connection == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Pool pool = Helpers.GetPool(connection);
|
|
|
|
|
if (pool == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-10-26 17:01:55 +01:00
|
|
|
|
if (Helpers.FeatureForbidden(pool, Host.RestrictHA))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
// Show upsell dialog
|
2017-11-17 13:24:43 +01:00
|
|
|
|
using (var dlg = new UpsellDialog(HiddenFeatures.LinkLabelHidden ? Messages.UPSELL_BLURB_HA : Messages.UPSELL_BLURB_HA + Messages.UPSELL_BLURB_TRIAL,
|
2020-09-14 18:03:26 +02:00
|
|
|
|
InvisibleMessages.UPSELL_LEARNMOREURL_TRIAL))
|
2016-06-20 14:26:52 +02:00
|
|
|
|
dlg.ShowDialog(Parent);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else if (pool.ha_enabled)
|
|
|
|
|
{
|
2020-09-14 18:03:26 +02:00
|
|
|
|
if (pool.ha_statefiles.All(sf => pool.Connection.Resolve(new XenRef<VDI>(sf)) == null))//empty gives true, which is correct
|
2019-07-18 01:35:11 +02:00
|
|
|
|
{
|
|
|
|
|
log.ErrorFormat("Cannot resolve HA statefile VDI (pool {0} has {1} statefiles).",
|
|
|
|
|
pool.Name(), pool.ha_statefiles.Length);
|
|
|
|
|
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlg = new ErrorDialog(string.Format(Messages.HA_CONFIGURE_NO_STATEFILE, Helpers.GetName(pool).Ellipsise(30)),
|
|
|
|
|
ThreeButtonDialog.ButtonOK)
|
|
|
|
|
{
|
|
|
|
|
HelpName = "HADisable",
|
|
|
|
|
WindowTitle = Messages.CONFIGURE_HA
|
|
|
|
|
})
|
2019-07-18 01:35:11 +02:00
|
|
|
|
{
|
|
|
|
|
dlg.ShowDialog(Program.MainWindow);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-14 18:03:26 +02:00
|
|
|
|
else if (!Role.CanPerform(HA_PERMISSION_CHECKS, pool.Connection))
|
|
|
|
|
{
|
|
|
|
|
var msg = string.Format(Messages.RBAC_HA_CONFIGURE_WARNING,
|
|
|
|
|
Role.FriendlyCSVRoleList(Role.ValidRoleList(HA_PERMISSION_CHECKS, pool.Connection)),
|
|
|
|
|
Role.FriendlyCSVRoleList(pool.Connection.Session.Roles));
|
|
|
|
|
|
|
|
|
|
using (var dlg = new ErrorDialog(msg))
|
|
|
|
|
dlg.ShowDialog(Parent);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MainWindowCommandInterface.ShowPerConnectionWizard(connection, new EditVmHaPrioritiesDialog(pool));
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MainWindowCommandInterface.ShowPerConnectionWizard(connection, new HAWizard(pool));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ExecuteCore(SelectedItemCollection selection)
|
|
|
|
|
{
|
|
|
|
|
Execute(selection[0].Connection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool CanExecuteCore(SelectedItemCollection selection)
|
|
|
|
|
{
|
2020-09-14 18:03:26 +02:00
|
|
|
|
return CanExecuteHACommand(selection);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-14 18:05:12 +02:00
|
|
|
|
protected override string GetCantExecuteReasonCore(IXenObject item)
|
|
|
|
|
{
|
|
|
|
|
var reason = base.GetCantExecuteReasonCore(item);
|
|
|
|
|
if (!string.IsNullOrEmpty(reason) && reason != Messages.UNKNOWN)
|
|
|
|
|
return reason;
|
|
|
|
|
|
|
|
|
|
Pool pool = item == null ? null : Helpers.GetPool(item.Connection);
|
|
|
|
|
|
|
|
|
|
if (pool != null && !pool.Connection.Cache.Hosts.Any(Host.RestrictPoolSecretRotation) && pool.is_psr_pending)
|
|
|
|
|
return Messages.ROTATE_POOL_SECRET_PENDING_HA;
|
|
|
|
|
|
|
|
|
|
return Messages.UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool CanExecute(Pool pool)
|
|
|
|
|
{
|
|
|
|
|
return pool.Connection.Cache.Hosts.Any(Host.RestrictPoolSecretRotation) || !pool.is_psr_pending;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
public override string MenuText => Messages.CONFIGURE_HA_ELLIPSIS;
|
|
|
|
|
}
|
2019-07-18 01:35:11 +02:00
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
internal class HADisableCommand : HACommand
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of this Command. The parameter-less constructor is required if
|
|
|
|
|
/// this Command is to be attached to a ToolStrip menu item or button. It should not be used in any other scenario.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public HADisableCommand()
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-07-18 01:35:11 +02:00
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
public HADisableCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection)
|
|
|
|
|
: base(mainWindow, selection)
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-07-18 01:35:11 +02:00
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
public HADisableCommand(IMainWindow mainWindow, IXenConnection connection)
|
|
|
|
|
: base(mainWindow, Helpers.GetPoolOfOne(connection))
|
|
|
|
|
{
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
protected override void ExecuteCore(SelectedItemCollection selection)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-14 18:03:26 +02:00
|
|
|
|
Pool pool = selection.Count == 1 ? selection[0].PoolAncestor : null;
|
|
|
|
|
if (pool == null || !pool.ha_enabled)
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
if (pool.ha_statefiles.All(sf => pool.Connection.Resolve(new XenRef<VDI>(sf)) == null)) //empty gives true, which is correct
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-14 18:03:26 +02:00
|
|
|
|
using (var dlg = new ErrorDialog(string.Format(Messages.HA_DISABLE_NO_STATEFILE,
|
|
|
|
|
Helpers.GetName(pool).Ellipsise(30)),
|
|
|
|
|
ThreeButtonDialog.ButtonOK)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-14 18:03:26 +02:00
|
|
|
|
HelpName = "HADisable",
|
|
|
|
|
WindowTitle = Messages.DISABLE_HA
|
|
|
|
|
})
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-14 18:03:26 +02:00
|
|
|
|
dlg.ShowDialog(Parent);
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 18:03:26 +02:00
|
|
|
|
// Confirm the user wants to disable HA
|
|
|
|
|
using (var dlg = new NoIconDialog(string.Format(Messages.HA_DISABLE_QUERY,
|
|
|
|
|
Helpers.GetName(pool).Ellipsise(30)),
|
|
|
|
|
ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-09-14 18:03:26 +02:00
|
|
|
|
HelpName = "HADisable",
|
|
|
|
|
WindowTitle = Messages.DISABLE_HA
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
if (dlg.ShowDialog(Parent) != DialogResult.Yes)
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-14 18:03:26 +02:00
|
|
|
|
|
|
|
|
|
var action = new DisableHAAction(pool);
|
|
|
|
|
// We will need to re-enable buttons when the action completes
|
|
|
|
|
action.Completed += Program.MainWindow.action_Completed;
|
|
|
|
|
action.RunAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool CanExecuteCore(SelectedItemCollection selection)
|
|
|
|
|
{
|
|
|
|
|
return CanExecuteHACommand(selection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool CanExecute(Pool pool)
|
|
|
|
|
{
|
|
|
|
|
return pool.ha_enabled;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2020-09-14 18:03:26 +02:00
|
|
|
|
|
|
|
|
|
public override string MenuText => Messages.DISABLE_HA_HOTKEY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal class HACommand : Command
|
|
|
|
|
{
|
|
|
|
|
public HACommand()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HACommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection)
|
|
|
|
|
: base(mainWindow, selection)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HACommand(IMainWindow mainWindow, IXenConnection connection)
|
|
|
|
|
: base(mainWindow, Helpers.GetPoolOfOne(connection))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HACommand(IMainWindow mainWindow, Pool pool)
|
|
|
|
|
: base(mainWindow, pool)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool CanExecuteCore(SelectedItemCollection selection)
|
|
|
|
|
{
|
|
|
|
|
return new HAConfigureCommand(MainWindowCommandInterface, selection).CanExecute() ||
|
|
|
|
|
new HADisableCommand(MainWindowCommandInterface, selection).CanExecute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string GetCantExecuteReasonCore(IXenObject item)
|
|
|
|
|
{
|
|
|
|
|
Pool pool = item == null ? null : Helpers.GetPoolOfOne(item.Connection);
|
|
|
|
|
|
|
|
|
|
if (pool == null)
|
|
|
|
|
return Messages.POOL_GONE;
|
|
|
|
|
|
|
|
|
|
if (!pool.IsVisible())
|
|
|
|
|
return Messages.HA_STANDALONE_SERVER;
|
|
|
|
|
|
|
|
|
|
Host master = Helpers.GetMaster(pool.Connection);
|
|
|
|
|
if (master == null)
|
|
|
|
|
return Messages.POOL_MASTER_GONE;
|
|
|
|
|
|
|
|
|
|
if (pool.Locked)
|
|
|
|
|
return Messages.POOL_EDIT_IN_PROGRESS;
|
|
|
|
|
|
|
|
|
|
var action = HelpersGUI.FindActiveHaAction(pool.Connection);
|
|
|
|
|
if (action != null)
|
|
|
|
|
return string.Format(action is EnableHAAction ? Messages.HA_PAGE_ENABLING : Messages.HA_PAGE_DISABLING,
|
|
|
|
|
Helpers.GetName(pool.Connection));
|
|
|
|
|
|
|
|
|
|
return Messages.UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected bool CanExecuteHACommand(SelectedItemCollection selection)
|
|
|
|
|
{
|
|
|
|
|
if (selection.Count != 1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Pool pool = selection[0].PoolAncestor;
|
|
|
|
|
|
|
|
|
|
if (pool == null || pool.Locked ||
|
|
|
|
|
pool.Connection == null || !pool.Connection.IsConnected ||
|
|
|
|
|
Helpers.GetMaster(pool.Connection) == null ||
|
|
|
|
|
HelpersGUI.FindActiveHaAction(pool.Connection) != null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return CanExecute(pool);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual bool CanExecute(Pool pool)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string MenuText => Messages.MAINWINDOW_HIGH_AVAILABILITY;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|