CP-41573: Add helper function to fetch host EUA

Signed-off-by: Danilo Del Busso <danilo.delbusso@cloud.com>
This commit is contained in:
Danilo Del Busso 2023-04-28 14:14:31 +01:00 committed by Konstantina Chremmou
parent 34eb5ff9b0
commit e265a1f23e

View File

@ -28,6 +28,7 @@
* SUCH DAMAGE.
*/
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
@ -1580,5 +1581,33 @@ namespace XenAdmin.Core
return queryString;
}
public static bool TryLoadHostEua(Host host, Uri targetUri, out string eua)
{
eua = null;
if (host == null || targetUri == null)
{
return false;
}
var args = new Dictionary<string, string>
{
{ "url", targetUri.ToString()}
};
try
{
var result = Host.call_plugin(host.Connection.Session, host.opaque_ref, "prepare_host_upgrade.py", "getEUA", args);
var jsonPayloadDefinition = new { eua = string.Empty };
var parsedPayload = JsonConvert.DeserializeAnonymousType(result, jsonPayloadDefinition);
eua = parsedPayload.eua;
}
catch (Exception ex)
{
log.Error(ex);
}
return eua != null;
}
}
}