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 XenAdmin.Network;
|
|
|
|
|
using XenAPI;
|
2016-02-19 18:31:30 +01:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2021-08-31 12:31:16 +02:00
|
|
|
|
/// Encapsulates whether a supporter can join a given pool
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static class PoolJoinRules
|
|
|
|
|
{
|
|
|
|
|
// The order of the enum determines the order we sort the hosts in, in the New Pool Wizard
|
|
|
|
|
public enum Reason
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
WillBeCoordinator,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Allowed,
|
|
|
|
|
Connecting,
|
2021-08-31 12:31:16 +02:00
|
|
|
|
CoordinatorNotConnected,
|
|
|
|
|
CoordinatorConnecting,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
DifferentAdConfig,
|
|
|
|
|
HasRunningVMs,
|
|
|
|
|
HasSharedStorage,
|
|
|
|
|
IsAPool,
|
|
|
|
|
LicenseRestriction,
|
|
|
|
|
NotSameLinuxPack,
|
2021-08-31 12:31:16 +02:00
|
|
|
|
LicensedHostUnlicensedCoordinator,
|
|
|
|
|
UnlicensedHostLicensedCoordinator,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
LicenseMismatch,
|
2021-08-31 12:31:16 +02:00
|
|
|
|
CoordinatorPoolMaxNumberHostReached,
|
2017-10-12 12:28:44 +02:00
|
|
|
|
WillExceedPoolMaxSize,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
DifferentServerVersion,
|
2021-08-31 12:31:16 +02:00
|
|
|
|
DifferentHomogeneousUpdatesFromCoordinator,
|
2017-06-30 15:05:52 +02:00
|
|
|
|
DifferentHomogeneousUpdatesFromPool,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
DifferentCPUs,
|
|
|
|
|
DifferentNetworkBackends,
|
2021-08-31 12:31:16 +02:00
|
|
|
|
CoordinatorHasHA,
|
2016-02-19 18:31:30 +01:00
|
|
|
|
NotPhysicalPif,
|
2017-03-02 07:50:50 +01:00
|
|
|
|
NonCompatibleManagementInterface,
|
2021-08-31 12:31:16 +02:00
|
|
|
|
WrongRoleOnCoordinator,
|
|
|
|
|
WrongRoleOnSupporter,
|
2020-05-10 01:45:36 +02:00
|
|
|
|
HasClusteringEnabled,
|
2018-07-10 12:23:13 +02:00
|
|
|
|
WrongNumberOfIpsCluster,
|
|
|
|
|
WrongNumberOfIpsBond,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
NotConnected,
|
2021-06-29 16:36:49 +02:00
|
|
|
|
TlsVerificationOnlyOnPool,
|
|
|
|
|
TlsVerificationOnlyOnPoolJoiner,
|
2021-09-01 15:43:23 +02:00
|
|
|
|
TlsVerificationOnlyOnCoordinator,
|
|
|
|
|
TlsVerificationOnlyOnCoordinatorJoiner
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The order of if's in CanJoinPool() determines which reason we display if there is more than one.
|
2021-08-31 12:31:16 +02:00
|
|
|
|
// At least as far as WillBeCoordinator, some callers may rely on the order.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
// Also, some of the private functions in this file rely on previous tests (especially for
|
|
|
|
|
// null-ness and connectedness) having been done first.
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether a server can join a pool (or form a pool with a standalone server)
|
|
|
|
|
/// </summary>
|
2021-08-31 12:31:16 +02:00
|
|
|
|
/// <param name="supporterConnection">The connection of the server that wants to join the pool</param>
|
|
|
|
|
/// <param name="coordinatorConnection">The connection of the existing pool or of the proposed coordinator of a new pool</param>
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <param name="allowLicenseUpgrade">Whether we can upgrade a free host to a v6 license of the pool it's joining</param>
|
2021-08-31 12:31:16 +02:00
|
|
|
|
/// <param name="allowCpuLevelling">Whether we can apply CPU levelling to the supporter before it joins the pool</param>
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <returns>The reason why the server can't join the pool, or Reason.Allowed if it's OK</returns>
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static Reason CanJoinPool(IXenConnection supporterConnection, IXenConnection coordinatorConnection, bool allowLicenseUpgrade, bool allowCpuLevelling, bool allowSupporterAdConfig, int poolSizeIncrement = 1)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-01 15:43:23 +02:00
|
|
|
|
if (supporterConnection == null || !supporterConnection.IsConnected)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.NotConnected;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Host supporterHost = Helpers.GetCoordinator(supporterConnection);
|
2021-09-01 15:43:23 +02:00
|
|
|
|
if (supporterHost == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.Connecting;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (LicenseRestriction(supporterHost))
|
2016-01-15 15:42:36 +01:00
|
|
|
|
return Reason.LicenseRestriction;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (IsAPool(supporterConnection))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.IsAPool;
|
|
|
|
|
|
2021-09-01 15:43:23 +02:00
|
|
|
|
if (coordinatorConnection == null || !coordinatorConnection.IsConnected)
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return Reason.CoordinatorNotConnected;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Host coordinatorHost = Helpers.GetCoordinator(coordinatorConnection);
|
2021-06-29 16:36:49 +02:00
|
|
|
|
|
2021-09-01 15:43:23 +02:00
|
|
|
|
if (coordinatorHost == null)
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return Reason.CoordinatorConnecting;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (WillBeCoordinator(supporterConnection, coordinatorConnection))
|
|
|
|
|
return Reason.WillBeCoordinator;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!RoleOK(coordinatorConnection))
|
|
|
|
|
return Reason.WrongRoleOnCoordinator;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!CompatibleCPUs(supporterHost, coordinatorHost, allowCpuLevelling))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.DifferentCPUs;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (DifferentServerVersion(supporterHost, coordinatorHost))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.DifferentServerVersion;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (DifferentHomogeneousUpdates(supporterHost, coordinatorHost))
|
|
|
|
|
return coordinatorHost.Connection.Cache.Hosts.Length > 1 ? Reason.DifferentHomogeneousUpdatesFromPool : Reason.DifferentHomogeneousUpdatesFromCoordinator;
|
2017-06-30 15:05:52 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (FreeHostPaidCoordinator(supporterHost, coordinatorHost, allowLicenseUpgrade))
|
|
|
|
|
return Reason.UnlicensedHostLicensedCoordinator;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (PaidHostFreeCoordinator(supporterHost, coordinatorHost))
|
|
|
|
|
return Reason.LicensedHostUnlicensedCoordinator;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (LicenseMismatch(supporterHost, coordinatorHost))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.LicenseMismatch;
|
2017-09-22 17:57:09 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (CoordinatorPoolMaxNumberHostReached(coordinatorConnection))
|
|
|
|
|
return Reason.CoordinatorPoolMaxNumberHostReached;
|
2017-10-12 12:28:44 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (WillExceedPoolMaxSize(coordinatorConnection, poolSizeIncrement))
|
2017-10-12 12:28:44 +02:00
|
|
|
|
return Reason.WillExceedPoolMaxSize;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!SameLinuxPack(supporterHost, coordinatorHost))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.NotSameLinuxPack;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!RoleOK(supporterConnection))
|
|
|
|
|
return Reason.WrongRoleOnSupporter;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (HasSharedStorage(supporterConnection))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.HasSharedStorage;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (HasRunningVMs(supporterConnection))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.HasRunningVMs;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (DifferentNetworkBackends(supporterHost, coordinatorHost))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.DifferentNetworkBackends;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!CompatibleAdConfig(supporterHost, coordinatorHost, allowSupporterAdConfig))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.DifferentAdConfig;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (HaEnabled(coordinatorConnection))
|
|
|
|
|
return Reason.CoordinatorHasHA;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (Helpers.FeatureForbidden(supporterConnection, Host.RestrictManagementOnVLAN) && HasSupporterAnyNonPhysicalPif(supporterConnection))
|
2016-02-19 18:31:30 +01:00
|
|
|
|
return Reason.NotPhysicalPif;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!Helpers.FeatureForbidden(supporterConnection, Host.RestrictManagementOnVLAN) && !HasCompatibleManagementInterface(supporterConnection))
|
2017-03-02 07:50:50 +01:00
|
|
|
|
return Reason.NonCompatibleManagementInterface;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporterHost?.Connection?.Cache.Clusters.FirstOrDefault() != null)
|
2020-05-10 01:45:36 +02:00
|
|
|
|
return Reason.HasClusteringEnabled;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!HasIpForClusterNetwork(coordinatorConnection, supporterHost, out var clusterHostInBond))
|
2021-06-29 16:36:49 +02:00
|
|
|
|
return clusterHostInBond ? Reason.WrongNumberOfIpsBond : Reason.WrongNumberOfIpsCluster;
|
|
|
|
|
|
2021-09-01 15:43:23 +02:00
|
|
|
|
var coordinatorPool = Helpers.GetPool(coordinatorConnection);
|
|
|
|
|
var coordinatorPoolOfOne = Helpers.GetPoolOfOne(coordinatorConnection);
|
|
|
|
|
var supporterPoolOfOne = Helpers.GetPoolOfOne(supporterConnection);
|
2021-06-29 16:36:49 +02:00
|
|
|
|
|
2021-09-01 15:43:23 +02:00
|
|
|
|
if (coordinatorPoolOfOne.tls_verification_enabled && !supporterPoolOfOne.tls_verification_enabled)
|
|
|
|
|
return coordinatorPool == null ? Reason.TlsVerificationOnlyOnCoordinator : Reason.TlsVerificationOnlyOnPool;
|
2021-06-29 16:36:49 +02:00
|
|
|
|
|
2021-09-01 15:43:23 +02:00
|
|
|
|
if (!coordinatorPoolOfOne.tls_verification_enabled && supporterPoolOfOne.tls_verification_enabled)
|
|
|
|
|
return coordinatorPool == null ? Reason.TlsVerificationOnlyOnCoordinatorJoiner : Reason.TlsVerificationOnlyOnPoolJoiner;
|
2018-07-10 12:23:13 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Reason.Allowed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ReasonMessage(Reason reason)
|
|
|
|
|
{
|
|
|
|
|
switch (reason)
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
case Reason.WillBeCoordinator:
|
|
|
|
|
return Messages.COORDINATOR;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
case Reason.Allowed:
|
|
|
|
|
return "";
|
|
|
|
|
case Reason.Connecting:
|
|
|
|
|
return Messages.CONNECTING;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
case Reason.CoordinatorNotConnected:
|
|
|
|
|
return Messages.NEWPOOL_COORDINATOR_DISCONNECTED;
|
|
|
|
|
case Reason.CoordinatorConnecting:
|
|
|
|
|
return Messages.NEWPOOL_COORDINATOR_CONNECTING;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
case Reason.DifferentAdConfig:
|
|
|
|
|
return Messages.NEWPOOL_DIFFERING_AD_CONFIG;
|
|
|
|
|
case Reason.HasRunningVMs:
|
|
|
|
|
return Messages.NEWPOOL_HAS_RUNNING_VMS;
|
|
|
|
|
case Reason.HasSharedStorage:
|
|
|
|
|
return Messages.NEWPOOL_HAS_SHARED_STORAGE;
|
|
|
|
|
case Reason.IsAPool:
|
|
|
|
|
return Messages.NEWPOOL_IS_A_POOL;
|
|
|
|
|
case Reason.LicenseRestriction:
|
|
|
|
|
return Messages.NEWPOOL_POOLINGRESTRICTED;
|
|
|
|
|
case Reason.NotSameLinuxPack:
|
|
|
|
|
return Messages.NEWPOOL_LINUXPACK;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
case Reason.LicensedHostUnlicensedCoordinator:
|
|
|
|
|
return Messages.NEWPOOL_LICENSED_HOST_UNLICENSED_COORDINATOR;
|
|
|
|
|
case Reason.UnlicensedHostLicensedCoordinator:
|
|
|
|
|
return Messages.NEWPOOL_UNLICENSED_HOST_LICENSED_COORDINATOR;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
case Reason.LicenseMismatch:
|
|
|
|
|
return Messages.NEWPOOL_LICENSEMISMATCH;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
case Reason.CoordinatorPoolMaxNumberHostReached:
|
2017-09-22 17:57:09 +02:00
|
|
|
|
return Messages.NEWPOOL_MAX_NUMBER_HOST_REACHED;
|
2017-10-12 12:28:44 +02:00
|
|
|
|
case Reason.WillExceedPoolMaxSize:
|
|
|
|
|
return Messages.NEWPOOL_WILL_EXCEED_POOL_MAX_SIZE;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
case Reason.DifferentServerVersion:
|
|
|
|
|
return Messages.NEWPOOL_DIFF_SERVER;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
case Reason.DifferentHomogeneousUpdatesFromCoordinator:
|
|
|
|
|
return Messages.NEWPOOL_DIFFERENT_HOMOGENEOUS_UPDATES_FROM_COORDINATOR;
|
2017-06-30 15:05:52 +02:00
|
|
|
|
case Reason.DifferentHomogeneousUpdatesFromPool:
|
|
|
|
|
return Messages.NEWPOOL_DIFFERENT_HOMOGENEOUS_UPDATES_FROM_POOL;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
case Reason.DifferentCPUs:
|
|
|
|
|
return Messages.NEWPOOL_DIFF_HARDWARE;
|
|
|
|
|
case Reason.DifferentNetworkBackends:
|
|
|
|
|
return Messages.NEWPOOL_DIFFERENT_NETWORK_BACKENDS;
|
|
|
|
|
case Reason.NotConnected:
|
|
|
|
|
return Messages.DISCONNECTED;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
case Reason.CoordinatorHasHA:
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Messages.POOL_JOIN_FORBIDDEN_BY_HA;
|
2016-02-19 18:31:30 +01:00
|
|
|
|
case Reason.NotPhysicalPif :
|
|
|
|
|
return Messages.POOL_JOIN_NOT_PHYSICAL_PIF;
|
2017-03-02 07:50:50 +01:00
|
|
|
|
case Reason.NonCompatibleManagementInterface :
|
|
|
|
|
return Messages.POOL_JOIN_NON_COMPATIBLE_MANAGEMENT_INTERFACE;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
case Reason.WrongRoleOnCoordinator:
|
|
|
|
|
return Messages.NEWPOOL_COORDINATOR_ROLE;
|
|
|
|
|
case Reason.WrongRoleOnSupporter:
|
|
|
|
|
return Messages.NEWPOOL_SUPPORTER_ROLE;
|
2020-05-10 01:45:36 +02:00
|
|
|
|
case Reason.HasClusteringEnabled:
|
|
|
|
|
return Messages.NEW_POOL_CLUSTERING_ENABLED;
|
2018-07-10 12:23:13 +02:00
|
|
|
|
case Reason.WrongNumberOfIpsCluster:
|
|
|
|
|
return Messages.NEWPOOL_IP_COUNT_CLUSTER;
|
|
|
|
|
case Reason.WrongNumberOfIpsBond:
|
|
|
|
|
return Messages.NEWPOOL_IP_COUNT_BOND;
|
2021-06-29 16:36:49 +02:00
|
|
|
|
case Reason.TlsVerificationOnlyOnPool:
|
|
|
|
|
return Messages.POOL_JOIN_CERTIFICATE_CHECKING_ONLY_ON_POOL;
|
|
|
|
|
case Reason.TlsVerificationOnlyOnPoolJoiner:
|
|
|
|
|
return Messages.POOL_JOIN_CERTIFICATE_CHECKING_ONLY_ON_POOL_JOINER;
|
2021-09-01 15:43:23 +02:00
|
|
|
|
case Reason.TlsVerificationOnlyOnCoordinator:
|
|
|
|
|
return Messages.POOL_JOIN_CERTIFICATE_CHECKING_ONLY_ON_COORDINATOR;
|
|
|
|
|
case Reason.TlsVerificationOnlyOnCoordinatorJoiner:
|
|
|
|
|
return Messages.POOL_JOIN_CERTIFICATE_CHECKING_ONLY_ON_COORDINATOR_JOINER;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
default:
|
|
|
|
|
System.Diagnostics.Trace.Assert(false, "Unknown reason");
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private static bool WillBeCoordinator(IXenConnection supporter, IXenConnection coordinator)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
// Assume we have already tested that the connection has no other reason why it can't be a coordinator
|
2013-06-24 13:41:48 +02:00
|
|
|
|
// (e.g., connected, licensing restrictions, ...)
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return supporter == coordinator;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool HasSharedStorage(IXenConnection connection)
|
|
|
|
|
{
|
|
|
|
|
foreach (SR sr in connection.Cache.SRs)
|
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (sr.shared && !sr.IsToolsSR())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool HasRunningVMs(IXenConnection connection)
|
|
|
|
|
{
|
|
|
|
|
foreach (VM vm in connection.Cache.VMs)
|
|
|
|
|
{
|
2022-09-01 11:56:25 +02:00
|
|
|
|
if (vm.IsRealVm() && vm.power_state == XenAPI.vm_power_state.Running)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool IsAPool(IXenConnection connection)
|
|
|
|
|
{
|
|
|
|
|
return Helpers.GetPool(connection) != null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 15:42:36 +01:00
|
|
|
|
private static bool LicenseRestriction(Host host)
|
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
return Host.RestrictPooling(host);
|
2016-01-15 15:42:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
// If CompatibleCPUs(supporter, coordinator, false) is true, the CPUs can be pooled without masking first.
|
|
|
|
|
// If CompatibleCPUs(supporter, coordinator, true) is true but CompatibleCPUs(supporter, coordinator, false) is false,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
// the CPUs can be pooled but only if they are masked first.
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static bool CompatibleCPUs(Host supporter, Host coordinator, bool allowCpuLevelling)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter == null || coordinator == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Dictionary<string, string> supporter_cpu_info = supporter.cpu_info;
|
|
|
|
|
Dictionary<string, string> coordinator_cpu_info = coordinator.cpu_info;
|
|
|
|
|
if (!Helper.AreEqual2(supporter_cpu_info, null) && !Helper.AreEqual2(coordinator_cpu_info, null))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
// Host.cpu_info is supported
|
|
|
|
|
// From this point on, it is only necessary to have matching vendor and features
|
2021-08-31 12:31:16 +02:00
|
|
|
|
// (after masking the supporter, if allowed).
|
|
|
|
|
if (supporter_cpu_info["vendor"] != coordinator_cpu_info["vendor"])
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return false;
|
|
|
|
|
|
2016-03-07 16:04:38 +01:00
|
|
|
|
// As of Dundee, feature levelling makes all CPUs from the same vendor compatible
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (Helpers.DundeeOrGreater(coordinator) || Helpers.DundeeOrGreater(supporter))
|
2016-03-07 16:04:38 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter_cpu_info["features"] == coordinator_cpu_info["features"])
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (allowCpuLevelling)
|
|
|
|
|
{
|
|
|
|
|
string cpuid_feature_mask = null;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Pool pool = Helpers.GetPoolOfOne(coordinator.Connection);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (pool != null && pool.other_config.ContainsKey("cpuid_feature_mask"))
|
|
|
|
|
cpuid_feature_mask = pool.other_config["cpuid_feature_mask"];
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return MaskableTo(supporter_cpu_info["maskable"], supporter_cpu_info["physical_features"], coordinator_cpu_info["features"], cpuid_feature_mask);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Host.cpu_info not supported: use the old method which compares vendor, family, model and flags
|
2021-08-31 12:31:16 +02:00
|
|
|
|
foreach (Host_cpu cpu1 in supporter.Connection.Cache.Host_cpus)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
foreach (Host_cpu cpu2 in coordinator.Connection.Cache.Host_cpus)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (cpu1.vendor != cpu2.vendor ||
|
|
|
|
|
cpu1.family != cpu2.family ||
|
|
|
|
|
cpu1.model != cpu2.model ||
|
|
|
|
|
cpu1.flags != cpu2.flags)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Can the features represented by "from" be masked to become the features represented by "to"?
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="mask_type">"no", "base" (can only mask first 64 bits) or "full"</param>
|
|
|
|
|
/// <param name="from">The unmasked features, as a set of 32 hex digits, possibly separated by spaces or dashes</param>
|
|
|
|
|
/// <param name="to">The target features, as a set of 32 hex digits, possibly separated by spaces or dashes</param>
|
|
|
|
|
/// <param name="feature_mask">A mask of features to ignore for the comparison</param>
|
|
|
|
|
public static bool MaskableTo(string mask_type, string from, string to, string feature_mask)
|
|
|
|
|
{
|
|
|
|
|
if (mask_type == "no")
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
string from2 = from.Replace(" ", "");
|
|
|
|
|
from2 = from2.Replace("-", "");
|
|
|
|
|
string to2 = to.Replace(" ", "");
|
|
|
|
|
to2 = to2.Replace("-", "");
|
|
|
|
|
if (from2.Length != 32 || to2.Length != 32)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
string fm2;
|
|
|
|
|
if (feature_mask == null)
|
|
|
|
|
fm2 = "ffffffffffffffffffffffffffffffff";
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fm2 = feature_mask.Replace(" ", "");
|
|
|
|
|
fm2 = fm2.Replace("-", "");
|
|
|
|
|
if (fm2.Length != 32)
|
|
|
|
|
fm2 = "ffffffffffffffffffffffffffffffff";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compare int64-by-int64. AMD can mask all the bits; some Intel chips can only mask the first half.
|
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
|
{
|
|
|
|
|
string fromPart = from2.Substring(16 * i, 16);
|
|
|
|
|
string toPart = to2.Substring(16 * i, 16);
|
|
|
|
|
string fmPart = fm2.Substring(16 * i, 16);
|
|
|
|
|
|
|
|
|
|
ulong fromInt = Convert.ToUInt64(fromPart, 16);
|
|
|
|
|
ulong toInt = Convert.ToUInt64(toPart, 16);
|
|
|
|
|
ulong fmInt = Convert.ToUInt64(fmPart, 16);
|
|
|
|
|
fromInt &= fmInt;
|
|
|
|
|
toInt &= fmInt;
|
|
|
|
|
|
|
|
|
|
if (i == 1 && mask_type == "base") // must be an exact match
|
|
|
|
|
{
|
|
|
|
|
if (fromInt != toInt)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else // "from" must be maskable to "to"
|
|
|
|
|
{
|
|
|
|
|
if ((fromInt & toInt) != toInt)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private static bool DifferentServerVersion(Host supporter, Host coordinator)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter.API_version_major != coordinator.API_version_major ||
|
|
|
|
|
supporter.API_version_minor != coordinator.API_version_minor)
|
2017-04-10 10:25:51 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (Helpers.FalconOrGreater(supporter) && string.IsNullOrEmpty(supporter.GetDatabaseSchema()))
|
2017-04-10 10:25:51 +02:00
|
|
|
|
return true;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (Helpers.FalconOrGreater(coordinator) && string.IsNullOrEmpty(coordinator.GetDatabaseSchema()))
|
2017-04-10 10:25:51 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter.GetDatabaseSchema() != coordinator.GetDatabaseSchema())
|
2017-04-10 10:25:51 +02:00
|
|
|
|
return true;
|
2017-07-27 15:47:12 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return
|
2021-08-31 12:31:16 +02:00
|
|
|
|
!Helpers.ElyOrGreater(coordinator) && !Helpers.ElyOrGreater(supporter) && supporter.BuildNumber() != coordinator.BuildNumber() ||
|
|
|
|
|
supporter.PlatformVersion() != coordinator.PlatformVersion() ||
|
|
|
|
|
supporter.ProductBrand() != coordinator.ProductBrand();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-30 15:05:52 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check whether all updates that request homogeneity are in fact homogeneous
|
2021-08-31 12:31:16 +02:00
|
|
|
|
/// between coordinator and supporter. This is used in CanJoinPool and prevents the pool from being created
|
2017-06-30 15:05:52 +02:00
|
|
|
|
/// </summary>
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private static bool DifferentHomogeneousUpdates(Host supporter, Host coordinator)
|
2017-06-30 15:05:52 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter == null || coordinator == null)
|
2017-06-30 15:05:52 +02:00
|
|
|
|
return false;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!Helpers.ElyOrGreater(supporter) || !Helpers.ElyOrGreater(coordinator))
|
2017-06-30 17:01:02 +02:00
|
|
|
|
return false;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var coordinatorUpdates = coordinator.AppliedUpdates().Where(update => update.EnforceHomogeneity()).Select(update => update.uuid).ToList();
|
|
|
|
|
var supporterUpdates = supporter.AppliedUpdates().Where(update => update.EnforceHomogeneity()).Select(update => update.uuid).ToList();
|
2017-06-30 15:05:52 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return coordinatorUpdates.Count != supporterUpdates.Count || !coordinatorUpdates.All(supporterUpdates.Contains);
|
2017-06-30 15:05:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private static bool SameLinuxPack(Host supporter, Host coordinator)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return supporter.LinuxPackPresent() == coordinator.LinuxPackPresent();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static bool CompatibleAdConfig(Host supporter, Host coordinator, bool allowSupporterConfig)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter == null || coordinator == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// CA-30223: There is no need to check the config of the auth services are the same, as xapi only relies on these two values being equal
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter.external_auth_type != coordinator.external_auth_type ||
|
|
|
|
|
supporter.external_auth_service_name != coordinator.external_auth_service_name)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
// if the supporter is AD free and we are allowing the configure then we can solve this
|
|
|
|
|
if (supporter.external_auth_type == Auth.AUTH_TYPE_NONE && allowSupporterConfig)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static bool FreeHostPaidCoordinator(Host supporter, Host coordinator, bool allowLicenseUpgrade)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter == null || coordinator == null)
|
2013-07-01 11:37:25 +02:00
|
|
|
|
return false;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return supporter.IsFreeLicense() && !coordinator.IsFreeLicense() && !allowLicenseUpgrade;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private static bool PaidHostFreeCoordinator(Host supporter, Host coordinator)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter == null || coordinator == null)
|
2013-07-01 17:48:22 +02:00
|
|
|
|
return false;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return !supporter.IsFreeLicense() && coordinator.IsFreeLicense();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private static bool LicenseMismatch(Host supporter, Host coordinator)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Host.Edition supporterEdition = Host.GetEdition(supporter.edition);
|
|
|
|
|
Host.Edition coordinatorEdition = Host.GetEdition(coordinator.edition);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return supporterEdition != Host.Edition.Free && coordinatorEdition != Host.Edition.Free && supporterEdition != coordinatorEdition;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private static bool CoordinatorPoolMaxNumberHostReached(IXenConnection connection)
|
2017-09-22 17:57:09 +02:00
|
|
|
|
{
|
|
|
|
|
return Helpers.FeatureForbidden(connection, Host.RestrictPoolSize) && connection.Cache.HostCount > 2;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 12:28:44 +02:00
|
|
|
|
public static bool WillExceedPoolMaxSize(IXenConnection connection, int poolSizeIncrement)
|
|
|
|
|
{
|
|
|
|
|
return Helpers.FeatureForbidden(connection, Host.RestrictPoolSize) && connection.Cache.HostCount + poolSizeIncrement > 3;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private static bool HaEnabled(IXenConnection connection)
|
|
|
|
|
{
|
|
|
|
|
Pool pool = Helpers.GetPoolOfOne(connection);
|
|
|
|
|
return (pool != null && pool.ha_enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool RoleOK(IXenConnection connection)
|
|
|
|
|
{
|
2022-01-29 03:50:54 +01:00
|
|
|
|
return Role.CanPerform(new RbacMethodList("pool.join"), connection, out _);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private static bool DifferentNetworkBackends(Host supporter, Host coordinator)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter.software_version.ContainsKey("network_backend") &&
|
|
|
|
|
coordinator.software_version.ContainsKey("network_backend") &&
|
|
|
|
|
supporter.software_version["network_backend"] != coordinator.software_version["network_backend"])
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var coordinatorPool = Helpers.GetPoolOfOne(coordinator.Connection);
|
|
|
|
|
var supporterPool = Helpers.GetPoolOfOne(supporter.Connection);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return coordinatorPool != null && supporterPool != null &&
|
|
|
|
|
coordinatorPool.vSwitchController() && supporterPool.vSwitchController() &&
|
|
|
|
|
coordinatorPool.vswitch_controller != supporterPool.vswitch_controller;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check whether all supp packs that request homogeneity are in fact homogeneous
|
|
|
|
|
/// across the proposed pool. This is only a warning; it does not prevent the pool being created;
|
|
|
|
|
/// so it is not used by CanJoinPool.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>A list of strings: each string is the name of a bad supp pack with a reason in brackets</returns>
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static List<string> HomogeneousSuppPacksDiffering(List<Host> supporters, IXenObject poolOrCoordinator)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
List<Host> allHosts = new List<Host>(supporters);
|
|
|
|
|
allHosts.AddRange(poolOrCoordinator.Connection.Cache.Hosts);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
// Make a dictionary of all supp packs that should be homogeneous
|
|
|
|
|
Dictionary<string, string> homogeneousPacks = new Dictionary<string, string>();
|
|
|
|
|
foreach (Host host in allHosts)
|
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
var suppPacks = host.SuppPacks();
|
|
|
|
|
foreach (Host.SuppPack suppPack in suppPacks)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (suppPack.Homogeneous)
|
|
|
|
|
homogeneousPacks[suppPack.OriginatorAndName] = suppPack.Description;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now for each such supp pack, see whether it is in fact homogeneous.
|
|
|
|
|
// If not, add it to the list of bad packs with a reason.
|
|
|
|
|
|
|
|
|
|
List<string> badPacks = new List<string>();
|
|
|
|
|
|
|
|
|
|
foreach (string pack in homogeneousPacks.Keys)
|
|
|
|
|
{
|
|
|
|
|
// Is it present on all hosts, with the same version?
|
|
|
|
|
List<Host> missingHosts = new List<Host>();
|
|
|
|
|
string expectedVersion = null;
|
|
|
|
|
bool versionsDiffer = false;
|
|
|
|
|
|
|
|
|
|
foreach (Host host in allHosts)
|
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
Host.SuppPack matchingPack = host.SuppPacks().Find(sp => (sp.OriginatorAndName == pack));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (matchingPack == null)
|
|
|
|
|
missingHosts.Add(host);
|
|
|
|
|
else if (expectedVersion == null)
|
|
|
|
|
expectedVersion = matchingPack.Version;
|
|
|
|
|
else if (matchingPack.Version != expectedVersion)
|
|
|
|
|
versionsDiffer = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (missingHosts.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
badPacks.Add(string.Format(Messages.SUPP_PACK_MISSING_ON,
|
|
|
|
|
homogeneousPacks[pack], // the Description field from the pack, which we cunningly remembered to save above
|
|
|
|
|
string.Join("\n", missingHosts.ConvertAll(host => host.ToString()).ToArray()))); // comma-separated list of hosts
|
|
|
|
|
}
|
|
|
|
|
else if (versionsDiffer)
|
|
|
|
|
{
|
|
|
|
|
badPacks.Add(string.Format(Messages.SUPP_PACK_VERSIONS_DIFFER, homogeneousPacks[pack]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return badPacks;
|
|
|
|
|
}
|
2015-10-30 16:52:24 +01:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check whether the host that joins the pool has a more extensive feature set than the pool (as long as the CPU vendor is common)
|
|
|
|
|
/// In this case the host will transparently be down-levelled to the pool level (without needing reboots)
|
|
|
|
|
/// </summary>
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static bool HostHasMoreFeatures(Host supporter, Pool pool)
|
2015-10-30 16:52:24 +01:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter == null || pool == null)
|
2015-10-30 16:52:24 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Dictionary<string, string> supporter_cpu_info = supporter.cpu_info;
|
2015-10-30 16:52:24 +01:00
|
|
|
|
Dictionary<string, string> pool_cpu_info = pool.cpu_info;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!Helper.AreEqual2(supporter_cpu_info, null) && !Helper.AreEqual2(pool_cpu_info, null))
|
2015-10-30 16:52:24 +01:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
// if pool has less features than supporter, then supporter will be down-levelled
|
|
|
|
|
return FewerFeatures(pool_cpu_info, supporter_cpu_info);
|
2015-10-30 16:52:24 +01:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check whether the host that joins the pool has a less extensive feature set than the pool (as long as the CPU vendor is common)
|
|
|
|
|
/// In this case the pool is transparently down-levelled to the new host's level (without needing reboots)
|
|
|
|
|
/// </summary>
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static bool HostHasFewerFeatures(Host supporter, Pool pool)
|
2015-10-30 16:52:24 +01:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (supporter == null || pool == null)
|
2015-10-30 16:52:24 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Dictionary<string, string> supporter_cpu_info = supporter.cpu_info;
|
2015-10-30 16:52:24 +01:00
|
|
|
|
Dictionary<string, string> pool_cpu_info = pool.cpu_info;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (!Helper.AreEqual2(supporter_cpu_info, null) && !Helper.AreEqual2(pool_cpu_info, null))
|
2015-10-30 16:52:24 +01:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
// if supporter has less features than pool, then pool will be down-levelled
|
|
|
|
|
return FewerFeatures(supporter_cpu_info, pool_cpu_info);
|
2015-10-30 16:52:24 +01:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-04 17:33:23 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check whether first CPU has fewer features than the second.
|
|
|
|
|
/// It returns true if the first feature set is less than the second one in at least one bit
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool FewerFeatures(Dictionary<string, string> cpu_infoA, Dictionary<string, string> cpu_infoB)
|
2015-10-30 16:52:24 +01:00
|
|
|
|
{
|
|
|
|
|
if (cpu_infoA.ContainsKey("features_hvm") && cpu_infoB.ContainsKey("features_hvm") &&
|
2015-11-04 17:33:23 +01:00
|
|
|
|
FewerFeatures(cpu_infoA["features_hvm"], cpu_infoB["features_hvm"]))
|
|
|
|
|
return true;
|
|
|
|
|
if (cpu_infoA.ContainsKey("features_pv") && cpu_infoB.ContainsKey("features_pv") &&
|
|
|
|
|
FewerFeatures(cpu_infoA["features_pv"], cpu_infoB["features_pv"]))
|
2015-10-30 16:52:24 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-04 17:33:23 +01:00
|
|
|
|
public static bool FewerFeatures(string featureSetA, string featureSetB)
|
2015-10-30 16:52:24 +01:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(featureSetA) || string.IsNullOrEmpty(featureSetB))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
string stringA = featureSetA.Replace(" ", "");
|
|
|
|
|
stringA = stringA.Replace("-", "");
|
|
|
|
|
string stringB = featureSetB.Replace(" ", "");
|
|
|
|
|
stringB = stringB.Replace("-", "");
|
|
|
|
|
|
|
|
|
|
if (stringA.Length < stringB.Length)
|
|
|
|
|
stringA = stringA.PadRight(stringB.Length, '0');
|
|
|
|
|
if (stringB.Length < stringA.Length)
|
|
|
|
|
stringB = stringB.PadRight(stringA.Length, '0');
|
|
|
|
|
|
2015-11-04 17:33:23 +01:00
|
|
|
|
for (int i = 0; i < stringA.Length / 8; ++i)
|
2015-10-30 16:52:24 +01:00
|
|
|
|
{
|
2015-11-04 17:33:23 +01:00
|
|
|
|
uint intA = Convert.ToUInt32(stringA.Substring(8 * i, 8), 16);
|
|
|
|
|
uint intB = Convert.ToUInt32(stringB.Substring(8 * i, 8), 16);
|
2015-10-30 16:52:24 +01:00
|
|
|
|
|
2015-11-04 17:33:23 +01:00
|
|
|
|
if ((intA & intB) != intB)
|
2015-10-30 16:52:24 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-02-19 18:31:30 +01:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static bool HasSupporterAnyNonPhysicalPif(IXenConnection supporterConnection)
|
2016-02-19 18:31:30 +01:00
|
|
|
|
{
|
|
|
|
|
return
|
2021-08-31 12:31:16 +02:00
|
|
|
|
supporterConnection.Cache.PIFs.Any(p => !p.physical);
|
2016-02-19 18:31:30 +01:00
|
|
|
|
}
|
2017-03-02 07:50:50 +01:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static bool HasCompatibleManagementInterface(IXenConnection supporterConnection)
|
2017-03-02 07:50:50 +01:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
/* if there are non physical pifs present then the supporter should have
|
2017-05-31 06:18:12 +02:00
|
|
|
|
* only one VLAN and it has to be the management interface.
|
2017-03-02 07:50:50 +01:00
|
|
|
|
* Bonds and cross server private networks are not allowed */
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
int numberOfNonPhysicalPifs = supporterConnection.Cache.PIFs.Count(p => !p.physical);
|
2017-03-02 07:50:50 +01:00
|
|
|
|
|
|
|
|
|
/* allow the case where there are only physical pifs */
|
|
|
|
|
if (numberOfNonPhysicalPifs == 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if(numberOfNonPhysicalPifs != 1)
|
|
|
|
|
return false;
|
|
|
|
|
else
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return supporterConnection.Cache.PIFs.Any(p => !p.physical && p.management && p.VLAN != -1);
|
2017-03-02 07:50:50 +01:00
|
|
|
|
}
|
2018-07-10 12:23:13 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
public static bool HasIpForClusterNetwork(IXenConnection coordinatorConnection, Host supporterHost, out bool clusterHostInBond)
|
2018-07-10 12:23:13 +02:00
|
|
|
|
{
|
2018-07-12 15:56:17 +02:00
|
|
|
|
clusterHostInBond = false;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var clusterHost = coordinatorConnection.Cache.Cluster_hosts.FirstOrDefault();
|
2018-07-10 12:23:13 +02:00
|
|
|
|
|
|
|
|
|
if (clusterHost == null)
|
|
|
|
|
return true;
|
2018-07-12 15:56:17 +02:00
|
|
|
|
|
2018-07-10 12:23:13 +02:00
|
|
|
|
var clusterHostPif = clusterHost.Connection.Resolve(clusterHost.PIF);
|
2018-07-12 15:56:17 +02:00
|
|
|
|
|
|
|
|
|
if (clusterHostPif == null)
|
|
|
|
|
return true;
|
|
|
|
|
|
2019-01-09 16:04:36 +01:00
|
|
|
|
// if this PIF is a VLAN, then use the tagged_PIF field of the VLAN
|
|
|
|
|
if (clusterHostPif.VLAN >= 0)
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var vlan = coordinatorConnection.Resolve(clusterHostPif.VLAN_master_of);
|
2019-01-09 16:04:36 +01:00
|
|
|
|
|
|
|
|
|
if (vlan != null)
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var taggedPif = coordinatorConnection.Resolve(vlan.tagged_PIF);
|
2019-01-09 16:04:36 +01:00
|
|
|
|
if (taggedPif != null)
|
|
|
|
|
clusterHostPif = taggedPif;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-10 12:23:13 +02:00
|
|
|
|
clusterHostInBond = clusterHostPif.IsBondNIC();
|
|
|
|
|
|
|
|
|
|
var pifsWithIPAddress = 0;
|
|
|
|
|
|
|
|
|
|
List<string> ids = new List<string>();
|
|
|
|
|
|
|
|
|
|
if (clusterHostInBond)
|
|
|
|
|
{
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
List<PIF> members = new List<PIF>();
|
2018-07-10 12:23:13 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var bonds = coordinatorConnection.ResolveAll(clusterHostPif.bond_master_of);
|
2018-07-12 14:40:50 +02:00
|
|
|
|
|
|
|
|
|
foreach (var bond in bonds)
|
2018-07-10 12:23:13 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
members.AddRange(coordinatorConnection.ResolveAll(bond.slaves));
|
2018-07-10 12:23:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
ids.AddRange(members.Select(member => member.device));
|
2018-07-10 12:23:13 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ids.Add(clusterHostPif.device);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var pifs = supporterHost.Connection.ResolveAll(supporterHost.PIFs);
|
2018-07-12 14:40:50 +02:00
|
|
|
|
|
|
|
|
|
foreach (var pif in pifs)
|
2018-07-10 12:23:13 +02:00
|
|
|
|
{
|
|
|
|
|
if (pif.IsManagementInterface(false) && ids.Contains(pif.device))
|
|
|
|
|
{
|
|
|
|
|
pifsWithIPAddress += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pifsWithIPAddress == 1;
|
|
|
|
|
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|