コード例 #1
0
        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.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;
                    }
                    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);
                });
            });
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
                }
            });
        }
コード例 #4
0
        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 (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);
        }