コード例 #1
0
        public async Task <SshResponse> RunCommandAsync(string command)
        {
            SshResponse result = null;

            if (!await ConnectionUtil.CheckConnectionAsync(host))
            {
                throw new Exception(string.Format("Server {0} unreachable", host));
            }

            await Task.Run(() =>
            {
                KeyboardInteractiveAuthenticationMethod keyboardbAuthentication = new KeyboardInteractiveAuthenticationMethod(credential.UserName);
                PasswordAuthenticationMethod pauth            = new PasswordAuthenticationMethod(credential.UserName, credential.Password);
                keyboardbAuthentication.AuthenticationPrompt += new EventHandler <AuthenticationPromptEventArgs>(HandleKeyEvent);
                ConnectionInfo connectionInfo = new ConnectionInfo(host, 22, credential.UserName, pauth, keyboardbAuthentication);

                using (SshClient client = new SshClient(connectionInfo))
                {
                    try
                    {
                        client.Connect();
                        var commandResult = client.RunCommand(command);
                        result            = new SshResponse(commandResult.Result, commandResult.ExitStatus);
                    }
                    catch (Exception e)
                    {
                        result = new SshResponse(e.Message, -1);
                    }
                }
            });

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Exports an SCP file
        /// </summary>
        /// <param name="target">SCP target</param>
        /// <param name="exportUse">Scp use strategy</param>
        /// <returns></returns>
        public async Task <string> ExportScpFileAsync(string target, string exportUse)
        {
            if (!await ConnectionUtil.CheckConnectionAsync(host))
            {
                throw new Exception(string.Format("Server {0} unreachable", host));
            }

            string jobUri = await CreateExportJobAsync(target, exportUse);

            return(await GetFileContentAsync(jobUri));
        }
コード例 #3
0
        public async Task<string> GetServiceTagAsync()
        {
            if (!await ConnectionUtil.CheckConnectionAsync(host))
                throw new Exception(string.Format("Server {0} unreachable", host));

            var request = new RestRequest(ChassisRoot);
            request.AddHeader("Accept", "*/*");
            var response = await client.ExecuteTaskAsync(request);

            if (!response.IsSuccessful)
                throw new RedfishException(string.Format("Fail to get Service Tag, Error code {0}",
                    response.StatusCode));

            JObject responseBody = JObject.Parse(response.Content);
            return responseBody["SKU"].ToString();
        }
コード例 #4
0
        /// <summary>
        /// Performs a firmware update from a local file
        /// </summary>
        /// <param name="path">Fila Path</param>
        /// <param name="option">Update mode</param>
        /// <returns>Location for Update Job</returns>
        public async Task <string> UpdateFirmwareAsync(string path, string option)
        {
            if (!await ConnectionUtil.CheckConnectionAsync(host))
            {
                throw new Exception(string.Format("Server {0} unreachable", host));
            }

            string location = await UploadFileAsync(path);

            List <string> uris = new List <string>()
            {
                location
            };

            var request = new RestRequest(DellUpdateService, Method.POST, DataFormat.Json);

            request.AddHeader("Accept", "*/*");

            var body = new
            {
                SoftwareIdentityURIs = uris,
                InstallUpon          = option
            };

            request.AddJsonBody(body);
            var response = await restClient.ExecuteTaskAsync(request);

            if (!response.IsSuccessful)
            {
                throw new RedfishException(string.Format("Fail to create update Job, Error Code {0}",
                                                         response.StatusCode));
            }

            return(response.Headers
                   .Where(x => x.Name == "Location")
                   .Select(x => x.Value)
                   .FirstOrDefault().ToString());
        }
コード例 #5
0
        /// <summary>
        /// Performs an SCP File Import
        /// </summary>
        /// <param name="path">Local SCP file path</param>
        /// <param name="target">SCP Target</param>
        /// <param name="shutdownType">Shutdown strategy</param>
        /// <param name="powerStatus">Host power status</param>
        /// <returns></returns>
        public async Task <string> ImportScpFileAsync(string path, string target, string shutdownType, string powerStatus)
        {
            if (!await ConnectionUtil.CheckConnectionAsync(host))
            {
                throw new Exception(string.Format("Server {0} unreachable", host));
            }

            var request = new RestRequest(ImportSystemConfiguration, Method.POST, DataFormat.Json);

            request.AddHeader("Accept", "*/*");

            string file = File.ReadAllText(path);
            var    body = new
            {
                ImportBuffer    = file,
                ShareParameters = new
                {
                    Target = target
                },
                ShutdownType   = shutdownType,
                HostPowerState = powerStatus
            };

            request.AddJsonBody(body);
            var response = await client.ExecuteTaskAsync(request);

            if (!response.IsSuccessful)
            {
                throw new RedfishException(string.Format("Fail to import the file, Error Code {0}",
                                                         response.StatusCode));
            }

            return(response.Headers
                   .Where(x => x.Name == "Location")
                   .Select(x => x.Value)
                   .FirstOrDefault().ToString());
        }