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.Actions;
|
|
|
|
|
using XenAdmin.Dialogs;
|
2017-05-25 17:29:27 +02:00
|
|
|
|
using XenAdmin.Dialogs.ScheduledSnapshots;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Dialogs.VMAppliances;
|
|
|
|
|
using XenAdmin.Network;
|
|
|
|
|
using XenAdmin.Wizards;
|
|
|
|
|
using XenAdmin.Wizards.NewPolicyWizard;
|
|
|
|
|
using XenAdmin.Wizards.NewVMApplianceWizard;
|
|
|
|
|
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-05-25 15:56:13 +02:00
|
|
|
|
/// A helper class for dealing with a group of VMs (currently either a VMSS or a vApp);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// it contains all the functions necessary to abstract away what type of group it is.
|
|
|
|
|
///
|
|
|
|
|
/// In C++, we would use template specialization for this, but C# generics don't have that, so we
|
|
|
|
|
/// end up switching on T. It's ugly, but it's the way that maximises the amount of shared code.
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
2016-02-17 09:02:24 +01:00
|
|
|
|
static class VMGroup<T> where T : XenObject<T>
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
// This section covers all the functions that depend on the type of group we're talking about.
|
|
|
|
|
|
|
|
|
|
internal static T[] GroupsInCache(ICache cache)
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
return typeof(T) == typeof(VMSS)? cache.VMSSs as T[] : cache.VM_appliances as T[];
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static XenRef<T> VmToGroup(VM vm)
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
return typeof(T) == typeof(VMSS) ? vm.snapshot_schedule as XenRef<T> : vm.appliance as XenRef<T>;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static List<XenRef<VM>> GroupToVMs(T group)
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
return typeof(T) == typeof(VMSS) ? (group as VMSS).VMs : (group as VM_appliance).VMs;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string ChangeOneWarningString
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.CHANGE_VM_SNAPSHOT_SCHEDULE_WARNING : Messages.CHANGE_VMS_APPLIANCE_WARNING; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string ChangeMultipleWarningString
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.CHANGE_VMS_SNAPSHOT_SCHEDULE_WARNING : Messages.CHANGE_VMS_APPLIANCES_WARNING; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string NewGroupString
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.NEW_SCHEDULE : Messages.NEW_VM_APPLIANCE; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string ChangeVMsGroupString
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.CHANGE_VMSS_POLICY : Messages.CHANGE_VMS_APPLIANCE; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string AssignMainMenuString
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.ASSIGN_VMSS_POLICY : Messages.ASSIGN_VM_APPLIANCE; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string AssignContextMenuString
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.ASSIGN_VMSS_POLICY_CONTEXT_MENU : Messages.ASSIGN_VM_APPLIANCE; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string ManageMainMenuString
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.VMSS_MAIN_MENU : Messages.VM_APPLIANCES_MENU; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string ManageContextMenuString
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.VMSS_CONTEXT_MENU : Messages.VM_APPLIANCES_MENU; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string ChooseVMsPage_Text
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.VMSS_VMS : Messages.NEWVMAPPLIANCE_VMSPAGE_TEXT; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string ChooseVMsPage_Title
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.VMSS_VMS_TITLE : Messages.NEWVMAPPLIANCE_VMSPAGE_TITLE; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string ChooseVMsPage_Rubric
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.CHOOSE_VMS_VMSS_RUBRIC : Messages.CHOOSE_VMS_VAPP_RUBRIC; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string ChooseVMsPage_CurrentGroup
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? Messages.CURRENT_SCHEDULE : Messages.CURRENT_VAPP; }
|
2016-02-19 06:49:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
internal static string ChooseVMsPage_HelpID
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return "VMs"; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string UpsellBlurb
|
|
|
|
|
{
|
2016-01-21 09:54:22 +01:00
|
|
|
|
get
|
|
|
|
|
{
|
2016-01-28 22:43:15 +01:00
|
|
|
|
if (HiddenFeatures.LinkLabelHidden)
|
2017-05-25 15:56:13 +02:00
|
|
|
|
return typeof(T) == typeof(VMSS) ? Messages.UPSELL_BLURB_VMSS : Messages.UPSELL_BLURB_VM_APPLIANCES;
|
2016-01-21 09:54:22 +01:00
|
|
|
|
else
|
2017-11-17 13:24:43 +01:00
|
|
|
|
return typeof(T) == typeof(VMSS) ? Messages.UPSELL_BLURB_VMSS + Messages.UPSELL_BLURB_TRIAL : Messages.UPSELL_BLURB_VM_APPLIANCES + Messages.UPSELL_BLURB_TRIAL;
|
2016-01-21 09:54:22 +01:00
|
|
|
|
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string UpsellLearnMoreUrl
|
|
|
|
|
{
|
2017-11-17 13:24:43 +01:00
|
|
|
|
get { return InvisibleMessages.UPSELL_LEARNMOREURL_TRIAL; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 12:19:04 +02:00
|
|
|
|
internal static AsyncAction AssignVMsToGroupAction(T group, List<XenRef<VM>> vms, bool suppressHistory)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
return typeof(T) == typeof(VMSS) ? (AsyncAction)(new AssignVMsToPolicyAction(group as VMSS, vms, suppressHistory)) :
|
|
|
|
|
(AsyncAction)(new AssignVMsToVMApplianceAction(group as VM_appliance, vms, suppressHistory));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static AsyncAction RemoveVMsFromGroupAction(T group, List<XenRef<VM>> vms)
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
return typeof(T) == typeof(VMSS) ? (AsyncAction)(new RemoveVMsFromPolicyAction(group as VMSS, vms)) :
|
|
|
|
|
(AsyncAction)(new RemoveVMsFromVMApplianceAction(group as VM_appliance, vms));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static XenWizardBase NewGroupWizard(Pool pool)
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
return typeof(T) == typeof(VMSS) ? (XenWizardBase) new NewPolicyWizard(pool) : new NewVMApplianceWizard(pool);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static XenWizardBase NewGroupWizard(Pool pool, List<VM> vms)
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
return typeof(T) == typeof(VMSS) ? new NewPolicyWizard(pool, vms) : (XenWizardBase)new NewVMApplianceWizard(pool, vms);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static XenDialogBase ManageGroupsDialog(Pool pool)
|
|
|
|
|
{
|
2017-05-25 17:29:27 +02:00
|
|
|
|
return typeof(T) == typeof(VMSS) ? (XenDialogBase)(new ScheduledSnapshotsDialog(pool)) : (XenDialogBase)(new VMAppliancesDialog(pool));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static bool FeaturePossible(IXenConnection connection)
|
|
|
|
|
{
|
2017-02-06 07:08:26 +01:00
|
|
|
|
//VMSS is enabled Falcon onwards
|
|
|
|
|
if ((typeof(T) == typeof(VMSS)) && !Helpers.FalconOrGreater(connection))
|
2016-01-27 11:36:48 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-05-25 15:56:13 +02:00
|
|
|
|
return true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static Predicate<Host> FeatureRestricted
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
get { return typeof(T) == typeof(VMSS) ? ((Predicate<Host>)Host.RestrictVMSnapshotSchedule) : (Predicate<Host>)Host.RestrictVMAppliances; }
|
2016-02-17 09:02:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-20 13:40:11 +02:00
|
|
|
|
internal static bool IsQuescingSupported(IXenConnection connection)
|
2016-02-17 09:02:24 +01:00
|
|
|
|
{
|
2019-08-20 13:40:11 +02:00
|
|
|
|
return typeof(T) == typeof(VMSS) && !Helpers.QuebecOrGreater(connection);
|
2016-02-18 11:49:40 +01:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|