当前位置: 首页>>代码示例>>C#>>正文


C# Contracts.ChassisResponse类代码示例

本文整理汇总了C#中Contracts.ChassisResponse的典型用法代码示例。如果您正苦于以下问题:C# Contracts.ChassisResponse类的具体用法?C# Contracts.ChassisResponse怎么用?C# Contracts.ChassisResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Contracts.ChassisResponse类属于命名空间,在下文中一共展示了Contracts.ChassisResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApiGreenSignalling

        // 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;

            // Return Success if there is no active serial console session in progress - by checking the safe mode
            if (!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(BladeId, ConfigLoaded.InactiveBladeSerialSessionToken, true);
                if (sessionResponse.completionCode != Contracts.CompletionCode.Success)
                {
                    Tracer.WriteError("BladeSerialSessionMetadata.ApiGreenSignalling:Error stopserialsession failed BladeId: {0}", BladeId);

                    if (sessionResponse.completionCode != Contracts.CompletionCode.NoActiveSerialSession)
                    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;
            }
        }
开发者ID:silupher,项目名称:ChassisManager,代码行数:47,代码来源:BladeSerialSessionMetadata.cs

示例2: commandImplementation

        /// <summary>
        /// command specific implementation 
        /// </summary>
        internal override void commandImplementation()
        {
            Contracts.ChassisResponse myResponse = new Contracts.ChassisResponse();
            dynamic uname = null;

            try
            {
                if (this.argVal.TryGetValue('u', out uname) && this.argVal.ContainsKey('a'))
                {
                    myResponse = WcsCli2CmConnectionManager.channel.ChangeChassisControllerUserRole((string)uname, WCSSecurityRole.WcsCmAdmin);
                }
                else if (this.argVal.TryGetValue('u', out uname) && this.argVal.ContainsKey('o'))
                {
                    myResponse = WcsCli2CmConnectionManager.channel.ChangeChassisControllerUserRole((string)uname, WCSSecurityRole.WcsCmOperator);
                }
                else if (this.argVal.TryGetValue('u', out uname) && this.argVal.ContainsKey('r'))
                {
                    myResponse = WcsCli2CmConnectionManager.channel.ChangeChassisControllerUserRole((string)uname, WCSSecurityRole.WcsCmUser);
                }
                else
                {
                    Console.WriteLine(WcsCliConstants.invalidCommandString);
                }
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            if (myResponse == null)
            {
                Console.WriteLine(WcsCliConstants.serviceResponseEmpty);
                return;
            }

            if (myResponse.completionCode == Contracts.CompletionCode.Success)
            {
                Console.WriteLine(WcsCliConstants.commandSucceeded);
            }
            else if (myResponse.completionCode == Contracts.CompletionCode.Failure)
            {
                Console.WriteLine(WcsCliConstants.commandFailure);
            }
            else if (myResponse.completionCode == Contracts.CompletionCode.Timeout)
            {
                Console.WriteLine(WcsCliConstants.commandTimeout);
            }
            else if (myResponse.completionCode == Contracts.CompletionCode.UserNotFound)
            {
                Console.WriteLine(WcsCliConstants.commandUserNotFound);
            }
            else
            {
                Console.WriteLine("Command failed with the completion code: {0}", myResponse.completionCode.ToString());
            }
        }
开发者ID:kewencai,项目名称:ChassisManager,代码行数:60,代码来源:Commands.cs

示例3: GetAllBladesPsuAlertDefaultPowerCap

        /// <summary>
        /// Get All Blades PSU ALERT Default Power Cap
        /// </summary>
        public AllBladesPsuAlertDpcResponse GetAllBladesPsuAlertDefaultPowerCap()
        {
            AllBladesPsuAlertDpcResponse responses = new AllBladesPsuAlertDpcResponse();
            responses.completionCode = Contracts.CompletionCode.Unknown;
            responses.statusDescription = String.Empty;
            responses.bladeDpcResponseCollection = new List<BladePsuAlertDpcResponse>();
            Contracts.CompletionCode[] bladeInternalResponseCollection = new Contracts.CompletionCode[ConfigLoaded.Population];
            Tracer.WriteUserLog("Invoked GetAllBladesPsuAlertDefaultPowerCap");
            Tracer.WriteInfo("Received GetAllBladsePsuAlertDefaultPowerCap for all blades");

            for (int loop = 0; loop < ConfigLoaded.Population; loop++)
            {
                responses.bladeDpcResponseCollection.Add(GetBladePsuAlertDefaultPowerCap(loop + 1));
                // Set the internal blade response to the blade completion code.
                bladeInternalResponseCollection[loop] = responses.bladeDpcResponseCollection[loop].completionCode;
            }

            Contracts.ChassisResponse varResponse = new Contracts.ChassisResponse();
            varResponse = ChassisManagerUtil.ValidateAllBladeResponse(bladeInternalResponseCollection);
            responses.completionCode = varResponse.completionCode;
            responses.statusDescription = varResponse.statusDescription;
            return responses;
        }
开发者ID:rockyshek,项目名称:ocs-source-code-and-operations-toolkit-for-open-cloudserver,代码行数:26,代码来源:ChassisManager.cs

示例4: GetAllBladesPowerReading

        /// <summary>
        /// Get power reading for all blades
        /// </summary>
        /// <returns>Array of blade responses containing the power reading</returns>
        public GetAllBladesPowerReadingResponse GetAllBladesPowerReading()
        {
            byte MaxbladeCount = (byte)ConfigLoaded.Population;
            GetAllBladesPowerReadingResponse responses = new GetAllBladesPowerReadingResponse();
            responses.completionCode = Contracts.CompletionCode.Unknown;
            responses.statusDescription = string.Empty;
            responses.bladePowerReadingCollection = new List<BladePowerReadingResponse>();
            Contracts.CompletionCode[] bladeInternalResponseCollection = new Contracts.CompletionCode[MaxbladeCount];

            Tracer.WriteUserLog("Invoked GetAllBladesPowerReading()");

            try
            {
                for (int index = 0; index < ConfigLoaded.Population; index++)
                {
                    int bladeId = index + 1;
                    responses.bladePowerReadingCollection.Add(GetBladePowerReading((int)bladeId));

                    // Set the internal blade response to the blade completion code.
                    bladeInternalResponseCollection[index] = responses.bladePowerReadingCollection[index].completionCode;
                }
            }
            catch (Exception ex)
            {
                responses.completionCode = Contracts.CompletionCode.Failure;
                responses.statusDescription = responses.completionCode.ToString() + ": " + ex.Message;
                Tracer.WriteError("GetAllBladesPowerReading Exception" + ex);
                return responses;
            }

            Contracts.ChassisResponse varResponse = new Contracts.ChassisResponse();
            varResponse = ChassisManagerUtil.ValidateAllBladeResponse(bladeInternalResponseCollection);
            responses.completionCode = varResponse.completionCode;
            responses.statusDescription = varResponse.statusDescription;
            return responses;
        }
开发者ID:rockyshek,项目名称:ocs-source-code-and-operations-toolkit-for-open-cloudserver,代码行数:40,代码来源:ChassisManager.cs

示例5: UpdatePSUFirmware

        /// <summary>
        /// Update firmware on specified PSU
        /// </summary>
        /// <param name="psuId">The psu identifier.</param>
        /// <param name="fwFilepath">The firmware image file path. The file must be in hex format.</param>
        /// <param name="primaryImage">
        /// True:  Firmware image is for primary controller. 
        /// False: Firmware image is for secondary controller. 
        /// <returns>
        /// Response indicating if firmware upgrade was started successfully.
        /// </returns>
        public Contracts.ChassisResponse UpdatePSUFirmware(int psuId, string fwFilepath, bool primaryImage)
        {
            Tracer.WriteUserLog("Invoked UpdatePSUFirmware(psuId: {0}, fwFilepath: {1}, primaryImage: {2})", psuId, fwFilepath, primaryImage);

            Contracts.ChassisResponse response = new Contracts.ChassisResponse();
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            // Check PSU ID
            if (ChassisManagerUtil.CheckPsuId(psuId) != CompletionCode.Success)
            {
                Tracer.WriteWarning("UpdatePSUFirmware failed. Invalid PSU Id: {0}", psuId);

                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                response.statusDescription = Contracts.CompletionCode.ParameterOutOfRange.ToString();
                return response;
            }

            // Firmware upgrade only valid for Emerson PSU
            if (!(ChassisState.Psu[psuId - 1] is EmersonPsu))
            {
                Tracer.WriteWarning("UpdatePSUFirmware failed. PSU {0} is not an Emerson PSU.", psuId);

                response.completionCode = Contracts.CompletionCode.Failure;
                response.statusDescription = "UpdatePSUFirmware() only supported on Emerson PSU.";
                return response;
            }

            // If firmware update is already in progress, return error
            if (ChassisState.PsuFwUpdateInProgress[psuId - 1])
            {
                response.completionCode = Contracts.CompletionCode.PSUFirmwareUpdateInProgress;
                response.statusDescription = "PSU firmware update in progress";
                return response;
            }

            try
            {
                Tracer.WriteInfo("UpdatePSUFirmware: Updating PSU: {0} with file {1}. primaryImage: {2}", psuId, fwFilepath, primaryImage);

                // Check that firmware image file can be opened for reading.
                // If file does not exist or cannot be read, the method will throw an exception
                File.OpenRead(fwFilepath);

                // Build firmware update data
                EmersonPsu.FirmwareUpdateInfo fwUpdateInfo = new EmersonPsu.FirmwareUpdateInfo();
                fwUpdateInfo.fwFilepath = fwFilepath;
                fwUpdateInfo.primaryImage = primaryImage;

                // Execute firmware update
                EmersonPsu emersonPsu = (EmersonPsu)ChassisState.Psu[(psuId - 1)];
                CompletionCode completionCode = emersonPsu.ExecuteFirmwareUpdate(fwUpdateInfo);
                if (completionCode == CompletionCode.Success)
                {
                    response.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                    response.completionCode = Contracts.CompletionCode.Failure;
                    response.statusDescription = response.completionCode.ToString();
                }
            }
            catch (Exception ex)
            {
                Tracer.WriteWarning("UpdatePSUFirmware failed with exception: " + ex.Message);

                response.completionCode = Contracts.CompletionCode.Failure;
                response.statusDescription = response.completionCode.ToString() + ": " + ex.Message;
                return response;
            }

            return response;
        }
开发者ID:rockyshek,项目名称:ocs-source-code-and-operations-toolkit-for-open-cloudserver,代码行数:84,代码来源:ChassisManager.cs

示例6: StopBladeSerialSession

        /// <summary>
        /// Stops serial session on a blade
        /// </summary>
        public Contracts.ChassisResponse StopBladeSerialSession(int bladeId, string sessionToken, bool forceKill)
        {
            Contracts.ChassisResponse response = new Contracts.ChassisResponse();
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Tracer.WriteInfo("Received StopBladeSerialSession(bladeId: {0})", bladeId);
            Tracer.WriteUserLog("Invoked StopBladeSerialSession(bladeId: {0})", bladeId);

                if (ChassisManagerUtil.CheckBladeId((byte)bladeId) != (byte)CompletionCode.Success)
                {
                    response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;

                    Tracer.WriteWarning("StopBladeSerialSession failed: Blade ID: {0} out of range: ", bladeId);
                    return response;
                }

                response = CheckBladeAndFirmwareState((byte)bladeId);
            if (response.completionCode != Contracts.CompletionCode.Success)
                {
                    return response;
                }

                if (!FunctionValidityChecker.CheckBladeTypeValidity((byte)bladeId))
                {
                    response.completionCode = Contracts.CompletionCode.CommandNotValidForBlade;
                    return response;
                }

            response = ChassisState.BladeSerialMetadata[bladeId].StopBladeSerialSession(bladeId, sessionToken, forceKill);

            if (ChassisManagerUtil.CheckCompletionCode(response.completionCode))
            {
                Tracer.WriteInfo("StopBladeSerialSession succeeded for bladeId: " + bladeId);
            }
            else
            {
                Tracer.WriteError("StopBladeSerialSession failed for bladeId: {0} with completion code: {1}",
                    bladeId, response.completionCode.ToString());
            }

            response.statusDescription = response.completionCode.ToString();
            return response;
        }
开发者ID:rockyshek,项目名称:ocs-source-code-and-operations-toolkit-for-open-cloudserver,代码行数:47,代码来源:ChassisManager.cs

示例7: AddChassisControllerUser

        /// <summary>
        /// Method to add chassis controller user
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="passwordString">password</param>
        /// <returns>Response indicating if add user was success/failure</returns>
        public Contracts.ChassisResponse AddChassisControllerUser(string userName, string passwordString, Contracts.WCSSecurityRole role)
        {
            Contracts.ChassisResponse response = new Contracts.ChassisResponse();
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Tracer.WriteUserLog("Invoked AddChassisControllerUser(UserName: {0}, role: {1})", userName, role.ToString());
            try
            {
                // password never expires flag.
                int neverExpire = 0x10000;

                // Check if security role is valid
                if (!Enum.IsDefined(typeof(WCSSecurityRole), role))
                {
                    Tracer.WriteError("AddChassisControllerUser: Invalid security role " + role.ToString());
                    response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                    response.statusDescription = "Input security role is invalid";
                    return response;
                }

                // Return BadRequest if any data is missing.
                if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(passwordString))
                {
                    Tracer.WriteError("AddChassisControllerUser: Invalid input parameters.");
                    response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                    response.statusDescription = "Username or Password is null or empty";
                    return response;
                }

                userName = userName.Trim();
                passwordString = passwordString.Trim();

                if (userName == null || passwordString == null)
                {
                    Tracer.WriteError("AddChassisControllerUser: Invalid input parameters.");

                    response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                    response.statusDescription = "Username or Password is null or empty";
                    return response;
                }

                DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
                DirectoryEntry NewUser = AD.Children.Add(userName, "user");

                // create account
                NewUser.Invoke("SetPassword", new object[] { passwordString });
                NewUser.Invoke("Put", new object[] { "Description", "WcsCli chassis manager request" });
                NewUser.CommitChanges();

                // update properteis for password to never expire.
                int userProperties = (int)NewUser.Properties["userFlags"].Value;
                NewUser.Properties["userFlags"].Value = userProperties | neverExpire;
                NewUser.CommitChanges();

                DirectoryEntry grp;
                // Find group, if not exists, create
                grp = ChassisManagerUtil.FindGroupIfNotExistsCreate(role);

                if (grp != null)
                {
                    grp.Invoke("Add", new object[] { NewUser.Path.ToString() });

                    Tracer.WriteInfo("AddChassisControllerUser: User Account Created Successfully");
                    response.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                    Tracer.WriteInfo("AddChassisControllerUser: Failed to create account, failed to add user to group");
                    response.completionCode = Contracts.CompletionCode.Failure;
                    response.statusDescription = String.Format("AddChassisControllerUser: Failed to create account, failed to add user to group");
                }

                return response;
            }
            catch (Exception ex)
            {
                Tracer.WriteError("AddChassisControllerUser: failed with exception: " + ex);

                // check if password did not meet the requirements, display appropriate message to user.
                if (ex.ToString().Contains("0x800708C5") || ex.ToString().Contains("password does not meet"))
                {
                    response.completionCode = Contracts.CompletionCode.UserPasswordDoesNotMeetRequirement;
                    response.statusDescription = "User password does not meet requirement";
                }
                else if (ex.ToString().Contains("0x800708B0"))
                {
                    response.completionCode = Contracts.CompletionCode.UserAccountExists;
                    response.statusDescription = "User account already exists";
                }
                else
                {
                    response.completionCode = Contracts.CompletionCode.Failure;
                    response.statusDescription = String.Format("AddChassisControllerUser failed. Unknown Error.");
//.........这里部分代码省略.........
开发者ID:rockyshek,项目名称:ocs-source-code-and-operations-toolkit-for-open-cloudserver,代码行数:101,代码来源:ChassisManager.cs

示例8: GetAllBladesInfo

        /// <summary>
        /// Get information for all blades
        /// </summary>
        /// <returns>Array of blade info response</returns>
        public GetAllBladesInfoResponse GetAllBladesInfo()
        {
            byte maxbladeCount = (byte)ConfigLoaded.Population;

            Tracer.WriteInfo("Received GetAllBladesInfo()");
            Tracer.WriteUserLog("Invoked GetAllBladesInfo()");

            // Server side class structure to populate blade information
            GetAllBladesInfoResponse responses = new GetAllBladesInfoResponse();
            responses.completionCode = Contracts.CompletionCode.Unknown;
            responses.statusDescription = string.Empty;
            responses.bladeInfoResponseCollection = new List<BladeInfoResponse>();
            Contracts.CompletionCode[] bladeInternalResponseCollection = new Contracts.CompletionCode[maxbladeCount];

            Tracer.WriteInfo("GetAllBladesInfo: Processing Blades ");

            // Loop to populate blade information for requested number of blades
            for (int loop = 0; loop < maxbladeCount; loop++)
            {
                int bladeId = loop + 1; // we need to get for all blades

                //Call getBladeInfo for the Blade ID
                responses.bladeInfoResponseCollection.Add(this.GetBladeInfo(bladeId));

                // Set the internal blade response to the blade completion code.
                bladeInternalResponseCollection[loop] = responses.bladeInfoResponseCollection[loop].completionCode;

            }

            Tracer.WriteInfo("GetAllBladesInfo: Completed populating for Blades");

            Contracts.ChassisResponse varResponse = new Contracts.ChassisResponse();
            varResponse = ChassisManagerUtil.ValidateAllBladeResponse(bladeInternalResponseCollection);
            responses.completionCode = varResponse.completionCode;
            responses.statusDescription = varResponse.statusDescription;

            return responses;
        }
开发者ID:rockyshek,项目名称:ocs-source-code-and-operations-toolkit-for-open-cloudserver,代码行数:42,代码来源:ChassisManager.cs

示例9: RemoveChassisControllerUser

        /// <summary>
        /// Method to remove user. **TO-DO* Authenticate who can Add/delete user.
        /// </summary>
        /// <param name="userName">User Name</param>
        /// <returns>Chassis Response to indicate if reomve user operation was success/failure</returns>
        public Contracts.ChassisResponse RemoveChassisControllerUser(string userName)
        {
            Contracts.ChassisResponse response = new Contracts.ChassisResponse();
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Tracer.WriteUserLog("Invoked RemoveChassisControllerUser(userName: {0})", userName);
            try
            {
                userName = userName.Trim();

                if (userName == null)
                {
                    Tracer.WriteError("RemoveChassisControllerUser: Invalid input parameters.");
                    response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                    response.statusDescription = "Username is null";
                    return response;
                }

                DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
                DirectoryEntry myEntry = AD.Children.Find(userName, "user");
                AD.Children.Remove(myEntry);
                Tracer.WriteInfo("RemoveChassisControllerUser: User Account deleted Successfully");
                response.completionCode = Contracts.CompletionCode.Success;

                return response;
            }
            catch (Exception ex)
            {
                Tracer.WriteError("RemoveChassisControllerUser: failed with exception: " + ex);

                // check the exception code for password did not meet the requirements, display appropriate message to user.
                if (ex.ToString().Contains("0x800708C5") || ex.ToString().Contains("password does not meet"))
                {
                    response.completionCode = Contracts.CompletionCode.UserPasswordDoesNotMeetRequirement;
                    response.statusDescription = "User password does not meet system requirements";
                }
                // check the exception code for user not found
                else if (ex.ToString().Contains("0x800708AD"))
                {
                    response.completionCode = Contracts.CompletionCode.UserNotFound;
                    response.statusDescription = "User not found";
                }
                else
                {
                    response.completionCode = Contracts.CompletionCode.Failure;
                    response.statusDescription = String.Format("RemoveChassisControllerUser failed. Unknown Error.");
                }
                return response;
            }
        }
开发者ID:rockyshek,项目名称:ocs-source-code-and-operations-toolkit-for-open-cloudserver,代码行数:56,代码来源:ChassisManager.cs

示例10: ChangeChassisControllerUserRole

        /// <summary>
        /// Method to change chassis controller user role
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="role">WCS Security role</param>
        /// <returns>Chassis Response indicating if the update user settings was a success/failure</returns>
        public Contracts.ChassisResponse ChangeChassisControllerUserRole(string userName, WCSSecurityRole role)
        {
            Contracts.ChassisResponse response = new Contracts.ChassisResponse();
            DirectoryEntry grp;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Tracer.WriteUserLog(String.Format("Invoked ChangeChassisControllerUserRole(userName: {0}, role: {1})", userName, role.ToString()));
            try
            {
                // Validate input parameters

                // Check if input user security role is valid
                if (!Enum.IsDefined(typeof(WCSSecurityRole), role))
                {
                    Tracer.WriteError("ChangeChassisControllerUser: Invalid security role " + role.ToString());
                    response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                    response.statusDescription = "Input security role is invalid";
                    return response;
                }

                userName = userName.Trim();

                if (userName == null)
                {
                    Tracer.WriteError("ChangeChassisControllerUserRole: Invalid input parameters.");
                    response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                    response.statusDescription = "User name provided is null";
                    return response;
                }

                DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
                DirectoryEntry myEntry = AD.Children.Find(userName, "user");

                // Remove user from other WCS security group , if it exists in them
                // This step is required as if the user permissions are decreased from
                // admin to user, then he should no longer be in admin role.Similar with operator to user.

                if (role != WCSSecurityRole.WcsCmAdmin)
                {
                    ChassisManagerUtil.RemoveUserFromWCSSecurityGroups(userName, WCSSecurityRole.WcsCmAdmin);
                }

                if (role != WCSSecurityRole.WcsCmOperator)
                {
                    ChassisManagerUtil.RemoveUserFromWCSSecurityGroups(userName, WCSSecurityRole.WcsCmOperator);
                }

                if (role != WCSSecurityRole.WcsCmUser)
                {
                    ChassisManagerUtil.RemoveUserFromWCSSecurityGroups(userName, WCSSecurityRole.WcsCmUser);
                }

                // Add if user does not already exists in the given group
                if (!ChassisManagerUtil.CheckIfUserExistsInGroup(userName, role))
                {
                    // Find group if not exists create new
                    grp = ChassisManagerUtil.FindGroupIfNotExistsCreate(role);

                    if (grp != null)
                    {
                        // Add user to group
                        grp.Invoke("Add", new object[] { myEntry.Path.ToString() });
                        grp.CommitChanges();
                        grp.Close();
                    }
                    else
                    {
                        Tracer.WriteError("ChangeChassisControllerUserRole: Failed to change user role, failed to find/add group");
                        response.completionCode = Contracts.CompletionCode.Failure;
                        response.statusDescription = String.Format("ChangeChassisControllerUserRole: Failed to change user role, failed to find/add group");
                        return response;
                    }
                }

                Tracer.WriteInfo("ChangeChassisControllerUserRole: Role changed successfully");
                response.completionCode = Contracts.CompletionCode.Success;
                return response;
            }
            catch (Exception ex)
            {
                Tracer.WriteError("ChangeChassisControllerUserRole: failed with exception: " + ex);

                // user already belongs to the role, we don't need any action hence consider it success
                if (ex.ToString().Contains("The specified account name is already a member of the group"))
                {
                    response.completionCode = Contracts.CompletionCode.Success;
                }
                // check if password did not meet the requirements, display appropriate message to user.
                else if (ex.ToString().Contains("0x800708C5") || ex.ToString().Contains("password does not meet"))
                {
                    response.completionCode = Contracts.CompletionCode.UserPasswordDoesNotMeetRequirement;
                    response.statusDescription = "User password does not meet system requirements";
                }
//.........这里部分代码省略.........
开发者ID:rockyshek,项目名称:ocs-source-code-and-operations-toolkit-for-open-cloudserver,代码行数:101,代码来源:ChassisManager.cs

示例11: ChangeChassisControllerUserPassword

        /// <summary>
        /// Method to change chassis controller user password to given values
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="newPassword">New password</param>
        /// <returns>Chassis Response indicating if user password change was a success/failure</returns>
        public Contracts.ChassisResponse ChangeChassisControllerUserPassword(string userName, string newPassword)
        {
            Contracts.ChassisResponse response = new Contracts.ChassisResponse();
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Tracer.WriteUserLog("Invoked ChangeChassisControllerUserPassword(userName: {0})", userName);
            try
            {
                userName = userName.Trim();
                newPassword = newPassword.Trim();

                if (userName == null || newPassword == null)
                {
                    Tracer.WriteError("ChangeChassisControllerUserPassword: Invalid input parameters.");
                    response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                    response.statusDescription = "User name or password is null";
                    return response;
                }

                DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
                DirectoryEntry myEntry = AD.Children.Find(userName, "user");

                if (myEntry != null)
                {
                    myEntry.Invoke("SetPassword", new object[] { newPassword });
                    myEntry.CommitChanges();
                    Tracer.WriteInfo("ChangeChassisControllerUserPassword: Password changed Successfully for user: {0}", userName);
                    response.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                    Tracer.WriteError("ChangeChassisControllerUserPassword: Failed to change user password, User: {0} does not exists",
                        userName);
                }
                return response;
            }
            catch (Exception ex)
            {
                Tracer.WriteError("ChangeChassisControllerUserPassword: failed with exception: " + ex);
                response.completionCode = Contracts.CompletionCode.Failure;

                // check if password did not meet the requirements, display appropriate message to user.
                if (ex.ToString().Contains("0x800708C5") || ex.ToString().Contains("password does not meet"))
                {
                    response.completionCode = Contracts.CompletionCode.UserPasswordDoesNotMeetRequirement;
                    response.statusDescription = "User password does not meet system requirements";
                }
                // check the exception code for user not found
                else if (ex.ToString().Contains("0x800708AD"))
                {
                    response.completionCode = Contracts.CompletionCode.UserNotFound;
                    response.statusDescription = "User not found";
                }
                else
                {
                    response.statusDescription = String.Format("ChangeChassisControllerUserPassword failed. Unknown Error.");
                }
                return response;
            }
        }
开发者ID:rockyshek,项目名称:ocs-source-code-and-operations-toolkit-for-open-cloudserver,代码行数:67,代码来源:ChassisManager.cs

示例12: StopSerialPortConsole

        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;
        }
开发者ID:kewencai,项目名称:ChassisManager,代码行数:48,代码来源:SerialConsoleMetadata.cs

示例13: SendSerialPortData

        public Contracts.ChassisResponse SendSerialPortData(int portID, string sessionToken, byte[] data)
        {
            Contracts.ChassisResponse response = new Contracts.ChassisResponse();
            response.completionCode = Contracts.CompletionCode.Failure;
            this.portId = portID;

            Tracer.WriteInfo("Received SendSerialPortConsoleData({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("SendSerialPortData({0}): Send 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)this.portId);
            SerialStatusPacket serialStatus = new SerialStatusPacket();
            if (data != null && data.Length != 0)
            {
                serialStatus = currConsole.sendSerialData(data);
                if (serialStatus.completionCode != CompletionCode.Success)
                {
                    Tracer.WriteError("SendBladeSerialData({0}): Error in SerialPortConsole.SendSerialData()", portId);
                    return response;
                }
            } // If data is null or if data has zero length, we are renewing activity lease and returning success to the user
            response.completionCode = Contracts.CompletionCode.Success;
            return response;
        }
开发者ID:kewencai,项目名称:ChassisManager,代码行数:37,代码来源:SerialConsoleMetadata.cs

示例14: SerialPortConsoleInactivityCheck

        // Function to be called by the getbladerequirement monitoring thread if chassisManagerSafeState is true
        internal void SerialPortConsoleInactivityCheck(int portID)
        {
            // Negative values in clientInactivityTimeoutIn100ms indicate infinite timeout - return immediately.
            if (clientInactivityTimeoutInSecs < 0)
            {
                Tracer.WriteError("Infinite client session inactivity timeout set for COM{0}", portId);
                return;
            }

            // ConfigLoaded.SerialPortConsoleClientSessionInactivityTimeout has 100ms scaling - therefore divide by 10 to get seconds
            TimeSpan span = new TimeSpan(0, 0, 0, ConfigLoaded.SerialPortConsoleClientSessionInactivityTimeoutInSecs);

            if (clientInactivityTimeoutInSecs > 0)
            {
                span = new TimeSpan(0, 0, 0, clientInactivityTimeoutInSecs);
            }
            DateTime currTime = DateTime.Now;
            DateTime lastActivityBound = currTime.Subtract(span);

            if (CompareAndSwapMetadata(ConfigLoaded.InactiveSerialPortSessionToken, ConfigLoaded.InactiveSerialPortSessionToken) == CompletionCode.Success)
            {
                return;
            }

            // Check if inactive since 2 minutes back - if so write secret metadata
            if (!SetSecretMetadataIfInactive(lastActivityBound))
            {
                Tracer.WriteInfo("SerialConsolePortInactiveCheck({0}): Activity detected", this.portId);
                return; // Activity detected and hence not stopping the serial session
            }

            Contracts.ChassisResponse sessionResponse = new Contracts.ChassisResponse();
            sessionResponse = StopSerialPortConsole(portID, ConfigLoaded.SecretSerialPortSessionToken);
            if (sessionResponse.completionCode != Contracts.CompletionCode.Success)
                Tracer.WriteError("SerialConsolePortInactiveCheck({0}): Error StopBladeSerialSession failure", this.portId);
        }
开发者ID:kewencai,项目名称:ChassisManager,代码行数:37,代码来源:SerialConsoleMetadata.cs

示例15: SetAllBladesPsuAlert

        /// <summary>
        /// Activate Deactivate PSU ALERT Action against all blades.
        /// </summary>
        public Contracts.AllBladesResponse SetAllBladesPsuAlert(bool enableProchot, int action, bool removeCap)
        {
            Contracts.AllBladesResponse responses = new Contracts.AllBladesResponse();
            responses.completionCode = Contracts.CompletionCode.Unknown;
            responses.statusDescription = String.Empty;
            responses.bladeResponseCollection = new List<BladeResponse>();
            Contracts.CompletionCode[] bladeInternalResponseCollection = new Contracts.CompletionCode[ConfigLoaded.Population];

            Tracer.WriteUserLog("Invoked SetAllBladesPsuAlert");
            Tracer.WriteInfo("Received SetAllBladesPsuAlert");

            for (int loop = 0; loop < ConfigLoaded.Population; loop++)
            {
                responses.bladeResponseCollection.Add(SetBladePsuAlert(loop + 1, enableProchot, action, removeCap));
                // Set the internal blade response to the blade completion code.
                bladeInternalResponseCollection[loop] = responses.bladeResponseCollection[loop].completionCode;
            }

            Contracts.ChassisResponse varResponse = new Contracts.ChassisResponse();
            varResponse = ChassisManagerUtil.ValidateAllBladeResponse(bladeInternalResponseCollection);
            responses.completionCode = varResponse.completionCode;
            responses.statusDescription = varResponse.statusDescription;
            return responses;
        }
开发者ID:rockyshek,项目名称:ocs-source-code-and-operations-toolkit-for-open-cloudserver,代码行数:27,代码来源:ChassisManager.cs


注:本文中的Contracts.ChassisResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。