예제 #1
0
        private bool CanExecute(VBD vbd)
        {
            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 || vdi.Locked || vbd.Locked)
            {
                return(false);
            }
            if (vm.power_state != vm_power_state.Running)
            {
                return(false);
            }
            if (vdi.type == vdi_type.system && vbd.GetIsOwner())
            {
                return(false);
            }
            if (AreIODriversNeededAndMissing(vm))
            {
                return(false);
            }
            if (!vbd.currently_attached)
            {
                return(false);
            }

            return(vbd.allowed_operations.Contains(vbd_operations.unplug));
        }
예제 #2
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));
        }