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;
|
|
|
|
|
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;
|
|
|
|
|
|
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";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private const string UpdateXmlUrl = @"http://updates.xensource.com/XenServer/updates.xml";
|
|
|
|
|
|
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; }
|
|
|
|
|
private readonly bool _checkForXenCenter;
|
|
|
|
|
private readonly bool _checkForServerVersion;
|
|
|
|
|
private readonly bool _checkForPatches;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2014-01-08 14:17:02 +01:00
|
|
|
|
public DownloadUpdatesXmlAction(bool checkForXenCenter, bool checkForServerVersion, bool checkForPatches)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
: base(null, "_get_updates", "_get_updates", true)
|
|
|
|
|
{
|
|
|
|
|
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;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Run()
|
|
|
|
|
{
|
|
|
|
|
this.Description = Messages.AVAILABLE_UPDATES_SEARCHING;
|
|
|
|
|
|
|
|
|
|
XmlDocument xdoc = FetchCheckForUpdatesXml(UpdateXmlUrl);
|
|
|
|
|
|
2014-01-08 14:17:02 +01:00
|
|
|
|
GetXenCenterVersions(xdoc);
|
|
|
|
|
GetXenServerPatches(xdoc);
|
|
|
|
|
GetXenServerVersions(xdoc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 = "";
|
|
|
|
|
bool is_latest = false;
|
|
|
|
|
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")
|
|
|
|
|
is_latest = attrib.Value.ToUpperInvariant() == bool.TrueString.ToUpperInvariant();
|
|
|
|
|
else if (attrib.Name == "url")
|
|
|
|
|
url = attrib.Value;
|
|
|
|
|
else if (attrib.Name == "timestamp")
|
|
|
|
|
timestamp = attrib.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XenCenterVersions.Add(new XenCenterVersion(version_lang, name, is_latest, url, timestamp));
|
|
|
|
|
}
|
|
|
|
|
}
|
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 = "";
|
|
|
|
|
string patchVersion = "";
|
|
|
|
|
string url = "";
|
|
|
|
|
string patchUrl = "";
|
|
|
|
|
string timestamp = "";
|
|
|
|
|
string priority = "";
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 10:31:57 +01:00
|
|
|
|
var conflictingPatches = new List<string>();
|
|
|
|
|
var requiredPatches = new List<string>();
|
|
|
|
|
|
|
|
|
|
var conflictingPatchesNode = version.ChildNodes.Cast<XmlNode>().FirstOrDefault(childNode => childNode.Name == ConflictingPatchesNode);
|
|
|
|
|
|
|
|
|
|
if (conflictingPatchesNode != null)
|
|
|
|
|
{
|
|
|
|
|
conflictingPatches.AddRange(from XmlNode node in conflictingPatchesNode.ChildNodes
|
|
|
|
|
where node.Attributes != null
|
|
|
|
|
select node.Attributes.Cast<XmlAttribute>().First(attrib => attrib.Name == "uuid").Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var requiredPatchesNode = version.ChildNodes.Cast<XmlNode>().FirstOrDefault(childNode => childNode.Name == RequiredPatchesNode);
|
|
|
|
|
|
|
|
|
|
if (requiredPatchesNode != null)
|
|
|
|
|
{
|
|
|
|
|
requiredPatches.AddRange(from XmlNode node in requiredPatchesNode.ChildNodes
|
|
|
|
|
where node.Attributes != null
|
|
|
|
|
select node.Attributes.Cast<XmlAttribute>().First(attrib => attrib.Name == "uuid").Value);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
XenServerPatches.Add(new XenServerPatch(uuid, name, description, guidance, patchVersion, url,
|
2014-02-17 10:31:57 +01:00
|
|
|
|
patchUrl, timestamp, priority, conflictingPatches, requiredPatches));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-08 14:17:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetXenServerVersions(XmlDocument xdoc)
|
|
|
|
|
{
|
|
|
|
|
if (!_checkForServerVersion)
|
|
|
|
|
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;
|
|
|
|
|
string url = "";
|
|
|
|
|
string timestamp = "";
|
|
|
|
|
string buildNumber = "";
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<XenServerPatch> patches = new List<XenServerPatch>();
|
|
|
|
|
|
|
|
|
|
foreach (XmlNode childnode in version.ChildNodes)
|
|
|
|
|
{
|
|
|
|
|
if (childnode.Name != "patch")
|
|
|
|
|
continue;
|
2014-01-08 14:17:02 +01:00
|
|
|
|
XenServerPatch patch = XenServerPatches.Find(item => item.Uuid == childnode.Attributes["uuid"].Value);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (patch == null)
|
|
|
|
|
continue;
|
|
|
|
|
patches.Add(patch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XenServerVersions.Add(new XenServerVersion(version_oem, name, is_latest, url, patches, timestamp,
|
|
|
|
|
buildNumber));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual XmlDocument FetchCheckForUpdatesXml(string location)
|
|
|
|
|
{
|
|
|
|
|
XmlDocument xdoc;
|
|
|
|
|
using (Stream xmlstream = HTTPHelper.GET(new Uri(location), Connection, false))
|
|
|
|
|
{
|
|
|
|
|
xdoc = Helpers.LoadXmlDocument(xmlstream);
|
|
|
|
|
}
|
|
|
|
|
return xdoc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|