Exemplo n.º 1
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            if (XenAdmin.Properties.Settings.Default.RequirePass && Program.MasterPassword == null)
                return Messages.ENTER_MASTER_PASSWORD_TO_ACCESS_SETTINGS_TT;

            return base.GetCantExecuteReasonCore(item);
        }
        public void CheckContextMenuText()
        {
            var selectedVdi1 = new SelectedItem(new VDI());
            var selectedVdi2 = new SelectedItem(new VDI());

            var cmd = new MigrateVirtualDiskCommand(mw, new[] { selectedVdi1 });
            Assert.AreEqual(Messages.MOVE_VDI_CONTEXT_MENU, cmd.ContextMenuText);

            cmd = new MigrateVirtualDiskCommand(mw, new[] { selectedVdi1, selectedVdi2 });
            Assert.AreEqual(Messages.MAINWINDOW_MOVE_OBJECTS, cmd.ContextMenuText);
        }
Exemplo n.º 3
0
        private static bool CanExecute(SelectedItem selection)
        {
            IXenConnection connection = selection.Connection;
            Host host = selection.XenObject as Host;
            bool is_host = (host != null 
                );
            bool is_master = is_host && host.IsMaster();
            bool connected = connection != null && connection.IsConnected;

            return (connected && is_master) || (connection != null && connection.InProgress && !connection.IsConnected);
        }
Exemplo n.º 4
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            Host host = item.XenObject as Host;
            
            if (host == null)
                return base.GetCantExecuteReasonCore(item);

            if (!host.IsLive)
                return Messages.HOST_NOT_LIVE;

            return base.GetCantExecuteReasonCore(item);
        }
            private bool CanExecute(SelectedItem selection)
            {
                VM vm = selection.XenObject as VM;

                if (vm != null && !vm.is_a_template && !vm.Locked)
                {
                    if (vm.allowed_operations != null && vm.allowed_operations.Contains(XenAPI.vm_operations.start)
                        && Helpers.EnabledTargetExists(selection.HostAncestor, selection.Connection))
                    {
                        return selection.Connection != null && selection.Connection.Cache.HostCount > 1;
                    }
                }
                return false;
            }
            private bool CanExecute(SelectedItem selection)
            {
                VM vm = selection.XenObject as VM;
                
                if (vm != null && !vm.is_a_template && !vm.Locked)
                {
                    if (vm.allowed_operations != null && vm.allowed_operations.Contains(vm_operations.suspend))
                    {
                        return false;
                    }

                    if (vm.allowed_operations != null && vm.allowed_operations.Contains(vm_operations.resume) && EnabledTargetExists(selection.HostAncestor, selection.Connection))
                    {
                        // CA-19215: "Resume on" option present and enabled for VM on standalone host.
                        return selection.Connection != null && selection.Connection.Cache.HostCount > 1;
                    }
                }
                return false;
            }
Exemplo n.º 7
0
 public DisconnectHostCommand(IMainWindow mainWindow, SelectedItem selection)
     : base(mainWindow, selection)
 {
 }
Exemplo n.º 8
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VDI vdi = item.XenObject as VDI;
            if (vdi == null)
                return base.GetCantExecuteReasonCore(item);
            if (vdi.is_a_snapshot)
                return Messages.CANNOT_MOVE_VDI_IS_SNAPSHOT;
            if (vdi.Locked)
                return Messages.CANNOT_MOVE_VDI_IN_USE;
            if (vdi.IsHaType)
                return Messages.CANNOT_MOVE_HA_VD;
            if (vdi.IsMetadataForDR)
                return Messages.CANNOT_MOVE_DR_VD;
            if (vdi.GetVMs().Any(vm => !vm.IsRunning) && !Helpers.DundeeOrGreater(vdi.Connection))
                return Messages.CANNOT_MIGRATE_VDI_NON_RUNNING_VM;
            SR sr = GetSR(vdi);
            if (sr == null)
                return base.GetCantExecuteReasonCore(item);
            if (sr.HBALunPerVDI)
                return Messages.UNSUPPORTED_SR_TYPE;

            return base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 9
0
 public ExportVMCommand(IMainWindow mainWindow, SelectedItem selection)
     : base(mainWindow, selection)
 {
 }
Exemplo n.º 10
0
 protected override string GetCantExecuteReasonCore(SelectedItem item)
 {
     SR sr = item.XenObject as SR;
     if (sr != null && !sr.SupportsTrim)
     {
         return Messages.TOOLTIP_SR_TRIM_UNSUPPORTED;
     }
     return base.GetCantExecuteReasonCore(item);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Builds the context menu for the specified selection.
 /// </summary>
 /// <param name="selection">The selection for which the context menu items are required.</param>
 /// <returns>The context menu items.</returns>
 public ToolStripItem[] Build(SelectedItem selection)
 {
     return Build(new SelectedItem[] { selection });
 }
Exemplo n.º 12
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            Pool poolAncestor = item.PoolAncestor;
            bool inPool = poolAncestor != null;

            if (inPool )
            {
                Host master = Helpers.GetMaster(poolAncestor.Connection);

                if (master == null)
                {
                    return Messages.FIELD_DISABLED;
                }
                else if (HelpersGUI.FindActiveHaAction(poolAncestor.Connection) != null || poolAncestor.Locked)
                {
                    return Messages.POOL_EDIT_IN_PROGRESS;
                }
            }
            return base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 13
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VBD vbd = item.XenObject as VBD;

            if (vbd == null)
            {
                return(base.GetCantExecuteReasonCore(item));
            }

            VDI vdi = vbd.Connection.Resolve <VDI>(vbd.VDI);
            VM  vm  = vbd.Connection.Resolve <VM>(vbd.VM);

            if (vm == null || vm.not_a_real_vm() || vdi == null)
            {
                return(base.GetCantExecuteReasonCore(item));
            }


            SR sr = vdi.Connection.Resolve <SR>(vdi.SR);

            if (sr == null)
            {
                return(Messages.SR_COULD_NOT_BE_CONTACTED);
            }

            if (vdi.Locked)
            {
                var vdiType = vdi.VDIType();
                return(vdiType == VDI.FriendlyType.SNAPSHOT
                    ? Messages.CANNOT_DEACTIVATE_SNAPSHOT_IN_USE
                    : vdiType == VDI.FriendlyType.ISO
                        ? Messages.CANNOT_DEACTIVATE_ISO_IN_USE
                        : Messages.CANNOT_DEACTIVATE_VDI_IN_USE);
            }

            if (vm.power_state != vm_power_state.Running)
            {
                return(string.Format(
                           Messages.CANNOT_DEACTIVATE_VDI_VM_NOT_RUNNING,
                           Helpers.GetName(vm).Ellipsise(50)));
            }

            if (vdi.type == vdi_type.system && vbd.GetIsOwner())
            {
                return(Messages.TOOLTIP_DEACTIVATE_SYSVDI);
            }

            if (AreIODriversNeededAndMissing(vm))
            {
                return(string.Format(
                           vm.HasNewVirtualisationStates() ? Messages.CANNOT_DEACTIVATE_VDI_NEEDS_IO_DRIVERS : Messages.CANNOT_DEACTIVATE_VDI_NEEDS_TOOLS,
                           Helpers.GetName(vm).Ellipsise(50)));
            }

            if (!vbd.currently_attached)
            {
                return(string.Format(Messages.CANNOT_DEACTIVATE_NOT_ACTIVE, Helpers.GetName(vm).Ellipsise(50)));
            }

            return(base.GetCantExecuteReasonCore(item));
        }
Exemplo n.º 14
0
 public ExportResourceReportCommand(IMainWindow mainWindow, SelectedItem selection)
     : base(mainWindow, selection)
 {
 }
Exemplo n.º 15
0
 protected override string GetCantExecuteReasonCore(SelectedItem item)
 {
     return ConnectionAvailable() ? base.GetCantExecuteReasonCore(item) : Messages.FOLDER_NO_CONNECTION;
 }
Exemplo n.º 16
0
 protected override string GetCantExecuteReasonCore(SelectedItem item)
 {
     VM vm = item.XenObject as VM;
     if (vm == null)
     {
         return base.GetCantExecuteReasonCore(item);
     }
     if (vm.power_state != vm_power_state.Suspended)
     {
         return Messages.VM_NOT_SUSPENDED;
     }
     else if (vm.virtualisation_status == VM.VirtualisationStatus.PV_DRIVERS_NOT_INSTALLED || vm.virtualisation_status == VM.VirtualisationStatus.UNKNOWN)
     {
         return FriendlyErrorNames.VM_MISSING_PV_DRIVERS;
     }
     else if (vm.virtualisation_status == VM.VirtualisationStatus.PV_DRIVERS_OUT_OF_DATE)
     {
         return FriendlyErrorNames.VM_OLD_PV_DRIVERS;
     }
     return base.GetCantExecuteReasonCore(item);
 }
Exemplo n.º 17
0
 protected override string GetCantExecuteReasonCore(SelectedItem item)
 {
     return(ConnectionAvailable() ? base.GetCantExecuteReasonCore(item) : Messages.FOLDER_NO_CONNECTION);
 }
Exemplo n.º 18
0
 public ExportResourceReportCommand(IMainWindow mainWindow, SelectedItem selection)
     : base(mainWindow, selection)
 {
 }
Exemplo n.º 19
0
 public DeleteVMCommand(IMainWindow mainWindow, SelectedItem selection)
     : base(mainWindow, selection)
 {
 }
Exemplo n.º 20
0
 private static bool CanExecute(SelectedItem selection)
 {
     return(selection.Connection != null && selection.Connection.IsConnected && selection.PoolAncestor != null);
 }
Exemplo n.º 21
0
 private static bool CanExecute(SelectedItem selection)
 {
     return selection.Connection != null && selection.Connection.IsConnected && selection.PoolAncestor != null;
 }
Exemplo n.º 22
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VM vm = item.XenObject as VM;
            if (vm != null && _cantBootReasons.ContainsKey(vm))
                return _cantBootReasons[vm];

            return base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 23
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VBD vbd = item.XenObject as VBD;
            if (vbd == null)
                return base.GetCantExecuteReasonCore(item);

            VDI vdi = vbd.Connection.Resolve<VDI>(vbd.VDI);
            VM vm = vbd.Connection.Resolve<VM>(vbd.VM);
            if (vm == null || vm.not_a_real_vm || vdi == null)
                return base.GetCantExecuteReasonCore(item);


            SR sr = vdi.Connection.Resolve<SR>(vdi.SR);
            if (sr == null)
                return Messages.SR_COULD_NOT_BE_CONTACTED;

            if (vdi.Locked)
                return vdi.VDIType == VDI.FriendlyType.SNAPSHOT ? Messages.CANNOT_DEACTIVATE_SNAPSHOT_IN_USE
                    : vdi.VDIType == VDI.FriendlyType.ISO ? Messages.CANNOT_DEACTIVATE_ISO_IN_USE
                    : Messages.CANNOT_DEACTIVATE_VDI_IN_USE;

            if (vm.power_state != vm_power_state.Running)
                return string.Format(
                    Messages.CANNOT_DEACTIVATE_VDI_VM_NOT_RUNNING,
                    Helpers.GetName(vm).Ellipsise(50));

            if (vdi.type == vdi_type.system && vbd.IsOwner)
                return Messages.TOOLTIP_DEACTIVATE_SYSVDI;

            if (!vm.GetVirtualisationStatus.HasFlag(VM.VirtualisationStatus.IO_DRIVERS_INSTALLED))
                return string.Format(
                    vm.HasNewVirtualisationStates ? Messages.CANNOT_DEACTIVATE_VDI_NEEDS_IO_DRIVERS : Messages.CANNOT_DEACTIVATE_VDI_NEEDS_TOOLS,
                    Helpers.GetName(vm).Ellipsise(50));

            if (!vbd.currently_attached)
                return string.Format(Messages.CANNOT_DEACTIVATE_NOT_ACTIVE, Helpers.GetName(vm).Ellipsise(50));

            return base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 24
0
 public ExportVMCommand(IMainWindow mainWindow, SelectedItem selection)
     : base(mainWindow, selection)
 {
 }
Exemplo n.º 25
0
 /// <summary>
 /// Builds the context menu for the specified selection.
 /// </summary>
 /// <param name="selection">The selection for which the context menu items are required.</param>
 /// <returns>The context menu items.</returns>
 public ToolStripItem[] Build(SelectedItem selection)
 {
     return(Build(new SelectedItem[] { selection }));
 }
Exemplo n.º 26
0
 /// <summary>
 /// Gets the reason that the specified item from the selection cant execute. This is displayed in the error dialog.
 /// The default is "Unknown".
 /// </summary>
 protected virtual string GetCantExecuteReasonCore(SelectedItem item)
 {
     return(Messages.UNKNOWN);
 }
Exemplo n.º 27
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VDI vdi = item.XenObject as VDI;
            if (vdi == null)
                return base.GetCantExecuteReasonCore(item);

            if (vdi.is_a_snapshot)
                return Messages.CANNOT_MOVE_VDI_IS_SNAPSHOT;
            if (vdi.Locked)
                return Messages.CANNOT_MOVE_VDI_IN_USE;
            if (vdi.IsHaType)
                return Messages.CANNOT_MOVE_HA_VD;
            if (vdi.IsMetadataForDR)
                return Messages.CANNOT_MOVE_DR_VD;
            if (vdi.VBDs.Count != 0)
                return Messages.CANNOT_MOVE_VDI_WITH_VBDS;

            SR sr = vdi.Connection.Resolve(vdi.SR);
            if (sr == null)
                return base.GetCantExecuteReasonCore(item);

            if (sr.HBALunPerVDI)
                return Messages.UNSUPPORTED_SR_TYPE;

            return base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Command"/> class.
 /// </summary>
 /// <param name="mainWindow">The application main window.</param>
 /// <param name="selection">The selection context for the Command.</param>
 protected Command(IMainWindow mainWindow, SelectedItem selection)
     : this(mainWindow, new [] { selection })
 {
 }
Exemplo n.º 29
0
 protected override string GetCantExecuteReasonCore(SelectedItem item)
 {
     SR sr = item.XenObject as SR;
     if (sr == null)
     {
         return base.GetCantExecuteReasonCore(item);
     }
     if (!sr.HasPBDs)
     {
         return Messages.SR_DETACHED;
     }
     else if (sr.HasRunningVMs())
     {
         return Messages.SR_HAS_RUNNING_VMS;
     }
     else if (!sr.CanCreateWithXenCenter)
     {
         return Messages.SR_CANNOT_BE_DESTROYED_WITH_XC;
     }
     else if (HelpersGUI.GetActionInProgress(sr))
     {
         return Messages.SR_ACTION_IN_PROGRESS;
     }
     return base.GetCantExecuteReasonCore(item);
 }
Exemplo n.º 30
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VM vm = item.XenObject as VM;
            if (vm == null)
            {
                return base.GetCantExecuteReasonCore(item);
            }

            switch (vm.power_state)
            {
                case vm_power_state.Halted:
                    return Messages.VM_SHUT_DOWN;
                case vm_power_state.Paused:
                    return Messages.VM_PAUSED;
                case vm_power_state.Suspended:
                    return Messages.VM_SUSPENDED;
                case vm_power_state.unknown:
                    return base.GetCantExecuteReasonCore(item);
            }

            return GetCantExecuteNoToolsOrDriversReasonCore(item) ?? base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 31
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            Host host = item.HostAncestor;

            if (host == null && item.Connection != null)
            {
                host = Helpers.GetMaster(item.Connection);
            }

            if (host == null || !Helpers.GeorgeOrGreater(host))
            {
                return Messages.SNAPSHOT_REQUIRE_GEORGE;
            }

            return base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 32
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VM vm = item.XenObject as VM;
            if (vm == null)
            {
                return base.GetCantExecuteReasonCore(item);
            }
            if (vm.power_state != vm_power_state.Suspended)
            {
                return Messages.VM_NOT_SUSPENDED;
            }

            return GetCantExecuteNoToolsOrDriversReasonCore(item) ?? base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 33
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VM vm = item.XenObject as VM;
            if (vm == null)
                return base.GetCantExecuteReasonCore(item);
            if (vm.power_state == vm_power_state.Running)
                return Messages.MAINWINDOW_EXPORT_VM_AS_BACKUP_TOOLTIP;

            return null;
        }
Exemplo n.º 34
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VDI vdi = item.XenObject as VDI;

            if (vdi == null)
            {
                return(base.GetCantExecuteReasonCore(item));
            }

            SR sr = vdi.Connection.Resolve <SR>(vdi.SR);

            if (sr == null)
            {
                return(Messages.SR_COULD_NOT_BE_CONTACTED);
            }

            VDI.FriendlyType vdiType = vdi.VDIType;

            if (vdi.Locked)
            {
                return(vdiType == VDI.FriendlyType.SNAPSHOT ? Messages.CANNOT_DELETE_SNAPSHOT_IN_USE
                    : vdiType == VDI.FriendlyType.ISO ? Messages.CANNOT_DELETE_ISO_IN_USE
                    : Messages.CANNOT_DELETE_VD_IN_USE);
            }

            if (sr.Physical)
            {
                return(FriendlyErrorNames.VDI_IS_A_PHYSICAL_DEVICE);
            }

            if (sr.IsToolsSR)
            {
                return(Messages.CANNOT_DELETE_TOOLS_SR);
            }

            if (vdi.IsUsedByHA)
            {
                return(Messages.CANNOT_DELETE_HA_VD);
            }

            if (vdi.IsMetadataForDR)
            {
                return(Messages.CANNOT_DELETE_DR_VD);
            }

            List <VBD> vbds = vdi.Connection.ResolveAll <VBD>(vdi.VBDs);

            if (vbds.Count > 1 && !AllowMultipleVBDDelete)
            {
                return(Messages.CANNOT_DELETE_VDI_MULTIPLE_VBDS);
            }

            foreach (VBD vbd in vbds)
            {
                VM vm = vdi.Connection.Resolve <VM>(vbd.VM);

                if (vdiType == VDI.FriendlyType.SYSTEM_DISK)
                {
                    if (vm.power_state == vm_power_state.Running)
                    {
                        return(string.Format(
                                   Messages.CANNOT_DELETE_IN_USE_SYS_VD,
                                   Helpers.GetName(vm).Ellipsise(20)));
                    }
                }
                if (vbd.Locked)
                {
                    return(vdiType == VDI.FriendlyType.SNAPSHOT ? Messages.CANNOT_DELETE_SNAPSHOT_IN_USE
                    : vdiType == VDI.FriendlyType.ISO ? Messages.CANNOT_DELETE_ISO_IN_USE
                    : Messages.CANNOT_DELETE_VD_IN_USE);
                }

                if (vbd.currently_attached)
                {
                    if (!AllowRunningVMDelete)
                    {
                        return(string.Format(Messages.CANNOT_DELETE_VDI_ACTIVE_ON,
                                             Helpers.GetName(vm).Ellipsise(20)));
                    }
                    DeactivateVBDCommand cmd = new DeactivateVBDCommand(Program.MainWindow, vbd);
                    if (!cmd.CanExecute())
                    {
                        var reasons = cmd.GetCantExecuteReasons();
                        return(reasons.Count > 0
                            ? string.Format(Messages.CANNOT_DELETE_CANNOT_DEACTIVATE_REASON,
                                            Helpers.GetName(vm).Ellipsise(20), reasons.ElementAt(0).Value)
                            : Messages.UNKNOWN);
                    }
                }
            }

            // This is a necessary final check, there are other blocking reasons non covered in this method
            // Known examples:
            // - someone else is calling a delete on this vdi already, altering the allowed ops
            // - the storage manager cannot perform a delete on the SR due to drivers
            if (!vdi.allowed_operations.Contains(vdi_operations.destroy))
            {
                return(vdiType == VDI.FriendlyType.SNAPSHOT ? Messages.CANNOT_DELETE_SNAPSHOT_GENERIC
                    : vdiType == VDI.FriendlyType.ISO ? Messages.CANNOT_DELETE_ISO_GENERIC
                    : Messages.CANNOT_DELETE_VD_GENERIC);
            }

            return(base.GetCantExecuteReasonCore(item));
        }
Exemplo n.º 35
0
 public DeleteTemplateCommand(IMainWindow mainWindow, SelectedItem selection)
     : base(mainWindow, selection)
 {
 }
Exemplo n.º 36
0
 public DeleteSnapshotCommand(IMainWindow mainWindow, SelectedItem selection)
     : base(mainWindow, selection)
 {
 }
 public DisconnectHostCommand(IMainWindow mainWindow, SelectedItem selection)
     : base(mainWindow, selection)
 {
 }
Exemplo n.º 38
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VM vm = (VM)item.XenObject;
            if (vm == null)
                return base.GetCantExecuteReasonCore(item);

            switch (vm.power_state)
            {
                case vm_power_state.Halted:
                    return Messages.VM_SHUT_DOWN;
                case vm_power_state.Paused:
                    return Messages.VM_PAUSED;
                case vm_power_state.Suspended:
                    return Messages.VM_SUSPENDED;
                case vm_power_state.unknown:
                    return base.GetCantExecuteReasonCore(item);
            }

            if (vm.virtualisation_status == VM.VirtualisationStatus.PV_DRIVERS_NOT_INSTALLED || vm.virtualisation_status == VM.VirtualisationStatus.UNKNOWN)
            {
                return FriendlyErrorNames.VM_MISSING_PV_DRIVERS;
            }

            if (vm.virtualisation_status == VM.VirtualisationStatus.PV_DRIVERS_OUT_OF_DATE)
            {
                return FriendlyErrorNames.VM_OLD_PV_DRIVERS;
            }
            return base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 39
0
 protected override string GetCantExecuteReasonCore(SelectedItem item)
 {
     Host host = item.XenObject as Host;
     if (host == null)
     {
         return base.GetCantExecuteReasonCore(item);
     }
     if (!host.IsLive)
     {
         return Messages.HOST_ALREADY_SHUT_DOWN;
     }
     else if (HelpersGUI.HasActiveHostAction(host))
     {
         return Messages.HOST_ACTION_IN_PROGRESS;
     }
     return base.GetCantExecuteReasonCore(item);
 }
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VDI vdi = item.XenObject as VDI;
            if (vdi == null)
                return base.GetCantExecuteReasonCore(item);

            SR sr = vdi.Connection.Resolve<SR>(vdi.SR);
            if (sr == null)
                return Messages.SR_COULD_NOT_BE_CONTACTED;

            VDI.FriendlyType vdiType = vdi.VDIType;

            if (vdi.Locked)
                return vdiType == VDI.FriendlyType.SNAPSHOT ? Messages.CANNOT_DELETE_SNAPSHOT_IN_USE
                    : vdiType == VDI.FriendlyType.ISO ? Messages.CANNOT_DELETE_ISO_IN_USE
                    : Messages.CANNOT_DELETE_VD_IN_USE;

            if (sr.Physical)
                return FriendlyErrorNames.VDI_IS_A_PHYSICAL_DEVICE;

            if (sr.IsToolsSR)
                return Messages.CANNOT_DELETE_TOOLS_SR;

            if (vdi.IsUsedByHA)
                return Messages.CANNOT_DELETE_HA_VD;

            if (vdi.IsMetadataForDR)
                return Messages.CANNOT_DELETE_DR_VD;

            List<VBD> vbds = vdi.Connection.ResolveAll<VBD>(vdi.VBDs);
            if (vbds.Count > 1 && !AllowMultipleVBDDelete)
                return Messages.CANNOT_DELETE_VDI_MULTIPLE_VBDS;

            foreach (VBD vbd in vbds)
            {
                VM vm = vdi.Connection.Resolve<VM>(vbd.VM);

                if (vdiType == VDI.FriendlyType.SYSTEM_DISK)
                {

                    if (vm.power_state == vm_power_state.Running)
                        return string.Format(
                            Messages.CANNOT_DELETE_IN_USE_SYS_VD,
                            Helpers.GetName(vm).Ellipsise(20));
                }
                if (vbd.Locked)
                    return vdiType == VDI.FriendlyType.SNAPSHOT ? Messages.CANNOT_DELETE_SNAPSHOT_IN_USE
                    : vdiType == VDI.FriendlyType.ISO ? Messages.CANNOT_DELETE_ISO_IN_USE
                    : Messages.CANNOT_DELETE_VD_IN_USE;

                if (vbd.currently_attached)
                {
                    if (!AllowRunningVMDelete)
                    {
                        return string.Format(Messages.CANNOT_DELETE_VDI_ACTIVE_ON,
                            Helpers.GetName(vm).Ellipsise(20));
                    }
                    DeactivateVBDCommand cmd = new DeactivateVBDCommand(Program.MainWindow.CommandInterface, vbd);
                    if (!cmd.CanExecute())
                    {
                        return string.Format(Messages.CANNOT_DELETE_CANNOT_DEACTIVATE_REASON,
                            Helpers.GetName(vm).Ellipsise(20), cmd.ToolTipText);
                    }
                }
            }

            // This is a necessary final check, there are other blocking reasons non covered in this method
            // Known examples:
            // - someone else is calling a delete on this vdi already, altering the allowed ops
            // - the storage manager cannot perform a delete on the SR due to drivers
            if (!vdi.allowed_operations.Contains(vdi_operations.destroy))
                return vdiType == VDI.FriendlyType.SNAPSHOT ? Messages.CANNOT_DELETE_SNAPSHOT_GENERIC
                    : vdiType == VDI.FriendlyType.ISO ? Messages.CANNOT_DELETE_ISO_GENERIC
                    : Messages.CANNOT_DELETE_VD_GENERIC;

            return base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 41
0
        protected override string GetCantExecuteReasonCore(SelectedItem item)
        {
            VM vm = item.XenObject as VM;
            if (vm == null)
                return base.GetCantExecuteReasonCore(item);

            if (_recommendation.CantExecuteReasons.ContainsKey(vm))
            {
                return _recommendation.CantExecuteReasons[vm];
            }

            return base.GetCantExecuteReasonCore(item);
        }
Exemplo n.º 42
0
 /// <summary>
 /// Sets the main selection for XenCenter.
 /// </summary>
 /// <param name="item">The selection.</param>
 public void SetSelection(SelectedItem item)
 {
     SetSelection(new SelectedItem[] { item });
 }