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 System.Collections.Generic;
|
2018-12-20 13:19:44 +01:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAPI;
|
2017-11-17 02:04:45 +01:00
|
|
|
|
using XenCenterLib;
|
2019-07-03 12:07:55 +02:00
|
|
|
|
using XenCenterLib.Archive;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Actions
|
|
|
|
|
{
|
2018-12-20 13:19:44 +01:00
|
|
|
|
public class SingleHostStatusAction : StatusReportAction
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
private readonly Host host;
|
|
|
|
|
private readonly string[] capabilityKeys;
|
|
|
|
|
private readonly long size;
|
|
|
|
|
private readonly string[] RBAC_FAIL_STRINGS = {"HTTP", "403", "Forbidden"};
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
public SingleHostStatusAction(Host host, long size, List<string> capabilityKeys, string path, string time)
|
|
|
|
|
: base(host.Connection, string.Format(Messages.ACTION_SYSTEM_STATUS_COMPILING, Helpers.GetName(host)), path, time)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-12-20 13:19:44 +01:00
|
|
|
|
this.host = host;
|
|
|
|
|
this.capabilityKeys = capabilityKeys.ToArray();
|
|
|
|
|
this.size = size;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
public long DataTransferred;
|
|
|
|
|
|
2021-10-28 13:36:10 +02:00
|
|
|
|
public static RbacMethodList StaticRBACDependencies
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var list = new RbacMethodList("HTTP/get_system_status");
|
|
|
|
|
list.AddRange(Role.CommonSessionApiList);
|
|
|
|
|
list.AddRange(Role.CommonTaskApiList);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
protected override void Run()
|
|
|
|
|
{
|
2021-03-09 01:31:57 +01:00
|
|
|
|
Description = string.Format(Messages.ACTION_SYSTEM_STATUS_COMPILING, Helpers.GetName(host));
|
2018-12-20 13:19:44 +01:00
|
|
|
|
Status = ReportStatus.compiling;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
string hostname = Helpers.GetName(host);
|
2019-07-03 12:07:55 +02:00
|
|
|
|
hostname = TarSanitization.SanitizeTarPathMember(hostname);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (hostname.Length > 20)
|
|
|
|
|
hostname = hostname.Truncate(20);
|
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
string filename = string.Format("{1}\\{2}-bugtool-{0}.tar", hostname, filePath, timeString);
|
|
|
|
|
|
|
|
|
|
string entries_string = string.Join(",", capabilityKeys);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
log.DebugFormat("Getting system status for {0} on {1}", entries_string, hostname);
|
|
|
|
|
|
2020-12-24 00:07:03 +01:00
|
|
|
|
if (Session == null)
|
|
|
|
|
throw new Exception(Messages.CONNECTION_IO_EXCEPTION);
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-12-24 00:07:03 +01:00
|
|
|
|
RelatedTask = Task.create(Session, "get_system_status_task", host.address);
|
|
|
|
|
log.DebugFormat("HTTP GETTING file from {0} to {1}", host.address, filename);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-12-24 00:07:03 +01:00
|
|
|
|
HTTP_actions.get_system_status(dataRxDelegate,
|
|
|
|
|
() => XenAdminConfigManager.Provider.ForcedExiting || GetCancelling(),
|
|
|
|
|
XenAdminConfigManager.Provider.GetProxyTimeout(false),
|
|
|
|
|
host.address,
|
|
|
|
|
XenAdminConfigManager.Provider.GetProxyFromSettings(Connection),
|
|
|
|
|
filename, RelatedTask.opaque_ref, Session.opaque_ref, entries_string, "tar");
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-12-24 00:07:03 +01:00
|
|
|
|
PollToCompletion();
|
2018-12-20 13:19:44 +01:00
|
|
|
|
Status = ReportStatus.succeeded;
|
2022-01-11 14:20:16 +01:00
|
|
|
|
Tick(100, Messages.COMPLETED);
|
2018-12-20 13:19:44 +01:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2020-12-24 00:07:03 +01:00
|
|
|
|
PollToCompletion(suppressFailures: true);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-12-24 00:07:03 +01:00
|
|
|
|
if (e is HTTP.CancelledException || e is CancelledException)
|
|
|
|
|
{
|
|
|
|
|
log.Info("Getting system status cancelled");
|
|
|
|
|
Status = ReportStatus.cancelled;
|
|
|
|
|
Error = e;
|
|
|
|
|
Description = Messages.ACTION_SYSTEM_STATUS_CANCELLED;
|
|
|
|
|
throw new CancelledException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Error(string.Format("Getting system status from {0} failed", hostname), e);
|
2018-12-20 13:19:44 +01:00
|
|
|
|
Status = ReportStatus.failed;
|
|
|
|
|
Error = e;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
if (Win32.GetHResult(e) == Win32.ERROR_DISK_FULL)
|
|
|
|
|
{
|
|
|
|
|
Description = Messages.ACTION_SYSTEM_STATUS_DISK_FULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
if (!string.IsNullOrEmpty(Error.Message) && RBAC_FAIL_STRINGS.All(s => Error.Message.Contains(s)))
|
|
|
|
|
{
|
|
|
|
|
var roles = Host.Connection.Session.Roles;
|
|
|
|
|
roles.Sort();
|
|
|
|
|
Description = string.Format(Messages.BUGTOOL_RBAC_FAILURE, roles[0].FriendlyName());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Description = Messages.BUGTOOL_REPORTSTATUS_FAILED;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataRxDelegate(long rxd)
|
|
|
|
|
{
|
2018-12-20 13:19:44 +01:00
|
|
|
|
Status = ReportStatus.downloading;
|
|
|
|
|
DataTransferred = rxd;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
if (Cancelling)
|
|
|
|
|
throw new CancelledException();
|
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
//although the parent class's PercentComplete setter does correct out of range values,
|
|
|
|
|
//it throws an assertion to catch potentially erroneous percentage calculations;
|
|
|
|
|
//here, however, the error is expected because the MaxSize is only an estimate,
|
|
|
|
|
//hence the assertion is pointless, hence correct the value before assigning it to PercentComplete
|
|
|
|
|
|
|
|
|
|
PercentComplete = rxd < size ? (int)(rxd * 100L / size) : 100;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void RecomputeCanCancel()
|
|
|
|
|
{
|
|
|
|
|
CanCancel = !Cancelling;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|