public async Task <Responses.VmStringValue> GuestCommand(Requests.Command request) { var returnObject = new Responses.VmStringValue(); var executionResult = await this.Client.VSphere.GuestProcessRun(new Dictionary <string, string> { { "vm_id", request.Moid }, { "username", request.Username }, { "password", request.Password }, { "command", request.CommandText }, { "arguments", request.CommandArgs }, { "workdir", request.CommandWorkDirectory } }); Log.Trace($"ExecutionResult: {executionResult}"); try { returnObject.Id = executionResult.id; var commandTextObject = ((JObject)executionResult.result).First.First["stdout"]; returnObject.Value = commandTextObject.ToString(); } catch (Exception e) { Log.Error($"Object was not in expected format: {e}"); Console.WriteLine(e); returnObject.Exception = e; } return(returnObject); }
public async void GuestProcessRunReturnsSomething() { var r = new Requests.Command { Moid = "vm-303", Username = "******", Password = "******", CommandText = @"c:\windows\system32\cmd.exe", CommandArgs = "/C dir", CommandWorkDirectory = @"c:\windows\system32\cmd.exe" }; var o = await this.VSphere.GuestCommand(r); Assert.Null(o.Exception); Assert.NotNull(o); Assert.NotNull(o.Value); }