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.cbt_enabled) { return(Messages.CANNOT_MOVE_CBT_ENABLED_VDI); } 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 = vdi.Connection.Resolve(vdi.SR); if (sr == null) { return(base.GetCantExecuteReasonCore(item)); } if (sr.HBALunPerVDI()) { return(Messages.UNSUPPORTED_SR_TYPE); } if (Helpers.DundeePlusOrGreater(vdi.Connection) && !sr.allowed_operations.Contains(storage_operations.vdi_mirror)) { return(Messages.UNSUPPORTED_SR_TYPE); } return(base.GetCantExecuteReasonCore(item)); }
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.cbt_enabled) { return(Messages.CANNOT_MOVE_CBT_ENABLED_VDI); } 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)); }
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)); }