예제 #1
0
        /// <summary>
        /// Check if given user exists in the group provided
        /// </summary>
        /// <param name="uname">User name</param>
        /// <param name="role">Group</param>
        /// <returns>bool value true/false</returns>
        internal static bool CheckIfUserExistsInGroup(string uname, WCSSecurityRole role)
        {
            DirectoryEntry    AD     = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
            DirectorySearcher search = new DirectorySearcher("WinNT://" + Environment.MachineName + ",computer");
            bool userExistsInGrp     = false;

            try
            {
                DirectoryEntry myEntry = AD.Children.Find(uname, "user");
                DirectoryEntry grp     = AD.Children.Find(role.ToString(), "group");
                if (grp != null)
                {
                    if (grp.Properties["member"].Contains(myEntry))
                    {
                        Tracer.WriteInfo("user exists in group :" + role.ToString());
                        userExistsInGrp = true;
                    }
                }
            }
            // This exception is thrown when group does not exist
            catch (System.Runtime.InteropServices.COMException)
            {
                // Return false if group cannot be found
                userExistsInGrp = false;
            }

            return(userExistsInGrp);
        }
예제 #2
0
        private SerialStatusPacket openSerialPortConsole(byte id, int communicationDeviceTimeoutIn1ms, BaudRate baudrate)
        {
            // Initialize return packet
            SerialStatusPacket returnPacket = new SerialStatusPacket();

            returnPacket.completionCode = CompletionCode.UnspecifiedError;
            Tracer.WriteInfo("Invoked SerialPortConsole.openSerialPortConsole({0})", id);

            try
            {
                // Call device layer below
                SerialConsolePortOpenResponse serialResponse = (SerialConsolePortOpenResponse)this.SendReceive(this.SerialPortConsoleDeviceType,
                                                                                                               translateSerialPortId(this.PortId), new SerialConsolePortOpenRequest(communicationDeviceTimeoutIn1ms, baudrate),
                                                                                                               typeof(SerialConsolePortOpenResponse), (byte)PriorityLevel.User);

                // check for completion code
                if (serialResponse.CompletionCode != 0)
                {
                    Tracer.WriteError("SerialPortConsole.openSerialPortConsole({0}) error in commdev.sendreceive", id);
                    returnPacket.completionCode = (CompletionCode)serialResponse.CompletionCode;
                }
                else
                {
                    returnPacket.completionCode = CompletionCode.Success;
                }
            }
            catch (System.Exception ex)
            {
                returnPacket.completionCode = CompletionCode.UnspecifiedError;
                Tracer.WriteError(this.PortId, DeviceType.SerialPortConsole, ex);
            }

            return(returnPacket);
        }
        /// <summary>
        /// Resets Chassis Manager Fan -> High Watch dog timer
        /// </summary>
        private static void ResetWatchDog()
        {
            // Reset WatchDogTimer every TimePeriod after setting fan speeds
            ChassisState.Wdt.ResetWatchDogTimer();

            Tracer.WriteInfo("WatchDogTimer was reset");
        }
        private Contracts.PowerState getAcSocketStatus(byte deviceId)
        {
            GetAcSocketStatusResponse response = (GetAcSocketStatusResponse)this.SendReceive(DeviceType.PowerSwitch,
                                                                                             deviceId, new GetAcSocketStatusRequest(),
                                                                                             typeof(GetAcSocketStatusResponse), (byte)PriorityLevel.User);

            if (response.CompletionCode != 0)
            {
                Tracer.WriteInfo("getACSocketStatus - Returning error code: " + response.CompletionCode);
                return(Contracts.PowerState.NA);
            }
            else
            {
                Tracer.WriteInfo("getACSocketStatus - Returning status: " + response.status);
                if (response.status == (byte)Contracts.PowerState.ON)
                {
                    return(Contracts.PowerState.ON);
                }
                else if (response.status == (byte)Contracts.PowerState.OFF)
                {
                    return(Contracts.PowerState.OFF);
                }
                else
                {
                    return(Contracts.PowerState.NA);
                }
            }
        }
        /// <summary>
        /// Initialize Chassis constants and configs
        /// </summary>
        internal static byte Initialize()
        {
            byte status = (byte)CompletionCode.UnspecifiedError;

            status = CommunicationDeviceInitialize();

            Tracer.WriteInfo("Initializing chassis state");
            ChassisState.Initialize();

            BladeInitialize();

            if (status == (byte)CompletionCode.Success)
            {
                Tracer.WriteInfo("Starting Monitoring and internal management threads");
                getBladePwmReqtThread = new Thread(new ThreadStart(RunGetAllBladeRequirements));
                setFanSpeedThread     = new Thread(new ThreadStart(RunSetDeviceCommands));
                psuMonitorThread      = new Thread(new ThreadStart(PsuMonitor.MonitorPsuAlert));

                getBladePwmReqtThread.Start();
                setFanSpeedThread.Start();
                psuMonitorThread.Start();
            }

            return(status);
        }
예제 #6
0
        /// <summary>
        /// Identifies the PSU vendor at each psu slot using the modelnumber API of the PsuBase class
        /// (Assumes all PSU vendors implement the MFR_MODEL Pmbus command)
        /// Based on the model number, we bind the Psu class object to the corresponding child (vendor) class object
        /// </summary>
        private void PsuInitialize()
        {
            for (uint psuIndex = 0; psuIndex < MaxPsuCount; psuIndex++)
            {
                PsuModelNumberPacket modelNumberPacket = new PsuModelNumberPacket();
                modelNumberPacket = ChassisState.Psu[psuIndex].GetPsuModel();
                string   psuModelNumber = modelNumberPacket.ModelNumber;
                PsuModel model          = ChassisState.ConvertPsuModelNumberToPsuModel(psuModelNumber);

                switch (model)
                {
                case PsuModel.Delta:
                    ChassisState.Psu[psuIndex] = new DeltaPsu((byte)(psuIndex + 1));
                    Tracer.WriteInfo("Delta Psu identified at slot-{0}", psuIndex + 1);
                    break;

                case PsuModel.Emerson:
                    ChassisState.Psu[psuIndex] = new EmersonPsu((byte)(psuIndex + 1));
                    Tracer.WriteInfo("Emerson Psu identified at slot-{0}", psuIndex + 1);
                    break;

                default:
                    ChassisState.Psu[psuIndex] = new PsuBase((byte)(psuIndex + 1));
                    Tracer.WriteInfo("Unidentified PSU at slot-{0}", psuIndex + 1);
                    break;
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Write to Chassis Fru - (Important) note that this function enables write to any offset
        /// Offset checks ensures that we are within permissible limits, but cannot enforce semantics within those limits
        /// Length checks validity of packet, however empty fields in packet are responsibility of writing function
        /// User level priority since this is not an internal call
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        /// <param name="packet"></param>
        /// <returns></returns>
        public byte writeChassisFru(ushort offset, ushort length, byte[] packet)
        {
            byte deviceId = 1;

            ChassisFruWriteResponse response = new ChassisFruWriteResponse();

            try
            {
                response = (ChassisFruWriteResponse)this.SendReceive(DeviceType.ChassisFruEeprom, deviceId, new ChassisFruWriteRequest(offset, length, packet),
                                                                     typeof(ChassisFruWriteResponse), (byte)PriorityLevel.User);
            }
            catch (Exception ex)
            {
                Tracer.WriteWarning("ChassisFru write had an exception", ex);
            }

            if (response.CompletionCode != (byte)CompletionCode.Success)
            {
                Tracer.WriteError("Fru Write failed with completion code {0:X}", response.CompletionCode);
            }
            else
            {
                Tracer.WriteInfo("Fru Write succeeded");
            }

            return((byte)response.CompletionCode);
        }
예제 #8
0
        /// <summary>
        /// Reads raw CM information - can be called individually if needed
        /// User level priority since this is not an internal call
        /// </summary>
        public ChassisFruReadResponse readRawChassisFru(ushort offset, ushort length)
        {
            byte deviceId = 1;
            ChassisFruReadResponse response = new ChassisFruReadResponse();

            try
            {
                response = (ChassisFruReadResponse)this.SendReceive(DeviceType.ChassisFruEeprom, deviceId, new ChassisFruReadRequest(offset, length),
                                                                    typeof(ChassisFruReadResponse), (byte)PriorityLevel.User);
            }
            catch (Exception ex)
            {
                Tracer.WriteWarning("Chassis Fru read had an exception", ex);
            }

            if (response.CompletionCode != (byte)CompletionCode.Success)
            {
                Tracer.WriteError("Fru read failed with completion code {0:X}", response.CompletionCode);
            }
            else
            {
                Tracer.WriteInfo("Chassis Fru info read: {0:X}", response.DataReturned.ToString());
            }
            return(response);
        }
예제 #9
0
        internal static Contracts.ChassisResponse SendBladeSerialData(int bladeId, string sessionToken, byte[] data)
        {
            Contracts.ChassisResponse response = new Contracts.ChassisResponse();
            response.completionCode = Contracts.CompletionCode.Failure;
            Tracer.WriteInfo("BladeSerialSessionMetadata.SendBladeSerialData({0})", bladeId);

            // If there is NOT an already existing Blade serial session (indicated by a invalid bladeId and a invalid sessionToken), return failure with appropriate completion code
            if (CompareAndSwapMetadata(ConfigLoaded.InactiveBladePortId, ConfigLoaded.InactiveBladeSerialSessionToken, ConfigLoaded.InactiveBladePortId, ConfigLoaded.InactiveBladeSerialSessionToken) == CompletionCode.Success)
            {
                Tracer.WriteError("SendBladeSerialData({0}): Send failed because of no active session.", bladeId);
                response.completionCode = Contracts.CompletionCode.NoActiveSerialSession;
                return(response);
            }

            // If this bladeid currently holds the serial session, update the timestamp else return failure
            if (BladeSerialSessionMetadata.CompareAndSwapMetadata(bladeId, sessionToken, bladeId, sessionToken, DateTime.Now) != CompletionCode.Success)
            {
                response.completionCode = Contracts.CompletionCode.SerialSessionActive;
                return(response);
            }

            BladeSerialSession currSession  = new BladeSerialSession((byte)bladeId);
            SerialStatusPacket serialStatus = new SerialStatusPacket();

            serialStatus = currSession.sendSerialData(data);
            if (serialStatus.completionCode != CompletionCode.Success)
            {
                Tracer.WriteError("BladeSerialSessionMetadata.SendBladeSerialData({0}): Error in BladeSerialSession.sendSerialData()", bladeId);
                return(response);
            }
            response.completionCode = Contracts.CompletionCode.Success;
            return(response);
        }
        private BladePowerStatePacket SetBladePowerState(byte deviceId, byte state)
        {
            // Initialize return packet
            BladePowerStatePacket returnPacket = new BladePowerStatePacket();

            returnPacket.CompletionCode  = CompletionCode.UnspecifiedError;
            returnPacket.BladePowerState = 3;

            Tracer.WriteInfo("SetSledPowerState Switch id: " + deviceId);

            if (state == (byte)Contracts.PowerState.ON)
            {
                try
                {
                    BladePowerStateOnResponse response = (BladePowerStateOnResponse)this.SendReceive(this.DeviceType, deviceId, new BladePowerStateOnRequest(state), typeof(BladePowerStateOnResponse));
                    if (response.CompletionCode != 0)
                    {
                        returnPacket.CompletionCode = (CompletionCode)response.CompletionCode;
                    }
                    else
                    {
                        returnPacket.CompletionCode    = CompletionCode.Success;
                        returnPacket.BladePowerState   = 1; //NOTE: response is not actually returned.
                        returnPacket.DecompressionTime = response.DecompressionTime;
                    }
                }
                catch (System.Exception ex)
                {
                    returnPacket.CompletionCode  = CompletionCode.UnspecifiedError;
                    returnPacket.BladePowerState = 3;
                    Tracer.WriteError(this.DeviceId, DeviceType.Power, ex);
                }
            }
            else
            {
                try
                {
                    BladePowerStateOffResponse response = (BladePowerStateOffResponse)this.SendReceive(this.DeviceType, deviceId, new BladePowerStateOffRequest(state), typeof(BladePowerStateOffResponse));
                    if (response.CompletionCode != 0)
                    {
                        returnPacket.CompletionCode = (CompletionCode)response.CompletionCode;
                    }
                    else
                    {
                        returnPacket.CompletionCode    = CompletionCode.Success;
                        returnPacket.BladePowerState   = 0; // blade is off
                        returnPacket.DecompressionTime = 0; // blade is off.
                    }
                }
                catch (System.Exception ex)
                {
                    returnPacket.CompletionCode  = CompletionCode.UnspecifiedError;
                    returnPacket.BladePowerState = 3;
                    Tracer.WriteError(this.DeviceId, DeviceType.Power, ex);
                }
            }

            return(returnPacket);
        }
예제 #11
0
 public ChassisFruReadRequest(ushort offset, ushort length)
 {
     Tracer.WriteInfo("Offset: {0}, Length: {1} inside ChassisFru class", offset, length);
     this.lowOffset  = getLowByte(offset);
     this.highOffset = getHighByte(offset);
     this.lowLength  = getLowByte(length);
     this.highLength = getHighByte(length);
 }
예제 #12
0
        /// <summary>
        /// Read function
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public byte readChassisFru()
        {
            // Constants - TODO - move to config file
            ushort offset          = (ushort)ConfigLoaded.ChassisStartingOffset;
            ushort length          = (ushort)ConfigLoaded.ChassisFruLength;
            ushort internalUseSize = (ushort)ConfigLoaded.InternalUseSize; // bytes
            ushort chassisInfoSize = (ushort)ConfigLoaded.ChassisInfoSize; // bytes
            ushort boardInfoSize   = (ushort)ConfigLoaded.BoardInfoSize;   // bytes
            ushort productInfoSize = (ushort)ConfigLoaded.ProductInfoSize; // bytes

            try
            {
                ChassisFruReadResponse fruResponse = readRawChassisFru(offset, length);

                if (fruResponse.CompletionCode != 0 || fruResponse.DataReturned == null)
                {
                    Tracer.WriteInfo("Error in CM Fru Read {0}", fruResponse.CompletionCode);
                    this._completionCode = (byte)CompletionCode.UnspecifiedError;
                    return(this._completionCode);
                }

                Ipmi.FruCommonHeader commonHeader = new Ipmi.FruCommonHeader(fruResponse.DataReturned);
                ushort areaOffset;

                byte[] chassisInfoBytes = new byte[chassisInfoSize];
                byte[] boardInfoBytes   = new byte[boardInfoSize];
                byte[] productInfoBytes = new byte[productInfoSize];

                areaOffset = commonHeader.ChassisInfoStartingOffset;
                if (areaOffset != 0)
                {
                    Array.Copy(fruResponse.DataReturned, areaOffset, chassisInfoBytes, 0, chassisInfoSize);
                }

                areaOffset = commonHeader.BoardAreaStartingOffset;
                if (areaOffset != 0)
                {
                    Array.Copy(fruResponse.DataReturned, areaOffset, boardInfoBytes, 0, boardInfoSize);
                }

                areaOffset = commonHeader.ProductAreaStartingOffset;
                if (areaOffset != 0)
                {
                    Array.Copy(fruResponse.DataReturned, areaOffset, productInfoBytes, 0, productInfoSize);
                }

                this.PopulateChassisFru(commonHeader,
                                        chassisInfoBytes,
                                        boardInfoBytes,
                                        productInfoBytes, fruResponse.CompletionCode);
            }
            catch (Exception e)
            {
                Tracer.WriteError("CM Fru Read had exception {0}", e);
                this._completionCode = (byte)CompletionCode.UnspecifiedError;
            }
            return(this._completionCode);
        }
예제 #13
0
        /// <summary>
        /// Identifies the PSU vendor at each psu slot using the modelnumber API of the PsuBase class
        /// (Assumes all PSU vendors implement the MFR_MODEL Pmbus command)
        /// Based on the model number, we bind the Psu class object to the corresponding child (vendor) class object
        /// </summary>
        private static void PsuInitialize()
        {
            for (uint psuIndex = 0; psuIndex < ConfigLoaded.NumPsus; psuIndex++)
            {
                // Initially create instance of the base class
                // Later.. based on the psu model number, we create the appropriate psu class object
                Psu[psuIndex] = new PsuBase((byte)(psuIndex + 1));

                PsuModelNumberPacket modelNumberPacket = new PsuModelNumberPacket();
                modelNumberPacket = Psu[psuIndex].GetPsuModel();
                string   psuModelNumber = modelNumberPacket.ModelNumber;
                PsuModel model          = ConvertPsuModelNumberToPsuModel(psuModelNumber);

                switch (model)
                {
                case PsuModel.Delta:
                    Psu[psuIndex] = new DeltaPsu((byte)(psuIndex + 1));
                    Tracer.WriteInfo("Delta PSU identified at slot-{0}, Model Number: {1}", psuIndex + 1, psuModelNumber);
                    break;

                case PsuModel.EmersonWithLes:
                    Psu[psuIndex] = new EmersonPsu((byte)(psuIndex + 1), true);
                    Tracer.WriteInfo("Emerson with LES PSU identified at slot-{0}, Model Number: {1}", psuIndex + 1, psuModelNumber);
                    break;

                case PsuModel.EmersonNonLes:
                    Psu[psuIndex] = new EmersonPsu((byte)(psuIndex + 1), false);
                    Tracer.WriteInfo("Emerson non-LES PSU identified at slot-{0}, Model Number: {1}", psuIndex + 1, psuModelNumber);
                    break;

                default:
                    // Unknown PSUs
                    if (ConfigLoaded.ForceEmersonPsu)
                    {
                        // Force to Emerson PSU without LES to enable FW update methods in the EmersonPsu class to be called.
                        // This is useful when a previous FW update did not complete successfully.
                        // The PSU stays in bootloader mode and does not recognize the
                        // MFR_MODEL command and will return all 0xFFs for this command.
                        Psu[psuIndex] = new EmersonPsu((byte)(psuIndex + 1), false);
                        Tracer.WriteWarning("Forcing PSU instantiation to Emerson non-LES PSU at slot-{0}, Model Number: {1}",
                                            psuIndex + 1, psuModelNumber);
                    }
                    else
                    {
                        Psu[psuIndex] = new PsuBase((byte)(psuIndex + 1));
                        Tracer.WriteInfo("Unidentified PSU at slot-{0}, Model Number: {1}. Default to base PSU class.", psuIndex + 1, psuModelNumber);
                    }
                    break;
                }

                // Enable/disable Battery Extended Operation Mode
                Psu[psuIndex].SetBatteryExtendedOperationMode(ConfigLoaded.DatasafeOperationsEnabled ? true: false);
            }
        }
        /// <summary>
        /// Chassis Manager initialize function
        /// </summary>
        public void Initialize()
        {
            Tracer.WriteInfo("Chassis Manager Internal Initialization started..");
            byte status = ChassisManagerInternal.Initialize();

            if (status != (byte)CompletionCode.Success)
            {
                Tracer.WriteError("Chassis manager failed to initialize at {0}", DateTime.Now);
                this.Stop();
            }
            Tracer.WriteInfo("Chassis Manager initialization completed");
        }
예제 #15
0
        /// <summary>
        /// Check Blade Power limit is in acceptable range
        /// </summary>
        /// <param name="powerLimitInWatts"></param>
        /// <returns></returns>
        internal static bool CheckBladePowerLimit(double powerLimitInWatts)
        {
            bool success = false;

            Tracer.WriteInfo("Inside Check Blade Power Limit");
            if (powerLimitInWatts >= ConfigLoaded.MinPowerLimit && powerLimitInWatts <= ConfigLoaded.MaxPowerLimit)
            {
                success = true;
            }

            return(success);
        }
예제 #16
0
        internal static Contracts.StartSerialResponse StartBladeSerialSession(int bladeId, int timeoutInSecs)
        {
            Contracts.StartSerialResponse response = new Contracts.StartSerialResponse();
            response.completionCode     = Contracts.CompletionCode.Failure;
            response.serialSessionToken = null;
            Tracer.WriteInfo("BladeSerialSessionMetadata StartBladeSerialSession({0})", bladeId);

            // If there is an already existing Blade serial session (indicated by a valid bladeId and a valid sessionToken), return failure with appropriate completion code
            if (CompareAndSwapMetadata(ConfigLoaded.InactiveBladePortId, ConfigLoaded.InactiveBladeSerialSessionToken, ConfigLoaded.InactiveBladePortId, ConfigLoaded.InactiveBladeSerialSessionToken) != CompletionCode.Success)
            {
                Tracer.WriteError("StartBladeSerialSession({0}): Start failed because of already active session.", bladeId);
                response.completionCode = Contracts.CompletionCode.SerialSessionActive;
                return(response);
            }

            // Ipmi command to indicate start of serial session
            // This has to be executed before Enabling comm. dev. safe mode otherwise this will fail
            Ipmi.SerialMuxSwitch sms = WcsBladeFacade.SetSerialMuxSwitch((byte)bladeId, Ipmi.MuxSwtich.SwitchSystem);

            // If set serial mux fails - reverse all operations
            if (sms.CompletionCode != (byte)CompletionCode.Success)
            {
                Tracer.WriteError("BladeSerialSessionMetadata.StartBladeSerialSession({0}): Ipmi SetSerialMuxSwitch Failed", bladeId);
                if (!CommunicationDevice.DisableSafeMode())
                {
                    Tracer.WriteError("BladeSerialSessionMetadata.StartBladeSerialSession({0}): Unable to disable comm.dev. safe mode", bladeId);
                }
                // Whenever we disable safe mode, make sure that no more serial session activity may be performed - by reseting metadata
                if (!BladeSerialSessionMetadata.ResetMetadata())
                {
                    Tracer.WriteError("BladeSerialSessionMetadata.StopBladeSerialSession({0}): Unable to reset metadata", bladeId);
                }
                return(response);
            }

            byte[] randomNumber = new byte[8];
            new System.Security.Cryptography.RNGCryptoServiceProvider().GetNonZeroBytes(randomNumber);

            // Initialize Blade Serial Session MetaData - Init function does this automically
            // This function acts as a serialization point - only one active thread can proceed beyond this
            if (CompareAndSwapMetadata(ConfigLoaded.InactiveBladePortId, ConfigLoaded.InactiveBladeSerialSessionToken, bladeId, BitConverter.ToString(randomNumber), DateTime.Now) != CompletionCode.Success)
            {
                response.completionCode = Contracts.CompletionCode.SerialSessionActive;
                return(response);
            }

            response.completionCode     = Contracts.CompletionCode.Success;
            response.serialSessionToken = BitConverter.ToString(randomNumber);
            // Initializing TimeoutBladeSerialSessionInSecs with user defined session timeout
            ConfigLoaded.TimeoutBladeSerialSessionInSecs = timeoutInSecs;
            return(response);
        }
예제 #17
0
        /// <summary>
        /// Reinitialize the sled and set chassis state
        /// </summary>
        private void ReInitialize(byte sledId)
        {
            // Serialize initialize and power behavior per sled
            lock (ChassisState._lock[sledId - 1])
            {
                ChassisState.FailCount[sledId - 1] = 0;                // reset fail count since we are going to reinitialize the blade

                bool status = WcsBladeFacade.InitializeClient(sledId); // TODO: no completion code, only byte status returned

                if (status != true)
                {
                    // Initialization failed - move to fail state before retrying again
                    Tracer.WriteInfo("Reinitialization failed with code: {0} for Sled: {1}", status, sledId);
                    Tracer.WriteInfo("State Transition for Sled {0}: {1} -> Fail", sledId,
                                     ChassisState.GetStateName(sledId));

                    ChassisState.SetBladeState((byte)sledId, (byte)BladeState.Fail);

                    // check power status to see if the blade was manually switched off or removed
                    BladePowerStatePacket response = ChassisState.BladePower[sledId - 1].GetBladePowerState();

                    // If the blade was turned off, set correct status / TODO: do we need this here?
                    if (response.BladePowerState == (byte)Contracts.PowerState.OFF)
                    {
                        Tracer.WriteInfo("SledId {0} is in hard power off state", sledId);
                        Tracer.WriteInfo("State Transition for Sled {0}: {1} -> HardPowerOff", sledId,
                                         ChassisState.GetStateName(sledId));

                        ChassisState.SetBladeState(sledId, (byte)BladeState.HardPowerOff);
                    }
                }
                else
                {
                    // State change: I -> P
                    Tracer.WriteInfo("Reinitialization of Sled: {0} succeeded with status {1}", sledId, status);

                    Tracer.WriteInfo("State Transition for Sled {0}: {1} -> Probation", sledId,
                                     ChassisState.GetStateName(sledId));
                    ChassisState.SetBladeState(sledId, (byte)BladeState.Probation);

                    // Initialize Blade Type (Type might have changed when Blades were reinserted)
                    if (WcsBladeFacade.clients.ContainsKey(sledId))
                    {
                        ChassisState.BladeTypeCache[sledId - 1] = (byte)WcsBladeFacade.clients[sledId].BladeClassification;
                    }
                    else
                    {
                        ChassisState.BladeTypeCache[sledId - 1] = (byte)BladeType.Unknown;
                    }
                }
            }
        }
예제 #18
0
 /// <summary>
 /// Get the physical port name from a logical port ID.
 /// Returns null if an invalid logical port ID
 /// </summary>
 /// <param name="lpId"></param>
 /// <returns></returns>
 internal static protected string GetPhysicalPortNameFromLogicalId(int lpId)
 {
     if (lpId >= 0 && lpId < physicalPortNames.Length)
     {
         Tracer.WriteInfo("GetPhysicalPortNameFromLogicalId({0})", physicalPortNames[lpId]);
         return(physicalPortNames[lpId]);
     }
     else
     {
         Tracer.WriteInfo("GetPhysicalPortNameFromLogicalId: Error Invalid port");
         return(null);
     }
 }
예제 #19
0
        /// <summary>
        /// Checking portId range
        /// </summary>
        /// <param name="portId"></param>
        /// <returns></returns>
        internal static byte CheckSerialConsolePortId(byte portId)
        {
            Tracer.WriteInfo("Inside CheckPortID");
            int portIndex = GetSerialConsolePortIndexFromId(portId);

            if (portIndex == -1 || portIndex >= ConfigLoaded.MaxSerialConsolePorts)
            {
                return((byte)CompletionCode.InvalidBladeId);
            }
            else
            {
                return((byte)CompletionCode.Success);
            }
        }
예제 #20
0
        /// <summary>
        /// Checking bladeId range
        /// </summary>
        /// <param name="bladeId"></param>
        /// <returns></returns>
        internal static byte CheckBladeId(byte bladeId)
        {
            Tracer.WriteInfo("Inside CheckBladeID");
            byte maxBladeCount = (byte)ConfigLoaded.Population;

            if (bladeId < 1 || bladeId > maxBladeCount)
            {
                return((byte)CompletionCode.InvalidBladeId);
            }
            else
            {
                return((byte)CompletionCode.Success);
            }
        }
        public Contracts.ChassisResponse StopSerialPortConsole(int portID, string sessionToken, bool forceKillExistingSession = false)
        {
            Contracts.ChassisResponse response = new Contracts.ChassisResponse();
            response.completionCode = Contracts.CompletionCode.Failure;
            this.portId             = portID;

            Tracer.WriteInfo("Received StopSerialPortConsole({0}) with sessionToken({1}) and forcekill({2})", this.portId, sessionToken, forceKillExistingSession);
            Tracer.WriteUserLog("Received StopSerialPortConsole({0}) with sessionToken({1}) and forcekill({2})", this.portId, sessionToken, forceKillExistingSession);
            int currPort = this.portId;

            // If there is NOT an already existing serial session (indicated by an invalid sessionToken), return failure with appropriate completion code
            if (CompareAndSwapMetadata(ConfigLoaded.InactiveSerialPortSessionToken, ConfigLoaded.InactiveSerialPortSessionToken) == CompletionCode.Success)
            {
                Tracer.WriteError("StopSerialPortConsole({0}): Stop failed because of no active session.", portID);
                response.completionCode = Contracts.CompletionCode.NoActiveSerialSession;
                return(response);
            }

            if (!forceKillExistingSession)
            {
                // If this do not currently hold the serial session, return failure
                if (CompareAndSwapMetadata(sessionToken, sessionToken) != CompletionCode.Success)
                {
                    response.completionCode = Contracts.CompletionCode.SerialSessionActive;
                    return(response);
                } // else proceed further to stop the session
            }
            else
            {
                // else force kill the current session
            }

            // Ipmi command to indicate end of serial session
            if (!ResetMetadata())
            {
                Tracer.WriteError("StopSerialPortConsole({0}): Unable to reset metadata", this.portId);
            }
            SerialPortConsole  currConsole  = new SerialPortConsole((byte)currPort);
            SerialStatusPacket serialStatus = new SerialStatusPacket();

            serialStatus = currConsole.closeSerialPortConsole();
            if (serialStatus.completionCode != CompletionCode.Success)
            {
                Tracer.WriteError("StopSerialConsolePort({0}): Error in closeserialportconsole()", currPort);
                return(response);
            }
            response.completionCode = Contracts.CompletionCode.Success;
            return(response);
        }
예제 #22
0
        /// <summary>
        /// Enable safe mode
        /// </summary>
        static internal bool EnableSafeMode()
        {
            int logicalPortIdForServers = (byte)LogicalPortId.SerialPortServers;

            if ((portManagers == null) ||
                (portManagers[logicalPortIdForServers] == null))
            {
                Tracer.WriteError("[CommunicationDevice] Failed to enable safe mode");
                return(false);
            }
            portManagers[logicalPortIdForServers].EnableSafeMode();
            isSafeModeEnabled = true;
            Tracer.WriteInfo("[CommunicationDevice] Safe mode has been enabled");
            return(true);
        }
예제 #23
0
        /// <summary>
        /// Check if in safe mode
        /// </summary>
        static internal bool IsSafeMode()
        {
            int logicalPortIdForServers = (byte)LogicalPortId.SerialPortServers;

            if ((portManagers == null) ||
                (portManagers[logicalPortIdForServers] == null))
            {
                Tracer.WriteError("[CommunicationDevice] Failed to enable safe mode");
                return(false);
            }
            bool status = portManagers[logicalPortIdForServers].IsSafeMode();

            Tracer.WriteInfo("[CommunicationDevice] Safe mode status {0}", status);
            return(status);
        }
        /// <summary>
        /// Clears Psu Fault condition
        /// </summary>
        private static CompletionCode ClearPsuFault(byte psuId)
        {
            CompletionCode clearFaultCompletionCode = ChassisState.Psu[psuId - 1].SetPsuClearFaults();

            if (clearFaultCompletionCode != CompletionCode.Success)
            {
                Tracer.WriteError("ClearPsuFault for PSU {0} failed. Completion code({1})", psuId, clearFaultCompletionCode);
            }
            else
            {
                Tracer.WriteInfo("ClearPsuFault for PSU {0} succeeded.", psuId);
            }

            return(clearFaultCompletionCode);
        }
예제 #25
0
        /// <summary>
        /// Internal operation to call both hard power on (soft power on is not exposed to the user)
        /// </summary>
        /// <param name="bladeId">Blade ID</param>
        /// <returns>True/false for success/failure</returns>
        internal static bool PowerOn(int bladeId)
        {
            Tracer.WriteInfo("Received poweron({0})", bladeId);
            bool powerOnStatus = false;

            BladePowerStatePacket bladePowerSwitchStatePacket = new BladePowerStatePacket();
            CompletionCode        status;

            // Hard Power enable
            // Serialize setting of state and actual code logic
            lock (ChassisState.locker[bladeId - 1])
            {
                BladePowerStatePacket currState = ChassisState.BladePower[bladeId - 1].GetBladePowerState();

                if (currState.CompletionCode != CompletionCode.Success ||
                    (currState.BladePowerState == (byte)Contracts.PowerState.OFF))
                {
                    // No return here, because we still want to return a BMC state on the fall through,
                    // if Blade enable read fails for whatever reason
                    Tracer.WriteWarning("PowerOn: Blade {0} Power Enable state read failed (Completion Code: {1:X})", bladeId, currState.CompletionCode);

                    bladePowerSwitchStatePacket = ChassisState.BladePower[bladeId - 1].SetBladePowerState((byte)PowerState.ON);
                    status = bladePowerSwitchStatePacket.CompletionCode;
                    Tracer.WriteInfo("Hard poweron status " + status);

                    if (status == CompletionCode.Success)
                    {
                        // Hard power on status is true, so Blade should be set to Initialization state on success
                        Tracer.WriteInfo("PowerOn: State Transition for blade {0}: {1} -> Initialization", bladeId,
                                         ChassisState.GetStateName((byte)bladeId));

                        ChassisState.SetBladeState((byte)bladeId, (byte)BladeState.Initialization);
                        powerOnStatus = true;
                    }
                    else
                    {
                        Tracer.WriteWarning("PowerOn: Hard Power On failed for BladeId {0} with code {1:X}", bladeId, status);
                    }
                }
                else
                {
                    powerOnStatus = true; // the blade was already powered on, so we dont power it on again
                }
            }
            return(powerOnStatus);
        }
예제 #26
0
        // This function should be called before executing any service APIs
        // TODO: Add other checks that needs to be done before executing APIs - like check for chassis terminating etc
        internal static CompletionCode ApiGreenSignalling()
        {
            CompletionCode response = new CompletionCode();

            response = CompletionCode.UnspecifiedError;

            int currBladeId = bladeId;

            // Return Success if there is no active serial console session in progress
            if (!BladeSerialSessionMetadata.IsSerialConsoleSessionActive())
            {
                response = CompletionCode.Success;
                return(response);
            }

            // If App.config parameter, KillSerialConsoleSession, is enabled,
            // terminate existing serial console session and proceed executing incoming commmands.
            if (ConfigLoaded.KillSerialConsoleSession)
            {
                response = CompletionCode.UnspecifiedError;

                Tracer.WriteInfo("Kill serial console session is enabled to allow incoming commands to succeed.");
                Contracts.ChassisResponse sessionResponse = new Contracts.ChassisResponse();
                sessionResponse = StopBladeSerialSession(ConfigLoaded.InactiveBladePortId, ConfigLoaded.InactiveBladeSerialSessionToken, true);
                if (sessionResponse.completionCode != Contracts.CompletionCode.Success)
                {
                    Tracer.WriteError("BladeSerialSessionMetadata.ApiGreenSignalling:Error stopserialsession failed");
                    return(response);
                }

                response = CompletionCode.Success;
                return(response);
            }
            // If App.config parameter, KillSerialConsoleSession, is not  enabled, maintain existing serial console session,
            // and ignore incoming commands, with explicit failure message output as warning in trace, since it will not
            // affect service correctness.
            else
            {
                response = CompletionCode.SerialPortOtherErrors;
                Tracer.WriteWarning("Serial console session in progress. Ignore incoming command with message:{0}", response);

                // We are returning non-Success completion code (represented as SerialPortOtherErrors)
                // to indicate/trigger the failure of this incoming command.
                return(response);
            }
        }
        /// <summary>
        /// Halt all threads and stop all activities
        /// </summary>
        internal static void Halt()
        {
            // Stop the internal get and set threads by setting this global variable
            ChassisState.ShutDown = true;

            // Wait for threads to complete their current logic before stopping
            if (getBladePwmReqtThread != null)
            {
                try
                {
                    getBladePwmReqtThread.Join(ConfigLoaded.ThreadJoinTimeout);
                    Tracer.WriteInfo("OnStop: getBladePwmReqtThread thread joined");
                }
                catch (Exception ex)
                {
                    Tracer.WriteError(0, "Halt.getBladePwmReqtThread", ex);
                }
            }

            if (setFanSpeedThread != null)
            {
                try
                {
                    setFanSpeedThread.Join(ConfigLoaded.ThreadJoinTimeout);
                    Tracer.WriteInfo("OnStop: setFanSpeedThread thread joined");
                }
                catch (Exception ex)
                {
                    Tracer.WriteError(0, "Halt.setFanSpeedThread", ex);
                }
            }

            if (psuMonitorThread != null)
            {
                try
                {
                    psuMonitorThread.Join(ConfigLoaded.ThreadJoinTimeout);
                    Tracer.WriteInfo("OnStop: psuMonitorThread thread joined");
                }
                catch (Exception ex)
                {
                    Tracer.WriteError(0, "Halt.psuMonitorThread", ex);
                }
            }
        }
예제 #28
0
        /// <summary>
        /// The code that is executed by the worker thread
        /// 1. Wait for a new work item
        /// 2. Generate a data packet using the request information
        /// 3. Send the generated packet over the port
        /// 4. Receive the response from the target hardware device
        /// 5. Generate/copy a response packet
        /// 6. Signal the waiting user-level thread
        /// 7. Repeat above
        /// Note: For serviceability purpose, continue to execute
        /// the main loop even with an unhandled exception
        /// </summary>
        private void WorkerThreadFunction()
        {
            while (true)
            {
                try
                {
                    while (true)
                    {
                        WorkItem workItem;

                        // Get a new work item
                        workItem = GetWorkItem();

                        if (workItem != null)
                        {
                            Tracer.WriteInfo("[Worker] logicalPortId: {0}, Signaled", logicalPortId);
                            if (shouldTerminateWorkerThread == true)
                            {
                                Tracer.WriteWarning("[Worker] Draining the remaining work item before terminating CM");
                            }
                            SendReceive(ref workItem);
                        }
                        else
                        {
                            // If CM is about to gracefully terminate and there is no more work item in the
                            // queues (i.e., all the queues have been drained), stop this worker thread
                            // by exiting from the main loop
                            if (shouldTerminateWorkerThread == true)
                            {
                                Tracer.WriteInfo("[Worker] Stopping worker threads", logicalPortId);
                                return;
                            }
                            WaitForWorkItem();
                        }
                    }
                }
                catch (Exception e)
                {
                    Tracer.WriteError("Unhandled Exception in PortManager worker thread main loop");
                    Tracer.WriteError(e);
                }
            }
        }
        public Contracts.SerialDataResponse ReceiveSerialPortData(int portID, string sessionToken)
        {
            Contracts.SerialDataResponse response = new Contracts.SerialDataResponse();
            response.completionCode = Contracts.CompletionCode.Failure;
            this.portId             = portID;

            Tracer.WriteInfo("Received ReceiveSerialPortConsoleData({0})", this.portId);

            // If there is NOT an already existing serial session (indicated by an invalid sessionToken), return failure with appropriate completion code
            if (CompareAndSwapMetadata(ConfigLoaded.InactiveSerialPortSessionToken, ConfigLoaded.InactiveSerialPortSessionToken) == CompletionCode.Success)
            {
                Tracer.WriteError("ReceiveSerialPortData({0}): Receive failed because of no active session.", portID);
                response.completionCode = Contracts.CompletionCode.NoActiveSerialSession;
                return(response);
            }

            // If this bladeid currently holds the serial session, update the timestamp else return failure
            if (this.CompareAndSwapMetadata(sessionToken, sessionToken, DateTime.Now) != CompletionCode.Success)
            {
                response.completionCode = Contracts.CompletionCode.SerialSessionActive;
                return(response);
            }

            SerialPortConsole currConsole = new SerialPortConsole((byte)portId);
            SerialDataPacket  serialData  = new SerialDataPacket();

            serialData = currConsole.receiveSerialData();
            if (serialData.completionCode != CompletionCode.Success)
            {
                // Common-case: lots of timeouts if device do not have any data to send over serial
                if (serialData.completionCode == CompletionCode.Timeout)
                {
                    Tracer.WriteInfo("ReceiveSerialPortData({0}) Timeout in SerialConsolePort.receiveSerialData()", portId);
                    response.completionCode = Contracts.CompletionCode.Timeout;
                    return(response);
                }
                Tracer.WriteError("ReceiveSerialPortData({0}) Unknown Error in SerialConsolePort.receiveSerialData()", portId);
                return(response);
            }
            response.data           = serialData.data;
            response.completionCode = Contracts.CompletionCode.Success;
            return(response);
        }
예제 #30
0
        /// <summary>
        /// Find group with given name, if not exists create
        /// </summary>
        /// <param name="role">Group name</param>
        /// <returns>Group DirectorEntry</returns>
        internal static DirectoryEntry FindGroupIfNotExistsCreate(WCSSecurityRole role)
        {
            try
            {
                DirectoryEntry AD  = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
                DirectoryEntry grp = AD.Children.Find(role.ToString(), "group");
                if (grp == null)
                {
                    ChassisManagerUtil.CreateNewGroup(role);
                }

                return(grp);
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                Tracer.WriteInfo(" Group: {0} not found , creating new", role.ToString());
                return(ChassisManagerUtil.CreateNewGroup(role));
            }
        }