2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* 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;
|
|
|
|
|
using XenAdmin.Actions.Wlb;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Wlb;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Actions.HostActions
|
|
|
|
|
{
|
|
|
|
|
public class HostPowerOnAction : AsyncAction
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
2023-07-14 16:30:04 +02:00
|
|
|
|
|
|
|
|
|
public HostPowerOnAction(Host host)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: base(host.Connection, Messages.HOST_POWER_ON)
|
|
|
|
|
{
|
|
|
|
|
Host = host;
|
|
|
|
|
AddCommonAPIMethodsToRoleCheck();
|
|
|
|
|
|
|
|
|
|
ApiMethodsToRoleCheck.Add("pool.send_wlb_configuration");
|
|
|
|
|
ApiMethodsToRoleCheck.Add("host.power_on");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Run()
|
|
|
|
|
{
|
|
|
|
|
bool succeeded = false;
|
|
|
|
|
string name = Helpers.GetName(Host);
|
2023-07-14 16:30:04 +02:00
|
|
|
|
Host coordinator = Helpers.GetCoordinator(Connection);
|
2021-08-31 12:31:16 +02:00
|
|
|
|
AppliesTo.Add(coordinator.opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Title = string.Format(Messages.ACTION_HOST_START_TITLE, name);
|
|
|
|
|
Description = Messages.ACTION_HOST_STARTING;
|
2023-07-14 16:30:04 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
Host.power_on(Session, Host.opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Description = Messages.ACTION_HOST_STARTED;
|
|
|
|
|
succeeded = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
if (e is Failure f)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
if (f.ErrorDescription.Count > 2)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
switch (f.ErrorDescription[2])
|
|
|
|
|
{
|
|
|
|
|
case "DRAC_NO_SUPP_PACK":
|
|
|
|
|
throw new Exception(Messages.DRAC_NO_SUPP_PACK);
|
|
|
|
|
case "DRAC_POWERON_FAILED":
|
|
|
|
|
throw new Exception(Messages.DRAC_POWERON_FAILED);
|
|
|
|
|
case "ILO_CONNECTION_ERROR":
|
|
|
|
|
throw new Exception(Messages.ILO_CONNECTION_ERROR);
|
|
|
|
|
case "ILO_POWERON_FAILED":
|
|
|
|
|
throw new Exception(Messages.ILO_POWERON_FAILED);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2023-07-14 16:30:04 +02:00
|
|
|
|
|
|
|
|
|
throw new Exception(string.Format(Messages.POWER_ON_REQUEST_FAILED, Host));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
if (Helpers.WlbConfigured(Connection) && Helpers.WlbEnabledAndConfigured(Connection))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
UpdateHostLastPowerOnSucceeded(succeeded, Host);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-20 15:34:14 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attempts to set the LastPowerOnSucceeded flag in the WLB Host configuration
|
|
|
|
|
/// </summary>
|
2023-07-14 16:30:04 +02:00
|
|
|
|
private void UpdateHostLastPowerOnSucceeded(bool succeeded, Host host)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
WlbHostConfiguration hostConfig = new WlbHostConfiguration(host.uuid);
|
|
|
|
|
hostConfig.LastPowerOnSucceeded = succeeded;
|
|
|
|
|
if (!succeeded)
|
|
|
|
|
{
|
|
|
|
|
hostConfig.ParticipatesInPowerManagement = false;
|
|
|
|
|
}
|
2023-07-14 16:30:04 +02:00
|
|
|
|
|
|
|
|
|
Pool pool = Helpers.GetPoolOfOne(host.Connection);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (null != pool)
|
|
|
|
|
{
|
|
|
|
|
SendWlbConfigurationAction action = new SendWlbConfigurationAction(pool, hostConfig.ToDictionary(), SendWlbConfigurationKind.SetHostConfiguration);
|
2022-04-05 12:52:32 +02:00
|
|
|
|
action.RunSync(Session);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-03-16 02:50:45 +01:00
|
|
|
|
throw new Failure(Failure.INTERNAL_ERROR, string.Format(Messages.POOL_GONE, BrandManager.BrandConsole));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error("Unable to set the host's LastPowerOnSucceeded status.", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|