public void GenerateByOneIdAndOneServerName() { // Arrange var scriptName = "vm-by-id-server-name"; var template = PCLIScriptsReader.GetArgumentTransformationScript(scriptName); var idParameter = new PlaceholderValue { PlaceholderName = "id", Value = new [] { "vm-2" } }; var serverParameter = new PlaceholderValue { PlaceholderName = "server", Value = new[] { "10.23.45.67" } }; var expected = "Get-VM -Id 'vm-2' -Server '10.23.45.67'"; // Act var actual = new PCLIScriptsGenerator( template.ScriptTemplate, new [] { new PlaceholderValueList { Values = new [] { idParameter, serverParameter } } }).Generate(); // Assert Assert.AreEqual(expected, actual.Script); }
public void GenerateByTwoIdAndOneServerGuid() { // Arrange var scriptName = "vm-by-id-server-instance-uuid"; var template = PCLIScriptsReader.GetArgumentTransformationScript(scriptName); var idParameter = new PlaceholderValue { PlaceholderName = "id", Value = new[] { "vm-2", "vm-3" } }; var serverParameter = new PlaceholderValue { PlaceholderName = "server_instance_uuid", Value = new[] { "uuid_uuid" } }; var expected = "Get-VM -Id 'vm-2','vm-3' -Server ($global:DefaultVIServers | Where-Object {$_.InstanceUuid -eq 'uuid_uuid'})"; // Act var actual = new PCLIScriptsGenerator( template.ScriptTemplate, new[] { new PlaceholderValueList { Values = new [] { idParameter, serverParameter } } }).Generate(); // Assert Assert.AreEqual(expected, actual.Script); }
public ActionResult <ArgumentScriptTemplate> Get([FromRoute] string id) { var result = PCLIScriptsReader.GetArgumentTransformationScript(id); return(result == null ? NotFound( new ErrorDetails( ApiErrorCodes.GetErrorCode(nameof(APIGatewayResources.ArgumentScriptsController_ArgumentTransformationScriptNotFound)), string.Format(APIGatewayResources.ArgumentScriptsController_ArgumentTransformationScriptNotFound, id))) : (ActionResult <ArgumentScriptTemplate>)Ok(result)); }
public void TransformationTemplateIsRetrievedByName() { // Arrange var scriptName = "vm-by-id-server-name"; var expectedContent = "Get-VM -Id <id> -Server <server>"; // Act var actual = PCLIScriptsReader.GetArgumentTransformationScript(scriptName); // Assert Assert.AreEqual(scriptName, actual.Id); Assert.AreEqual(expectedContent, actual.ScriptTemplate); Assert.AreEqual("VMware.VimAutomation.Types.VirtualMachine", actual.ResultType); Assert.AreEqual("PowerCLI", actual.ScriptRuntime); }
public ActionResult <ArgumentScript> Create([FromBody] ArgumentScript argumentScript) { var template = PCLIScriptsReader.GetArgumentTransformationScript(argumentScript.TemplateId); if (template == null) { return(NotFound( new ErrorDetails( ApiErrorCodes.GetErrorCode(nameof(APIGatewayResources.ArgumentScriptsController_ArgumentTransformationScriptNotFound)), string.Format(APIGatewayResources.ArgumentScriptsController_ArgumentTransformationScriptNotFound, argumentScript.TemplateId)))); } return(Ok( new PCLIScriptsGenerator( template.ScriptTemplate, argumentScript.PlaceholderValueList).Generate())); }
public void GenerateByOneIdAndTwoServerName() { // Arrange var scriptName = "vm-by-id-server-name"; var template = PCLIScriptsReader.GetArgumentTransformationScript(scriptName); var idParameter = new PlaceholderValue { PlaceholderName = "id", Value = new[] { "vm-2" } }; var serverParameter = new PlaceholderValue { PlaceholderName = "server", Value = new[] { "10.23.45.67" } }; var server2Parameter = new PlaceholderValue { PlaceholderName = "server", Value = new[] { "67.45.23.10" } }; var expectedSb = new StringBuilder(); expectedSb.AppendLine("Get-VM -Id 'vm-2' -Server '10.23.45.67'"); expectedSb.AppendLine("Get-VM -Id 'vm-2' -Server '67.45.23.10'"); var expected = expectedSb.ToString().Trim(); // Act var actual = new PCLIScriptsGenerator( template.ScriptTemplate, new[] { new PlaceholderValueList { Values = new [] { idParameter, serverParameter } }, new PlaceholderValueList { Values = new [] { idParameter, server2Parameter } } }).Generate(); // Assert Assert.AreEqual(expected, actual.Script); }