public DevTestLabs(IAzure azure, DevTestLabsClient dtl, ILogger functionsLog)
 {
     // Keep a handle to the paramenters so we can use them later
     azureClient = azure;
     dtlClient   = dtl;
     log         = functionsLog;
 }
Esempio n. 2
0
        private static async Task ListLabsAsync()
        {
            var client = new DevTestLabsClient(new CustomLoginCredentials())
            {
                SubscriptionId = ConfigurationManager.AppSettings["SubscriptionId"]
            };

            foreach (var lab in await client.Lab.ListBySubscriptionAsync())
            {
                Console.WriteLine($"{lab.UniqueIdentifier}\t{lab.Name}");
            }
        }
Esempio n. 3
0
        public DevTestLabsClient LoginToDevTestLabsAPIs(string subscriptionId)
        {
            // We are logging into Azure with a token, this is the standard way of logging in for the DTL client
            // Example here:  https://github.com/Azure/azure-devtestlab/blob/master/SdkSamples/DtlClient/Program.cs
            var Dtlclient = new DevTestLabsClient(new CustomDtlLoginCredentials()
            {
                AuthenticationToken = accessToken
            })
            {
                SubscriptionId = subscriptionId
            };

            return(Dtlclient);
        }
Esempio n. 4
0
        private static void AddAllowedPortsToSubnet(
            string subscriptionId,
            string labResourceGroupName,
            string labName,
            string labVirtualNetworkName,
            string location)
        {
            var virtualNetworkSubnetName = labVirtualNetworkName + "Subnet";

            var client = new DevTestLabsClient(new CustomLoginCredentials())
            {
                SubscriptionId = ConfigurationManager.AppSettings["SubscriptionId"]
            };

            Console.WriteLine("Fetching the lab...");
            var lab = client.Labs.Get(labResourceGroupName, labName);

            Console.WriteLine($"Lab ID: {lab.Id}");
            Console.WriteLine("Getting the lab's virtual network");
            var virtualNetwork = client.VirtualNetworks.Get(labResourceGroupName, labName, virtualNetworkSubnetName);

            Console.WriteLine("Virtual network ID: " + virtualNetwork.Id);
            Console.WriteLine("Enter Transport Protocol: TCP or UDP");
            string transportProtocol = Console.ReadLine();

            if (transportProtocol != null &&
                transportProtocol.ToLowerInvariant() != "tcp" ||
                transportProtocol.ToLowerInvariant() != "udp")

            {
                Console.WriteLine("Only TCP and UDP allowed exiting ... ");
                return;
            }

            string portRequest = Console.ReadLine();

            int.TryParse(portRequest, out int backendPort);

            if (transportProtocol != null && backendPort > 0)
            {
                var port = new Port(transportProtocol, backendPort);
                virtualNetwork.SubnetOverrides[0].SharedPublicIpAddressConfiguration.AllowedPorts.Add(port);
                return;
            }
        }
Esempio n. 5
0
        private static void BulkCreateVirtualMachinesForLab(
            string subscriptionId,
            string labResourceGroupName,
            string labName,
            string labVirtualNetworkName,
            string location,
            int vmCount)
        {
            var virtualNetworkSubnetName = labVirtualNetworkName + "Subnet";

            var client = new DevTestLabsClient(new CustomLoginCredentials())
            {
                SubscriptionId = subscriptionId
            };

            Console.WriteLine("Fetching the lab...");
            var lab = client.Lab.GetResource(labResourceGroupName, labName);

            Console.WriteLine($"Lab ID: {lab.Id}");

            Console.WriteLine("Getting the lab's virtual network");
            var virtualNetwork = client.VirtualNetwork.GetResource(labResourceGroupName, labName, labVirtualNetworkName);

            Console.WriteLine("Virtual network ID: " + virtualNetwork.Id);

            Console.WriteLine($"Bulk-creating {vmCount} virtual machines...");
            client.Lab.CreateEnvironment(labResourceGroupName, labName, new LabVirtualMachineCreationParameter
            {
                BulkCreationParameters = new BulkCreationParameters
                {
                    InstanceCount = vmCount
                },
                Location   = location,
                AllowClaim = false,
                DisallowPublicIpAddress = true, /* Shared IP addresss */
                Name                  = "testvm1",
                Size                  = "Standard_DS1_V2",
                UserName              = "******",
                Password              = "******",
                LabVirtualNetworkId   = virtualNetwork.Id,
                LabSubnetName         = virtualNetworkSubnetName,
                StorageType           = StorageType.Premium,
                GalleryImageReference = new GalleryImageReference
                {
                    Offer     = "BizTalk-Server",
                    OsType    = "Windows",
                    Publisher = "MicrosoftBizTalkServer",
                    Sku       = "2016-Standard",
                    Version   = "latest"
                },
                NetworkInterface = new NetworkInterfaceProperties
                {
                    SharedPublicIpAddressConfiguration = new SharedPublicIpAddressConfiguration
                    {
                        InboundNatRules = new List <InboundNatRule>
                        {
                            new InboundNatRule
                            {
                                TransportProtocol = "tcp",
                                BackendPort       = 3389,
                            }
                        }
                    }
                }
            });
        }
Esempio n. 6
0
 private void SetupManagementClients(MockContext context)
 {
     DevTestLabsClient = GetDevTestLabsManagementClient(context);
     _helper.SetupManagementClients(DevTestLabsClient);
 }