2017-01-16 21:14:56 +01:00
|
|
|
|
/* 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;
|
2019-01-10 14:24:42 +01:00
|
|
|
|
using System.IO;
|
2015-02-20 14:07:20 +01:00
|
|
|
|
using System.Linq;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
using XenAdmin.Core;
|
2015-02-20 14:07:20 +01:00
|
|
|
|
using XenAPI;
|
2015-07-14 11:05:13 +02:00
|
|
|
|
using XenAdmin.Alerts;
|
2019-01-10 14:24:42 +01:00
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Wizards.PatchingWizard.PlanActions;
|
|
|
|
|
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.PatchingWizard
|
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public partial class PatchingWizard_UploadPage : AutomatedUpdatesBasePage
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
|
|
|
|
public PatchingWizard_UploadPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Accessors
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public readonly List<HostUpdateMapping> PatchMappings = new List<HostUpdateMapping>();
|
|
|
|
|
|
2015-02-24 14:29:41 +01:00
|
|
|
|
public UpdateType SelectedUpdateType { private get; set; }
|
2019-01-10 14:24:42 +01:00
|
|
|
|
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
|
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
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
|
|
|
|
|
2019-01-10 14:24:42 +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();
|
2016-09-09 13:02:59 +02:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public Pool_update PoolUpdate
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
get
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
foreach (var mapping in PatchMappings)
|
2015-07-15 14:03:11 +02:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
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;
|
2015-07-15 14:03:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
return null;
|
2015-07-15 14:03:11 +02:00
|
|
|
|
}
|
2015-07-14 11:05:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public Dictionary<Host, VDI> SuppPackVdis
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
get
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
if (string.IsNullOrEmpty(SelectedPatchFilePath))
|
|
|
|
|
return null;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
var suppPackVdis = new Dictionary<Host, VDI>();
|
|
|
|
|
foreach (var mapping in PatchMappings)
|
2015-09-07 13:18:01 +02:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
if (mapping is SuppPackMapping m && m.Path.Equals(SelectedPatchFilePath))
|
|
|
|
|
{
|
|
|
|
|
foreach (var kvp in m.SuppPackVdis)
|
|
|
|
|
suppPackVdis[kvp.Key] = kvp.Value;
|
|
|
|
|
}
|
2015-09-07 13:18:01 +02:00
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
return suppPackVdis;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-10 14:24:42 +01:00
|
|
|
|
#endregion
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
#region XenTabPage overrides
|
2015-09-04 18:09:22 +02:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public override string Text { get { return Messages.PATCHINGWIZARD_UPLOADPAGE_TEXT; } }
|
2015-09-04 18:09:22 +02:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public override string PageTitle
|
2015-02-20 14:07:20 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
get { return Messages.PATCHINGWIZARD_UPLOADPAGE_TITLE_ONLY_UPLOAD; }
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public override string HelpID { get { return "UploadPatch"; } }
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public override bool EnableNext()
|
|
|
|
|
{
|
|
|
|
|
return IsSuccess;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public override bool EnableCancel()
|
2015-09-07 13:18:01 +02:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
return true;
|
2015-09-07 13:18:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public override bool EnablePrevious()
|
2017-01-23 13:36:47 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
return _thisPageIsCompleted;
|
2017-01-23 13:36:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
if (direction == PageLoadedDirection.Back)
|
|
|
|
|
_thisPageIsCompleted = false;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override string BlurbText()
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
return Messages.PATCHINGWIZARD_SINGLEUPLOAD_TITLE;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
protected override string SuccessMessageOnCompletion(bool multiplePools)
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +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
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
protected override string FailureMessageOnCompletion(bool multiplePools)
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +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
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 18:16:40 +01:00
|
|
|
|
protected override string WarningMessageOnCompletion(bool multiplePools)
|
|
|
|
|
{
|
|
|
|
|
var msg = multiplePools
|
|
|
|
|
? Messages.PATCHINGWIZARD_SINGLEUPLOAD_WARNING_MANY
|
|
|
|
|
: Messages.PATCHINGWIZARD_SINGLEUPLOAD_WARNING_ONE;
|
|
|
|
|
return string.Format(msg, GetUpdateName());
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
protected override string SuccessMessagePerPool(Pool pool)
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
return string.Format( Messages.PATCHINGWIZARD_SINGLEUPLOAD_SUCCESS_ONE, GetUpdateName());
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
protected override string FailureMessagePerPool(bool multipleErrors)
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +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
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 18:16:40 +01:00
|
|
|
|
protected override string WarningMessagePerPool(Pool pool)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
protected override string UserCancellationMessage()
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
return Messages.PATCHINGWIZARD_SINGLEUPLOAD_CANCELLATION;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 14:23:49 +01:00
|
|
|
|
protected override string ReconsiderCancellationMessage()
|
|
|
|
|
{
|
|
|
|
|
return Messages.PATCHINGWIZARD_SINGLEUPLOAD_CANCELLATION_RECONSIDER;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
protected override List<HostPlan> GenerateHostPlans(Pool pool, out List<Host> applicableHosts)
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
var master = Helpers.GetMaster(pool);
|
|
|
|
|
var planActions = new List<PlanAction>();
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
var alertPatch = SelectedUpdateAlert == null ? null : SelectedUpdateAlert.Patch;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
bool download = alertPatch != null && PatchFromDisk.Key == null &&
|
|
|
|
|
(!AllDownloadedPatches.ContainsKey(alertPatch) || !File.Exists(AllDownloadedPatches[alertPatch]));
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
if (download)
|
|
|
|
|
planActions.Add(new DownloadPatchPlanAction(master.Connection, alertPatch, AllDownloadedPatches, PatchFromDisk));
|
2016-11-10 18:18:51 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
var skipDiskSpaceCheck = SelectedUpdateType != UpdateType.Legacy ||
|
|
|
|
|
Helpers.ElyOrGreater(master.Connection); //this is superfluous; just added for completeness
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
if (alertPatch != null)
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
planActions.Add(new UploadPatchToMasterPlanAction(this, master.Connection, alertPatch,
|
|
|
|
|
PatchMappings, AllDownloadedPatches, PatchFromDisk, skipDiskSpaceCheck));
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2015-07-15 14:03:11 +02:00
|
|
|
|
}
|
2019-01-10 14:24:42 +01:00
|
|
|
|
else if (!string.IsNullOrEmpty(SelectedPatchFilePath))
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +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
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
var hostPlan = new HostPlan(master, null, planActions, null);
|
|
|
|
|
applicableHosts = new List<Host> {master};
|
|
|
|
|
return new List<HostPlan> {hostPlan};
|
2015-07-15 14:03:11 +02:00
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
private string GetUpdateName()
|
2015-07-15 14:03:11 +02:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
if (SelectedUpdateAlert != null)
|
|
|
|
|
return SelectedUpdateAlert.Patch.Name;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
try
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
return Path.GetFileName(SelectedPatchFilePath);
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
2019-01-10 14:24:42 +01:00
|
|
|
|
catch
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2019-01-10 14:24:42 +01:00
|
|
|
|
return string.Empty;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-15 14:03:11 +02:00
|
|
|
|
}
|