Пример #1
0
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            VM vm = (VM)selection[0].XenObject;

            using (var dlg = new ThreeButtonDialog(
                       new ThreeButtonDialog.Details(
                           SystemIcons.Warning,
                           string.Format(Messages.CONVERT_TEMPLATE_DIALOG_TEXT, vm.Name.Ellipsise(25)),
                           Messages.CONVERT_TO_TEMPLATE),
                       new ThreeButtonDialog.TBDButton(Messages.CONVERT, DialogResult.OK, ThreeButtonDialog.ButtonType.ACCEPT, true),
                       ThreeButtonDialog.ButtonCancel))
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    List <AsyncAction> actions = new List <AsyncAction>();
                    actions.Add(new SetVMOtherConfigAction(vm.Connection, vm, "instant", "true"));
                    actions.Add(new VMToTemplateAction(vm));

                    MainWindowCommandInterface.AllowHistorySwitch();
                    MainWindowCommandInterface.CloseActiveWizards(vm);

                    RunMultipleActions(actions, string.Format(Messages.ACTION_VM_TEMPLATIZING_TITLE, vm.Name),
                                       Messages.ACTION_VM_TEMPLATIZING, Messages.ACTION_VM_TEMPLATIZED, true);
                }
            }
        }
Пример #2
0
        protected void RunAction(IEnumerable <VM> vms, string title, string startDescription, string endDescription,
                                 Dictionary <VM, List <VBD> > vbdsToEjectDict)
        {
            MainWindowCommandInterface.AllowHistorySwitch();
            var actions = GetActions(vms, title, startDescription, endDescription, vbdsToEjectDict);

            RunMultipleActions(actions, title, startDescription, endDescription, true);
        }
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            Host host = selection[0].HostAncestor;

            DialogResult result = new RemoveCrashDumpsWarningDialog(host).ShowDialog(Parent);

            if (result == DialogResult.OK)
            {
                MainWindowCommandInterface.AllowHistorySwitch();
                new DestroyHostCrashDumpAction(host).RunAsync();
            }
        }
Пример #4
0
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            MainWindowCommandInterface.AllowHistorySwitch();

            List <AsyncAction> actions = new List <AsyncAction>();

            foreach (Host host in selection.AsXenObjects <Host>(CanExecute))
            {
                var action = new HostPowerOnAction(host);
                action.Completed += s => MainWindowCommandInterface.Refresh();
                actions.Add(action);
            }
            RunMultipleActions(actions, null, Messages.ACTION_HOST_STARTING, Messages.ACTION_HOST_STARTED, true);
        }
        private void ExitMaintenanceMode(Host host)
        {
            List <VM> vmsToUnEvacuate = new List <VM>();

            vmsToUnEvacuate.AddRange(host.GetHaltedEvacuatedVMs());
            vmsToUnEvacuate.AddRange(host.GetMigratedEvacuatedVMs());
            vmsToUnEvacuate.AddRange(host.GetSuspendedEvacuatedVMs());

            List <VM> to_remove = new List <VM>();

            foreach (VM vm in vmsToUnEvacuate)
            {
                if (vm.resident_on == host.opaque_ref)
                {
                    to_remove.Add(vm);
                }
            }
            foreach (VM vm in to_remove)
            {
                vmsToUnEvacuate.Remove(vm);
            }

            DialogResult result = DialogResult.No;

            if (vmsToUnEvacuate.Count > 0 && !MainWindowCommandInterface.RunInAutomatedTestMode)
            {
                result = new RestoreVMsDialog(vmsToUnEvacuate, host).ShowDialog();

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                if (!host.Connection.IsConnected)
                {
                    MainWindow.ShowDisconnectedMessage(null);
                    return;
                }
            }

            MainWindowCommandInterface.AllowHistorySwitch();
            MainWindowCommandInterface.CloseActiveWizards(host.Connection);
            var action = new EnableHostAction(host, result == DialogResult.Yes, AddHostToPoolCommand.EnableNtolDialog);

            action.Completed += delegate { MainWindowCommandInterface.Refresh(); };
            action.RunAsync();
            MainWindowCommandInterface.Refresh();
        }
Пример #6
0
        /// <summary>
        /// Attempts to install tools on the vm
        /// </summary>
        /// <param name="vm"></param>
        /// <returns>null if user cancels or an AsyncAction. This is either the InstallPVToolsAction or the CreateCdDriveAction if the VM needed a DVD drive.</returns>
        private AsyncAction SingleVMExecute(VM vm)
        {
            if (vm.FindVMCDROM() == null)
            {
                if (new ThreeButtonDialog(
                        new ThreeButtonDialog.Details(
                            null,
                            Messages.NEW_DVD_DRIVE_REQUIRED,
                            Messages.XENCENTER),
                        ThreeButtonDialog.ButtonYes,
                        ThreeButtonDialog.ButtonNo).ShowDialog(Parent) == DialogResult.Yes)
                {
                    MainWindowCommandInterface.AllowHistorySwitch();
                    CreateCdDriveAction createDriveAction = new CreateCdDriveAction(vm, true, NewDiskDialog.ShowMustRebootBoxCD, NewDiskDialog.ShowVBDWarningBox);
                    new ActionProgressDialog(createDriveAction, ProgressBarStyle.Marquee).ShowDialog(Parent);

                    if (createDriveAction.Succeeded)
                    {
                        ShowMustRebootBox();
                    }
                    return(createDriveAction);
                }
            }
            else
            {
                DialogResult dr = new InstallToolsWarningDialog(vm.Connection).ShowDialog(Parent);
                if (dr == DialogResult.Yes)
                {
                    MainWindowCommandInterface.AllowHistorySwitch();
                    InstallPVToolsAction installToolsAction = new InstallPVToolsAction(vm, XSToolsSRNotFound, Properties.Settings.Default.ShowHiddenVMs);
                    installToolsAction.Completed += InstallToolsActionCompleted;

                    installToolsAction.RunAsync();
                    return(installToolsAction);
                }
            }
            return(null);
        }
Пример #7
0
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            Host host = (Host)selection[0].XenObject;

            if (_filename == null)
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.AddExtension     = true;
                dialog.Filter           = string.Format("{0} (*.xbk)|*.xbk|{1} (*.*)|*.*", Messages.XS_BACKUP_FILES, Messages.ALL_FILES);
                dialog.FilterIndex      = 0;
                dialog.RestoreDirectory = true;
                dialog.DefaultExt       = "xbk";

                if (dialog.ShowDialog(Parent) != DialogResult.Cancel)
                {
                    MainWindowCommandInterface.AllowHistorySwitch();
                    new HostBackupRestoreAction(host, HostBackupRestoreAction.HostBackupRestoreType.backup, dialog.FileName).RunAsync();
                }
            }
            else
            {
                new HostBackupRestoreAction(host, HostBackupRestoreAction.HostBackupRestoreType.backup, _filename).RunAsync();
            }
        }
Пример #8
0
        /// <summary>
        /// Attempts to install tools on several VMs
        /// </summary>
        /// <param name="vms"></param>
        /// <returns>Whether the action was launched (i.e., the user didn't Cancel)</returns>
        private bool MultipleVMExecute(List <VM> vms)
        {
            bool newDvdDrivesRequired = false;

            foreach (VM vm in vms)
            {
                if (CanExecute(vm) && vm.FindVMCDROM() == null)
                {
                    newDvdDrivesRequired = true;
                    break;
                }
            }

            if (newDvdDrivesRequired)
            {
                if (new ThreeButtonDialog(new ThreeButtonDialog.Details(SystemIcons.Warning, Messages.NEW_DVD_DRIVES_REQUIRED, Messages.XENCENTER),
                                          ThreeButtonDialog.ButtonYes,
                                          ThreeButtonDialog.ButtonNo).ShowDialog(Parent) == DialogResult.Yes)
                {
                    MainWindowCommandInterface.AllowHistorySwitch();

                    foreach (VM vm in vms)
                    {
                        if (CanExecute(vm) && vm.FindVMCDROM() == null)
                        {
                            CreateCdDriveAction createDriveAction = new CreateCdDriveAction(vm, true, NewDiskDialog.ShowMustRebootBoxCD, NewDiskDialog.ShowVBDWarningBox);
                            new ActionProgressDialog(createDriveAction, ProgressBarStyle.Marquee).ShowDialog(Parent);
                        }
                    }
                    ShowMustRebootBox();
                    return(true);
                }
            }
            else
            {
                List <IXenConnection> vmConnections = new List <IXenConnection>();
                foreach (VM vm in vms)
                {
                    vmConnections.Add(vm.Connection);
                }

                if (new InstallToolsWarningDialog(null, true, vmConnections).ShowDialog(Parent) == DialogResult.Yes)
                {
                    MainWindowCommandInterface.AllowHistorySwitch();

                    foreach (VM vm in vms)
                    {
                        InstallPVToolsAction installToolsAction = new InstallPVToolsAction(vm, XSToolsSRNotFound, Properties.Settings.Default.ShowHiddenVMs);

                        if (vms.IndexOf(vm) == 0)
                        {
                            installToolsAction.Completed += FirstInstallToolsActionCompleted;
                        }
                        else
                        {
                            installToolsAction.Completed += InstallToolsActionCompleted;
                        }
                        installToolsAction.RunAsync();
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #9
0
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            Dictionary <SelectedItem, string> reasons = new Dictionary <SelectedItem, string>();

            foreach (Host host in _hosts)
            {
                PoolJoinRules.Reason reason = PoolJoinRules.CanJoinPool(host.Connection, _pool.Connection, true, true, true);
                if (reason != PoolJoinRules.Reason.Allowed)
                {
                    reasons[new SelectedItem(host)] = PoolJoinRules.ReasonMessage(reason);
                }
            }

            if (reasons.Count > 0)
            {
                string title = Messages.ERROR_DIALOG_ADD_TO_POOL_TITLE;
                string text  = string.Format(Messages.ERROR_DIALOG_ADD_TO_POOL_TEXT, Helpers.GetName(_pool).Ellipsise(500));

                new CommandErrorDialog(title, text, reasons).ShowDialog(Parent);
                return;
            }

            if (_confirm && !ShowConfirmationDialog())
            {
                // Bail out if the user doesn't want to continue.
                return;
            }

            if (!Helpers.IsConnected(_pool))
            {
                string message = _hosts.Count == 1
                                     ? string.Format(Messages.ADD_HOST_TO_POOL_DISCONNECTED_POOL,
                                                     Helpers.GetName(_hosts[0]).Ellipsise(500), Helpers.GetName(_pool).Ellipsise(500))
                                     : string.Format(Messages.ADD_HOST_TO_POOL_DISCONNECTED_POOL_MULTIPLE,
                                                     Helpers.GetName(_pool).Ellipsise(500));

                new ThreeButtonDialog(
                    new ThreeButtonDialog.Details(SystemIcons.Error, message, Messages.XENCENTER)).ShowDialog(Parent);
                return;
            }

            // Check supp packs and warn
            List <string> badSuppPacks = PoolJoinRules.HomogeneousSuppPacksDiffering(_hosts, _pool);

            if (!HelpersGUI.GetPermissionFor(badSuppPacks, sp => true,
                                             Messages.ADD_HOST_TO_POOL_SUPP_PACK, Messages.ADD_HOST_TO_POOL_SUPP_PACKS, false, "PoolJoinSuppPacks"))
            {
                return;
            }

            // Are there any hosts which are forbidden from masking their CPUs for licensing reasons?
            // If so, we need to show upsell.
            Host master = Helpers.GetMaster(_pool);

            if (null != _hosts.Find(host =>
                                    !PoolJoinRules.CompatibleCPUs(host, master, false) &&
                                    Helpers.FeatureForbidden(host, Host.RestrictCpuMasking) &&
                                    !PoolJoinRules.FreeHostPaidMaster(host, master, false))) // in this case we can upgrade the license and then mask the CPU
            {
                UpsellDialog dlg = new UpsellDialog(Messages.UPSELL_BLURB_CPUMASKING, InvisibleMessages.UPSELL_LEARNMOREURL_CPUMASKING);
                dlg.ShowDialog(Parent);
                return;
            }

            // Get permission for any fix-ups: 1) Licensing free hosts; 2) CPU masking 3) Ad configuration
            // (We already know that these things are fixable because we have been through CanJoinPool() above).
            if (!HelpersGUI.GetPermissionFor(_hosts, host => PoolJoinRules.FreeHostPaidMaster(host, master, false),
                                             Messages.ADD_HOST_TO_POOL_LICENSE_MESSAGE, Messages.ADD_HOST_TO_POOL_LICENSE_MESSAGE_MULTIPLE, true, "PoolJoinRelicensing")
                ||
                !HelpersGUI.GetPermissionFor(_hosts, host => !PoolJoinRules.CompatibleCPUs(host, master, false),
                                             Messages.ADD_HOST_TO_POOL_CPU_MASKING_MESSAGE, Messages.ADD_HOST_TO_POOL_CPU_MASKING_MESSAGE_MULTIPLE, true, "PoolJoinCpuMasking")
                ||
                !HelpersGUI.GetPermissionFor(_hosts, host => !PoolJoinRules.CompatibleAdConfig(host, master, false),
                                             Messages.ADD_HOST_TO_POOL_AD_MESSAGE, Messages.ADD_HOST_TO_POOL_AD_MESSAGE_MULTIPLE, true, "PoolJoinAdConfiguring")
                )

            {
                return;
            }

            MainWindowCommandInterface.SelectObjectInTree(_pool, false);
            MainWindowCommandInterface.AllowHistorySwitch();

            List <AsyncAction> actions = new List <AsyncAction>();

            foreach (Host host in _hosts)
            {
                string opaque_ref          = host.opaque_ref;
                AddHostToPoolAction action = new AddHostToPoolAction(_pool, host, GetAdPrompt, NtolDialog, ApplyLicenseEditionCommand.ShowLicensingFailureDialog);
                action.Completed += s => Program.ShowObject(opaque_ref);
                actions.Add(action);

                // hide connection. If the action fails, re-show it.
                Program.HideObject(opaque_ref);
            }

            RunMultipleActions(actions, string.Format(Messages.ADDING_SERVERS_TO_POOL, _pool.Name), Messages.POOLCREATE_ADDING, Messages.POOLCREATE_ADDED, true);
        }
Пример #10
0
 private AsyncAction GetAction(VM vm, List <VBD> deleteDisks, List <VM> deleteSnapshots)
 {
     MainWindowCommandInterface.AllowHistorySwitch();
     return(new VMDestroyAction(vm, deleteDisks, deleteSnapshots));
 }
Пример #11
0
 protected override void ExecuteCore(SelectedItemCollection selection)
 {
     MainWindowCommandInterface.AllowHistorySwitch();
     new HVMBootAction((VM)selection[0].XenObject).RunAsync();
 }
        private void Execute(Host host, string filepath)
        {
            MainWindowCommandInterface.BringToFront();

            if (filepath == "")
            {
                // Showing this dialog has the (undocumented) side effect of changing the working directory
                // to that of the file selected. This means a handle to the directory persists, making
                // it undeletable until the program exits, or the working dir moves on. So, save and
                // restore the working dir...
                String oldDir = "";
                try
                {
                    oldDir = Directory.GetCurrentDirectory();
                    OpenFileDialog dialog = new OpenFileDialog();
                    dialog.AddExtension     = true;
                    dialog.Filter           = string.Format("{0} (*.xbk)|*.xbk|{1} (*.*)|*.*", Messages.XS_BACKUP_FILES, Messages.ALL_FILES);
                    dialog.FilterIndex      = 0;
                    dialog.RestoreDirectory = true;
                    dialog.DefaultExt       = "xbk";
                    dialog.CheckPathExists  = false;
                    if (dialog.ShowDialog(Parent) == DialogResult.Cancel)
                    {
                        return;
                    }
                    filepath = dialog.FileName;
                }
                finally
                {
                    Directory.SetCurrentDirectory(oldDir);
                }
            }

            if (host == null)
            {
                SelectHostDialog hostdialog = new SelectHostDialog();
                hostdialog.TheHost       = host;
                hostdialog.DispString    = Messages.BACKUP_SELECT_HOST;
                hostdialog.SetPicture    = Properties.Resources.backup_restore_32;
                hostdialog.HelpString    = "Backup"; // dont i18n
                hostdialog.Text          = Messages.BACKUP_SELECT_HOST_TITLE;
                hostdialog.okbutton.Text = Messages.BACKUP_SELECT_HOST_BUTTON;
                hostdialog.FormClosed   += delegate
                {
                    if (hostdialog.DialogResult != DialogResult.OK)
                    {
                        return;
                    }
                    host = hostdialog.TheHost;
                    MainWindowCommandInterface.AllowHistorySwitch();
                    HostBackupRestoreAction action = new HostBackupRestoreAction(host, HostBackupRestoreAction.HostBackupRestoreType.restore, filepath);
                    action.Completed += RestoreAction_Completed;
                    action.RunAsync();
                };
                hostdialog.Show(Parent);
            }
            else
            {
                MainWindowCommandInterface.AllowHistorySwitch();
                HostBackupRestoreAction action = new HostBackupRestoreAction(host, HostBackupRestoreAction.HostBackupRestoreType.restore, filepath);
                action.Completed += RestoreAction_Completed;
                action.RunAsync();
            }
        }
Пример #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="vm">The VM to export.</param>
        /// <param name="host">Used for filtering purposes. May be null.</param>
        private void Execute(IXenConnection connection, VM vm, Host host)
        {
            /*
             * These properties have not been copied over to the new save file dialog.
             *
             * dlg.AddExtension = true;
             * dlg.CheckPathExists = true;
             * dlg.CreatePrompt = false;
             * dlg.CheckFileExists = false;
             * dlg.OverwritePrompt = true;
             * dlg.ValidateNames = true;*/

            string filename;
            bool   verify;

            // Showing this dialog has the (undocumented) side effect of changing the working directory
            // to that of the file selected. This means a handle to the directory persists, making
            // it undeletable until the program exits, or the working dir moves on. So, save and
            // restore the working dir...
            String oldDir = "";

            try
            {
                oldDir = Directory.GetCurrentDirectory();
                while (true)
                {
                    ExportVMDialog dlg = new ExportVMDialog();
                    dlg.DefaultExt = "xva";
                    dlg.Filter     = Messages.MAINWINDOW_XVA_BLURB;
                    dlg.Title      = Messages.MAINWINDOW_XVA_TITLE;

                    if (dlg.ShowDialog(Parent) != DialogResult.OK)
                    {
                        return;
                    }

                    filename = dlg.FileName;
                    verify   = dlg.Verify;

                    // CA-12975: Warn the user if the export operation does not have enough disk space to
                    // complete.  This is an approximation only.
                    Win32.DiskSpaceInfo diskSpaceInfo = Win32.GetDiskSpaceInfo(dlg.FileName);

                    if (diskSpaceInfo == null)
                    {
                        // Could not determine free disk space. Carry on regardless.
                        break;
                    }
                    else
                    {
                        ulong   freeSpace   = diskSpaceInfo.FreeBytesAvailable;
                        decimal neededSpace = vm.GetRecommendedExportSpace(Properties.Settings.Default.ShowHiddenVMs);
                        ulong   spaceLeft   = 100 * Util.BINARY_MEGA; // We want the user to be left with some disk space afterwards
                        if (neededSpace >= freeSpace - spaceLeft)
                        {
                            string msg = string.Format(Messages.CONFIRM_EXPORT_NOT_ENOUGH_MEMORY, Util.DiskSizeString((long)neededSpace),
                                                       Util.DiskSizeString((long)freeSpace), vm.Name);

                            DialogResult dr = new ThreeButtonDialog(
                                new ThreeButtonDialog.Details(SystemIcons.Warning, msg),
                                "ExportVmDialogInsufficientDiskSpace",
                                new ThreeButtonDialog.TBDButton(Messages.CONTINUE_WITH_EXPORT, DialogResult.OK),
                                new ThreeButtonDialog.TBDButton(Messages.CHOOSE_ANOTHER_DESTINATION, DialogResult.Retry),
                                ThreeButtonDialog.ButtonCancel).ShowDialog(Parent);

                            if (dr == DialogResult.Retry)
                            {
                                continue;
                            }
                            else if (dr == DialogResult.Cancel)
                            {
                                return;
                            }
                        }
                        if (diskSpaceInfo.IsFAT && neededSpace > (4 * Util.BINARY_GIGA) - 1)
                        {
                            string msg = string.Format(Messages.CONFIRM_EXPORT_FAT, Util.DiskSizeString((long)neededSpace),
                                                       Util.DiskSizeString(4 * Util.BINARY_GIGA), vm.Name);

                            DialogResult dr = new ThreeButtonDialog(
                                new ThreeButtonDialog.Details(SystemIcons.Warning, msg),
                                "ExportVmDialogFSLimitExceeded",
                                new ThreeButtonDialog.TBDButton(Messages.CONTINUE_WITH_EXPORT, DialogResult.OK),
                                new ThreeButtonDialog.TBDButton(Messages.CHOOSE_ANOTHER_DESTINATION, DialogResult.Retry),
                                ThreeButtonDialog.ButtonCancel).ShowDialog(Parent);

                            if (dr == DialogResult.Retry)
                            {
                                continue;
                            }
                            else if (dr == DialogResult.Cancel)
                            {
                                return;
                            }
                        }
                        break;
                    }
                }
            }
            finally
            {
                Directory.SetCurrentDirectory(oldDir);
            }

            MainWindowCommandInterface.AllowHistorySwitch();

            new ExportVmAction(connection, host, vm, filename, verify).RunAsync();
        }