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.Linq;
|
|
|
|
|
using XenAdmin.Core;
|
2015-08-21 16:18:18 +02:00
|
|
|
|
using XenAdmin.Model;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAPI
|
|
|
|
|
{
|
|
|
|
|
public partial class Pool : IComparable<Pool>, IEquatable<Pool>
|
|
|
|
|
{
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return Name();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public override string Description()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return name_description;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public override string Name()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (name_label != "")
|
|
|
|
|
return name_label;
|
|
|
|
|
|
|
|
|
|
if (Connection == null)
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
|
|
|
|
Host master = Connection.Resolve(this.master);
|
|
|
|
|
return master == null ? "" : master.Name();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
internal override string LocationString()
|
2015-01-14 17:20:36 +01:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return string.Empty;
|
2015-01-14 17:20:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public List<SR> GetHAHeartbeatSRs()
|
|
|
|
|
{
|
|
|
|
|
List<SR> result = new List<SR>();
|
|
|
|
|
|
|
|
|
|
foreach (string opaqueRef in ha_statefiles)
|
|
|
|
|
{
|
|
|
|
|
XenRef<VDI> vdiRef = new XenRef<VDI>(opaqueRef);
|
|
|
|
|
VDI vdi = Connection.Resolve(vdiRef);
|
|
|
|
|
if (vdi == null)
|
|
|
|
|
continue;
|
|
|
|
|
SR sr = vdi.Connection.Resolve(vdi.SR);
|
|
|
|
|
if (sr != null)
|
|
|
|
|
result.Add(sr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public bool IsMasterUpgraded()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
Host master = Helpers.GetMaster(this);
|
|
|
|
|
foreach (var host in this.Connection.Cache.Hosts)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (host.LongProductVersion() != master.LongProductVersion())
|
|
|
|
|
return true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-05 12:57:16 +02:00
|
|
|
|
public bool IsFreeLicenseOrExpired()
|
2017-09-28 17:10:41 +02:00
|
|
|
|
{
|
2018-10-05 12:57:16 +02:00
|
|
|
|
return Connection.Cache.Hosts.Any(h => h.IsFreeLicenseOrExpired());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2017-09-03 04:33:29 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determine whether the given pool is a visible pool, i.e. not a pool-of-one.
|
|
|
|
|
/// </summary>
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public bool IsVisible()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return Connection != null && (name_label != "" || Connection.Cache.HostCount > 1);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 14:11:21 +02:00
|
|
|
|
private const string ROLLING_UPGRADE_IN_PROGRESS = "rolling_upgrade_in_progress";
|
|
|
|
|
private const string FORBID_RPU_FOR_HCI = "hci-forbid-rpu";
|
2016-06-29 13:57:29 +02:00
|
|
|
|
private const string FAULT_TOLERANCE_LIMIT_FOR_HCI = "hci-limit-fault-tolerance";
|
2016-09-15 17:37:37 +02:00
|
|
|
|
private const string FORBID_UPDATE_AUTO_RESTARTS = "hci-forbid-update-auto-restart";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public bool RollingUpgrade()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return other_config != null && other_config.ContainsKey(ROLLING_UPGRADE_IN_PROGRESS);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public bool IsUpgradeForbidden()
|
2016-06-20 14:11:21 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return other_config != null && other_config.ContainsKey(FORBID_RPU_FOR_HCI);
|
2016-06-20 14:11:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public bool IsAutoUpdateRestartsForbidden()
|
2016-09-15 17:37:37 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return other_config != null && other_config.ContainsKey(FORBID_UPDATE_AUTO_RESTARTS);
|
2016-09-15 17:37:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-29 13:57:29 +02:00
|
|
|
|
public static long GetMaximumTolerableHostFailures(Session session, Dictionary<XenRef<VM>, string> config)
|
|
|
|
|
{
|
|
|
|
|
long max = ha_compute_hypothetical_max_host_failures_to_tolerate(session, config);
|
|
|
|
|
long result;
|
|
|
|
|
Pool p = Helpers.GetPoolOfOne(session.Connection);
|
|
|
|
|
|
|
|
|
|
if (p!= null && p.other_config != null
|
|
|
|
|
&& p.other_config.ContainsKey(FAULT_TOLERANCE_LIMIT_FOR_HCI)
|
|
|
|
|
&& long.TryParse(p.other_config[FAULT_TOLERANCE_LIMIT_FOR_HCI], out result)
|
|
|
|
|
&& result <= max)//extra check in case the number set is accidentally wrong
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public string GetXCPluginSecret(string plugin_name, IXenObject obj)
|
|
|
|
|
{
|
|
|
|
|
return Get(gui_config, XCPluginSecretName(plugin_name, obj));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveXCPluginSecret(Session session, string plugin_name, IXenObject obj)
|
|
|
|
|
{
|
|
|
|
|
Pool.remove_from_gui_config(session, opaque_ref, XCPluginSecretName(plugin_name, obj));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetXCPluginSecret(Session session, string plugin_name, IXenObject obj, string secret_uuid)
|
|
|
|
|
{
|
|
|
|
|
string n = XCPluginSecretName(plugin_name, obj);
|
|
|
|
|
Pool.remove_from_gui_config(session, opaque_ref, n);
|
|
|
|
|
Pool.add_to_gui_config(session, opaque_ref, n, secret_uuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string XCPluginSecretName(string plugin_name, IXenObject obj)
|
|
|
|
|
{
|
|
|
|
|
return string.Format("XC_PLUGIN_SECRET_{0}_{1}_{2}", obj.Connection.Username, plugin_name, Helpers.GetUuid(obj));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Whether the vSwitch Controller appears to be configured.
|
|
|
|
|
// (Note that we can't tell whether it's actually working properly through the API).
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public bool vSwitchController()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (string.IsNullOrEmpty(vswitch_controller))
|
|
|
|
|
return false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
foreach (Host h in Connection.Cache.Hosts)
|
|
|
|
|
{
|
|
|
|
|
if (Host.RestrictVSwitchController(h) ||
|
|
|
|
|
!h.software_version.ContainsKey("network_backend") ||
|
|
|
|
|
h.software_version["network_backend"] != "openvswitch")
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-03 04:33:29 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-27 12:34:57 +01:00
|
|
|
|
public bool HasSriovNic()
|
|
|
|
|
{
|
|
|
|
|
return Connection.Cache.PIFs.Any(pif => pif.SriovCapable());
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public List<XenAPI.Host> HostsToUpgrade()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
//First one to upgrade has to be the master
|
|
|
|
|
var master = Helpers.GetMaster(Connection);
|
|
|
|
|
|
|
|
|
|
List<XenAPI.Host> result = IsMasterUpgraded()
|
|
|
|
|
? Connection.Cache.Hosts.Where(host => host.LongProductVersion() != master.LongProductVersion()).ToList()
|
|
|
|
|
: Connection.Cache.Hosts.ToList();
|
|
|
|
|
result.Sort();
|
|
|
|
|
|
|
|
|
|
return result;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public bool IsPoolFullyUpgraded()
|
2013-12-13 18:35:40 +01:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
Host master = Helpers.GetMaster(this);
|
2013-12-13 18:35:40 +01:00
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
foreach (var host in this.Connection.Cache.Hosts)
|
|
|
|
|
{
|
|
|
|
|
if (host.LongProductVersion() != master.LongProductVersion())
|
|
|
|
|
return false;
|
2013-12-13 18:35:40 +01:00
|
|
|
|
}
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return true;
|
2013-12-13 18:35:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public Host SmallerVersionHost()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
Host hostWithSmallerVersion = null;
|
|
|
|
|
foreach (var host in this.Connection.Cache.Hosts)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (hostWithSmallerVersion == null)
|
|
|
|
|
hostWithSmallerVersion = host;
|
|
|
|
|
else if (Helpers.productVersionCompare(hostWithSmallerVersion.ProductVersion(), host.ProductVersion()) > 0)
|
|
|
|
|
hostWithSmallerVersion = host;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return hostWithSmallerVersion;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public virtual int CpuSockets()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return Connection.Cache.Hosts.Sum(h => h.CpuSockets());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2015-05-18 16:23:32 +02:00
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public bool HasGpu()
|
2015-01-19 17:49:47 +01:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return Connection.Cache.PGPUs.Length > 0;
|
2015-01-19 17:49:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public bool HasVGpu()
|
2015-01-19 17:49:47 +01:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return HasGpu() && Connection.Cache.PGPUs.Any(pGpu => pGpu.HasVGpu());
|
2015-01-19 17:49:47 +01:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2015-08-19 09:53:15 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// ssl_legacy is true if any host in the pool is in legacy mode
|
|
|
|
|
/// </summary>
|
2017-09-03 04:33:29 +02:00
|
|
|
|
public bool ssl_legacy()
|
2015-08-19 09:53:15 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return Connection.Cache.Hosts.Any(h => h.ssl_legacy);
|
2015-08-19 09:53:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-29 09:44:41 +02:00
|
|
|
|
#region Health Check settings
|
2017-09-03 04:33:29 +02:00
|
|
|
|
|
|
|
|
|
public HealthCheckSettings HealthCheckSettings()
|
2015-05-18 16:23:32 +02:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return new HealthCheckSettings(health_check_config);
|
2015-05-18 16:23:32 +02:00
|
|
|
|
}
|
2017-09-03 04:33:29 +02:00
|
|
|
|
|
2015-05-18 16:23:32 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
#region IEquatable<Pool> Members
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates whether the current object is equal to the specified object. This calls the implementation from XenObject.
|
|
|
|
|
/// This implementation is required for ToStringWrapper.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Equals(Pool other)
|
|
|
|
|
{
|
|
|
|
|
return base.Equals(other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|