/// <summary> /// Gets all of the expanded environments for a given Lab and generates RDP files to connect to them. /// </summary> internal static async Task CreateRdpFiles() { string resourceGroupName = ConfigurationManager.AppSettings["ResourceGroupName"]; string labAccountName = ConfigurationManager.AppSettings["LabAccountName"]; string labName = ConfigurationManager.AppSettings["LabName"]; string rdpFolderPath = ConfigurationManager.AppSettings["OutputPath"]; using (ManagedLabsClient client = new ManagedLabsClient(new CustomLoginCredentials(), new System.Net.Http.HttpClient() { BaseAddress = new Uri("https://management.azure.com") }, true) { SubscriptionId = ConfigurationManager.AppSettings["SubscriptionId"] }) { // Get all VMs within the lab List <(LSEnvironmentSetting, LSEnvironment)> envSettingEnvPairs = new List <(LSEnvironmentSetting, LSEnvironment)>(); foreach (LSEnvironmentSetting envSetting in (await client.EnvironmentSettings.ListAsync(resourceGroupName, labAccountName, labName).ConfigureAwait(false))) { foreach (LSEnvironment tempenvironment in await client.Environments.ListAsync(resourceGroupName, labAccountName, labName, envSetting.Name).ConfigureAwait(false)) { envSettingEnvPairs.Add((envSetting, tempenvironment)); } } // For each Environment, do an expand on the network interface to get RDP info LSEnvironment[] expandedEnvironments = await Task.WhenAll( envSettingEnvPairs.Select(envtuple => client.Environments.GetAsync(resourceGroupName, labAccountName, labName, envtuple.Item1.Name, envtuple.Item2.Name, "properties($expand=networkInterface)"))) .ConfigureAwait(false); // Generate RDP files Dictionary <string, HashSet <string> > uniquePublicIPs = new Dictionary <string, HashSet <string> >(); foreach (LSEnvironment env in expandedEnvironments) { string[] rdpAuth = env.NetworkInterface.RdpAuthority.Split(':'); if (!uniquePublicIPs.ContainsKey(rdpAuth[0])) { uniquePublicIPs.Add(rdpAuth[0], new HashSet <string>()); } uniquePublicIPs[rdpAuth[0]].Add(rdpAuth[1]); GenerateRdpFile(env.NetworkInterface.PrivateIpAddress, env.NetworkInterface.Username, rdpFolderPath, env.Name); Console.WriteLine(env.NetworkInterface.RdpAuthority + " " + env.NetworkInterface.PrivateIpAddress); } using (StreamWriter writer = new StreamWriter(File.OpenWrite(Path.Combine(rdpFolderPath, "UniqueIPAddresses.txt")))) { foreach (KeyValuePair <string, HashSet <string> > uniqueIp in uniquePublicIPs) { writer.WriteLine(uniqueIp.Key); foreach (string port in uniqueIp.Value) { writer.WriteLine("\t" + port); } } } } }
public void ListLabsTest() { using (MockContext context = MockContext.Start(this.GetType())) { ManagedLabsClient client = GetManagedLabsClient(context); var labs = client.LabAccounts.ListBySubscription().ToList(); Assert.NotEmpty(labs); } }
/// <summary> /// Gets all of the expanded environments for a given Lab and generates RDP files to connect to them. /// </summary> internal static async Task CreateRdpFiles() { string resourceGroupName = ConfigurationManager.AppSettings["ResourceGroupName"]; string labAccountName = ConfigurationManager.AppSettings["LabAccountName"]; string labName = ConfigurationManager.AppSettings["LabName"]; string rdpFolderPath = ConfigurationManager.AppSettings["OutputPath"]; using (ManagedLabsClient client = new ManagedLabsClient(new CustomLoginCredentials(), new System.Net.Http.HttpClient() { BaseAddress = new Uri("https://management.azure.com") }, true) { SubscriptionId = ConfigurationManager.AppSettings["SubscriptionId"] }) { // Get all VMs within the lab List <(LSEnvironmentSetting, LSEnvironment)> envSettingEnvPairs = new List <(LSEnvironmentSetting, LSEnvironment)>(); foreach (LSEnvironmentSetting envSetting in (await client.EnvironmentSettings.ListAsync(resourceGroupName, labAccountName, labName).ConfigureAwait(false))) { foreach (LSEnvironment tempenvironment in await client.Environments.ListAsync(resourceGroupName, labAccountName, labName, envSetting.Name).ConfigureAwait(false)) { envSettingEnvPairs.Add((envSetting, tempenvironment)); } } // For each Environment, do an expand on the network interface to get RDP info LSEnvironment[] expandedEnvironments = await Task.WhenAll( envSettingEnvPairs.Select(envtuple => client.Environments.GetAsync(resourceGroupName, labAccountName, labName, envtuple.Item1.Name, envtuple.Item2.Name, "properties($expand=networkInterface)"))) .ConfigureAwait(false); // Generate RDP files foreach (LSEnvironment env in expandedEnvironments) { GenerateRdpFile(env.NetworkInterface.RdpAuthority, env.NetworkInterface.Username, rdpFolderPath, env.Name); } } }
/// <summary> /// Gets all of the expanded environments for a given user and generates RDP files to connect to them. /// </summary> internal static async Task CreateRdpFiles() { string userName = ConfigurationManager.AppSettings["UserName"]; string rdpFolderPath = ConfigurationManager.AppSettings["OutputPath"]; using (ManagedLabsClient client = new ManagedLabsClient(new CustomLoginCredentials(), new System.Net.Http.HttpClient() { BaseAddress = new Uri("https://management.azure.com") }, true)) { // Get all VMs within the lab List <(LSLabDetails, LSEnvironmentDetails)> labEnvPairs = new List <(LSLabDetails, LSEnvironmentDetails)>(); foreach (LSLabDetails labDetails in (await client.GlobalUsers.ListLabsAsync(userName).ConfigureAwait(false)).Labs) { foreach (LSEnvironmentDetails tempenvironment in (await client.GlobalUsers.ListEnvironmentsAsync(userName, new Microsoft.Azure.Management.LabServices.Models.ListEnvironmentsPayload(labDetails.Id)).ConfigureAwait(false)).Environments) { labEnvPairs.Add((labDetails, tempenvironment)); } } // For each Environment, do an expand on the network interface to get RDP info List <LSEnvironment> expandedEnvironments = new List <LSEnvironment>(); foreach ((LSLabDetails lab, LSEnvironmentDetails env) in labEnvPairs) { ResourceId labId = ResourceId.FromString(lab.Id); ResourceId envId = ResourceId.FromString(env.Id); client.SubscriptionId = labId.SubscriptionId; expandedEnvironments.Add(await client.Environments.GetAsync(labId.ResourceGroupName, labId.Parent.Name, labId.Name, envId.Parent.Name, envId.Name, "properties($expand=networkInterface)").ConfigureAwait(false)); } // Generate RDP files foreach (LSEnvironment env in expandedEnvironments) { GenerateRdpFile(env.NetworkInterface.RdpAuthority, env.NetworkInterface.Username, rdpFolderPath, env.Name); } } }