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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-03-15 15:10:42 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Wizards.GenericPages;
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.NewPolicyWizard
|
|
|
|
|
{
|
|
|
|
|
public partial class NewPolicyWizard : XenWizardBase
|
|
|
|
|
{
|
2017-05-30 16:08:01 +02:00
|
|
|
|
private readonly NewPolicyPolicyNamePage xenTabPagePolicy;
|
2017-05-25 15:56:13 +02:00
|
|
|
|
private readonly NewVMGroupVMsPage<VMSS> xenTabPageVMsPage;
|
|
|
|
|
private readonly NewPolicySnapshotTypePage xenTabPageSnapshotType;
|
2017-05-30 16:08:01 +02:00
|
|
|
|
private readonly NewPolicySnapshotFrequencyPage xenTabPageSnapshotFrequency;
|
|
|
|
|
private readonly NewPolicyFinishPage xenTabPageFinish;
|
|
|
|
|
private readonly RBACWarningPage xenTabPageRBAC;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public readonly Pool Pool;
|
2019-03-15 15:10:42 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public NewPolicyWizard(Pool pool)
|
|
|
|
|
: base(pool.Connection)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Pool = pool;
|
2017-05-25 15:56:13 +02:00
|
|
|
|
|
|
|
|
|
this.Text = Messages.VMSS_WIZARD_TITLE;
|
|
|
|
|
|
2017-09-07 13:56:41 +02:00
|
|
|
|
xenTabPagePolicy = new NewPolicyPolicyNamePage();
|
2017-05-25 15:56:13 +02:00
|
|
|
|
xenTabPageSnapshotType = new NewPolicySnapshotTypePage();
|
|
|
|
|
xenTabPageVMsPage = new NewVMGroupVMsPage<VMSS>();
|
2019-03-15 15:10:42 +01:00
|
|
|
|
xenTabPageFinish = new NewPolicyFinishPage();
|
2017-05-25 15:56:13 +02:00
|
|
|
|
xenTabPageRBAC = new RBACWarningPage();
|
|
|
|
|
xenTabPageVMsPage.Pool = pool;
|
|
|
|
|
xenTabPageSnapshotFrequency = new NewPolicySnapshotFrequencyPage();
|
2019-03-15 15:10:42 +01:00
|
|
|
|
xenTabPageSnapshotFrequency.Connection = pool.Connection;
|
2017-05-25 15:56:13 +02:00
|
|
|
|
|
|
|
|
|
#region RBAC Warning Page Checks
|
|
|
|
|
if (Pool.Connection.Session.IsLocalSuperuser || Helpers.GetMaster(Pool.Connection).external_auth_type == Auth.AUTH_TYPE_NONE)
|
|
|
|
|
{
|
|
|
|
|
//do nothing
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RBACWarningPage.WizardPermissionCheck check;
|
|
|
|
|
check = new RBACWarningPage.WizardPermissionCheck(Messages.RBAC_WARNING_VMSS);
|
|
|
|
|
check.AddApiCheck("VMSS.async_create");
|
|
|
|
|
check.Blocking = true;
|
|
|
|
|
xenTabPageRBAC.AddPermissionChecks(xenConnection, check);
|
|
|
|
|
AddPage(xenTabPageRBAC, 0);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
AddPages(xenTabPagePolicy, xenTabPageVMsPage);
|
|
|
|
|
AddPage(xenTabPageSnapshotType);
|
|
|
|
|
AddPages(xenTabPageSnapshotFrequency);
|
|
|
|
|
AddPages(xenTabPageFinish);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NewPolicyWizard(Pool pool, List<VM> selection)
|
|
|
|
|
: this(pool)
|
|
|
|
|
{
|
|
|
|
|
this.xenTabPageVMsPage.SelectedVMs = selection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateWizardContent(XenTabPage senderPage)
|
|
|
|
|
{
|
|
|
|
|
var prevPageType = senderPage.GetType();
|
|
|
|
|
|
|
|
|
|
if (prevPageType == typeof(NewPolicyPolicyNamePage))
|
|
|
|
|
{
|
|
|
|
|
xenTabPageVMsPage.GroupName = xenTabPagePolicy.PolicyName;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (prevPageType == typeof(NewPolicySnapshotFrequencyPage))
|
|
|
|
|
{
|
2019-03-15 15:10:42 +01:00
|
|
|
|
xenTabPageFinish.Summary = string.Format(Messages.VMSS_POLICY_SUMMARY,
|
|
|
|
|
xenTabPagePolicy.PolicyName,
|
|
|
|
|
string.Join(", ", xenTabPageVMsPage.SelectedVMs.Select(vm => vm.Name())),
|
|
|
|
|
xenTabPageSnapshotType.BackupTypeToString,
|
|
|
|
|
xenTabPageSnapshotFrequency.FormattedSchedule);
|
2017-05-25 15:56:13 +02:00
|
|
|
|
xenTabPageFinish.SelectedVMsCount = xenTabPageVMsPage.SelectedVMs.Count;
|
|
|
|
|
}
|
|
|
|
|
else if (prevPageType == typeof(NewVMGroupVMsPage<VMSS>))
|
|
|
|
|
{
|
|
|
|
|
xenTabPageSnapshotType.SelectedVMs = xenTabPageVMsPage.SelectedVMs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void FinishWizard()
|
|
|
|
|
{
|
|
|
|
|
var vmss = new VMSS
|
|
|
|
|
{
|
|
|
|
|
name_label = xenTabPagePolicy.PolicyName,
|
|
|
|
|
name_description = xenTabPagePolicy.PolicyDescription,
|
2019-03-15 15:10:42 +01:00
|
|
|
|
type = xenTabPageSnapshotType.BackupType,
|
|
|
|
|
frequency = xenTabPageSnapshotFrequency.Frequency,
|
2017-05-25 15:56:13 +02:00
|
|
|
|
schedule = xenTabPageSnapshotFrequency.Schedule,
|
|
|
|
|
retained_snapshots = xenTabPageSnapshotFrequency.BackupRetention,
|
2019-03-15 15:10:42 +01:00
|
|
|
|
enabled = xenTabPageVMsPage.SelectedVMs.Count != 0,
|
2017-05-25 15:56:13 +02:00
|
|
|
|
Connection = Pool.Connection
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var action = new CreateVMPolicy(vmss, xenTabPageVMsPage.SelectedVMs, xenTabPageFinish.RunNow);
|
|
|
|
|
|
|
|
|
|
action.RunAsync();
|
|
|
|
|
base.FinishWizard();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string WizardPaneHelpID()
|
|
|
|
|
{
|
|
|
|
|
if (CurrentStepTabPage is RBACWarningPage)
|
|
|
|
|
{
|
|
|
|
|
return FormatHelpId("Rbac");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "NewPolicyWizardVMSS_" + CurrentStepTabPage.HelpID + "Pane";
|
2019-03-15 15:10:42 +01:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|