2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* 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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Network;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Actions
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public abstract class PatchAction : AsyncAction
|
|
|
|
|
{
|
|
|
|
|
public PatchAction(IXenConnection conn, string title) : base(conn, title) { }
|
|
|
|
|
public PatchAction(IXenConnection conn, string title, bool suppress) : base(conn, title, suppress) { }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected XenRef<Pool_patch> BringPatchToPoolForHost(Host host, Pool_patch patch)
|
|
|
|
|
{
|
|
|
|
|
// Check the patch exists on the pool this host is connected to
|
|
|
|
|
XenRef<Pool_patch> patch_ref = host.Connection.Cache.FindRef(patch);
|
|
|
|
|
if (patch_ref != null)
|
|
|
|
|
return patch_ref;
|
|
|
|
|
|
2015-02-20 14:39:13 +01:00
|
|
|
|
Description = String.Format(Messages.DOWNLOADING_PATCH_FROM, patch.Connection.Name);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
// 1st download patch from the pool that has it (the connection on the xenobject)
|
|
|
|
|
|
|
|
|
|
string filename = Path.GetTempFileName();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Connection = patch.Connection;
|
|
|
|
|
Session = patch.Connection.DuplicateSession();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
HTTPHelper.Get(this, true, filename, patch.Connection.Hostname,
|
|
|
|
|
(HTTP_actions.get_sss)HTTP_actions.get_pool_patch_download,
|
2018-02-12 12:54:27 +01:00
|
|
|
|
Session.opaque_ref, patch.uuid);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2015-02-20 14:07:20 +01:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
throw new PatchDownloadFailedException(string.Format(Messages.PATCH_DOWNLOAD_FAILED, patch.name_label, patch.Connection.Name), e);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Connection = null;
|
|
|
|
|
Session = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Then, put it on the pool that doesn't have it
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
Description = String.Format(Messages.UPLOADING_PATCH_TO, host.Name());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
Connection = host.Connection;
|
|
|
|
|
Session = host.Connection.DuplicateSession();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string result = HTTPHelper.Put(this, true, filename, host.Connection.Hostname,
|
2018-02-12 12:54:27 +01:00
|
|
|
|
(HTTP_actions.put_ss)HTTP_actions.put_pool_patch_upload, Session.opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
return new XenRef<Pool_patch>(result);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Connection = null;
|
|
|
|
|
Session = null;
|
2017-09-03 04:33:29 +02:00
|
|
|
|
Description = String.Format(Messages.PATCH_UPLOADED, host.Name());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
File.Delete(filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ApplyPatchAction : PatchAction
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2017-02-03 18:41:23 +01:00
|
|
|
|
private readonly Pool_patch patch;
|
2018-07-12 19:02:16 +02:00
|
|
|
|
private readonly Host host;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2017-02-03 18:41:23 +01:00
|
|
|
|
public ApplyPatchAction(Pool_patch patch, Host host)
|
2017-09-03 04:33:29 +02:00
|
|
|
|
: base(host.Connection, string.Format(Messages.UPDATES_WIZARD_APPLYING_UPDATE, patch.Name(), host.Name()))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-02-03 18:41:23 +01:00
|
|
|
|
this.patch = patch;
|
|
|
|
|
this.host = host;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Run()
|
|
|
|
|
{
|
|
|
|
|
SafeToExit = false;
|
2016-03-24 19:24:12 +01:00
|
|
|
|
|
2018-07-12 19:02:16 +02:00
|
|
|
|
if (patch.AppliedOn(host) != DateTime.MaxValue)
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
XenRef<Pool_patch> patchRef = BringPatchToPoolForHost(host, patch);
|
|
|
|
|
|
2018-07-12 19:02:16 +02:00
|
|
|
|
Description = string.Format(Messages.APPLYING_PATCH, patch.Name(), host.Name());
|
2019-11-08 12:42:18 +01:00
|
|
|
|
log.DebugFormat("Applying update '{0}' to server '{1}'", patch.Name(), host.Name());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-11-21 12:21:47 +01:00
|
|
|
|
RelatedTask = Pool_patch.async_apply(Session, patchRef, host.opaque_ref);
|
|
|
|
|
PollToCompletion();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-11-08 12:42:18 +01:00
|
|
|
|
log.DebugFormat("Applied update '{0}' to server '{1}'. Result: {2}.", patch.Name(), host.Name(), Result);
|
2018-07-12 19:02:16 +02:00
|
|
|
|
Description = string.Format(Messages.PATCH_APPLIED, patch.Name(), host.Name());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-20 14:07:20 +01:00
|
|
|
|
|
|
|
|
|
public class PatchDownloadFailedException : ApplicationException
|
|
|
|
|
{
|
|
|
|
|
public PatchDownloadFailedException(string message, Exception innerException) :
|
|
|
|
|
base(message, innerException) { }
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|