private void RefreshTab(T group) { ColumnQuiesceSupported.Visible = VMGroup <T> .isQuescingSupported; _group = group; if (Pool != null) { dataGridView1.Rows.Clear(); foreach (var vm in Pool.Connection.Cache.VMs) { int index = 0; if (vm.is_a_real_vm() && vm.Show(Properties.Settings.Default.ShowHiddenVMs)) { bool selected = group != null && VMGroup <T> .GroupToVMs(group).Contains(new XenRef <VM>(vm.opaque_ref)); index = dataGridView1.Rows.Add(new VMDataGridViewRow(selected, vm)); if (SelectedVMs.Contains(vm)) { dataGridView1.Rows[index].Cells[0].Value = true; } else if (selected && !SelectedVMs.Contains(vm)) { SelectedVMs.Add(vm); } } } dataGridView1.Sort(ColumnCheckBox, ListSortDirection.Ascending); dataGridView1.AutoResizeColumns(); } UpdateCounterLabelAndButtons(); }
/// <summary> /// Find out if any VMs are already assigned to a different group, and if so, check they can be moved /// </summary> /// <param name="vms">All the VMs to be assigned to the group</param> /// <param name="group">The group to assign the VMs to (null for a new group)</param> /// <param name="groupName">The name of the group to assign the VMs to</param> /// <returns>Whether the user is happy to proceed</returns> public static bool ChangesOK(List <VM> vms, T group, string groupName) { var vmsWithExistingGroup = vms.FindAll(vm => { T oldGroup = vm.Connection.Resolve(VMGroup <T> .VmToGroup(vm)); return(oldGroup != null && (group == null || oldGroup.opaque_ref != group.opaque_ref)); }); if (vmsWithExistingGroup.Count == 0) { return(true); } string text; if (vmsWithExistingGroup.Count == 1) { VM vm = vmsWithExistingGroup[0]; T oldGroup = vm.Connection.Resolve(VMGroup <T> .VmToGroup(vm)); text = string.Format(VMGroup <T> .ChangeOneWarningString, vm.Name.Ellipsise(250), oldGroup.Name.Ellipsise(250), groupName.Ellipsise(250)); } else { text = string.Format(VMGroup <T> .ChangeMultipleWarningString, groupName.Ellipsise(250)); } return(new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Warning, text, VMGroup <T> .ChangeVMsGroupString), ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo). ShowDialog() == DialogResult.Yes); }
protected override void ExecuteCore(SelectedItemCollection selection) { // remove single VM from group if (selection.Count == 1) { XenRef <VM> vmRefInGroup = VMGroup <T> .GroupToVMs(_group).FirstOrDefault(vmRef => vmRef.opaque_ref == selection[0].XenObject.opaque_ref); if (vmRefInGroup != null) { var vmRefs = new List <XenRef <VM> > { vmRefInGroup }; VMGroup <T> .RemoveVMsFromGroupAction(_group, vmRefs).RunAsync(); return; } } if (!ChangesOK(selection.AsXenObjects <VM>(), _group, _group.Name)) { return; } var selectedRefVMs = selection.AsXenObjects().ConvertAll <XenRef <VM> >(converterVMRefs); selectedRefVMs.AddRange(VMGroup <T> .GroupToVMs(_group)); VMGroup <T> .AssignVMsToGroupAction(_group, selectedRefVMs).RunAsync(); }
private void MoveToGroup(object item) { ObservableCollection <object> tree = new ObservableCollection <object> (); tree.Add(VMModel.GetInstance().RootVMGroup); MoveToGroupDialog dlg = new MoveToGroupDialog(tree); dlg.Owner = Window1.GetWindow(View.Parent); dlg.ShowDialog(); if (dlg.DialogResult.HasValue && dlg.DialogResult.Value) { //only VMGroup selected VMGroup group = dlg.CheckedItem as VMGroup; if ((item is VMGroup) && (ActiveVMList.Count == 0)) { model.MoveToGroup(item as VMGroup, group); group.Save(); } else {//Some VM in Group selected or single VM is selected on tree model.MoveToGroup(ActiveVMList, group); model.ActiveVMList.Clear(); group.Save(); } } }
protected override void OnDropDownOpening(EventArgs e) { base.DropDownItems.Clear(); var cmd = new NewGroupCommand(Command.MainWindowCommandInterface, Command.GetSelection()); var item = new CommandToolStripMenuItem(cmd); base.DropDownItems.Add(item); T[] groups = VMGroup <T> .GroupsInCache(Command.GetSelection()[0].Connection.Cache); if (groups.Length > 0) { base.DropDownItems.Add(new ToolStripSeparator()); } Array.Sort(groups); for (int index = 0; index < groups.Length; index++) { T group = groups[index]; var menuText = index < 9 ? String.Format(Messages.DYNAMIC_MENUITEM_WITH_ACCESS_KEY, index + 1, group.Name) : String.Format(Messages.DYNAMIC_MENUITEM_WITHOUT_ACCESS_KEY, group.Name); var cmdGroup = new AssignGroupToVMCommand(Command.MainWindowCommandInterface, Command.GetSelection(), group, menuText); var itemGroup = new CommandToolStripMenuItem(cmdGroup); if (Command.GetSelection().Count == 1 && VMGroup <T> .VmToGroup((VM)Command.GetSelection()[0].XenObject).opaque_ref == group.opaque_ref) { itemGroup.Checked = true; } base.DropDownItems.Add(itemGroup); } }
void Refresh(bool selected) { _selectedCell.Value = selected; _nameCell.Value = Vm.Name; _descriptionCell.Value = Vm.Description; T group = Vm.Connection.Resolve(VMGroup <T> .VmToGroup(Vm)); _currentGroupCell.Value = group == null ? Messages.NONE : group.Name; }
protected override bool CanExecuteCore(SelectedItemCollection selection) { if (typeof(T) == typeof(VMSS) && selection.Any(s => !Helpers.FalconOrGreater(s.Connection))) { return(false); } return(selection.FirstAsXenObject != null && selection.FirstAsXenObject.Connection != null && selection.FirstAsXenObject.Connection.IsConnected && VMGroup <T> .FeaturePossible(selection.FirstAsXenObject.Connection) && (selection.PoolAncestor != null || selection.HostAncestor != null)); //CA-61207: this check ensures there's no cross-pool selection }
public VMDataGridViewRow(bool selected, VM vm) { Vm = vm; Cells.Add(_selectedCell); Cells.Add(_nameCell); Cells.Add(_descriptionCell); Cells.Add(_currentGroupCell); if (VMGroup <T> .IsQuiescingSupported(vm.Connection)) { _quiesce_supported = new DataGridViewTextBoxCell(); Cells.Add(_quiesce_supported); } Refresh(selected); }
protected override void OnDropDownOpening(EventArgs e) { base.DropDownItems.Clear(); var cmd = new NewGroupCommand(Command.MainWindowCommandInterface, Command.GetSelection()); var item = new CommandToolStripMenuItem(cmd); base.DropDownItems.Add(item); T[] groups = VMGroup <T> .GroupsInCache(Command.GetSelection()[0].Connection.Cache); if (groups.Length > 0) { base.DropDownItems.Add(new ToolStripSeparator()); } Array.Sort(groups); for (int index = 0, offset = 0; index < groups.Length; index++) { T group = groups[index]; /* do not add unsupported policies to the drop down for VMSS */ XenAPI.VMSS policy = group as VMSS; if (policy != null && policy.policy_type == policy_backup_type.snapshot_with_quiesce) { List <VM> vms = Command.GetSelection().AsXenObjects <VM>(); bool doNotInclude = vms.Any(vm => !vm.allowed_operations.Contains(vm_operations.snapshot_with_quiesce)); if (doNotInclude) { offset--; continue; } } var menuText = (index + offset) < 9 ? String.Format(Messages.DYNAMIC_MENUITEM_WITH_ACCESS_KEY, (index + offset) + 1, group.Name) : String.Format(Messages.DYNAMIC_MENUITEM_WITHOUT_ACCESS_KEY, group.Name); var cmdGroup = new AssignGroupToVMCommand(Command.MainWindowCommandInterface, Command.GetSelection(), group, menuText); var itemGroup = new CommandToolStripMenuItem(cmdGroup); if (Command.GetSelection().Count == 1 && VMGroup <T> .VmToGroup((VM)Command.GetSelection()[0].XenObject).opaque_ref == group.opaque_ref) { itemGroup.Checked = true; } base.DropDownItems.Add(itemGroup); } }
protected override string GetCantExecuteReasonCore(SelectedItem item) { Pool poolAncestor = item.PoolAncestor; if (poolAncestor != null) { string reason = VMGroup <T> .CantExecuteReason(poolAncestor.Connection); if (!string.IsNullOrEmpty(reason)) { return(reason); } } return(base.GetCantExecuteReasonCore(item)); }
void Refresh(bool selected) { _selectedCell.Value = selected; _nameCell.Value = Vm.Name(); _descriptionCell.Value = Vm.Description(); T group = Vm.Connection.Resolve(VMGroup <T> .VmToGroup(Vm)); _currentGroupCell.Value = group == null ? Messages.NONE : group.Name(); if (VMGroup <T> .isQuescingSupported) { if (Vm.allowed_operations.Contains((vm_operations.snapshot_with_quiesce)) && !Helpers.FeatureForbidden(Vm, Host.RestrictVss)) { _quiesce_supported.Value = Messages.YES; } else { _quiesce_supported.Value = Messages.NO; } } }
/// <summary> /// Find out if any VMs are already assigned to a different group, and if so, check they can be moved /// </summary> /// <param name="vms">All the VMs to be assigned to the group</param> /// <param name="group">The group to assign the VMs to (null for a new group)</param> /// <param name="groupName">The name of the group to assign the VMs to</param> /// <returns>Whether the user is happy to proceed</returns> public static bool ChangesOK(List <VM> vms, T group, string groupName) { var vmsWithExistingGroup = vms.FindAll(vm => { T oldGroup = vm.Connection.Resolve(VMGroup <T> .VmToGroup(vm)); return(oldGroup != null && (group == null || oldGroup.opaque_ref != group.opaque_ref)); }); if (vmsWithExistingGroup.Count == 0) { return(true); } string text; if (vmsWithExistingGroup.Count == 1) { VM vm = vmsWithExistingGroup[0]; T oldGroup = vm.Connection.Resolve(VMGroup <T> .VmToGroup(vm)); text = string.Format(VMGroup <T> .ChangeOneWarningString, vm.Name().Ellipsise(250), oldGroup.Name().Ellipsise(250), groupName.Ellipsise(250)); } else { text = string.Format(VMGroup <T> .ChangeMultipleWarningString, groupName.Ellipsise(250)); } DialogResult dialogResult; using (var dlg = new WarningDialog(text, ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo) { WindowTitle = VMGroup <T> .ChangeVMsGroupString }) { dialogResult = dlg.ShowDialog(); } return(dialogResult == DialogResult.Yes); }
protected override void FinishWizard() { var action = VMGroup <T> .VMCreateObjectAction( xenTabPagePolicy.PolicyName, xenTabPagePolicy.PolicyDescription, xenTabPageSnapshotType.BackupType, xenTabPageSnapshotFrequency.Frequency, xenTabPageSnapshotFrequency.Schedule, xenTabPageSnapshotFrequency.BackupRetention, xenTabPageArchive != null?xenTabPageArchive.ArchiveFrequency : vmpp_archive_frequency.unknown, xenTabPageArchive != null?xenTabPageArchive.ArchiveConfig : null, xenTabPageArchive != null?xenTabPageArchive.ArchiveTargetType : vmpp_archive_target_type.unknown, xenTabPageArchive != null?xenTabPageArchive.Schedule : null, xenTabPageEmail != null?xenTabPageEmail.EmailEnabled : false, xenTabPageEmail != null?xenTabPageEmail.EmailSettings : null, xenTabPageVMsPage.SelectedVMs.Count == 0?false : true, xenTabPageVMsPage.SelectedVMs, xenTabPageFinish.RunNow, Pool.Connection); action.RunAsync(); base.FinishWizard(); }
private void RefreshPoolTitle(Pool pool) { int protectedVMs = 0; int realVMs = 0; foreach (var vm in pool.Connection.Cache.VMs) { if (vm.is_a_real_vm && vm.Show(Properties.Settings.Default.ShowHiddenVMs)) { realVMs++; if (vm.Connection.Resolve(VMGroup <T> .VmToGroup(vm)) != null) { protectedVMs++; } } } 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); }
public override AsyncAction SaveSettings() { return(VMGroup <T> .AssignVMsToGroupAction(_clone, SelectedVMsRefs, true)); }
public bool CanExecute(VM vm) { return(vm != null && vm.is_a_real_vm && !vm.Locked && VMGroup <T> .FeaturePossible(vm.Connection) && !Helpers.FeatureForbidden(vm.Connection, VMGroup <T> .FeatureRestricted)); }
protected override void ExecuteCore(SelectedItemCollection selection) { MainWindowCommandInterface.ShowPerConnectionWizard(selection[0].Connection, VMGroup <T> .NewGroupWizard(Helpers.GetPoolOfOne(selection[0].Connection), selection.AsXenObjects <VM>())); }
public VMGroupViewModel(VMGroup vmGrp) : base(vmGrp) { }
private void LoadPolicies() { dataGridView1.SuspendLayout(); var selectedPolicy = currentSelected; dataGridView1.Rows.Clear(); 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 */ if (!VMGroup <T> .isVMPolicyVMPP) { var messages = Pool.Connection.Cache.Messages; List <XenAPI.Message> value = new List <XenAPI.Message>(); foreach (var message in messages) { if (message.cls == cls.VMSS) { if (policyMessage.TryGetValue(message.obj_uuid, out value)) { value.Add(message); } } } } /* add only 10 messages for each policy and referesh the rows*/ foreach (var policy in policyList) { /* 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++) { policy.PolicyAlerts.Add(new PolicyAlert(messageListSorted[messageCount].priority, messageListSorted[messageCount].name, messageListSorted[messageCount].timestamp, messageListSorted[messageCount].body, policy.Name)); } if (dataGridView1.ColumnCount > 0) { dataGridView1.Rows.Add(new PolicyRow(policy)); } } RefreshButtons(); if (selectedPolicy != null) { foreach (PolicyRow row in dataGridView1.Rows) { if (row._policy.uuid == selectedPolicy.uuid) { dataGridView1.ClearSelection(); row.Selected = true; break; } } } RefreshPoolTitle(Pool); dataGridView1.ResumeLayout(); }
protected override void ExecuteCore(SelectedItemCollection selection) { var pool = Helpers.GetPoolOfOne(selection.FirstAsXenObject.Connection); if (pool != null) { if (Helpers.FeatureForbidden(pool.Connection, VMGroup <T> .FeatureRestricted)) { ShowUpsellDialog(Parent); } else { this.MainWindowCommandInterface.ShowPerConnectionWizard(pool.Connection, VMGroup <T> .ManageGroupsDialog(pool)); } } }