xenadmin/XenAdmin/Wizards/PatchingWizard/PatchingWizard_UploadPage.cs

250 lines
9.2 KiB
C#
Raw Normal View History

/* Copyright (c) Citrix Systems, Inc.
* 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;
using System.IO;
using System.Linq;
2015-02-24 14:29:41 +01:00
using XenAdmin.Core;
using XenAPI;
using XenAdmin.Alerts;
using XenAdmin.Controls;
using XenAdmin.Wizards.PatchingWizard.PlanActions;
2015-02-24 14:29:41 +01:00
namespace XenAdmin.Wizards.PatchingWizard
{
public partial class PatchingWizard_UploadPage : AutomatedUpdatesBasePage
2015-02-24 14:29:41 +01:00
{
public PatchingWizard_UploadPage()
{
InitializeComponent();
}
#region Accessors
public readonly List<HostUpdateMapping> PatchMappings = new List<HostUpdateMapping>();
2015-02-24 14:29:41 +01:00
public UpdateType SelectedUpdateType { private get; set; }
public string SelectedPatchFilePath { get; set; }
public XenServerPatchAlert SelectedUpdateAlert { private get; set; }
public KeyValuePair<XenServerPatch, string> PatchFromDisk { private get; set; }
public List<Host> SelectedServers { private get; set; }
2015-02-24 14:29:41 +01:00
public Pool_patch Patch
{
get
{
if (SelectedUpdateAlert != null)
return (from HostUpdateMapping mapping in PatchMappings
let m = mapping as PoolPatchMapping
where m != null && m.XenServerPatch.Equals(SelectedUpdateAlert.Patch)
select m.Pool_patch).FirstOrDefault();
2015-02-24 14:29:41 +01:00
if (SelectedPatchFilePath != null)
return (from HostUpdateMapping mapping in PatchMappings
let m = mapping as OtherLegacyMapping
where m != null && m.Path.Equals(SelectedPatchFilePath)
select m.Pool_patch).FirstOrDefault();
return null;
}
}
2015-02-24 14:29:41 +01:00
public Pool_update PoolUpdate
2015-02-24 14:29:41 +01:00
{
get
2015-02-24 14:29:41 +01:00
{
foreach (var mapping in PatchMappings)
{
if (mapping is PoolUpdateMapping updateMapping &&
SelectedUpdateAlert != null && updateMapping.XenServerPatch.Equals(SelectedUpdateAlert.Patch))
return updateMapping.Pool_update;
if (mapping is SuppPackMapping suppPackMapping && suppPackMapping.Path.Equals(SelectedPatchFilePath))
return suppPackMapping.Pool_update;
}
return null;
}
}
public Dictionary<Host, VDI> SuppPackVdis
2015-02-24 14:29:41 +01:00
{
get
2015-02-24 14:29:41 +01:00
{
if (string.IsNullOrEmpty(SelectedPatchFilePath))
return null;
2015-02-24 14:29:41 +01:00
var suppPackVdis = new Dictionary<Host, VDI>();
foreach (var mapping in PatchMappings)
{
if (mapping is SuppPackMapping m && m.Path.Equals(SelectedPatchFilePath))
{
foreach (var kvp in m.SuppPackVdis)
suppPackVdis[kvp.Key] = kvp.Value;
}
}
2015-02-24 14:29:41 +01:00
return suppPackVdis;
2015-02-24 14:29:41 +01:00
}
}
#endregion
2015-02-24 14:29:41 +01:00
#region XenTabPage overrides
public override string Text { get { return Messages.PATCHINGWIZARD_UPLOADPAGE_TEXT; } }
public override string PageTitle
{
get { return Messages.PATCHINGWIZARD_UPLOADPAGE_TITLE_ONLY_UPLOAD; }
}
2015-02-24 14:29:41 +01:00
public override string HelpID { get { return "UploadPatch"; } }
2015-02-24 14:29:41 +01:00
public override bool EnableNext()
{
return IsSuccess;
2015-02-24 14:29:41 +01:00
}
public override bool EnableCancel()
{
return true;
}
public override bool EnablePrevious()
{
return _thisPageIsCompleted;
}
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
2015-02-24 14:29:41 +01:00
{
if (direction == PageLoadedDirection.Back)
_thisPageIsCompleted = false;
2015-02-24 14:29:41 +01:00
}
#endregion
protected override string BlurbText()
2015-02-24 14:29:41 +01:00
{
return Messages.PATCHINGWIZARD_SINGLEUPLOAD_TITLE;
2015-02-24 14:29:41 +01:00
}
protected override string SuccessMessageOnCompletion(bool multiplePools)
2015-02-24 14:29:41 +01:00
{
var msg = multiplePools
? Messages.PATCHINGWIZARD_SINGLEUPLOAD_SUCCESS_MANY
: Messages.PATCHINGWIZARD_SINGLEUPLOAD_SUCCESS_ONE;
return string.Format(msg, GetUpdateName());
2015-02-24 14:29:41 +01:00
}
protected override string FailureMessageOnCompletion(bool multiplePools)
2015-02-24 14:29:41 +01:00
{
var msg = multiplePools
? Messages.PATCHINGWIZARD_SINGLEUPLOAD_FAILURE_MANY
: Messages.PATCHINGWIZARD_SINGLEUPLOAD_FAILURE_ONE;
return string.Format(msg, GetUpdateName());
2015-02-24 14:29:41 +01:00
}
protected override string SuccessMessagePerPool(Pool pool)
2015-02-24 14:29:41 +01:00
{
return string.Format( Messages.PATCHINGWIZARD_SINGLEUPLOAD_SUCCESS_ONE, GetUpdateName());
2015-02-24 14:29:41 +01:00
}
protected override string FailureMessagePerPool(bool multipleErrors)
2015-02-24 14:29:41 +01:00
{
var msg = multipleErrors
? Messages.PATCHINGWIZARD_SINGLEUPLOAD_FAILURE_PER_POOL_MANY
: Messages.PATCHINGWIZARD_SINGLEUPLOAD_FAILURE_PER_POOL_ONE;
return string.Format(msg, GetUpdateName());
2015-02-24 14:29:41 +01:00
}
protected override string UserCancellationMessage()
2015-02-24 14:29:41 +01:00
{
return Messages.PATCHINGWIZARD_SINGLEUPLOAD_CANCELLATION;
2015-02-24 14:29:41 +01:00
}
protected override string ReconsiderCancellationMessage()
{
return Messages.PATCHINGWIZARD_SINGLEUPLOAD_CANCELLATION_RECONSIDER;
}
protected override List<HostPlan> GenerateHostPlans(Pool pool, out List<Host> applicableHosts)
2015-02-24 14:29:41 +01:00
{
var master = Helpers.GetMaster(pool);
var planActions = new List<PlanAction>();
2015-02-24 14:29:41 +01:00
var alertPatch = SelectedUpdateAlert == null ? null : SelectedUpdateAlert.Patch;
2015-02-24 14:29:41 +01:00
bool download = alertPatch != null && PatchFromDisk.Key == null &&
(!AllDownloadedPatches.ContainsKey(alertPatch) || !File.Exists(AllDownloadedPatches[alertPatch]));
2015-02-24 14:29:41 +01:00
if (download)
planActions.Add(new DownloadPatchPlanAction(master.Connection, alertPatch, AllDownloadedPatches, PatchFromDisk));
var skipDiskSpaceCheck = SelectedUpdateType != UpdateType.Legacy ||
!Helpers.CreamOrGreater(master.Connection) ||
Helpers.ElyOrGreater(master.Connection); //this is superfluous; just added for completeness
2015-02-24 14:29:41 +01:00
if (alertPatch != null)
2015-02-24 14:29:41 +01:00
{
planActions.Add(new UploadPatchToMasterPlanAction(this, master.Connection, alertPatch,
PatchMappings, AllDownloadedPatches, PatchFromDisk, skipDiskSpaceCheck));
2015-02-24 14:29:41 +01:00
}
else if (!string.IsNullOrEmpty(SelectedPatchFilePath))
2015-02-24 14:29:41 +01:00
{
var servers = SelectedServers.Where(s => s.Connection == master.Connection).ToList();
planActions.Add(new UploadPatchToMasterPlanAction(this, master.Connection, servers, SelectedPatchFilePath,
SelectedUpdateType, PatchMappings, skipDiskSpaceCheck));
2015-02-24 14:29:41 +01:00
}
var hostPlan = new HostPlan(master, null, planActions, null);
applicableHosts = new List<Host> {master};
return new List<HostPlan> {hostPlan};
}
2015-02-24 14:29:41 +01:00
private string GetUpdateName()
{
if (SelectedUpdateAlert != null)
return SelectedUpdateAlert.Patch.Name;
2015-02-24 14:29:41 +01:00
try
2015-02-24 14:29:41 +01:00
{
return Path.GetFileName(SelectedPatchFilePath);
2015-02-24 14:29:41 +01:00
}
catch
2015-02-24 14:29:41 +01:00
{
return string.Empty;
2015-02-24 14:29:41 +01:00
}
}
}
}