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.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Wizards.NewPolicyWizard;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Dialogs.VMProtectionRecovery;
|
|
|
|
|
using XenCenterLib;
|
2016-02-15 05:35:26 +01:00
|
|
|
|
using XenAdmin.Alerts;
|
2016-04-06 06:08:11 +02:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Dialogs.VMProtection_Recovery
|
|
|
|
|
{
|
2016-01-29 12:34:44 +01:00
|
|
|
|
public partial class VMProtectionPoliciesDialog: XenDialogBase
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
public readonly Pool Pool;
|
|
|
|
|
public VMProtectionPoliciesDialog(Pool pool)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
: base(pool.Connection)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Pool = pool;
|
2016-02-15 05:35:26 +01:00
|
|
|
|
InitializeComponent();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
localServerTime1.Pool = pool;
|
|
|
|
|
chevronButton1.Text = Messages.SHOW_RUN_HISTORY;
|
|
|
|
|
chevronButton1.Image = Properties.Resources.PDChevronDown;
|
|
|
|
|
policyHistory1.Visible = false;
|
2016-02-15 05:35:26 +01:00
|
|
|
|
policyHistory1.pool = pool;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2016-02-15 05:35:26 +01:00
|
|
|
|
public VMProtectionPoliciesDialog() { }
|
|
|
|
|
|
|
|
|
|
protected virtual void chevronButton1_KeyDown(object sender, KeyEventArgs e) {}
|
|
|
|
|
protected virtual void chevronButton1_ButtonClick(object sender, EventArgs e) { }
|
|
|
|
|
protected virtual void buttonProperties_Click(object sender, EventArgs e) { }
|
|
|
|
|
protected virtual void button1_Click(object sender, EventArgs e) { }
|
|
|
|
|
protected virtual void buttonEnable_Click(object sender, EventArgs e) { }
|
|
|
|
|
protected virtual void VMProtectionPoliciesDialog_FormClosed(object sender, FormClosedEventArgs e) { }
|
|
|
|
|
protected virtual void dataGridView1_SelectionChanged(object sender, EventArgs e) { }
|
|
|
|
|
protected virtual void VMProtectionPoliciesDialog_Load(object sender, EventArgs e) { }
|
|
|
|
|
protected virtual void buttonCancel_Click(object sender, System.EventArgs e) { }
|
|
|
|
|
protected virtual void buttonNew_Click(object sender, System.EventArgs e) { }
|
|
|
|
|
protected virtual void buttonDelete_Click(object sender, EventArgs e) { }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PolicyRow : DataGridViewRow
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
private DataGridViewTextBoxCell _name = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell _numVMs = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell _nextRunTime = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell _status = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell _nextArchiveRuntime = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextAndImageCell _lastResult = new DataGridViewTextAndImageCell();
|
2016-02-18 11:49:40 +01:00
|
|
|
|
public readonly IVMPolicy _policy;
|
2016-02-15 05:35:26 +01:00
|
|
|
|
public PolicyRow(IVMPolicy policy)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Cells.Add(_name);
|
|
|
|
|
Cells.Add(_status);
|
|
|
|
|
Cells.Add(_numVMs);
|
|
|
|
|
Cells.Add(_nextRunTime);
|
2016-01-29 12:34:44 +01:00
|
|
|
|
Cells.Add(_nextArchiveRuntime);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Cells.Add(_lastResult);
|
2016-02-18 11:49:40 +01:00
|
|
|
|
_policy = policy;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
RefreshRow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DateTime? GetVMPPDateTime(Func<DateTime> getDateTimeFunc)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return getDateTimeFunc();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Error("An error occurred while obtaining VMPP date time: ", e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshRow()
|
|
|
|
|
{
|
2016-02-18 11:49:40 +01:00
|
|
|
|
_name.Value = _policy.Name;
|
|
|
|
|
_numVMs.Value = _policy.VMs.FindAll(vm => _policy.Connection.Resolve(vm).is_a_real_vm).Count;
|
|
|
|
|
_status.Value = _policy.is_enabled ? Messages.ENABLED : Messages.DISABLED;
|
|
|
|
|
if (_policy.is_running)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_status.Value = Messages.RUNNING_SNAPSHOTS;
|
2016-02-18 11:49:40 +01:00
|
|
|
|
if (this._policy.hasArchive)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2016-02-18 11:49:40 +01:00
|
|
|
|
if (_policy.is_archiving)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
_status.Value = Messages.RUNNING_ARCHIVE;
|
|
|
|
|
}
|
2016-02-18 11:49:40 +01:00
|
|
|
|
_lastResult.Value = _policy.LastResult;
|
|
|
|
|
if (_policy.LastResult == Messages.FAILED)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_lastResult.Image = Properties.Resources._075_WarningRound_h32bit_16;
|
2016-02-18 11:49:40 +01:00
|
|
|
|
else if (_policy.LastResult == Messages.NOT_YET_RUN)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_lastResult.Image = null;
|
|
|
|
|
else
|
|
|
|
|
_lastResult.Image = Properties.Resources._075_TickRound_h32bit_16;
|
|
|
|
|
|
2016-02-18 11:49:40 +01:00
|
|
|
|
DateTime? nextRunTime = GetVMPPDateTime(() => _policy.GetNextRunTime());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
_nextRunTime.Value = nextRunTime.HasValue
|
|
|
|
|
? HelpersGUI.DateTimeToString(nextRunTime.Value, Messages.DATEFORMAT_DMY_HM,
|
|
|
|
|
true)
|
|
|
|
|
: Messages.VM_PROTECTION_POLICY_HOST_NOT_LIVE;
|
2016-02-18 11:49:40 +01:00
|
|
|
|
if (this._policy.hasArchive)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2016-02-18 11:49:40 +01:00
|
|
|
|
DateTime? nextArchiveRuntime = GetVMPPDateTime(() => _policy.GetNextArchiveRunTime());
|
2016-02-15 05:35:26 +01:00
|
|
|
|
_nextArchiveRuntime.Value = nextArchiveRuntime.HasValue
|
|
|
|
|
? nextArchiveRuntime == DateTime.MinValue
|
|
|
|
|
? Messages.NEVER
|
|
|
|
|
: HelpersGUI.DateTimeToString(nextArchiveRuntime.Value,
|
|
|
|
|
Messages.DATEFORMAT_DMY_HM, true)
|
|
|
|
|
: Messages.VM_PROTECTION_POLICY_HOST_NOT_LIVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Dialogs.VMPolicies
|
|
|
|
|
{
|
|
|
|
|
public class VMPoliciesDialogSpecific<T> : XenAdmin.Dialogs.VMProtection_Recovery.VMProtectionPoliciesDialog where T : XenObject<T>
|
|
|
|
|
{
|
|
|
|
|
public VMPoliciesDialogSpecific() { }
|
|
|
|
|
public VMPoliciesDialogSpecific(Pool pool)
|
|
|
|
|
: base(pool)
|
|
|
|
|
{
|
|
|
|
|
RefreshPoolTitle(pool);
|
2016-02-17 09:02:24 +01:00
|
|
|
|
if (VMGroup<T>.isVMPolicyVMPP)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
SetupDeprecationBanner();
|
2016-02-17 09:02:24 +01:00
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
|
|
|
|
private void RefreshPoolTitle(Pool pool)
|
|
|
|
|
{
|
|
|
|
|
int protectedVMs = 0;
|
|
|
|
|
int realVMs = 0;
|
|
|
|
|
|
2016-02-17 09:02:24 +01:00
|
|
|
|
foreach (var vm in pool.Connection.Cache.VMs)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2016-02-17 09:02:24 +01:00
|
|
|
|
if (vm.is_a_real_vm && vm.Show(Properties.Settings.Default.ShowHiddenVMs))
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2016-02-17 09:02:24 +01:00
|
|
|
|
realVMs++;
|
|
|
|
|
if (vm.Connection.Resolve(VMGroup<T>.VmToGroup(vm)) != null)
|
|
|
|
|
protectedVMs++;
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-17 09:02:24 +01:00
|
|
|
|
this.Text = VMGroup<T>.VMPolicyDialogTitle;
|
|
|
|
|
label2.Text = VMGroup<T>.VMPolicyDialogText;
|
|
|
|
|
labelPolicyTitle.Text = string.Format(Helpers.IsPool(pool.Connection)
|
|
|
|
|
? VMGroup<T>.VMPolicyDialogSchedulesInPool
|
|
|
|
|
: VMGroup<T>.VMPolicyDialogSchedulesInServer,
|
|
|
|
|
pool.Name.Ellipsise(45), protectedVMs, realVMs);
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VMPPCollectionChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadPolicies();
|
|
|
|
|
}
|
2016-01-29 12:34:44 +01:00
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
private void LoadPolicies()
|
|
|
|
|
{
|
|
|
|
|
dataGridView1.SuspendLayout();
|
|
|
|
|
var selectedPolicy = currentSelected;
|
|
|
|
|
dataGridView1.Rows.Clear();
|
2016-03-29 07:54:53 +02:00
|
|
|
|
var policyList = VMGroup<T>.VMPolicies(Pool.Connection.Cache);
|
|
|
|
|
|
|
|
|
|
/* creating a dictionary to hold (policy_uuid, message list) */
|
|
|
|
|
|
|
|
|
|
Dictionary<string, List<XenAPI.Message>> policyMessage = new Dictionary<string, List<XenAPI.Message>>();
|
|
|
|
|
|
|
|
|
|
/* populate the dictionary with policy uuid */
|
|
|
|
|
|
|
|
|
|
foreach (var policy in policyList)
|
|
|
|
|
{
|
|
|
|
|
policy.PolicyAlerts.Clear();
|
|
|
|
|
List<XenAPI.Message> messageList = new List<XenAPI.Message>();
|
|
|
|
|
policyMessage.Add(policy.uuid, messageList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* iterate through all messages and populate the dictionary with message list */
|
2016-02-17 09:02:24 +01:00
|
|
|
|
|
2016-02-18 11:49:40 +01:00
|
|
|
|
if (!VMGroup<T>.isVMPolicyVMPP)
|
|
|
|
|
{
|
|
|
|
|
var messages = Pool.Connection.Cache.Messages;
|
2016-03-29 07:54:53 +02:00
|
|
|
|
List<XenAPI.Message> value = new List<XenAPI.Message>();
|
|
|
|
|
|
2016-02-18 11:49:40 +01:00
|
|
|
|
foreach (var message in messages)
|
|
|
|
|
{
|
|
|
|
|
if (message.cls == cls.VMSS)
|
|
|
|
|
{
|
2016-03-29 07:54:53 +02:00
|
|
|
|
if (policyMessage.TryGetValue(message.obj_uuid, out value))
|
|
|
|
|
{
|
|
|
|
|
value.Add(message);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 11:49:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-29 07:54:53 +02:00
|
|
|
|
|
|
|
|
|
/* add only 10 messages for each policy and referesh the rows*/
|
2016-04-06 06:08:11 +02:00
|
|
|
|
|
2016-03-29 07:54:53 +02:00
|
|
|
|
foreach (var policy in policyList)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2016-04-06 06:08:11 +02:00
|
|
|
|
/* message list need not be always sorted */
|
|
|
|
|
|
|
|
|
|
var messageListSorted = policyMessage[policy.uuid].OrderByDescending(message => message.timestamp).ToList();
|
|
|
|
|
for (int messageCount = 0; messageCount < 10 && messageCount < messageListSorted.Count; messageCount++)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2017-01-10 07:18:18 +01:00
|
|
|
|
policy.PolicyAlerts.Add(new PolicyAlert(messageListSorted[messageCount].priority, messageListSorted[messageCount].name, messageListSorted[messageCount].timestamp, messageListSorted[messageCount].body, policy.Name));
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
2016-04-06 06:08:11 +02:00
|
|
|
|
if (dataGridView1.ColumnCount > 0)
|
|
|
|
|
dataGridView1.Rows.Add(new PolicyRow(policy));
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
2016-03-29 07:54:53 +02:00
|
|
|
|
|
|
|
|
|
RefreshButtons();
|
2016-02-15 05:35:26 +01:00
|
|
|
|
if (selectedPolicy != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (PolicyRow row in dataGridView1.Rows)
|
|
|
|
|
{
|
2016-02-18 11:49:40 +01:00
|
|
|
|
if (row._policy.uuid == selectedPolicy.uuid)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
|
|
|
|
dataGridView1.ClearSelection();
|
|
|
|
|
row.Selected = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2016-02-15 05:35:26 +01:00
|
|
|
|
RefreshPoolTitle(Pool);
|
|
|
|
|
dataGridView1.ResumeLayout();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void buttonNew_Click(object sender, System.EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-02-15 05:35:26 +01:00
|
|
|
|
new NewPolicyWizardSpecific<T>(Pool).Show(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
protected override void buttonCancel_Click(object sender, System.EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
protected override void VMProtectionPoliciesDialog_Load(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-02-17 09:02:24 +01:00
|
|
|
|
if (!VMGroup<T>.isVMPolicyVMPP)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
|
|
|
|
this.dataGridView1.Columns["ColumnNextArchive"].Visible = false;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
LoadPolicies();
|
|
|
|
|
localServerTime1.GetServerTime();
|
2016-02-15 05:35:26 +01:00
|
|
|
|
Pool.Connection.Cache.RegisterBatchCollectionChanged<T>(VMPPCollectionChanged);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
protected override void buttonDelete_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-02-17 09:02:24 +01:00
|
|
|
|
var selectedPolicies = new List<IVMPolicy>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
int numberOfProtectedVMs = 0;
|
|
|
|
|
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
|
|
|
|
|
{
|
2016-02-18 11:49:40 +01:00
|
|
|
|
var policy = (((PolicyRow)row)._policy);
|
2016-02-17 09:02:24 +01:00
|
|
|
|
selectedPolicies.Add(policy);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
numberOfProtectedVMs += policy.VMs.Count;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
string text = "";
|
|
|
|
|
if (selectedPolicies.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
text = String.Format(numberOfProtectedVMs == 0 ? Messages.CONFIRM_DELETE_POLICY_0 : Messages.CONFIRM_DELETE_POLICY, selectedPolicies[0].Name, numberOfProtectedVMs);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
text = string.Format(numberOfProtectedVMs == 0 ? Messages.CONFIRM_DELETE_POLICIES_0 : Messages.CONFIRM_DELETE_POLICIES, numberOfProtectedVMs);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 11:49:12 +02:00
|
|
|
|
using (var dlg = new ThreeButtonDialog(
|
2013-06-24 13:41:48 +02:00
|
|
|
|
new ThreeButtonDialog.Details(SystemIcons.Warning, text, Messages.DELETE_VM_PROTECTION_TITLE),
|
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
2016-06-20 11:49:12 +02:00
|
|
|
|
ThreeButtonDialog.ButtonNo))
|
|
|
|
|
{
|
|
|
|
|
if (dlg.ShowDialog(this) == DialogResult.Yes)
|
2017-01-25 03:26:51 +01:00
|
|
|
|
new DestroyPolicyAction<T>(Pool.Connection, selectedPolicies).RunAsync();
|
2016-06-20 11:49:12 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
private IVMPolicy currentSelected = null;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
protected override void dataGridView1_SelectionChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
RefreshButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshButtons()
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView1.SelectedRows.Count == 1)
|
|
|
|
|
{
|
2016-02-18 11:49:40 +01:00
|
|
|
|
currentSelected = ((PolicyRow)dataGridView1.SelectedRows[0])._policy;
|
2016-02-16 10:49:39 +01:00
|
|
|
|
buttonEnable.Text = currentSelected.is_enabled? Messages.DISABLE : Messages.ENABLE;
|
|
|
|
|
buttonEnable.Enabled = currentSelected.VMs.Count == 0 && !currentSelected.is_enabled? false : true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
buttonProperties.Enabled = true;
|
2016-02-16 10:49:39 +01:00
|
|
|
|
buttonRunNow.Enabled = currentSelected.is_enabled && !currentSelected.is_archiving && !currentSelected.is_running;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentSelected = null;
|
|
|
|
|
buttonProperties.Enabled = buttonEnable.Enabled = buttonRunNow.Enabled = false;
|
|
|
|
|
policyHistory1.Clear();
|
|
|
|
|
}
|
2016-02-16 10:49:39 +01:00
|
|
|
|
|
|
|
|
|
policyHistory1.RefreshTab(currentSelected);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
buttonDelete.Enabled = (dataGridView1.SelectedRows.Count != 0);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
protected override void VMProtectionPoliciesDialog_FormClosed(object sender, FormClosedEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-02-15 05:35:26 +01:00
|
|
|
|
Pool.Connection.Cache.DeregisterBatchCollectionChanged<T>(VMPPCollectionChanged);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
protected override void buttonEnable_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (currentSelected != null)
|
|
|
|
|
{
|
2016-02-17 09:02:24 +01:00
|
|
|
|
var action = new ChangePolicyEnabledAction<T>(currentSelected);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
action.RunAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-15 05:35:26 +01:00
|
|
|
|
|
|
|
|
|
protected override void button1_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (dataGridView1.SelectedRows.Count == 1)
|
|
|
|
|
{
|
2016-02-18 11:49:40 +01:00
|
|
|
|
var policy = ((PolicyRow)dataGridView1.SelectedRows[0])._policy;
|
2016-02-17 09:02:24 +01:00
|
|
|
|
var action = new RunPolicyNowAction<T>(policy);
|
2013-08-05 15:28:21 +02:00
|
|
|
|
action.Completed += action_Completed;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
buttonRunNow.Enabled = false;
|
|
|
|
|
action.RunAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 15:28:21 +02:00
|
|
|
|
void action_Completed(ActionBase sender)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-05 15:28:21 +02:00
|
|
|
|
Program.Invoke(Program.MainWindow, RefreshButtons);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetupDeprecationBanner()
|
|
|
|
|
{
|
2016-02-15 05:35:26 +01:00
|
|
|
|
if (deprecationBanner != null && !Helpers.ClearwaterOrGreater(Pool.Connection))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
deprecationBanner.AppliesToVersion = Messages.XENSERVER_6_2;
|
|
|
|
|
deprecationBanner.BannerType = DeprecationBanner.Type.Removal;
|
|
|
|
|
deprecationBanner.FeatureName = Messages.VMPP;
|
2016-01-28 22:43:15 +01:00
|
|
|
|
deprecationBanner.LinkUri = HiddenFeatures.LinkLabelHidden ? null : new Uri(InvisibleMessages.VMPR_DEPRECATION_URL);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
deprecationBanner.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
protected override void buttonProperties_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-02-16 10:49:39 +01:00
|
|
|
|
using (PropertiesDialog propertiesDialog = new PropertiesDialog((T)currentSelected))
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2016-02-16 10:49:39 +01:00
|
|
|
|
propertiesDialog.ShowDialog(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
protected override void chevronButton1_ButtonClick(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (chevronButton1.Text == Messages.HIDE_RUN_HISTORY)
|
|
|
|
|
{
|
2016-02-15 05:35:26 +01:00
|
|
|
|
chevronButton1.Text = Messages.SHOW_RUN_HISTORY;
|
|
|
|
|
chevronButton1.Image = Properties.Resources.PDChevronDown;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
policyHistory1.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-15 05:35:26 +01:00
|
|
|
|
chevronButton1.Text = Messages.HIDE_RUN_HISTORY;
|
|
|
|
|
chevronButton1.Image = Properties.Resources.PDChevronUp;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
policyHistory1.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
protected override void chevronButton1_KeyDown(object sender, KeyEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Space)
|
|
|
|
|
chevronButton1_ButtonClick(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 11:10:25 +02:00
|
|
|
|
internal override string HelpName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!VMGroup<T>.isVMPolicyVMPP)
|
|
|
|
|
{
|
|
|
|
|
return "VMSnapshotSchedulesDialog";
|
|
|
|
|
}
|
|
|
|
|
return "VMProtectionPoliciesDialog";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|