2013-06-24 13:41:48 +02: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;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
using XenAdmin.Dialogs;
|
|
|
|
using XenAPI;
|
|
|
|
using System.Linq;
|
2015-07-14 11:05:13 +02:00
|
|
|
using System.IO;
|
2015-07-20 15:28:44 +02:00
|
|
|
using XenAdmin.Alerts;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.PatchingWizard
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Remember that equals for patches dont work across connections because
|
|
|
|
/// we are not allow to override equals. YOU SHOULD NOT USE ANY OPERATION THAT IMPLIES CALL EQUALS OF Pool_path or Host_patch
|
|
|
|
/// You should do it manually or use delegates.
|
|
|
|
/// </summary>
|
|
|
|
public partial class PatchingWizard : XenWizardBase
|
|
|
|
{
|
|
|
|
private readonly PatchingWizard_PatchingPage PatchingWizard_PatchingPage;
|
|
|
|
private readonly PatchingWizard_SelectPatchPage PatchingWizard_SelectPatchPage;
|
|
|
|
private readonly PatchingWizard_ModePage PatchingWizard_ModePage;
|
|
|
|
private readonly PatchingWizard_SelectServers PatchingWizard_SelectServers;
|
2015-01-09 13:54:12 +01:00
|
|
|
private readonly PatchingWizard_UploadPage PatchingWizard_UploadPage;
|
2013-06-24 13:41:48 +02:00
|
|
|
private readonly PatchingWizard_PrecheckPage PatchingWizard_PrecheckPage;
|
|
|
|
private readonly PatchingWizard_FirstPage PatchingWizard_FirstPage;
|
|
|
|
|
|
|
|
public PatchingWizard()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
PatchingWizard_PatchingPage = new PatchingWizard_PatchingPage();
|
|
|
|
PatchingWizard_SelectPatchPage = new PatchingWizard_SelectPatchPage();
|
|
|
|
PatchingWizard_ModePage = new PatchingWizard_ModePage();
|
|
|
|
PatchingWizard_SelectServers = new PatchingWizard_SelectServers();
|
2015-01-09 13:54:12 +01:00
|
|
|
PatchingWizard_UploadPage = new PatchingWizard_UploadPage();
|
2013-06-24 13:41:48 +02:00
|
|
|
PatchingWizard_PrecheckPage = new PatchingWizard_PrecheckPage();
|
|
|
|
PatchingWizard_FirstPage = new PatchingWizard_FirstPage();
|
|
|
|
|
|
|
|
AddPage(PatchingWizard_FirstPage);
|
|
|
|
AddPage(PatchingWizard_SelectPatchPage);
|
|
|
|
AddPage(PatchingWizard_SelectServers);
|
2015-01-09 13:54:12 +01:00
|
|
|
AddPage(PatchingWizard_UploadPage);
|
2013-06-24 13:41:48 +02:00
|
|
|
AddPage(PatchingWizard_PrecheckPage);
|
|
|
|
AddPage(PatchingWizard_ModePage);
|
|
|
|
AddPage(PatchingWizard_PatchingPage);
|
|
|
|
}
|
|
|
|
|
2015-07-20 15:28:44 +02:00
|
|
|
public void AddAlert(XenServerPatchAlert alert)
|
|
|
|
{
|
|
|
|
PatchingWizard_SelectPatchPage.SelectDownloadAlert(alert);
|
|
|
|
PatchingWizard_SelectPatchPage.SelectedUpdateAlert = alert;
|
|
|
|
PatchingWizard_SelectServers.SelectedUpdateAlert = alert;
|
|
|
|
PatchingWizard_UploadPage.SelectedUpdateAlert = alert;
|
|
|
|
}
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
public void AddFile(string path)
|
|
|
|
{
|
|
|
|
PatchingWizard_SelectPatchPage.AddFile(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SelectServers(List<Host> selectedServers)
|
|
|
|
{
|
|
|
|
PatchingWizard_SelectServers.SelectServers(selectedServers);
|
2014-08-07 13:52:14 +02:00
|
|
|
PatchingWizard_SelectServers.DisableUnselectedServers();
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateWizardContent(XenTabPage senderPage)
|
|
|
|
{
|
|
|
|
var prevPageType = senderPage.GetType();
|
|
|
|
|
|
|
|
if (prevPageType == typeof(PatchingWizard_SelectPatchPage))
|
|
|
|
{
|
|
|
|
var updateType = PatchingWizard_SelectPatchPage.SelectedUpdateType;
|
|
|
|
var newPatch = PatchingWizard_SelectPatchPage.SelectedNewPatch;
|
|
|
|
var existPatch = PatchingWizard_SelectPatchPage.SelectedExistingPatch;
|
2015-07-14 11:05:13 +02:00
|
|
|
var alertPatch = PatchingWizard_SelectPatchPage.SelectedUpdateAlert;
|
2015-07-20 16:27:41 +02:00
|
|
|
var fileFromDiskAlertPatch = PatchingWizard_SelectPatchPage.FileFromDiskAlert;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
PatchingWizard_SelectServers.SelectedUpdateType = updateType;
|
2015-01-09 13:54:12 +01:00
|
|
|
PatchingWizard_SelectServers.Patch = existPatch;
|
2015-07-20 15:28:44 +02:00
|
|
|
PatchingWizard_SelectServers.SelectedUpdateAlert = alertPatch;
|
2015-07-20 16:27:41 +02:00
|
|
|
PatchingWizard_SelectServers.FileFromDiskAlert = fileFromDiskAlertPatch;
|
2015-01-09 13:54:12 +01:00
|
|
|
|
|
|
|
PatchingWizard_UploadPage.SelectedUpdateType = updateType;
|
|
|
|
PatchingWizard_UploadPage.SelectedExistingPatch = existPatch;
|
2015-09-04 18:09:22 +02:00
|
|
|
PatchingWizard_UploadPage.SelectedNewPatchPath = newPatch;
|
2015-07-14 11:05:13 +02:00
|
|
|
PatchingWizard_UploadPage.SelectedUpdateAlert = alertPatch;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
2015-01-26 16:48:52 +01:00
|
|
|
PatchingWizard_ModePage.Patch = existPatch;
|
2015-07-20 15:28:44 +02:00
|
|
|
PatchingWizard_ModePage.SelectedUpdateAlert = alertPatch;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
2015-01-26 16:48:52 +01:00
|
|
|
PatchingWizard_PrecheckPage.Patch = existPatch;
|
|
|
|
PatchingWizard_PatchingPage.Patch = existPatch;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
PatchingWizard_PrecheckPage.SelectedUpdateType = updateType;
|
|
|
|
|
|
|
|
PatchingWizard_ModePage.SelectedUpdateType = updateType;
|
|
|
|
|
|
|
|
PatchingWizard_PatchingPage.SelectedUpdateType = updateType;
|
|
|
|
PatchingWizard_PatchingPage.SelectedNewPatch = newPatch;
|
|
|
|
}
|
|
|
|
else if (prevPageType == typeof(PatchingWizard_SelectServers))
|
|
|
|
{
|
|
|
|
var selectedServers = PatchingWizard_SelectServers.SelectedServers;
|
2015-01-09 13:54:12 +01:00
|
|
|
|
|
|
|
PatchingWizard_PrecheckPage.SelectedServers = selectedServers;
|
|
|
|
|
|
|
|
PatchingWizard_ModePage.SelectedServers = selectedServers;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
2015-01-09 13:54:12 +01:00
|
|
|
PatchingWizard_PatchingPage.SelectedMasters = PatchingWizard_SelectServers.SelectedMasters;
|
|
|
|
PatchingWizard_PatchingPage.SelectedServers = selectedServers;
|
|
|
|
PatchingWizard_PatchingPage.SelectedPools = PatchingWizard_SelectServers.SelectedPools;
|
|
|
|
|
|
|
|
PatchingWizard_UploadPage.SelectedMasters = PatchingWizard_SelectServers.SelectedMasters;
|
2015-01-20 15:22:29 +01:00
|
|
|
PatchingWizard_UploadPage.SelectedServers = selectedServers;
|
2015-01-09 13:54:12 +01:00
|
|
|
}
|
|
|
|
else if (prevPageType == typeof(PatchingWizard_UploadPage))
|
|
|
|
{
|
2013-06-24 13:41:48 +02:00
|
|
|
if (PatchingWizard_SelectPatchPage.SelectedUpdateType == UpdateType.NewRetail)
|
|
|
|
{
|
|
|
|
PatchingWizard_SelectPatchPage.SelectedUpdateType = UpdateType.Existing;
|
2015-01-09 13:54:12 +01:00
|
|
|
PatchingWizard_SelectPatchPage.SelectedExistingPatch = PatchingWizard_UploadPage.Patch;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
PatchingWizard_SelectServers.SelectedUpdateType = UpdateType.Existing;
|
2015-01-09 13:54:12 +01:00
|
|
|
PatchingWizard_SelectServers.Patch = PatchingWizard_UploadPage.Patch;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
2015-01-09 13:54:12 +01:00
|
|
|
PatchingWizard_PrecheckPage.Patch = PatchingWizard_UploadPage.Patch;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
2015-01-09 13:54:12 +01:00
|
|
|
PatchingWizard_ModePage.Patch = PatchingWizard_UploadPage.Patch;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
2015-01-09 13:54:12 +01:00
|
|
|
PatchingWizard_PatchingPage.Patch = PatchingWizard_UploadPage.Patch;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
2015-01-26 16:43:36 +01:00
|
|
|
PatchingWizard_PatchingPage.SuppPackVdis = PatchingWizard_UploadPage.SuppPackVdis;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
else if (prevPageType == typeof(PatchingWizard_ModePage))
|
|
|
|
{
|
|
|
|
PatchingWizard_PatchingPage.ManualTextInstructions = PatchingWizard_ModePage.ManualTextInstructions;
|
|
|
|
PatchingWizard_PatchingPage.IsAutomaticMode = PatchingWizard_ModePage.IsAutomaticMode;
|
2015-07-08 18:35:50 +02:00
|
|
|
PatchingWizard_PatchingPage.RemoveUpdateFile = PatchingWizard_ModePage.RemoveUpdateFile;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
else if (prevPageType == typeof(PatchingWizard_PrecheckPage))
|
|
|
|
{
|
|
|
|
PatchingWizard_PatchingPage.ProblemsResolvedPreCheck = PatchingWizard_PrecheckPage.ProblemsResolvedPreCheck;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private delegate List<AsyncAction> GetActionsDelegate();
|
|
|
|
|
|
|
|
private List<AsyncAction> BuildSubActions(params GetActionsDelegate[] getActionsDelegate)
|
|
|
|
{
|
|
|
|
List<AsyncAction> result = new List<AsyncAction>();
|
|
|
|
foreach (GetActionsDelegate getActionDelegate in getActionsDelegate)
|
|
|
|
{
|
|
|
|
var list = getActionDelegate();
|
|
|
|
if (list != null && list.Count > 0)
|
|
|
|
result.AddRange(list);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<AsyncAction> GetUnwindChangesActions()
|
|
|
|
{
|
|
|
|
if (PatchingWizard_PrecheckPage.ProblemsResolvedPreCheck == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
var actionList = (from problem in PatchingWizard_PrecheckPage.ProblemsResolvedPreCheck
|
|
|
|
where problem.SolutionActionCompleted
|
|
|
|
select problem.UnwindChanges());
|
|
|
|
|
|
|
|
return actionList.Where(action => action != null &&
|
|
|
|
action.Connection != null &&
|
|
|
|
action.Connection.IsConnected).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<AsyncAction> GetRemovePatchActions(List<Pool_patch> patchesToRemove)
|
|
|
|
{
|
|
|
|
if (patchesToRemove == null)
|
|
|
|
return null;
|
|
|
|
|
2015-09-04 18:09:22 +02:00
|
|
|
List<AsyncAction> list = new List<AsyncAction>();
|
|
|
|
foreach (Pool_patch patch in patchesToRemove)
|
|
|
|
{
|
|
|
|
if (patch.Connection != null && patch.Connection.IsConnected)
|
|
|
|
{
|
|
|
|
if (patch.HostsAppliedTo().Count == 0)
|
|
|
|
{
|
|
|
|
list.Add(new RemovePatchAction(patch));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list.Add(new DelegatedAsyncAction(patch.Connection, Messages.REMOVE_PATCH, "", "", session => Pool_patch.async_pool_clean(session, patch.opaque_ref)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private List<AsyncAction> GetRemovePatchActions()
|
|
|
|
{
|
2015-09-07 13:18:01 +02:00
|
|
|
return GetRemovePatchActions(PatchingWizard_UploadPage.NewUploadedPatches.Keys.ToList());
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
2015-01-26 16:45:55 +01:00
|
|
|
private List<AsyncAction> GetRemoveVdiActions(List<VDI> vdisToRemove)
|
|
|
|
{
|
|
|
|
if (vdisToRemove == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
var list = (from vdi in vdisToRemove
|
|
|
|
where vdi.Connection != null && vdi.Connection.IsConnected
|
|
|
|
select new DestroyDiskAction(vdi));
|
|
|
|
|
|
|
|
return list.OfType<AsyncAction>().ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<AsyncAction> GetRemoveVdiActions()
|
|
|
|
{
|
|
|
|
return GetRemoveVdiActions(PatchingWizard_UploadPage.AllCreatedSuppPackVdis); ;
|
|
|
|
}
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
private void RunMultipleActions(string title, string startDescription, string endDescription,
|
|
|
|
List<AsyncAction> subActions)
|
|
|
|
{
|
|
|
|
if (subActions.Count > 0)
|
|
|
|
{
|
|
|
|
using (MultipleAction multipleAction = new MultipleAction(xenConnection, title, startDescription,
|
2014-07-21 12:19:04 +02:00
|
|
|
endDescription, subActions, false, true))
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
ActionProgressDialog dialog = new ActionProgressDialog(multipleAction, ProgressBarStyle.Blocks);
|
|
|
|
dialog.ShowDialog(Program.MainWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnCancel()
|
|
|
|
{
|
2015-09-04 18:18:26 +02:00
|
|
|
base.OnCancel();
|
|
|
|
|
2015-01-26 16:45:55 +01:00
|
|
|
List<AsyncAction> subActions = BuildSubActions(GetUnwindChangesActions, GetRemovePatchActions, GetRemoveVdiActions);
|
2013-06-24 13:41:48 +02:00
|
|
|
RunMultipleActions(Messages.REVERT_WIZARD_CHANGES, Messages.REVERTING_WIZARD_CHANGES,
|
|
|
|
Messages.REVERTED_WIZARD_CHANGES, subActions);
|
|
|
|
|
2015-07-15 17:36:37 +02:00
|
|
|
RemoveDownloadedPatches();
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void RemoveUnwantedPatches(List<Pool_patch> patchesToRemove)
|
|
|
|
{
|
|
|
|
List<AsyncAction> subActions = GetRemovePatchActions(patchesToRemove);
|
|
|
|
RunMultipleActions(Messages.REMOVE_UPDATES, Messages.REMOVING_UPDATES, Messages.REMOVED_UPDATES, subActions);
|
|
|
|
}
|
|
|
|
|
2015-01-26 16:45:55 +01:00
|
|
|
private void RemoveTemporaryVdis()
|
|
|
|
{
|
|
|
|
List<AsyncAction> subActions = GetRemoveVdiActions();
|
|
|
|
RunMultipleActions(Messages.REMOVE_UPDATES, Messages.REMOVING_UPDATES, Messages.REMOVED_UPDATES, subActions);
|
|
|
|
}
|
|
|
|
|
2015-07-15 17:36:37 +02:00
|
|
|
private void RemoveDownloadedPatches()
|
|
|
|
{
|
2015-09-04 18:18:26 +02:00
|
|
|
foreach (string downloadedPatch in PatchingWizard_UploadPage.AllDownloadedPatches.Values)
|
2015-07-15 17:36:37 +02:00
|
|
|
{
|
2015-09-04 18:18:26 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (File.Exists(downloadedPatch))
|
|
|
|
{
|
|
|
|
File.Delete(downloadedPatch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
log.DebugFormat("Could not remove downloaded patch {0} ", downloadedPatch);
|
|
|
|
}
|
|
|
|
}
|
2015-07-15 17:36:37 +02:00
|
|
|
}
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
protected override void FinishWizard()
|
|
|
|
{
|
2015-01-09 13:54:12 +01:00
|
|
|
if (PatchingWizard_UploadPage.NewUploadedPatches != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
List<Pool_patch> patchesToRemove =
|
2015-09-07 13:18:01 +02:00
|
|
|
PatchingWizard_UploadPage.NewUploadedPatches.Keys.ToList().Where(
|
2016-02-08 11:14:05 +01:00
|
|
|
patch => !string.Equals(patch.uuid, PatchingWizard_UploadPage.Patch.uuid, System.StringComparison.OrdinalIgnoreCase)).ToList();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
RemoveUnwantedPatches(patchesToRemove);
|
|
|
|
}
|
|
|
|
|
2015-01-26 16:45:55 +01:00
|
|
|
if (PatchingWizard_UploadPage.AllCreatedSuppPackVdis != null)
|
|
|
|
RemoveTemporaryVdis();
|
|
|
|
|
2015-07-15 17:36:37 +02:00
|
|
|
RemoveDownloadedPatches();
|
2015-07-14 11:05:13 +02:00
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
base.FinishWizard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|