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;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
using System.Drawing;
|
2015-02-20 14:07:20 +01:00
|
|
|
|
using System.Linq;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Dialogs;
|
2015-02-20 14:07:20 +01:00
|
|
|
|
using XenAPI;
|
2015-07-14 11:05:13 +02:00
|
|
|
|
using XenAdmin.Alerts;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.PatchingWizard
|
|
|
|
|
{
|
|
|
|
|
public partial class PatchingWizard_UploadPage : XenTabPage
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
2015-07-15 14:03:11 +02:00
|
|
|
|
private DownloadAndUnzipXenServerPatchAction downloadAction = null;
|
2017-03-16 12:41:14 +01:00
|
|
|
|
private const int EllipsiseValueDownDescription = 80;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
|
|
|
|
public PatchingWizard_UploadPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Text { get { return Messages.PATCHINGWIZARD_UPLOADPAGE_TEXT; } }
|
|
|
|
|
|
2015-09-07 14:37:52 +02:00
|
|
|
|
private string pageTitle = Messages.PATCHINGWIZARD_UPLOADPAGE_TITLE_ONLY_UPLOAD;
|
|
|
|
|
public override string PageTitle { get { return pageTitle; } }
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
|
|
|
|
public override string HelpID { get { return "UploadPatch"; } }
|
|
|
|
|
|
|
|
|
|
#region Accessors
|
|
|
|
|
public List<Host> SelectedMasters { private get; set; }
|
|
|
|
|
public List<Host> SelectedServers { private get; set; }
|
|
|
|
|
public UpdateType SelectedUpdateType { private get; set; }
|
2015-09-04 18:09:22 +02:00
|
|
|
|
public string SelectedNewPatchPath { get; set; }
|
2015-02-24 14:29:41 +01:00
|
|
|
|
public Pool_patch SelectedExistingPatch { private get; set; }
|
2015-07-14 11:05:13 +02:00
|
|
|
|
public Alert SelectedUpdateAlert { private get; set; }
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2015-09-07 13:18:01 +02:00
|
|
|
|
public readonly Dictionary<Pool_patch, string> NewUploadedPatches = new Dictionary<Pool_patch, string>();
|
2015-09-04 18:09:22 +02:00
|
|
|
|
private Dictionary<string, List<Host>> uploadedUpdates = new Dictionary<string, List<Host>>();
|
2015-09-07 14:37:52 +02:00
|
|
|
|
private Pool_patch _patch;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
public Pool_patch Patch
|
|
|
|
|
{
|
|
|
|
|
get { return _patch; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 13:02:59 +02:00
|
|
|
|
private Pool_update _poolUpdate;
|
|
|
|
|
public Pool_update PoolUpdate
|
|
|
|
|
{
|
|
|
|
|
get { return _poolUpdate; }
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 12:03:34 +02:00
|
|
|
|
public Dictionary<string, string> AllDownloadedPatches = new Dictionary<string, string>();
|
2015-02-24 14:29:41 +01:00
|
|
|
|
public readonly List<VDI> AllCreatedSuppPackVdis = new List<VDI>();
|
|
|
|
|
public Dictionary<Host, VDI> SuppPackVdis = new Dictionary<Host, VDI>();
|
2017-01-23 13:36:47 +01:00
|
|
|
|
public Dictionary<Pool_update, string> AllIntroducedPoolUpdates = new Dictionary<Pool_update, string>();
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public override void PageLoaded(PageLoadedDirection direction)
|
|
|
|
|
{
|
|
|
|
|
base.PageLoaded(direction);
|
2015-07-15 14:03:11 +02:00
|
|
|
|
|
2015-02-20 14:29:00 +01:00
|
|
|
|
canUpload = true;
|
|
|
|
|
canDownload = true;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
UpdateButtons();
|
|
|
|
|
|
|
|
|
|
if (SelectedUpdateType == UpdateType.Existing)
|
|
|
|
|
_patch = SelectedExistingPatch;
|
|
|
|
|
|
2015-07-15 14:03:11 +02:00
|
|
|
|
if (direction == PageLoadedDirection.Forward)
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2015-07-15 14:03:11 +02:00
|
|
|
|
flickerFreeListBox1.Items.Clear();
|
2015-07-21 12:03:34 +02:00
|
|
|
|
var selectedPatch = SelectedUpdateAlert != null ? ((XenServerPatchAlert)SelectedUpdateAlert).Patch : null;
|
2015-09-04 18:09:22 +02:00
|
|
|
|
if (selectedPatch != null && String.IsNullOrEmpty(SelectedNewPatchPath) &&
|
2015-07-21 12:03:34 +02:00
|
|
|
|
(!AllDownloadedPatches.Any(kvp => kvp.Key == selectedPatch.Uuid)
|
|
|
|
|
|| String.IsNullOrEmpty(AllDownloadedPatches[selectedPatch.Uuid])
|
|
|
|
|
|| !File.Exists(AllDownloadedPatches[selectedPatch.Uuid])))
|
2015-07-14 11:05:13 +02:00
|
|
|
|
{
|
|
|
|
|
DownloadFile();
|
2015-09-07 14:37:52 +02:00
|
|
|
|
label2.Text = Messages.PATCHINGWIZARD_UPLOADPAGE_MESSAGE_DOWNLOAD_AND_UPLOAD;
|
|
|
|
|
pageTitle = Messages.PATCHINGWIZARD_UPLOADPAGE_TITLE_DOWNLOAD_AND_UPLOAD;
|
2015-07-14 11:05:13 +02:00
|
|
|
|
}
|
2015-07-15 14:03:11 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-07 14:37:52 +02:00
|
|
|
|
label2.Text = Messages.PATCHINGWIZARD_UPLOADPAGE_MESSAGE_ONLY_UPLOAD;
|
|
|
|
|
pageTitle = Messages.PATCHINGWIZARD_UPLOADPAGE_TITLE_ONLY_UPLOAD;
|
2015-07-21 12:03:34 +02:00
|
|
|
|
if (selectedPatch != null && AllDownloadedPatches.ContainsKey(selectedPatch.Uuid))
|
2015-09-04 18:09:22 +02:00
|
|
|
|
SelectedNewPatchPath = AllDownloadedPatches[selectedPatch.Uuid];
|
2015-07-15 14:03:11 +02:00
|
|
|
|
PrepareUploadActions();
|
|
|
|
|
TryUploading();
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-08 15:47:58 +01:00
|
|
|
|
public override void SelectDefaultControl()
|
|
|
|
|
{
|
|
|
|
|
flickerFreeListBox1.Select();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 11:05:13 +02:00
|
|
|
|
private void DownloadFile()
|
|
|
|
|
{
|
|
|
|
|
string patchUri = ((XenServerPatchAlert)SelectedUpdateAlert).Patch.PatchUrl;
|
|
|
|
|
if (string.IsNullOrEmpty(patchUri))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Uri address = new Uri(patchUri);
|
|
|
|
|
string tempFile = Path.GetTempFileName();
|
|
|
|
|
|
2016-10-19 12:29:57 +02:00
|
|
|
|
bool isIso = SelectedUpdateType == UpdateType.ISO;
|
2016-10-19 14:42:16 +02:00
|
|
|
|
|
2017-07-21 16:56:27 +02:00
|
|
|
|
downloadAction = new DownloadAndUnzipXenServerPatchAction(SelectedUpdateAlert.Name, address, tempFile, false, isIso ? Branding.UpdateIso : Branding.Update);
|
2015-07-15 14:03:11 +02:00
|
|
|
|
|
|
|
|
|
if (downloadAction != null)
|
|
|
|
|
{
|
|
|
|
|
downloadAction.Changed += singleAction_Changed;
|
|
|
|
|
downloadAction.Completed += singleAction_Completed;
|
|
|
|
|
}
|
2015-07-14 11:05:13 +02:00
|
|
|
|
|
2015-07-15 14:03:11 +02:00
|
|
|
|
downloadAction.RunAsync();
|
|
|
|
|
|
|
|
|
|
flickerFreeListBox1.Items.Clear();
|
|
|
|
|
flickerFreeListBox1.Items.Add(downloadAction);
|
|
|
|
|
flickerFreeListBox1.Refresh();
|
|
|
|
|
OnPageUpdated();
|
|
|
|
|
|
|
|
|
|
UpdateActionProgress(downloadAction);
|
2015-07-14 11:05:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 14:29:41 +01:00
|
|
|
|
public override void PageCancelled()
|
|
|
|
|
{
|
|
|
|
|
foreach (var action in uploadActions.Values.Where(action => action != null && !action.IsCompleted))
|
|
|
|
|
{
|
|
|
|
|
CancelAction(action);
|
|
|
|
|
}
|
2015-07-15 14:03:11 +02:00
|
|
|
|
if (downloadAction != null)
|
|
|
|
|
{
|
|
|
|
|
CancelAction(downloadAction);
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool EnableNext()
|
|
|
|
|
{
|
2015-07-15 14:03:11 +02:00
|
|
|
|
return uploadActions.Values.All(action => action == null || action.Succeeded) && (downloadAction == null || downloadAction.Succeeded);
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool EnablePrevious()
|
|
|
|
|
{
|
2015-07-15 14:03:11 +02:00
|
|
|
|
return !canUpload || uploadActions.Values.All(action => action == null || action.IsCompleted) && (downloadAction == null || downloadAction.IsCompleted) ;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Dictionary<Host, AsyncAction> uploadActions = new Dictionary<Host, AsyncAction>();
|
|
|
|
|
|
|
|
|
|
private static bool PatchExistsOnPool(Pool_patch patch, Host poolMaster)
|
|
|
|
|
{
|
|
|
|
|
var poolPatches = new List<Pool_patch>(poolMaster.Connection.Cache.Pool_patches);
|
|
|
|
|
|
2016-02-08 11:14:05 +01:00
|
|
|
|
return (poolPatches.Exists(p => string.Equals(p.uuid, patch.uuid, StringComparison.OrdinalIgnoreCase)));
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PrepareUploadActions()
|
|
|
|
|
{
|
|
|
|
|
OnPageUpdated();
|
|
|
|
|
SuppPackVdis.Clear();
|
|
|
|
|
uploadActions.Clear();
|
|
|
|
|
|
|
|
|
|
//Upload the patches to the masters if it is necessary
|
|
|
|
|
List<Host> masters = SelectedMasters;
|
|
|
|
|
|
|
|
|
|
foreach (Host selectedServer in masters)
|
|
|
|
|
{
|
|
|
|
|
AsyncAction action = null;
|
|
|
|
|
switch (SelectedUpdateType)
|
|
|
|
|
{
|
|
|
|
|
case UpdateType.NewRetail:
|
2015-09-04 18:09:22 +02:00
|
|
|
|
if (CanUploadUpdateOnHost(SelectedNewPatchPath, selectedServer))
|
2015-07-20 15:28:44 +02:00
|
|
|
|
{
|
2015-09-07 13:18:01 +02:00
|
|
|
|
bool deleteFileOnCancel = AllDownloadedPatches.ContainsValue(SelectedNewPatchPath);
|
|
|
|
|
action = new UploadPatchAction(selectedServer.Connection, SelectedNewPatchPath, true, deleteFileOnCancel);
|
2015-07-20 15:28:44 +02:00
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
break;
|
|
|
|
|
case UpdateType.Existing:
|
2015-07-20 15:28:44 +02:00
|
|
|
|
if (!PatchExistsOnPool(_patch, selectedServer))
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
|
|
|
|
//Download patch from server Upload in the selected server
|
|
|
|
|
action = new CopyPatchFromHostToOther(SelectedExistingPatch.Connection, selectedServer,
|
|
|
|
|
SelectedExistingPatch);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-08-31 11:42:09 +02:00
|
|
|
|
case UpdateType.ISO:
|
2015-09-04 18:09:22 +02:00
|
|
|
|
if (CanUploadUpdateOnHost(SelectedNewPatchPath, selectedServer))
|
|
|
|
|
{
|
2016-12-21 11:37:06 +01:00
|
|
|
|
_poolUpdate = null;
|
|
|
|
|
_patch = null;
|
|
|
|
|
|
2015-09-04 18:09:22 +02:00
|
|
|
|
action = new UploadSupplementalPackAction(
|
2015-02-24 14:29:41 +01:00
|
|
|
|
selectedServer.Connection,
|
|
|
|
|
SelectedServers.Where(s => s.Connection == selectedServer.Connection).ToList(),
|
2015-09-04 18:09:22 +02:00
|
|
|
|
SelectedNewPatchPath,
|
2015-02-24 14:29:41 +01:00
|
|
|
|
true);
|
2015-09-04 18:09:22 +02:00
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (action != null)
|
|
|
|
|
{
|
|
|
|
|
action.Changed += singleAction_Changed;
|
|
|
|
|
action.Completed += singleAction_Completed;
|
|
|
|
|
}
|
2015-09-07 13:18:01 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2017-01-23 13:36:47 +01:00
|
|
|
|
_poolUpdate = GetUpdateFromUpdatePath();
|
2015-09-07 13:18:01 +02:00
|
|
|
|
_patch = GetPatchFromPatchPath();
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
uploadActions.Add(selectedServer, action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (KeyValuePair<Host, AsyncAction> uploadAction in uploadActions)
|
|
|
|
|
{
|
|
|
|
|
flickerFreeListBox1.Items.Add(uploadAction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flickerFreeListBox1.Refresh();
|
|
|
|
|
OnPageUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-20 14:07:20 +01:00
|
|
|
|
private bool canUpload = true;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
private bool canDownload = true;
|
|
|
|
|
private DiskSpaceRequirements diskSpaceRequirements;
|
|
|
|
|
|
2015-09-04 18:09:22 +02:00
|
|
|
|
private bool CanUploadUpdateOnHost(string patchPath, Host host)
|
|
|
|
|
{
|
|
|
|
|
return !uploadedUpdates.ContainsKey(patchPath) || !uploadedUpdates[patchPath].Contains(host);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddToUploadedUpdates(string patchPath, Host host)
|
|
|
|
|
{
|
|
|
|
|
if(!uploadedUpdates.ContainsKey(patchPath))
|
|
|
|
|
{
|
|
|
|
|
List<Host> hosts = new List<Host>();
|
|
|
|
|
hosts.Add(host);
|
|
|
|
|
uploadedUpdates.Add(patchPath, hosts);
|
|
|
|
|
}
|
|
|
|
|
else if(!uploadedUpdates[patchPath].Contains(host))
|
|
|
|
|
{
|
|
|
|
|
uploadedUpdates[patchPath].Add(host);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 14:29:41 +01:00
|
|
|
|
private void TryUploading()
|
2015-02-20 14:07:20 +01:00
|
|
|
|
{
|
2015-02-24 14:29:41 +01:00
|
|
|
|
// reset progress bar and action progress description
|
|
|
|
|
UpdateActionProgress(null);
|
|
|
|
|
|
|
|
|
|
// Check if we can upload the patches to the masters if it is necessary.
|
|
|
|
|
// This check is only available for Cream or greater hosts.
|
|
|
|
|
// If we can upload (i.e. there is enough disk space) then start the upload.
|
|
|
|
|
// Otherwise display error.
|
|
|
|
|
canUpload = true;
|
|
|
|
|
diskSpaceRequirements = null;
|
|
|
|
|
var diskSpaceActions = new List<AsyncAction>();
|
2017-06-27 14:48:54 +02:00
|
|
|
|
foreach (Host master in SelectedMasters.Where(master => Helpers.CreamOrGreater(master.Connection) && !Helpers.ElyOrGreater(master.Connection)))
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
|
|
|
|
AsyncAction action = null;
|
|
|
|
|
switch (SelectedUpdateType)
|
|
|
|
|
{
|
|
|
|
|
case UpdateType.NewRetail:
|
2016-08-04 16:10:36 +02:00
|
|
|
|
if (CanUploadUpdateOnHost(SelectedNewPatchPath, master))
|
|
|
|
|
action = new CheckDiskSpaceForPatchUploadAction(master, SelectedNewPatchPath, true);
|
2015-02-24 14:29:41 +01:00
|
|
|
|
break;
|
|
|
|
|
case UpdateType.Existing:
|
|
|
|
|
if (SelectedExistingPatch != null && !PatchExistsOnPool(SelectedExistingPatch, master))
|
|
|
|
|
action = new CheckDiskSpaceForPatchUploadAction(master, SelectedExistingPatch, true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (action != null)
|
|
|
|
|
{
|
|
|
|
|
action.Changed += delegate
|
|
|
|
|
{
|
|
|
|
|
Program.Invoke(Program.MainWindow, () => UpdateActionDescription(action));
|
|
|
|
|
};
|
|
|
|
|
diskSpaceActions.Add(action);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (diskSpaceActions.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
StartUploading();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var multipleAction = new MultipleAction(Connection, "", "", "", diskSpaceActions, true, true, true))
|
|
|
|
|
{
|
|
|
|
|
multipleAction.Completed += delegate
|
|
|
|
|
{
|
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
|
|
|
|
{
|
|
|
|
|
if (multipleAction.Exception is NotEnoughSpaceException)
|
|
|
|
|
{
|
|
|
|
|
canUpload = false;
|
|
|
|
|
diskSpaceRequirements = (multipleAction.Exception as NotEnoughSpaceException).DiskSpaceRequirements;
|
|
|
|
|
}
|
|
|
|
|
UpdateButtons();
|
|
|
|
|
OnPageUpdated();
|
|
|
|
|
if (canUpload)
|
|
|
|
|
StartUploading();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
multipleAction.RunAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 13:18:01 +02:00
|
|
|
|
private Pool_patch GetPatchFromPatchPath()
|
|
|
|
|
{
|
|
|
|
|
foreach (var kvp in NewUploadedPatches)
|
|
|
|
|
{
|
|
|
|
|
if (kvp.Value == SelectedNewPatchPath)
|
|
|
|
|
{
|
|
|
|
|
return kvp.Key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 13:36:47 +01:00
|
|
|
|
private Pool_update GetUpdateFromUpdatePath()
|
|
|
|
|
{
|
|
|
|
|
foreach (var kvp in AllIntroducedPoolUpdates)
|
|
|
|
|
{
|
|
|
|
|
if (kvp.Value == SelectedNewPatchPath)
|
|
|
|
|
{
|
|
|
|
|
return kvp.Key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 14:29:41 +01:00
|
|
|
|
private void StartUploading()
|
|
|
|
|
{
|
|
|
|
|
// reset progress bar and action progress description
|
|
|
|
|
UpdateActionProgress(null);
|
|
|
|
|
|
|
|
|
|
// start the upload
|
|
|
|
|
var actions = uploadActions.Values.Where(a => a != null).ToList();
|
|
|
|
|
if (actions.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
using (var multipleAction = new MultipleAction(Connection, Messages.UPLOAD_PATCH_TITLE, Messages.UPLOAD_PATCH_DESCRIPTION, Messages.UPLOAD_PATCH_END_DESCRIPTION, actions, true, true, true))
|
|
|
|
|
{
|
|
|
|
|
multipleAction.Completed += multipleAction_Completed;
|
|
|
|
|
multipleAction.RunAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateButtons()
|
|
|
|
|
{
|
|
|
|
|
if (!canUpload && diskSpaceRequirements != null)
|
|
|
|
|
{
|
|
|
|
|
errorLinkLabel.Visible = true;
|
|
|
|
|
errorLinkLabel.Text = diskSpaceRequirements.GetMessageForActionLink();
|
2015-02-20 14:07:20 +01:00
|
|
|
|
}
|
|
|
|
|
else if (!canDownload)
|
|
|
|
|
{
|
2015-02-20 14:15:40 +01:00
|
|
|
|
errorLinkLabel.Visible = true;
|
|
|
|
|
errorLinkLabel.Text = Messages.PATCHINGWIZARD_MORE_INFO;
|
2015-02-20 14:07:20 +01:00
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
else
|
|
|
|
|
errorLinkLabel.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateActionProgress(AsyncAction action)
|
|
|
|
|
{
|
|
|
|
|
UpdateActionDescription(action);
|
|
|
|
|
progressBar1.Value = action == null ? 0 : action.PercentComplete;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateActionDescription(AsyncAction action)
|
|
|
|
|
{
|
|
|
|
|
if (action == null) // reset action description
|
|
|
|
|
{
|
|
|
|
|
labelProgress.Text = "";
|
|
|
|
|
labelProgress.ForeColor = SystemColors.ControlText;
|
|
|
|
|
}
|
|
|
|
|
else if (action.StartedRunning) // update description for started actions
|
|
|
|
|
{
|
|
|
|
|
labelProgress.Text = GetActionDescription(action);
|
|
|
|
|
labelProgress.ForeColor = !action.IsCompleted || action.Succeeded ? SystemColors.ControlText : Color.Red;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetActionDescription(AsyncAction action)
|
|
|
|
|
{
|
|
|
|
|
return !action.StartedRunning ? "" :
|
|
|
|
|
action.Exception == null
|
|
|
|
|
? action.Description
|
|
|
|
|
: action.Exception is CancelledException ? Messages.CANCELLED_BY_USER : action.Exception.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CancelAction(AsyncAction action)
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
OnPageUpdated();
|
|
|
|
|
action.Changed -= singleAction_Changed;
|
|
|
|
|
action.Completed -= singleAction_Completed;
|
|
|
|
|
action.Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void singleAction_Changed(object sender)
|
|
|
|
|
{
|
|
|
|
|
var action = sender as AsyncAction;
|
|
|
|
|
if (action == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
|
|
|
|
UpdateActionProgress(action);
|
|
|
|
|
flickerFreeListBox1.Refresh();
|
|
|
|
|
OnPageUpdated();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void singleAction_Completed(ActionBase sender)
|
|
|
|
|
{
|
|
|
|
|
var action = sender as AsyncAction;
|
|
|
|
|
if (action == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
action.Changed -= singleAction_Changed;
|
|
|
|
|
action.Completed -= singleAction_Completed;
|
|
|
|
|
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
|
|
|
|
if (action.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
Host master = Helpers.GetMaster(action.Connection);
|
|
|
|
|
|
|
|
|
|
if (action is UploadPatchAction)
|
2016-08-04 16:10:36 +02:00
|
|
|
|
{
|
2015-02-24 14:29:41 +01:00
|
|
|
|
_patch = (action as UploadPatchAction).PatchRefs[master];
|
2016-10-05 00:26:35 +02:00
|
|
|
|
_poolUpdate = null;
|
2016-08-04 16:10:36 +02:00
|
|
|
|
AddToUploadedUpdates(SelectedNewPatchPath, master);
|
|
|
|
|
}
|
2016-10-05 00:26:35 +02:00
|
|
|
|
|
2015-02-24 14:29:41 +01:00
|
|
|
|
if (action is CopyPatchFromHostToOther && action.Host != null)
|
2016-10-05 00:26:35 +02:00
|
|
|
|
{
|
|
|
|
|
_poolUpdate = null;
|
2015-02-24 14:29:41 +01:00
|
|
|
|
_patch = action.Host.Connection.Cache.Resolve((action as CopyPatchFromHostToOther).NewPatchRef);
|
2016-10-05 00:26:35 +02:00
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2015-09-07 13:18:01 +02:00
|
|
|
|
if (_patch != null && !NewUploadedPatches.ContainsKey(_patch))
|
2016-10-05 00:26:35 +02:00
|
|
|
|
{
|
2015-09-07 13:18:01 +02:00
|
|
|
|
NewUploadedPatches.Add(_patch, SelectedNewPatchPath);
|
2016-10-05 00:26:35 +02:00
|
|
|
|
_poolUpdate = null;
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
|
|
|
|
if (action is UploadSupplementalPackAction)
|
|
|
|
|
{
|
2016-10-05 13:55:34 +02:00
|
|
|
|
_patch = null;
|
|
|
|
|
|
2016-11-10 18:15:40 +01:00
|
|
|
|
foreach (var vdiRef in (action as UploadSupplementalPackAction).VdiRefsToCleanUp)
|
|
|
|
|
{
|
2015-02-24 14:29:41 +01:00
|
|
|
|
SuppPackVdis[vdiRef.Key] = action.Connection.Resolve(vdiRef.Value);
|
2016-11-10 18:15:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AllCreatedSuppPackVdis.AddRange(SuppPackVdis.Values.Where(vdi => !AllCreatedSuppPackVdis.Contains(vdi)));
|
2016-10-04 15:58:54 +02:00
|
|
|
|
|
2016-08-04 16:10:36 +02:00
|
|
|
|
AddToUploadedUpdates(SelectedNewPatchPath, master);
|
2016-09-09 13:02:59 +02:00
|
|
|
|
|
2016-10-04 15:58:54 +02:00
|
|
|
|
if (Helpers.ElyOrGreater(action.Connection))
|
|
|
|
|
{
|
2016-11-10 18:46:07 +01:00
|
|
|
|
var newPoolUpdate = ((UploadSupplementalPackAction)action).PoolUpdate;
|
|
|
|
|
|
2016-10-04 15:58:54 +02:00
|
|
|
|
if (newPoolUpdate != null)
|
|
|
|
|
{
|
|
|
|
|
_poolUpdate = newPoolUpdate;
|
2017-01-23 13:36:47 +01:00
|
|
|
|
AllIntroducedPoolUpdates.Add(PoolUpdate, SelectedNewPatchPath);
|
2016-10-04 15:58:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
2016-10-05 00:26:35 +02:00
|
|
|
|
|
2015-07-15 14:03:11 +02:00
|
|
|
|
if (action is DownloadAndUnzipXenServerPatchAction)
|
|
|
|
|
{
|
2015-09-04 18:09:22 +02:00
|
|
|
|
SelectedNewPatchPath = ((DownloadAndUnzipXenServerPatchAction)action).PatchPath;
|
2015-07-21 12:40:45 +02:00
|
|
|
|
if (SelectedUpdateAlert is XenServerPatchAlert && (SelectedUpdateAlert as XenServerPatchAlert).Patch != null)
|
|
|
|
|
{
|
2015-09-04 18:09:22 +02:00
|
|
|
|
AllDownloadedPatches.Add((SelectedUpdateAlert as XenServerPatchAlert).Patch.Uuid, SelectedNewPatchPath);
|
2015-07-21 12:40:45 +02:00
|
|
|
|
}
|
2015-07-20 15:28:44 +02:00
|
|
|
|
_patch = null;
|
2015-07-15 14:03:11 +02:00
|
|
|
|
PrepareUploadActions();
|
|
|
|
|
TryUploading();
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
2016-11-10 18:18:51 +01:00
|
|
|
|
else // if !action.Succeeded
|
|
|
|
|
{
|
|
|
|
|
if (action is UploadSupplementalPackAction)
|
|
|
|
|
{
|
|
|
|
|
_patch = null;
|
2016-11-10 18:46:07 +01:00
|
|
|
|
_poolUpdate = null;
|
2016-11-10 18:18:51 +01:00
|
|
|
|
|
|
|
|
|
foreach (var vdiRef in (action as UploadSupplementalPackAction).VdiRefsToCleanUp)
|
|
|
|
|
{
|
|
|
|
|
SuppPackVdis[vdiRef.Key] = action.Connection.Resolve(vdiRef.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AllCreatedSuppPackVdis.AddRange(SuppPackVdis.Values.Where(vdi => !AllCreatedSuppPackVdis.Contains(vdi)));
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 13:02:59 +02:00
|
|
|
|
private bool AllServersElyOrGreater()
|
|
|
|
|
{
|
|
|
|
|
foreach (var server in SelectedServers)
|
|
|
|
|
{
|
|
|
|
|
if (!Helpers.ElyOrGreater(server.Connection))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 14:29:41 +01:00
|
|
|
|
private void multipleAction_Completed(object sender)
|
|
|
|
|
{
|
|
|
|
|
var action = sender as AsyncAction;
|
|
|
|
|
if (action == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-02-20 14:07:20 +01:00
|
|
|
|
action.Completed -= multipleAction_Completed;
|
|
|
|
|
|
2015-02-24 14:29:41 +01:00
|
|
|
|
canDownload = !(action.Exception is PatchDownloadFailedException);
|
|
|
|
|
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2015-02-20 14:07:20 +01:00
|
|
|
|
labelProgress.Text = GetActionDescription(action);
|
2015-02-24 14:29:41 +01:00
|
|
|
|
UpdateButtons();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void flickerFreeListBox1_DrawItem(object sender, DrawItemEventArgs e)
|
2015-07-15 14:03:11 +02:00
|
|
|
|
{
|
|
|
|
|
if(e.Index >= 0 && (flickerFreeListBox1.Items[e.Index] is DownloadAndUnzipXenServerPatchAction))
|
|
|
|
|
{
|
|
|
|
|
DownloadAndUnzipXenServerPatchAction downAction = (DownloadAndUnzipXenServerPatchAction)flickerFreeListBox1.Items[e.Index];
|
|
|
|
|
drawActionText(Properties.Resources._000_Patch_h32bit_16,
|
|
|
|
|
downAction.Title,
|
|
|
|
|
GetActionDescription(downAction).Ellipsise(EllipsiseValueDownDescription),
|
|
|
|
|
GetTextColor(downAction),
|
|
|
|
|
e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-24 14:29:41 +01:00
|
|
|
|
if (e.Index < 0 || !(flickerFreeListBox1.Items[e.Index] is KeyValuePair<Host, AsyncAction>))
|
|
|
|
|
return;
|
|
|
|
|
var hostAndAction = (KeyValuePair<Host, AsyncAction>)flickerFreeListBox1.Items[e.Index];
|
|
|
|
|
var host = hostAndAction.Key;
|
|
|
|
|
var action = hostAndAction.Value;
|
|
|
|
|
|
|
|
|
|
using (SolidBrush backBrush = new SolidBrush(flickerFreeListBox1.BackColor))
|
|
|
|
|
{
|
|
|
|
|
e.Graphics.FillRectangle(backBrush, e.Bounds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var poolOrHost = Helpers.GetPool(host.Connection) ?? (IXenObject)host;
|
|
|
|
|
|
2017-03-16 12:41:14 +01:00
|
|
|
|
string text = action == null ? Messages.UPLOAD_PATCH_ALREADY_UPLOADED : GetActionDescription(action).Ellipsise(EllipsiseValueDownDescription);
|
2017-09-03 04:33:29 +02:00
|
|
|
|
drawActionText(Images.GetImage16For(poolOrHost),poolOrHost.Name(), text, GetTextColor(action), e);
|
2015-07-15 14:03:11 +02:00
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
|
2015-07-15 14:03:11 +02:00
|
|
|
|
private void drawActionText(Image icon, string actionTitle, string actionDescription, Color textColor,DrawItemEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
int width = Drawing.MeasureText(actionDescription, flickerFreeListBox1.Font).Width;
|
|
|
|
|
e.Graphics.DrawImage(icon, e.Bounds.Left, e.Bounds.Top);
|
|
|
|
|
Drawing.DrawText(e.Graphics, actionTitle, flickerFreeListBox1.Font,
|
|
|
|
|
new Rectangle(e.Bounds.Left + icon.Width, e.Bounds.Top, e.Bounds.Right - (width + icon.Width), e.Bounds.Height),
|
|
|
|
|
flickerFreeListBox1.ForeColor,
|
|
|
|
|
TextFormatFlags.Left | TextFormatFlags.EndEllipsis);
|
|
|
|
|
Drawing.DrawText(e.Graphics, actionDescription, flickerFreeListBox1.Font,
|
|
|
|
|
new Rectangle(e.Bounds.Right - width, e.Bounds.Top, width, e.Bounds.Height),
|
|
|
|
|
textColor, flickerFreeListBox1.BackColor);
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color GetTextColor(AsyncAction action)
|
|
|
|
|
{
|
|
|
|
|
Color textColor;
|
|
|
|
|
if (action == null || !action.StartedRunning) // not started yet
|
|
|
|
|
textColor = flickerFreeListBox1.ForeColor;
|
|
|
|
|
else if (!action.IsCompleted) // in progress
|
|
|
|
|
textColor = Color.Blue;
|
|
|
|
|
else textColor = action.Succeeded ? Color.Green : Color.Red; // completed
|
|
|
|
|
return textColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void errorLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
2015-02-20 14:07:20 +01:00
|
|
|
|
{
|
|
|
|
|
if (!canDownload)
|
|
|
|
|
{
|
2015-02-24 14:42:48 +01:00
|
|
|
|
var msgtemplate = SelectedExistingPatch.host_patches.Count > 0 ? Messages.PATCH_DOWNLOAD_FAILED_MORE_INFO : Messages.PATCH_DOWNLOAD_FAILED_MORE_INFO_NOT_APPLIED;
|
2016-02-04 11:55:18 +01:00
|
|
|
|
var msg = string.Format(msgtemplate, SelectedExistingPatch.name_label, SelectedExistingPatch.Connection.Name, Branding.Update);
|
2016-06-20 11:49:12 +02:00
|
|
|
|
using (var dlg = new ThreeButtonDialog(
|
|
|
|
|
new ThreeButtonDialog.Details(SystemIcons.Error, msg)))
|
|
|
|
|
{
|
|
|
|
|
dlg.ShowDialog(this);
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (diskSpaceRequirements == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (diskSpaceRequirements.CanCleanup)
|
|
|
|
|
{
|
2016-06-20 11:49:12 +02:00
|
|
|
|
using (var d = new ThreeButtonDialog(
|
|
|
|
|
new ThreeButtonDialog.Details(SystemIcons.Warning,
|
|
|
|
|
diskSpaceRequirements.GetSpaceRequirementsMessage()),
|
2015-02-24 14:29:41 +01:00
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.OK, DialogResult.OK),
|
2016-06-20 11:49:12 +02:00
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.CANCEL, DialogResult.Cancel)))
|
2015-02-24 14:29:41 +01:00
|
|
|
|
{
|
2016-06-20 11:49:12 +02:00
|
|
|
|
if (d.ShowDialog(this) == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
// do the cleanup and retry uploading
|
|
|
|
|
CleanupDiskSpaceAction action = new CleanupDiskSpaceAction(diskSpaceRequirements.Host, null,
|
|
|
|
|
true);
|
|
|
|
|
|
|
|
|
|
action.Completed += delegate
|
|
|
|
|
{
|
|
|
|
|
if (action.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
Program.Invoke(Program.MainWindow, TryUploading);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
action.RunAsync();
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-06-20 11:49:12 +02:00
|
|
|
|
using (var dlg = new ThreeButtonDialog(
|
|
|
|
|
new ThreeButtonDialog.Details(SystemIcons.Warning,
|
|
|
|
|
diskSpaceRequirements.GetSpaceRequirementsMessage())))
|
|
|
|
|
{
|
|
|
|
|
dlg.ShowDialog(this);
|
|
|
|
|
}
|
2015-02-24 14:29:41 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-15 14:03:11 +02:00
|
|
|
|
}
|