protected override string GetCantExecuteReasonCore(SelectedItem item) { VDI vdi = item.XenObject as VDI; if (vdi == null) { return(base.GetCantExecuteReasonCore(item)); } foreach (VBD vbd in vdi.Connection.ResolveAll <VBD>(vdi.VBDs)) { if (targetVM == null || vbd.VM.opaque_ref == targetVM.opaque_ref) { if (!vbd.currently_attached) { continue; } DeactivateVBDCommand cmd = new DeactivateVBDCommand(Program.MainWindow, vbd); if (!cmd.CanExecute()) { var reasons = cmd.GetCantExecuteReasons(); return(reasons.Count > 0 ? reasons.ElementAt(0).Value : Messages.UNKNOWN); } } } return(base.GetCantExecuteReasonCore(item)); }
protected override string GetCantExecuteReasonCore(SelectedItem item) { VDI vdi = item.XenObject as VDI; if (vdi == null) { return(base.GetCantExecuteReasonCore(item)); } foreach (VBD vbd in vdi.Connection.ResolveAll <VBD>(vdi.VBDs)) { if (targetVM == null || vbd.VM.opaque_ref == targetVM.opaque_ref) { if (!vbd.currently_attached) { continue; } DeactivateVBDCommand cmd = new DeactivateVBDCommand(Program.MainWindow, vbd); if (!cmd.CanExecute()) { return(cmd.ToolTipText); } } } return(base.GetCantExecuteReasonCore(item)); }
protected bool CanExecute(VDI vdi) { if (vdi == null) { return(false); } foreach (VBD vbd in vdi.Connection.ResolveAll <VBD>(vdi.VBDs)) { if (targetVM == null || vbd.VM.opaque_ref == targetVM.opaque_ref) { if (!vbd.currently_attached) { continue; } DeactivateVBDCommand cmd = new DeactivateVBDCommand(Program.MainWindow, vbd); if (!cmd.CanExecute()) { return(false); } } } return(true); }
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)); }
protected bool CanExecute(VDI vdi) { if (vdi == null) { return(false); } SR sr = vdi.Connection.Resolve <SR>(vdi.SR); if (sr == null) { return(false); } if (vdi.Locked) { return(false); } if (sr.Physical()) { return(false); } if (sr.IsToolsSR()) { return(false); } if (vdi.IsUsedByHA()) { return(false); } List <VBD> vbds = vdi.Connection.ResolveAll <VBD>(vdi.VBDs); if (vbds.Count > 1 && !AllowMultipleVBDDelete) { return(false); } foreach (VBD vbd in vbds) { VM vm = vdi.Connection.Resolve <VM>(vbd.VM); if (vdi.type == vdi_type.system) { if (vm.power_state == vm_power_state.Running) { return(false); } } if (vbd.Locked) { return(false); } if (vbd.currently_attached) { //Check if we can unplug DeactivateVBDCommand cmd = new DeactivateVBDCommand(Program.MainWindow, vbd); if (!AllowRunningVMDelete || !cmd.CanExecute()) { return(false); } } } if (sr.HBALunPerVDI()) { return(true); } if (!vdi.allowed_operations.Contains(vdi_operations.destroy)) { if (AllowRunningVMDelete) { // We deliberately DONT call allowed operations because we assume we know better :) // Xapi will think we can't delete because VBDs are plugged. We are going to unplug them. // Known risks of this method that will make us fail because we are disrespecting xapi: // - 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 return(true); } return(false); } return(true); }
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); }
protected bool CanExecute(VDI vdi) { SR sr = vdi.Connection.Resolve<SR>(vdi.SR); if (vdi == null || sr == null) return false; if (vdi.Locked) return false; if (sr.Physical) return false; if (sr.IsToolsSR) return false; if (vdi.IsUsedByHA) { return false; } List<VBD> vbds = vdi.Connection.ResolveAll<VBD>(vdi.VBDs); if (vbds.Count > 1 && !AllowMultipleVBDDelete) return false; foreach (VBD vbd in vbds) { VM vm = vdi.Connection.Resolve<VM>(vbd.VM); if (vdi.type == vdi_type.system) { if (vm.power_state == vm_power_state.Running) return false; } if (vbd.Locked) return false; if (vbd.currently_attached) { //Check if we can unplug DeactivateVBDCommand cmd = new DeactivateVBDCommand(Program.MainWindow.CommandInterface, vbd); if (!AllowRunningVMDelete || !cmd.CanExecute()) return false; } } if (sr.HBALunPerVDI) return true; if (!vdi.allowed_operations.Contains(vdi_operations.destroy)) { if (AllowRunningVMDelete) { // We deliberately DONT call allowed operations because we assume we know better :) // Xapi will think we can't delete because VBDs are plugged. We are going to unplug them. // Known risks of this method that will make us fail because we are disrespecting xapi: // - 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 return true; } return false; } return true; }
protected override string GetCantExecuteReasonCore(SelectedItem item) { VDI vdi = item.XenObject as VDI; if (vdi == null) return base.GetCantExecuteReasonCore(item); foreach (VBD vbd in vdi.Connection.ResolveAll<VBD>(vdi.VBDs)) { if (targetVM == null || vbd.VM.opaque_ref == targetVM.opaque_ref) { if (!vbd.currently_attached) continue; DeactivateVBDCommand cmd = new DeactivateVBDCommand(Program.MainWindow, vbd); if (!cmd.CanExecute()) { var reasons = cmd.GetCantExecuteReasons(); return reasons.Count > 0 ? reasons.ElementAt(0).Value : Messages.UNKNOWN; } } } return base.GetCantExecuteReasonCore(item); }
protected bool CanExecute(VDI vdi) { if (vdi == null) return false; foreach (VBD vbd in vdi.Connection.ResolveAll<VBD>(vdi.VBDs)) { if (targetVM == null || vbd.VM.opaque_ref == targetVM.opaque_ref) { if (!vbd.currently_attached) continue; DeactivateVBDCommand cmd = new DeactivateVBDCommand(Program.MainWindow, vbd); if (!cmd.CanExecute()) return false; } } return true; }
protected override string GetCantExecuteReasonCore(SelectedItem item) { VDI vdi = item.XenObject as VDI; if (vdi == null) return base.GetCantExecuteReasonCore(item); foreach (VBD vbd in vdi.Connection.ResolveAll<VBD>(vdi.VBDs)) { if (targetVM == null || vbd.VM.opaque_ref == targetVM.opaque_ref) { if (!vbd.currently_attached) continue; DeactivateVBDCommand cmd = new DeactivateVBDCommand(Program.MainWindow.CommandInterface, vbd); if (!cmd.CanExecute()) return cmd.ToolTipText; } } return base.GetCantExecuteReasonCore(item); }