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;
|
2014-02-17 10:31:57 +01:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAPI;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using XenAdmin.Core;
|
2016-06-08 15:16:35 +02:00
|
|
|
|
using System.Diagnostics;
|
2017-02-02 19:18:54 +01:00
|
|
|
|
using System.Net;
|
2017-04-26 13:45:49 +02:00
|
|
|
|
using System.Text;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2014-01-08 14:17:02 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
namespace XenAdmin.Actions
|
|
|
|
|
{
|
|
|
|
|
public class DownloadUpdatesXmlAction : AsyncAction
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
private const string XenCenterVersionsNode = "xencenterversions";
|
|
|
|
|
private const string XenServerVersionsNode = "serverversions";
|
|
|
|
|
private const string PatchesNode = "patches";
|
2014-02-17 10:31:57 +01:00
|
|
|
|
private const string ConflictingPatchesNode = "conflictingpatches";
|
|
|
|
|
private const string RequiredPatchesNode = "requiredpatches";
|
2014-03-05 11:29:59 +01:00
|
|
|
|
private const string ConflictingPatchNode = "conflictingpatch";
|
|
|
|
|
private const string RequiredPatchNode = "requiredpatch";
|
2016-02-02 20:12:38 +01:00
|
|
|
|
|
2014-03-05 11:29:59 +01:00
|
|
|
|
|
2014-01-08 14:17:02 +01:00
|
|
|
|
public List<XenCenterVersion> XenCenterVersions { get; private set; }
|
|
|
|
|
public List<XenServerVersion> XenServerVersions { get; private set; }
|
|
|
|
|
public List<XenServerPatch> XenServerPatches { get; private set; }
|
2015-08-04 18:28:29 +02:00
|
|
|
|
|
|
|
|
|
public List<XenServerVersion> XenServerVersionsForAutoCheck
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if(_checkForServerVersion)
|
|
|
|
|
{
|
|
|
|
|
return XenServerVersions;
|
|
|
|
|
}
|
|
|
|
|
return new List<XenServerVersion>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-08 14:17:02 +01:00
|
|
|
|
private readonly bool _checkForXenCenter;
|
|
|
|
|
private readonly bool _checkForServerVersion;
|
|
|
|
|
private readonly bool _checkForPatches;
|
2016-02-04 11:39:14 +01:00
|
|
|
|
private readonly string _checkForUpdatesUrl;
|
2017-04-26 13:45:49 +02:00
|
|
|
|
private readonly string _userAgent;
|
|
|
|
|
private readonly string _userAgentId;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2017-04-26 13:45:49 +02:00
|
|
|
|
public DownloadUpdatesXmlAction(bool checkForXenCenter, bool checkForServerVersion, bool checkForPatches, string userAgent, string userAgentId, string checkForUpdatesUrl = null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: base(null, "_get_updates", "_get_updates", true)
|
|
|
|
|
{
|
2016-06-08 15:16:35 +02:00
|
|
|
|
Debug.Assert(checkForUpdatesUrl != null, "Parameter checkForUpdatesUrl should not be null. This class does not default its value anymore.");
|
2017-04-26 13:45:49 +02:00
|
|
|
|
Debug.Assert(!string.IsNullOrWhiteSpace(userAgent) && !string.IsNullOrWhiteSpace(userAgentId));
|
2016-06-08 15:16:35 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
XenServerPatches = new List<XenServerPatch>();
|
|
|
|
|
XenServerVersions = new List<XenServerVersion>();
|
|
|
|
|
XenCenterVersions = new List<XenCenterVersion>();
|
2014-01-08 14:17:02 +01:00
|
|
|
|
|
|
|
|
|
_checkForXenCenter = checkForXenCenter;
|
|
|
|
|
_checkForServerVersion = checkForServerVersion;
|
|
|
|
|
_checkForPatches = checkForPatches;
|
2016-06-07 17:02:43 +02:00
|
|
|
|
_checkForUpdatesUrl = checkForUpdatesUrl;
|
2017-04-26 13:45:49 +02:00
|
|
|
|
_userAgent = userAgent;
|
|
|
|
|
_userAgentId = userAgentId;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Run()
|
|
|
|
|
{
|
|
|
|
|
this.Description = Messages.AVAILABLE_UPDATES_SEARCHING;
|
|
|
|
|
|
2016-02-04 11:39:14 +01:00
|
|
|
|
XmlDocument xdoc = FetchCheckForUpdatesXml(_checkForUpdatesUrl);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2014-01-08 14:17:02 +01:00
|
|
|
|
GetXenCenterVersions(xdoc);
|
|
|
|
|
GetXenServerPatches(xdoc);
|
|
|
|
|
GetXenServerVersions(xdoc);
|
2016-03-14 17:10:16 +01:00
|
|
|
|
|
2014-01-08 14:17:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetXenCenterVersions(XmlDocument xdoc)
|
|
|
|
|
{
|
|
|
|
|
if (!_checkForXenCenter)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
foreach (XmlNode versions in xdoc.GetElementsByTagName(XenCenterVersionsNode))
|
|
|
|
|
{
|
|
|
|
|
foreach (XmlNode version in versions.ChildNodes)
|
|
|
|
|
{
|
|
|
|
|
string version_lang = "";
|
|
|
|
|
string name = "";
|
2017-03-14 16:25:49 +01:00
|
|
|
|
bool latest = false;
|
|
|
|
|
bool latest_cr = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
string url = "";
|
|
|
|
|
string timestamp = "";
|
|
|
|
|
|
|
|
|
|
foreach (XmlAttribute attrib in version.Attributes)
|
|
|
|
|
{
|
|
|
|
|
if (attrib.Name == "value")
|
|
|
|
|
version_lang = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "name")
|
|
|
|
|
name = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "latest")
|
2017-03-14 16:25:49 +01:00
|
|
|
|
latest = attrib.Value.ToUpperInvariant() == bool.TrueString.ToUpperInvariant();
|
|
|
|
|
else if (attrib.Name == "latestcr")
|
|
|
|
|
latest_cr = attrib.Value.ToUpperInvariant() == bool.TrueString.ToUpperInvariant();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
else if (attrib.Name == "url")
|
|
|
|
|
url = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "timestamp")
|
|
|
|
|
timestamp = attrib.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 16:25:49 +01:00
|
|
|
|
XenCenterVersions.Add(new XenCenterVersion(version_lang, name, latest, latest_cr, url, timestamp));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-08 14:17:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetXenServerPatches(XmlDocument xdoc)
|
|
|
|
|
{
|
|
|
|
|
if (!_checkForPatches)
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
foreach (XmlNode versions in xdoc.GetElementsByTagName(PatchesNode))
|
|
|
|
|
{
|
|
|
|
|
foreach (XmlNode version in versions.ChildNodes)
|
|
|
|
|
{
|
|
|
|
|
string uuid = "";
|
|
|
|
|
string name = "";
|
|
|
|
|
string description = "";
|
|
|
|
|
string guidance = "";
|
2016-03-31 16:40:23 +02:00
|
|
|
|
string guidance_mandatory = "";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
string patchVersion = "";
|
|
|
|
|
string url = "";
|
|
|
|
|
string patchUrl = "";
|
|
|
|
|
string timestamp = "";
|
|
|
|
|
string priority = "";
|
2015-02-06 13:32:29 +01:00
|
|
|
|
string installationSize = "";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
foreach (XmlAttribute attrib in version.Attributes)
|
|
|
|
|
{
|
|
|
|
|
if (attrib.Name == "uuid")
|
|
|
|
|
uuid = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "name-label")
|
|
|
|
|
name = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "name-description")
|
|
|
|
|
description = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "after-apply-guidance")
|
|
|
|
|
guidance = attrib.Value;
|
2016-03-31 16:40:23 +02:00
|
|
|
|
else if (attrib.Name == "guidance-mandatory")
|
|
|
|
|
guidance_mandatory = attrib.Value;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
else if (attrib.Name == "version")
|
|
|
|
|
patchVersion = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "url")
|
|
|
|
|
url = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "patch-url")
|
|
|
|
|
patchUrl = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "timestamp")
|
|
|
|
|
timestamp = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "priority")
|
|
|
|
|
priority = attrib.Value;
|
2015-02-06 13:32:29 +01:00
|
|
|
|
else if (attrib.Name == "installation-size")
|
|
|
|
|
installationSize = attrib.Value;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-05 11:29:59 +01:00
|
|
|
|
var conflictingPatches = GetPatchDependencies(version, ConflictingPatchesNode, ConflictingPatchNode);
|
|
|
|
|
var requiredPatches = GetPatchDependencies(version, RequiredPatchesNode, RequiredPatchNode);
|
2014-02-17 10:31:57 +01:00
|
|
|
|
|
2016-03-31 16:40:23 +02:00
|
|
|
|
XenServerPatches.Add(new XenServerPatch(uuid, name, description, guidance, guidance_mandatory, patchVersion, url,
|
2016-03-16 14:41:10 +01:00
|
|
|
|
patchUrl, timestamp, priority, installationSize, conflictingPatches, requiredPatches));
|
2014-03-05 11:29:59 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-17 10:31:57 +01:00
|
|
|
|
|
2014-03-05 11:29:59 +01:00
|
|
|
|
// dependencies patches are listed in the xml as below:
|
|
|
|
|
// <conflictingpatches>
|
|
|
|
|
// <conflictingpatch uuid="00000000-0000-0000-0000-000000000000">
|
|
|
|
|
// </conflictingpatch>
|
|
|
|
|
// </conflictingpatches>
|
|
|
|
|
// <requiredpatches>
|
|
|
|
|
// <requiredgpatch uuid="00000000-0000-0000-0000-000000000000">
|
|
|
|
|
// </requiredgpatch>
|
|
|
|
|
// </requiredpatches>
|
|
|
|
|
private static List<string> GetPatchDependencies(XmlNode patchsNode, string dependenciesNodeName, string dependencyNodeName)
|
2014-02-17 10:31:57 +01:00
|
|
|
|
{
|
2014-03-05 11:29:59 +01:00
|
|
|
|
var dependenciesNode = patchsNode.ChildNodes.Cast<XmlNode>().FirstOrDefault(childNode => childNode.Name == dependenciesNodeName);
|
2014-02-17 10:31:57 +01:00
|
|
|
|
|
2014-03-05 11:29:59 +01:00
|
|
|
|
if (dependenciesNode == null)
|
|
|
|
|
return null;
|
2014-02-17 10:31:57 +01:00
|
|
|
|
|
2014-03-05 11:29:59 +01:00
|
|
|
|
var dependencies = new List<string>();
|
2014-02-17 10:31:57 +01:00
|
|
|
|
|
2014-03-05 11:29:59 +01:00
|
|
|
|
dependencies.AddRange(from XmlNode node in dependenciesNode.ChildNodes
|
2016-02-02 20:12:38 +01:00
|
|
|
|
where node.Attributes != null
|
2014-03-05 11:29:59 +01:00
|
|
|
|
from XmlAttribute attrib in node.Attributes
|
|
|
|
|
where node.Name == dependencyNodeName && node.Attributes != null && attrib.Name == "uuid"
|
|
|
|
|
select attrib.Value);
|
|
|
|
|
return dependencies;
|
2014-01-08 14:17:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetXenServerVersions(XmlDocument xdoc)
|
|
|
|
|
{
|
2015-08-03 16:06:01 +02:00
|
|
|
|
if (!_checkForServerVersion && !_checkForPatches)
|
2014-01-08 14:17:02 +01:00
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
foreach (XmlNode versions in xdoc.GetElementsByTagName(XenServerVersionsNode))
|
|
|
|
|
{
|
|
|
|
|
foreach (XmlNode version in versions.ChildNodes)
|
|
|
|
|
{
|
|
|
|
|
string version_oem = "";
|
|
|
|
|
string name = "";
|
|
|
|
|
bool is_latest = false;
|
2017-03-14 17:38:10 +01:00
|
|
|
|
bool is_latest_cr = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
string url = "";
|
|
|
|
|
string timestamp = "";
|
|
|
|
|
string buildNumber = "";
|
2017-03-17 11:57:43 +01:00
|
|
|
|
string patchUuid = "";
|
2017-08-25 11:56:04 +02:00
|
|
|
|
bool presentAsUpdate = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
foreach (XmlAttribute attrib in version.Attributes)
|
|
|
|
|
{
|
|
|
|
|
if (attrib.Name == "value")
|
|
|
|
|
version_oem = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "name")
|
|
|
|
|
name = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "latest")
|
|
|
|
|
is_latest = attrib.Value.ToUpperInvariant() == bool.TrueString.ToUpperInvariant();
|
2017-03-14 17:38:10 +01:00
|
|
|
|
else if (attrib.Name == "latestcr")
|
|
|
|
|
is_latest_cr = attrib.Value.ToUpperInvariant() == bool.TrueString.ToUpperInvariant();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
else if (attrib.Name == "url")
|
|
|
|
|
url = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "timestamp")
|
|
|
|
|
timestamp = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "build-number")
|
|
|
|
|
buildNumber = attrib.Value;
|
2017-03-17 11:57:43 +01:00
|
|
|
|
else if (attrib.Name == "patch-uuid")
|
|
|
|
|
patchUuid = attrib.Value;
|
2017-08-25 11:56:04 +02:00
|
|
|
|
else if (attrib.Name == "present-as-update")
|
|
|
|
|
presentAsUpdate = attrib.Value.ToUpperInvariant() == bool.TrueString.ToUpperInvariant();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<XenServerPatch> patches = new List<XenServerPatch>();
|
2016-08-08 19:30:54 +02:00
|
|
|
|
List<XenServerPatch> minimalPatches = null; //keep it null to indicate that there is no a minimalpatches tag
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
foreach (XmlNode childnode in version.ChildNodes)
|
|
|
|
|
{
|
2016-03-14 17:10:16 +01:00
|
|
|
|
if (childnode.Name == "minimalpatches")
|
|
|
|
|
{
|
2016-08-08 19:30:54 +02:00
|
|
|
|
minimalPatches = new List<XenServerPatch>();
|
|
|
|
|
|
2016-03-14 17:10:16 +01:00
|
|
|
|
foreach (XmlNode minimalpatch in childnode.ChildNodes)
|
|
|
|
|
{
|
|
|
|
|
if (minimalpatch.Name != "patch")
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
XenServerPatch mp = XenServerPatches.Find(p => string.Equals(p.Uuid, minimalpatch.Attributes["uuid"].Value, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
if (mp == null)
|
|
|
|
|
continue;
|
|
|
|
|
minimalPatches.Add(mp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (childnode.Name == "patch")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
XenServerPatch patch = XenServerPatches.Find(item => string.Equals(item.Uuid, childnode.Attributes["uuid"].Value, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
if (patch == null)
|
|
|
|
|
continue;
|
|
|
|
|
patches.Add(patch);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 17:38:10 +01:00
|
|
|
|
XenServerVersions.Add(new XenServerVersion(version_oem, name, is_latest, is_latest_cr, url, patches, minimalPatches, timestamp,
|
2017-08-25 11:56:04 +02:00
|
|
|
|
buildNumber, patchUuid, presentAsUpdate));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual XmlDocument FetchCheckForUpdatesXml(string location)
|
|
|
|
|
{
|
2016-06-07 17:02:43 +02:00
|
|
|
|
var xdoc = new XmlDocument();
|
|
|
|
|
var uri = new Uri(location);
|
2017-03-02 11:15:41 +01:00
|
|
|
|
var proxy = XenAdminConfigManager.Provider.GetProxyFromSettings(Connection, false);
|
2017-04-26 13:45:49 +02:00
|
|
|
|
|
2016-06-07 17:02:43 +02:00
|
|
|
|
if (uri.IsFile)
|
2016-05-04 12:21:23 +02:00
|
|
|
|
{
|
2016-06-07 17:02:43 +02:00
|
|
|
|
xdoc.Load(location);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-02 19:35:02 +01:00
|
|
|
|
using (var webClient = new WebClient())
|
|
|
|
|
{
|
|
|
|
|
webClient.Proxy = proxy;
|
2017-04-26 13:45:49 +02:00
|
|
|
|
webClient.Headers.Add("User-Agent", _userAgent);
|
|
|
|
|
webClient.Headers.Add("X-User-Agent-Id", _userAgentId);
|
2017-02-02 19:18:54 +01:00
|
|
|
|
|
2017-02-02 19:35:02 +01:00
|
|
|
|
using (var stream = new MemoryStream(webClient.DownloadData(uri)))
|
|
|
|
|
{
|
|
|
|
|
xdoc.Load(stream);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-04 12:21:23 +02:00
|
|
|
|
}
|
2017-02-02 19:18:54 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return xdoc;
|
|
|
|
|
}
|
2017-04-26 13:45:49 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|