Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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 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);

            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);
        }