private static async Task <string> GetIpAddressFromVmName(string vmName) { var command = File.ReadAllText(@"DeploymentScripts\get_ip_by_name.ps1").Replace("<name>", vmName); var remoteResult = await PowerShellProxy.ExecuteCommandAsync(command, "galaxy"); return(IpAddressRegex.Match(remoteResult).Value); }
public static async Task <DeploymentResult> DeployAndConfigureAsync(DeploymentDefinition deploymentDefinition) { var windowsHostNames = new List <string>(); var deployTasks = deploymentDefinition.WindowsTemplates .Select(s => { var hostName = "win_" + Guid.NewGuid(); windowsHostNames.Add(hostName); return(PowerShellProxy.ExecuteCommandAsync(CreateWindowsDeploymentScriptBlock(s, hostName), "bajor")); }).ToList(); var elkHostname = "elk_" + Guid.NewGuid(); deployTasks.Add( PowerShellProxy.ExecuteCommandAsync(CreateElkDeploymentScriptBlock(deploymentDefinition.ElkTemplate, elkHostname), "bajor")); await Task.WhenAll(deployTasks); var elkIp = await GetIpAddressFromVmName(elkHostname); var windowsIps = new List <string>(); foreach (var hostname in windowsHostNames) { var winIp = await GetIpAddressFromVmName(hostname); windowsIps.Add(winIp); // Configure Windows VM } return(new DeploymentResult { ElkIp = elkIp, WindowsIps = windowsIps }); }