private void EnableAppropriateHostsNoWlb(Session session) { SelectedItemCollection selection = Command.GetSelection(); IXenConnection connection = selection[0].Connection; VMOperationCommand cmdHome = new VMOperationHomeServerCommand(Command.MainWindowCommandInterface, selection, _operation, session); Host affinityHost = connection.Resolve(((VM)Command.GetSelection()[0].XenObject).affinity); VMOperationCommand cpmCmdHome = new CrossPoolMigrateToHomeCommand(Command.MainWindowCommandInterface, selection, affinityHost); Program.Invoke(Program.MainWindow, delegate { var firstItem = (VMOperationToolStripMenuSubItem)base.DropDownItems[0]; bool oldMigrateToHomeCmdCanRun = cmdHome.CanExecute(); if (affinityHost == null || _operation == vm_operations.start_on || !oldMigrateToHomeCmdCanRun && !cpmCmdHome.CanExecute()) { firstItem.Command = cmdHome; } else { firstItem.Command = oldMigrateToHomeCmdCanRun ? cmdHome : cpmCmdHome; } }); List <VMOperationToolStripMenuSubItem> dropDownItems = DropDownItems.Cast <VMOperationToolStripMenuSubItem>().ToList(); // Adds the migrate wizard button, do this before the enable checks on the other items Program.Invoke(Program.MainWindow, () => AddAdditionalMenuItems(selection)); foreach (VMOperationToolStripMenuSubItem item in dropDownItems) { if (_isDropDownClosed) { // Stop making requests to assert can start on each host after dropdown is closed break; } Host host = item.Tag as Host; if (host != null) { VMOperationCommand cmd = new VMOperationHostCommand(Command.MainWindowCommandInterface, selection, delegate { return(host); }, host.Name().EscapeAmpersands(), _operation, session); CrossPoolMigrateCommand cpmCmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, host, _resumeAfter); VMOperationToolStripMenuSubItem tempItem = item; Program.Invoke(Program.MainWindow, delegate { bool oldMigrateCmdCanRun = cmd.CanExecute(); if (_operation == vm_operations.start_on || (!oldMigrateCmdCanRun && !cpmCmd.CanExecute() && string.IsNullOrEmpty(cpmCmd.CantExecuteReason))) { tempItem.Command = cmd; } else { tempItem.Command = oldMigrateCmdCanRun ? cmd : cpmCmd; } }); } } }
public static void StartDiagnosisForm(VM vm, bool isStart) { ThreadPool.QueueUserWorkItem(delegate { string title = Messages.ERROR_DIALOG_START_VM_TITLE; string text = string.Format(Messages.ERROR_DIALOG_START_VM_TEXT, vm); if (Win32Window.GetWindowWithText(title) != null) { // don't bother showing this if there's one already up. return; } var connection = vm.Connection; Session session; try { session = connection.DuplicateSession(); if (session == null) { return; } } catch (Exception) { return; } var reasons = new Dictionary <IXenObject, string>(); foreach (Host host in connection.Cache.Hosts) { reasons[host] = string.Empty; if (!isStart && VMOperationHostCommand.VmCpuIncompatibleWithHost(host, vm)) { reasons[host] = FriendlyErrorNames.VM_INCOMPATIBLE_WITH_THIS_HOST; continue; } try { VM.assert_can_boot_here(session, vm.opaque_ref, host.opaque_ref); } catch (Failure failure) { reasons[host] = failure.Message; } catch (Exception e) { log.ErrorFormat("There was an error calling assert_can_boot_here on host {0}: {1}", host.Name(), e.Message); reasons[host] = Messages.HOST_MENU_UNKNOWN_ERROR; } } Program.Invoke(Program.MainWindow, () => { using (var dialog = new CommandErrorDialog(title, text, reasons)) dialog.ShowDialog(Program.MainWindow); }); }); }
private void EnableAppropriateHostsNoWlb(Session session) { SelectedItemCollection selection = Command.GetSelection(); IXenConnection connection = selection[0].Connection; VMOperationCommand cmdHome = new VMOperationHomeServerCommand(Command.MainWindowCommandInterface, selection, _operation, session); Host affinityHost = connection.Resolve(((VM)Command.GetSelection()[0].XenObject).affinity); VMOperationCommand cpmCmdHome = new CrossPoolMigrateToHomeCommand(Command.MainWindowCommandInterface, selection, affinityHost); Program.Invoke(Program.MainWindow, delegate { var firstItem = (VMOperationToolStripMenuSubItem)base.DropDownItems[0]; bool oldMigrateToHomeCmdCanRun = cmdHome.CanExecute(); if (affinityHost == null || _operation == vm_operations.start_on || !oldMigrateToHomeCmdCanRun && !cpmCmdHome.CanExecute()) { firstItem.Command = cmdHome; } else { firstItem.Command = oldMigrateToHomeCmdCanRun ? cmdHome : cpmCmdHome; } }); List <VMOperationToolStripMenuSubItem> dropDownItems = DropDownItems.Cast <VMOperationToolStripMenuSubItem>().ToList(); foreach (VMOperationToolStripMenuSubItem item in dropDownItems) { if (item.Tag is Host) { Host host = (Host)item.Tag; string hostNameText = host.Name.EscapeAmpersands(); VMOperationCommand cmd = new VMOperationHostCommand(Command.MainWindowCommandInterface, selection, delegate { return(host); }, hostNameText, _operation, session); VMOperationCommand cpmCmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, host) { MenuText = hostNameText }; VMOperationToolStripMenuSubItem tempItem = item; Program.Invoke(Program.MainWindow, delegate { bool oldMigrateCmdCanRun = cmd.CanExecute(); if (_operation == vm_operations.start_on || !oldMigrateCmdCanRun && !cpmCmd.CanExecute()) { tempItem.Command = cmd; } else { tempItem.Command = oldMigrateCmdCanRun ? cmd : cpmCmd; } }); } } Program.Invoke(Program.MainWindow, () => AddAdditionalMenuItems(selection)); }
protected override bool CanExecuteCore() { Host targetHost = GetTargetNodeAncestorAsXenObjectOrGroupingTag <Host>(); if (targetHost != null) { List <VM> draggedVMs = GetDraggedItemsAsXenObjects <VM>(); if (draggedVMs.Count > 0) { foreach (VM draggedVM in draggedVMs) { if (draggedVM == null || draggedVM.is_a_template || draggedVM.Locked || !(draggedVM.power_state == vm_power_state.Halted || draggedVM.power_state == vm_power_state.Suspended)) { return(false); } var draggedVMHome = draggedVM.Home(); if (draggedVMHome != null && draggedVMHome == targetHost) { return(false); } if (!targetHost.Connection.IsConnected) { return(false); } if (draggedVM.allowed_operations == null || !draggedVM.allowed_operations.Contains(vm_operations.migrate_send)) { return(false); } if (Helpers.productVersionCompare(Helpers.HostProductVersion(targetHost), Helpers.HostProductVersion(draggedVMHome ?? Helpers.GetMaster(draggedVM.Connection))) < 0) { return(false); } if (VMOperationHostCommand.VmCpuIncompatibleWithHost(targetHost, draggedVM)) { return(false); } } return(true); } } return(false); }
protected override bool CanExecuteCore() { Host targetHost = GetTargetNodeAncestorAsXenObjectOrGroupingTag <Host>(); if (targetHost != null) { List <VM> draggedVMs = GetDraggedItemsAsXenObjects <VM>(); if (draggedVMs.Count > 0) { foreach (VM draggedVM in draggedVMs) { if (draggedVM == null || draggedVM.is_a_template || draggedVM.Locked || !(draggedVM.power_state == vm_power_state.Halted || draggedVM.power_state == vm_power_state.Suspended)) { return(false); } var draggedVMHome = draggedVM.Home(); if (draggedVMHome != null && draggedVMHome == targetHost) { return(false); } if (!targetHost.Connection.IsConnected) { return(false); } if (draggedVM.allowed_operations == null || !draggedVM.allowed_operations.Contains(vm_operations.migrate_send)) { return(false); } if (VMOperationHostCommand.VmCpuFeaturesIncompatibleWithHost(targetHost, draggedVM)) { // target host does not offer some of the CPU features that the VM currently sees return(false); } } return(true); } } return(false); }
private void EnableAppropriateHostsNoWlb(Session session) { SelectedItemCollection selection = Command.GetSelection(); IXenConnection connection = selection[0].Connection; VMOperationCommand commandForFirstMenuItem = new VMOperationHomeServerCommand(Command.MainWindowCommandInterface, selection, _operation, session); Program.Invoke(Program.MainWindow, delegate { VMOperationToolStripMenuSubItem firstItem = (VMOperationToolStripMenuSubItem)base.DropDownItems[0]; firstItem.Command = commandForFirstMenuItem; }); List <VMOperationToolStripMenuSubItem> dropDownItems = DropDownItems.Cast <VMOperationToolStripMenuSubItem>().ToList(); foreach (VMOperationToolStripMenuSubItem item in dropDownItems) { if (item.Tag is Host) { Host host = (Host)item.Tag; VMOperationCommand cmd = new VMOperationHostCommand(Command.MainWindowCommandInterface, selection, delegate { return(host); }, host.Name.EscapeAmpersands(), _operation, session); VMOperationCommand cpmCmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, host) { MenuText = host.Name.EscapeAmpersands() }; VMOperationToolStripMenuSubItem tempItem = item; Program.Invoke(Program.MainWindow, delegate { bool oldMigrateCmdCanRun = cmd.CanExecute(); if (!oldMigrateCmdCanRun && !cpmCmd.CanExecute()) { tempItem.Command = cmd; } else { tempItem.Command = oldMigrateCmdCanRun ? cmd : cpmCmd; } }); } } Program.Invoke(Program.MainWindow, () => AddAdditionalMenuItems(selection)); }
public static void StartDiagnosisForm(VM vm, bool isStart) { ThreadPool.QueueUserWorkItem(delegate { string title = Messages.ERROR_DIALOG_START_VM_TITLE; string text = string.Format(Messages.ERROR_DIALOG_START_VM_TEXT, vm); if (Win32Window.GetWindowWithText(title) != null) { // don't bother showing this if there's one already up. return; } IXenConnection connection = vm.Connection; Session session = connection.DuplicateSession(); if (session != null) { Dictionary <Host, string> reasons = new Dictionary <Host, string>(); foreach (Host host in connection.Cache.Hosts) { reasons[host] = string.Empty; if (!isStart && VMOperationHostCommand.VmCpuFeaturesIncompatibleWithHost(host, vm)) { reasons[host] = FriendlyErrorNames.VM_INCOMPATIBLE_WITH_THIS_HOST; continue; } try { VM.assert_can_boot_here(session, vm.opaque_ref, host.opaque_ref); } catch (Failure failure) { reasons[host] = failure.Message; } } Program.Invoke(Program.MainWindow, () => CommandErrorDialog.Create <Host>(title, text, reasons).ShowDialog(Program.MainWindow)); } }); }
protected override bool CanExecuteCore() { Host targetHost = GetTargetNodeAncestorAsXenObjectOrGroupingTag <Host>(); if (targetHost != null) { List <VM> draggedVMs = GetDraggedItemsAsXenObjects <VM>(); if (draggedVMs.Count > 0) { foreach (VM draggedVM in draggedVMs) { Host draggedVMHome = draggedVM.Home(); if (draggedVM.Connection == null || !draggedVM.Connection.IsConnected) { return(false); } if (!LiveMigrateAllowedInVersion(targetHost, draggedVM)) { Pool targetPool = targetHost == null ? null : Helpers.GetPool(targetHost.Connection); if (targetPool == null) { return(false); } Pool draggedVMPool = Helpers.GetPool(draggedVM.Connection); if (draggedVMPool == null || draggedVMPool.opaque_ref != targetPool.opaque_ref) { // dragged VM must be in same pool as target return(false); } if (draggedVM.GetStorageHost(true) != null) { // dragged VM must be agile return(false); } } else { if (Helpers.FeatureForbidden(draggedVM.Connection, Host.RestrictIntraPoolMigrate)) { return(false); } } if (draggedVM.allowed_operations == null || !draggedVM.allowed_operations.Contains(vm_operations.pool_migrate)) { // migrate not allowed return(false); } if (draggedVMHome == null || draggedVMHome == targetHost) { // dragged VM must currently be shown below a host return(false); } if (Helpers.productVersionCompare(Helpers.HostProductVersion(targetHost), Helpers.HostProductVersion(draggedVMHome)) < 0) { return(false); } if (VMOperationHostCommand.VmCpuIncompatibleWithHost(targetHost, draggedVM)) { return(false); } } return(true); } } return(false); }
private void EnableAppropriateHostsNoWlb(Session session) { SelectedItemCollection selection = Command.GetSelection(); IXenConnection connection = selection[0].Connection; VMOperationCommand cmdHome = new VMOperationHomeServerCommand(Command.MainWindowCommandInterface, selection, _operation, session); Host affinityHost = connection.Resolve(((VM)Command.GetSelection()[0].XenObject).affinity); Program.Invoke(Program.MainWindow, delegate { var firstItem = (VMOperationToolStripMenuSubItem)base.DropDownItems[0]; bool oldMigrateToHomeCmdCanRun = cmdHome.CanExecute(); if (affinityHost == null || _operation == vm_operations.start_on || oldMigrateToHomeCmdCanRun) { firstItem.Command = cmdHome; firstItem.Enabled = oldMigrateToHomeCmdCanRun; } else { VMOperationCommand cpmCmdHome = new CrossPoolMigrateToHomeCommand(Command.MainWindowCommandInterface, selection, affinityHost); if (cpmCmdHome.CanExecute()) { firstItem.Command = cpmCmdHome; firstItem.Enabled = true; } else { firstItem.Command = cmdHome; firstItem.Enabled = false; } } }); List <VMOperationToolStripMenuSubItem> dropDownItems = DropDownItems.Cast <VMOperationToolStripMenuSubItem>().ToList(); // Adds the migrate wizard button, do this before the enable checks on the other items Program.Invoke(Program.MainWindow, () => AddAdditionalMenuItems(selection)); foreach (VMOperationToolStripMenuSubItem item in dropDownItems) { if (_isDropDownClosed) { // Stop making requests to assert can start on each host after dropdown is closed break; } Host host = item.Tag as Host; if (host != null) { // API calls could happen in CanExecute(), which take time to wait. // So a Producer-Consumer-Queue with size 25 is used here to : // 1. Make API calls for different menu items happen in parallel; // 2. Limit the count of concurrent threads (now it's 25). workerQueueWithouWlb.EnqueueItem(() => { if (_isDropDownClosed) { return; } VMOperationCommand cmd = new VMOperationHostCommand(Command.MainWindowCommandInterface, selection, delegate { return(host); }, host.Name().EscapeAmpersands(), _operation, session); CrossPoolMigrateCommand cpmCmd = new CrossPoolMigrateCommand(Command.MainWindowCommandInterface, selection, host, _resumeAfter); VMOperationToolStripMenuSubItem tempItem = item; bool oldMigrateCmdCanRun = cmd.CanExecute(); if ((_operation == vm_operations.start_on) || oldMigrateCmdCanRun) { Program.Invoke(Program.MainWindow, delegate { tempItem.Command = cmd; tempItem.Enabled = oldMigrateCmdCanRun; }); } else { bool crossPoolMigrateCmdCanRun = cpmCmd.CanExecute(); if (crossPoolMigrateCmdCanRun || !string.IsNullOrEmpty(cpmCmd.CantExecuteReason)) { Program.Invoke(Program.MainWindow, delegate { tempItem.Command = cpmCmd; tempItem.Enabled = crossPoolMigrateCmdCanRun; }); } else { Program.Invoke(Program.MainWindow, delegate { tempItem.Command = cmd; tempItem.Enabled = oldMigrateCmdCanRun; }); } } }); } } }