protected override string GetCantExecuteReasonCore(SelectedItem item) { VBD vbd = item.XenObject as VBD; if (vbd == null) { return(base.GetCantExecuteReasonCore(item)); } VM vm = vbd.Connection.Resolve <VM>(vbd.VM); VDI vdi = vbd.Connection.Resolve <VDI>(vbd.VDI); 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_ACTIVATE_SNAPSHOT_IN_USE : vdiType == VDI.FriendlyType.ISO ? Messages.CANNOT_ACTIVATE_ISO_IN_USE : Messages.CANNOT_ACTIVATE_VD_IN_USE); } if (vm.power_state != vm_power_state.Running) { return(string.Format( Messages.CANNOT_ACTIVATE_VD_VM_HALTED, Helpers.GetName(vm).Ellipsise(50))); } if (vdi.type == vdi_type.system) { return(Messages.TOOLTIP_DEACTIVATE_SYSVDI); } if (AreIODriversNeededAndMissing(vm)) { return(string.Format( vm.HasNewVirtualisationStates() ? Messages.CANNOT_ACTIVATE_VD_VM_NEEDS_IO_DRIVERS : Messages.CANNOT_ACTIVATE_VD_VM_NEEDS_TOOLS, Helpers.GetName(vm).Ellipsise(50))); } if (vbd.currently_attached) { return(string.Format(Messages.CANNOT_ACTIVATE_VD_ALREADY_ACTIVE, Helpers.GetName(vm).Ellipsise(50))); } return(base.GetCantExecuteReasonCore(item)); }
protected override string GetCantExecuteReasonCore(IXenObject item) { VDI vdi = item 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)); }