private void AddTunnelInterfacesToPool(BackendAddressPool backendAddressPool) { if (this.TunnelInterface != null) { backendAddressPool.TunnelInterfaces = new List <GatewayLoadBalancerTunnelInterface>(); foreach (var tun in this.TunnelInterface) { var tunnelinterface = NetworkResourceManagerProfile.Mapper.Map <GatewayLoadBalancerTunnelInterface>(tun); backendAddressPool.TunnelInterfaces.Add(tunnelinterface); } } }
private BackendAddressPool SetupBackendPoolWithLoadBalancerAddresses() { var backendAddressPool = new BackendAddressPool(); backendAddressPool.LoadBalancerBackendAddresses = new List <LoadBalancerBackendAddress>(); foreach (var psBackendAddress in this.LoadBalancerBackendAddress) { var backendAddress = NetworkResourceManagerProfile.Mapper.Map <LoadBalancerBackendAddress>(psBackendAddress); backendAddressPool.LoadBalancerBackendAddresses.Add(backendAddress); } return(backendAddressPool); }
public override void Execute() { base.Execute(); BackendAddressPool loadBalancerBackendAddressPool = null; if (this.IsParameterBound(c => c.LoadBalancer)) { this.ResourceGroupName = this.LoadBalancer.ResourceGroupName; this.LoadBalancerName = this.LoadBalancer.Name; } if (this.IsParameterBound(p => p.ResourceId)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.LoadBalancerName = resourceIdentifier.ParentResource.Split('/')[1]; this.Name = resourceIdentifier.ResourceName; } // Get single backend pool if (ShouldGetByName(this.ResourceGroupName, this.Name)) { loadBalancerBackendAddressPool = this.NetworkClient.NetworkManagementClient.LoadBalancerBackendAddressPools.Get(this.ResourceGroupName, this.LoadBalancerName, this.Name); var loadBalancerBackendAddressPoolModel = NetworkResourceManagerProfile.Mapper.Map <PSBackendAddressPool>(loadBalancerBackendAddressPool); WriteObject(loadBalancerBackendAddressPoolModel); } else { IPage <BackendAddressPool> backendAddressPoolPage = this.NetworkClient.NetworkManagementClient.LoadBalancerBackendAddressPools.List(this.ResourceGroupName, this.LoadBalancerName); // compose list of BackendAddressPools var backendAddressPoolList = ListNextLink <BackendAddressPool> .GetAllResourcesByPollingNextLink(backendAddressPoolPage, this.NetworkClient.NetworkManagementClient.LoadBalancerBackendAddressPools.ListNext); // convert list of BackendAddressPools to a list of Powershell BackendAddressPools List <PSBackendAddressPool> psBackendAddressPoolList = new List <PSBackendAddressPool>(); foreach (var backendAddressPool in backendAddressPoolList) { var backendAddressPoolModel = NetworkResourceManagerProfile.Mapper.Map <PSBackendAddressPool>(backendAddressPool); psBackendAddressPoolList.Add(backendAddressPoolModel); } WriteObject(psBackendAddressPoolList, true); } }
internal static BackendAddressPool CreateBackendAddressPoolConfig( string backendPoolName, string subscriptionId) { var backendAddressPool = new BackendAddressPool(); backendAddressPool.Name = backendPoolName; backendAddressPool.Id = LoadBalancerStrategy.GetResourceNotSetId( subscriptionId, LoadBalancerStrategy.LoadBalancerBackendAddressPoolName, backendAddressPool.Name); return(backendAddressPool); }
private PSBackendAddressPool CreatePsBackendPool() { var backendAddressPool = new BackendAddressPool(); //Include backend address pool IP's if provided by user if (this.IsParameterBound(c => c.LoadBalancerBackendAddress)) { backendAddressPool.LoadBalancerBackendAddresses = new List <LoadBalancerBackendAddress>(); foreach (var psBackendAddress in LoadBalancerBackendAddress) { var backendAddress = NetworkResourceManagerProfile.Mapper.Map <LoadBalancerBackendAddress>(psBackendAddress); backendAddressPool.LoadBalancerBackendAddresses.Add(backendAddress); } } var loadBalancerBackendAddressPool = this.NetworkClient.NetworkManagementClient.LoadBalancerBackendAddressPools.CreateOrUpdate(this.ResourceGroupName, this.LoadBalancerName, this.Name, backendAddressPool); var loadBalancerBackendAddressPoolModel = NetworkResourceManagerProfile.Mapper.Map <PSBackendAddressPool>(loadBalancerBackendAddressPool); return(loadBalancerBackendAddressPoolModel); }
public override void Execute() { base.Execute(); if (this.IsParameterBound(c => c.LoadBalancer)) { this.ResourceGroupName = this.LoadBalancer.ResourceGroupName; this.LoadBalancerName = this.LoadBalancer.Name; } BackendAddressPool existingloadBalancerBackendAddressPool = null; // Confirm if resource already exists try { existingloadBalancerBackendAddressPool = this.NetworkClient.NetworkManagementClient.LoadBalancerBackendAddressPools.Get(this.ResourceGroupName, this.LoadBalancerName, this.Name); } catch (Rest.Azure.CloudException exception) { if (exception.Response.StatusCode != System.Net.HttpStatusCode.NotFound) { throw exception; } } // Throw if object already exists if (existingloadBalancerBackendAddressPool != null) { throw new ArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresent, this.Name, this.ResourceGroupName)); } // Prompt user if Confirm or What if flag is specified if (ShouldProcess(Name, Microsoft.Azure.Commands.Network.Properties.Resources.CreatingResourceMessage)) { var backendPool = CreatePsBackendPool(); WriteObject(backendPool); } }
public virtual LoadBalancerBackendAddressPoolsCreateOrUpdateOperation StartCreateOrUpdate(string resourceGroupName, string loadBalancerName, string backendAddressPoolName, BackendAddressPool parameters, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (loadBalancerName == null) { throw new ArgumentNullException(nameof(loadBalancerName)); } if (backendAddressPoolName == null) { throw new ArgumentNullException(nameof(backendAddressPoolName)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var scope = _clientDiagnostics.CreateScope("LoadBalancerBackendAddressPoolsOperations.StartCreateOrUpdate"); scope.Start(); try { var originalResponse = RestClient.CreateOrUpdate(resourceGroupName, loadBalancerName, backendAddressPoolName, parameters, cancellationToken); return(new LoadBalancerBackendAddressPoolsCreateOrUpdateOperation(_clientDiagnostics, _pipeline, RestClient.CreateCreateOrUpdateRequest(resourceGroupName, loadBalancerName, backendAddressPoolName, parameters).Request, originalResponse)); } catch (Exception e) { scope.Failed(e); throw; } }
private static ApplicationGatewaySetConfiguration GenerateConfig() { ApplicationGatewaySetConfiguration config = new ApplicationGatewaySetConfiguration(); var frontEndIP1 = new FrontendIPConfiguration { Name = "FrontendIP1", Type = "Private" }; var frontEndPort1 = new FrontendPort { Name = "Port1", Port = 80, }; var probe1 = new Probe { Name = "Probe1", Protocol = "Http", Host = "127.0.0.1", Path = "/", Interval = 45, Timeout = 25, UnhealthyThreshold = 2 }; var backendServer1 = new BackendServer { IPAddress = "10.0.0.1", }; var backendServer2 = new BackendServer { IPAddress = "10.0.0.2", }; var backendAddressPool1 = new BackendAddressPool { Name = "Pool1", BackendServers = new List <BackendServer> { backendServer1, backendServer2 }, }; var backendHttpSettings1 = new BackendHttpSettings { Name = "Setting1", Port = 80, Protocol = Protocol.Http, CookieBasedAffinity = "Enabled", RequestTimeout = 45, Probe = "Probe1" }; var httpListener1 = new AGHttpListener { Name = "Listener1", FrontendPort = "Port1", Protocol = Protocol.Http, FrontendIP = "FrontendIP1", //SslCert = string.Empty, }; var httpLoadBalancingRule1 = new HttpLoadBalancingRule { Name = "Rule1", Type = "Basic", BackendHttpSettings = "Setting1", Listener = "Listener1", BackendAddressPool = "Pool1", }; config.FrontendIPConfigurations = new List <FrontendIPConfiguration> { frontEndIP1 }; config.FrontendPorts = new List <FrontendPort> { frontEndPort1 }; config.Probes = new List <Probe> { probe1 }; config.BackendAddressPools = new List <BackendAddressPool> { backendAddressPool1 }; config.BackendHttpSettingsList = new List <BackendHttpSettings> { backendHttpSettings1 }; config.HttpListeners = new List <AGHttpListener> { httpListener1 }; config.HttpLoadBalancingRules = new List <HttpLoadBalancingRule> { httpLoadBalancingRule1 }; return(config); }
public Func <RegionalContext, IRegionalEndpoint> BuildVMScaleSetApp(GlobalContext context) { var options = (CustomResourceOptions)ResourceOptions.Merge(context.Options, new CustomResourceOptions { DeleteBeforeReplace = true }); var file = File.ReadAllText("./vm/vmCustomData.yaml"); return((RegionalContext region) => { var location = region.Location; var domainName = $"rnddnplm{location}"; //TODO: random var publicIp = new PublicIp($"pip-{location}", new PublicIpArgs { ResourceGroupName = resourceGroup.Name, Location = location, AllocationMethod = "Static", DomainNameLabel = domainName, }, options); var loadBalancer = new LoadBalancer($"lb-{location}", new LoadBalancerArgs { ResourceGroupName = resourceGroup.Name, Location = location, FrontendIpConfigurations = { new LoadBalancerFrontendIpConfigurationsArgs { Name = "PublicIPAddress", PublicIpAddressId = publicIp.Id, } } }, options); var bpepool = new BackendAddressPool($"bap-{location}", new BackendAddressPoolArgs { ResourceGroupName = resourceGroup.Name, LoadbalancerId = loadBalancer.Id, }, options); var probe = new Probe($"ssh-probe-{location}".Truncate(16), new ProbeArgs { ResourceGroupName = resourceGroup.Name, LoadbalancerId = loadBalancer.Id, Port = 80, }, options); var rule = new Rule($"rule-{location}", new RuleArgs { ResourceGroupName = resourceGroup.Name, BackendAddressPoolId = bpepool.Id, BackendPort = 80, FrontendIpConfigurationName = "PublicIPAddress", FrontendPort = 80, LoadbalancerId = loadBalancer.Id, ProbeId = probe.Id, Protocol = "Tcp", }, options); var vnet = new VirtualNetwork($"vnet-{location}", new VirtualNetworkArgs { ResourceGroupName = resourceGroup.Name, Location = location, AddressSpaces = { "10.0.0.0/16" }, }, options); var subnet = new Subnet($"subnet-{location}", new SubnetArgs { ResourceGroupName = resourceGroup.Name, AddressPrefix = "10.0.2.0/24", VirtualNetworkName = vnet.Name, }, options); var customData = Output.All <string>(context.CosmosAccount.Endpoint, context.CosmosAccount.PrimaryMasterKey, context.Database.Name, context.Container.Name) .Apply(values => { return file.Replace("${ENDPOINT}", values[0]) .Replace("${MASTER_KEY}", values[1]) .Replace("${DATABASE}", values[2]) .Replace("${COLLECTION}", values[3]) .Replace("${LOCATION}", location); }); var scaleSet = new ScaleSet($"vmss-{location}", new ScaleSetArgs { ResourceGroupName = resourceGroup.Name, Location = location, NetworkProfiles = { new ScaleSetNetworkProfilesArgs { IpConfigurations = { new ScaleSetNetworkProfilesIpConfigurationsArgs { LoadBalancerBackendAddressPoolIds ={ bpepool.Id }, Name = "IPConfiguration", Primary = true, SubnetId = subnet.Id, } }, Name = "networkprofile", Primary = true, } }, OsProfile = new ScaleSetOsProfileArgs { AdminUsername = "******", AdminPassword = "******", ComputerNamePrefix = "lab", CustomData = customData, }, OsProfileLinuxConfig = new ScaleSetOsProfileLinuxConfigArgs { DisablePasswordAuthentication = false }, Sku = new ScaleSetSkuArgs { Capacity = 1, Name = "Standard_DS1_v2", Tier = "Standard", }, StorageProfileDataDisks = { new ScaleSetStorageProfileDataDisksArgs { Caching = "ReadWrite", CreateOption = "Empty", DiskSizeGb = 10, Lun = 0, } }, StorageProfileImageReference = new ScaleSetStorageProfileImageReferenceArgs { Offer = "UbuntuServer", Publisher = "Canonical", Sku = "18.04-LTS", Version = "latest", }, StorageProfileOsDisk = new ScaleSetStorageProfileOsDiskArgs { Caching = "ReadWrite", CreateOption = "FromImage", ManagedDiskType = "Standard_LRS", Name = "", }, UpgradePolicyMode = "Automatic", }, (CustomResourceOptions)ResourceOptions.Merge(options, new ResourceOptions { DependsOn = { bpepool, rule } })); var autoscale = new AutoscaleSetting($"as-{location}", new AutoscaleSettingArgs { ResourceGroupName = resourceGroup.Name, Location = location, Notification = new AutoscaleSettingNotificationArgs { Email = new AutoscaleSettingNotificationEmailArgs { CustomEmails = { "*****@*****.**" }, SendToSubscriptionAdministrator = true, SendToSubscriptionCoAdministrator = true, }, }, Profiles = { new AutoscaleSettingProfilesArgs { Capacity = new AutoscaleSettingProfilesCapacityArgs { Default = 1, Maximum = 10, Minimum = 1, }, Name = "defaultProfile", Rules = { new AutoscaleSettingProfilesRulesArgs { MetricTrigger = new AutoscaleSettingProfilesRulesMetricTriggerArgs { MetricName = "Percentage CPU", MetricResourceId = scaleSet.Id, Operator = "GreaterThan", Statistic = "Average", Threshold = 75, TimeAggregation = "Average", TimeGrain = "PT1M", TimeWindow = "PT5M", }, ScaleAction = new AutoscaleSettingProfilesRulesScaleActionArgs { Cooldown = "PT1M", Direction = "Increase", Type = "ChangeCount", Value = 1, }, }, new AutoscaleSettingProfilesRulesArgs { MetricTrigger = new AutoscaleSettingProfilesRulesMetricTriggerArgs { MetricName = "Percentage CPU", MetricResourceId = scaleSet.Id, Operator = "LessThan", Statistic = "Average", Threshold = 25, TimeAggregation = "Average", TimeGrain = "PT1M", TimeWindow = "PT5M", }, ScaleAction = new AutoscaleSettingProfilesRulesScaleActionArgs { Cooldown = "PT1M", Direction = "Decrease", Type = "ChangeCount", Value = 1, }, }, } } }, TargetResourceId = scaleSet.Id, }, options); return new AzureEndpoint(publicIp.Id); }); }
private void BuildFoodLoadBalancer() { var frontEndConfig = new LoadBalancerFrontendIpConfigurationArgs { Name = "frontendconfig", SubnetId = _Subnets["Food2"].Id, PrivateIpAddressAllocation = "Dynamic", PrivateIpAddressVersion = "IPv4" }; var lb = new LoadBalancer("foodLb2", new LoadBalancerArgs { ResourceGroupName = _ResourceGroup.Name, Location = _ResourceGroup.Location, Name = "foodLb", Sku = "Basic", // Standard FrontendIpConfigurations = frontEndConfig }); var healthProbe1 = new FrontdoorBackendPoolHealthProbeArgs { Name = "Probe1", Enabled = true, IntervalInSeconds = 5, Protocol = "TCP" }; var backendpool = new BackendAddressPool("Pool12", new BackendAddressPoolArgs { Name = "Pool12", ResourceGroupName = _ResourceGroup.Name, LoadbalancerId = lb.Id }); new NetworkInterfaceBackendAddressPoolAssociation("association12", new NetworkInterfaceBackendAddressPoolAssociationArgs { BackendAddressPoolId = backendpool.Id, NetworkInterfaceId = _foodVmNics[0].Id, IpConfigurationName = "Ipconfig1" }); new NetworkInterfaceBackendAddressPoolAssociation("association22", new NetworkInterfaceBackendAddressPoolAssociationArgs { BackendAddressPoolId = backendpool.Id, NetworkInterfaceId = _foodVmNics[1].Id, IpConfigurationName = "Ipconfig1" }); var lbRule = new Rule("rule12", new RuleArgs { Name = "rule12", ResourceGroupName = _ResourceGroup.Name, LoadbalancerId = lb.Id, Protocol = "TCP", FrontendPort = 80, BackendPort = 80, FrontendIpConfigurationName = frontEndConfig.Name, ProbeId = healthProbe1.Id, BackendAddressPoolId = backendpool.Id }); }
public VmScalesetStack() { var applicationPort = 80; var resourceGroup = new ResourceGroup("vmss-rg"); var network = new VirtualNetwork("vnet", new VirtualNetworkArgs { ResourceGroupName = resourceGroup.Name, AddressSpaces = { "10.0.0.0/16" } } ); var subnet = new Subnet("subnet", new SubnetArgs { ResourceGroupName = resourceGroup.Name, Name = "default", AddressPrefixes = "10.0.1.0/24", VirtualNetworkName = network.Name }); var publicIp = new PublicIp("public-ip", new PublicIpArgs { ResourceGroupName = resourceGroup.Name, AllocationMethod = "Dynamic" }); var lb = new LoadBalancer("lb", new LoadBalancerArgs { ResourceGroupName = resourceGroup.Name, FrontendIpConfigurations = new List <LoadBalancerFrontendIpConfigurationArgs> { new LoadBalancerFrontendIpConfigurationArgs { Name = "PublicIPAddress", PublicIpAddressId = publicIp.Id } } }); var bpePool = new BackendAddressPool("bpepool", new BackendAddressPoolArgs { ResourceGroupName = resourceGroup.Name, LoadbalancerId = lb.Id, }); var sshProbe = new Probe("ssh-probe", new ProbeArgs { ResourceGroupName = resourceGroup.Name, LoadbalancerId = lb.Id, Port = applicationPort, }); var natRule = new Rule("lbnatrule-http", new RuleArgs { ResourceGroupName = resourceGroup.Name, BackendAddressPoolId = bpePool.Id, BackendPort = applicationPort, FrontendIpConfigurationName = "PublicIPAddress", FrontendPort = applicationPort, LoadbalancerId = lb.Id, ProbeId = sshProbe.Id, Protocol = "Tcp", }); var scaleSet = new ScaleSet("vmscaleset", new ScaleSetArgs { ResourceGroupName = resourceGroup.Name, NetworkProfiles = new ScaleSetNetworkProfileArgs { IpConfigurations = new ScaleSetNetworkProfileIpConfigurationArgs[] { new ScaleSetNetworkProfileIpConfigurationArgs { LoadBalancerBackendAddressPoolIds = bpePool.Id, Name = "IPConfiguration", Primary = true, SubnetId = subnet.Id, } }, Name = "networkprofile", Primary = true }, OsProfile = new ScaleSetOsProfileArgs { ComputerNamePrefix = "vmlab", AdminUsername = "******", AdminPassword = "******", CustomData = @"#!/bin/bash echo ""Hello, World by $HOSTNAME!"" > index.html nohup python -m SimpleHTTPServer 80 &" }, OsProfileLinuxConfig = new ScaleSetOsProfileLinuxConfigArgs { DisablePasswordAuthentication = false }, Sku = new ScaleSetSkuArgs { Capacity = 1, Name = "Standard_DS1_v2", Tier = "Standard", }, StorageProfileOsDisk = new ScaleSetStorageProfileOsDiskArgs { Caching = "ReadWrite", CreateOption = "FromImage", ManagedDiskType = "Standard_LRS", Name = "" }, StorageProfileDataDisks = new ScaleSetStorageProfileDataDiskArgs { Caching = "ReadWrite", CreateOption = "Empty", DiskSizeGb = 10, Lun = 0 }, StorageProfileImageReference = new ScaleSetStorageProfileImageReferenceArgs { Offer = "UbuntuServer", Publisher = "Canonical", Sku = "16.04-LTS", Version = "latest", }, UpgradePolicyMode = "Manual" }, new CustomResourceOptions { DeleteBeforeReplace = true, DependsOn = bpePool }); var autoscale = new AutoscaleSetting("vmss-autoscale", new AutoscaleSettingArgs { ResourceGroupName = resourceGroup.Name, Notification = new AutoscaleSettingNotificationArgs { Email = new AutoscaleSettingNotificationEmailArgs { CustomEmails = new string[] { "*****@*****.**" }, SendToSubscriptionAdministrator = true, SendToSubscriptionCoAdministrator = true, }, }, Profiles = new AutoscaleSettingProfileArgs[] { new AutoscaleSettingProfileArgs { Capacity = new AutoscaleSettingProfileCapacityArgs { Default = 2, Maximum = 10, Minimum = 2, }, Name = "defaultProfile", Rules = new AutoscaleSettingProfileRuleArgs[] { new AutoscaleSettingProfileRuleArgs { MetricTrigger = new AutoscaleSettingProfileRuleMetricTriggerArgs { MetricName = "Percentage CPU", MetricResourceId = scaleSet.Id, Operator = "GreaterThan", Statistic = "Average", Threshold = 75, TimeAggregation = "Average", TimeGrain = "PT1M", TimeWindow = "PT5M", }, ScaleAction = new AutoscaleSettingProfileRuleScaleActionArgs { Cooldown = "PT1M", Direction = "Increase", Type = "ChangeCount", Value = 1, }, }, new AutoscaleSettingProfileRuleArgs { MetricTrigger = new AutoscaleSettingProfileRuleMetricTriggerArgs { MetricName = "Percentage CPU", MetricResourceId = scaleSet.Id, Operator = "LessThan", Statistic = "Average", Threshold = 25, TimeAggregation = "Average", TimeGrain = "PT1M", TimeWindow = "PT5M", }, ScaleAction = new AutoscaleSettingProfileRuleScaleActionArgs { Cooldown = "PT1M", Direction = "Decrease", Type = "ChangeCount", Value = 1, }, } } } }, TargetResourceId = scaleSet.Id }); // The public IP address is not allocated until the VM is running, so wait for that // resource to create, and then lookup the IP address again to report its public IP. this.IpAddress = Output .Tuple <string, string, string>(scaleSet.Id, publicIp.Name, resourceGroup.Name) .Apply <string>(async t => { (_, string name, string resourceGroupName) = t; var ip = await GetPublicIP.InvokeAsync(new GetPublicIPArgs { Name = name, ResourceGroupName = resourceGroupName }); return(ip.IpAddress); }); }
public override void Execute() { base.Execute(); BackendAddressPool backendAddressPool = null; if (this.IsParameterBound(c => c.LoadBalancer)) { this.ResourceGroupName = this.LoadBalancer.ResourceGroupName; this.LoadBalancerName = this.LoadBalancer.Name; } if (this.IsParameterBound(c => c.ResourceId)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.LoadBalancerName = resourceIdentifier.ParentResource.Split('/')[1]; this.Name = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.InputObject)) { ResourceIdentifier resourceIdentifier = new ResourceIdentifier(this.InputObject.Id); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.LoadBalancerName = resourceIdentifier.ParentResource.Split('/')[1]; this.Name = resourceIdentifier.ResourceName; backendAddressPool = NetworkResourceManagerProfile.Mapper.Map <BackendAddressPool>(this.InputObject); } // Confirm if resource already exists try { this.NetworkClient.NetworkManagementClient.LoadBalancerBackendAddressPools.Get(this.ResourceGroupName, this.LoadBalancerName, this.Name); } catch (Rest.Azure.CloudException exception) { if (exception.Response.StatusCode == System.Net.HttpStatusCode.NotFound) { throw new ArgumentException(string.Format(Properties.Resources.ResourceNotFound, Name)); } else { throw exception; } } // add loadbalancer address to the request available. if (this.IsParameterBound(c => c.LoadBalancerBackendAddress)) { backendAddressPool = SetupBackendPoolWithLoadBalancerAddresses(); } if (ShouldProcess(Name, Microsoft.Azure.Commands.Network.Properties.Resources.OverwritingResourceMessage)) { var loadBalancerBackendAddressPool = this.NetworkClient.NetworkManagementClient.LoadBalancerBackendAddressPools.CreateOrUpdate( this.ResourceGroupName, this.LoadBalancerName, this.Name, backendAddressPool); var loadBalancerBackendAddressPoolModel = NetworkResourceManagerProfile.Mapper.Map <PSBackendAddressPool>(loadBalancerBackendAddressPool); WriteObject(loadBalancerBackendAddressPoolModel); } }
public async Task ExpandResourceTest() { string resourceGroupName = Recording.GenerateAssetName("csmrg"); string location = TestEnvironment.Location; var resourceGroup = await CreateResourceGroup(resourceGroupName); // Create lbPublicIP string lbPublicIpName = Recording.GenerateAssetName("azsmnet"); string lbDomaingNameLabel = Recording.GenerateAssetName("azsmnet"); PublicIPAddress lbPublicIp = await CreateDefaultPublicIpAddress( lbPublicIpName, lbDomaingNameLabel, location, resourceGroup.GetPublicIPAddresses()); // Create Vnet string vnetName = Recording.GenerateAssetName("azsmnet"); string subnetName = Recording.GenerateAssetName("azsmnet"); VirtualNetwork vnet = await CreateVirtualNetwork(vnetName, subnetName, location, resourceGroup.GetVirtualNetworks()); // Create Nics string nic1name = Recording.GenerateAssetName("azsmnet"); string nic2name = Recording.GenerateAssetName("azsmnet"); string nic3name = Recording.GenerateAssetName("azsmnet"); NetworkInterface nic1 = await CreateNetworkInterface( nic1name, null, vnet.Data.Subnets[0].Id, location, "ipconfig", resourceGroup.GetNetworkInterfaces()); NetworkInterface nic2 = await CreateNetworkInterface( nic2name, null, vnet.Data.Subnets[0].Id, location, "ipconfig", resourceGroup.GetNetworkInterfaces()); NetworkInterface nic3 = await CreateNetworkInterface( nic3name, null, vnet.Data.Subnets[0].Id, location, "ipconfig", resourceGroup.GetNetworkInterfaces()); // Create the LoadBalancer var lbName = Recording.GenerateAssetName("azsmnet"); var frontendIpConfigName = Recording.GenerateAssetName("azsmnet"); var backEndAddressPoolName = Recording.GenerateAssetName("azsmnet"); var loadBalancingRuleName = Recording.GenerateAssetName("azsmnet"); var probeName = Recording.GenerateAssetName("azsmnet"); var inboundNatRule1Name = Recording.GenerateAssetName("azsmnet"); var inboundNatRule2Name = Recording.GenerateAssetName("azsmnet"); // Populate the loadBalancerCreateOrUpdateParameter var loadBalancerData = new LoadBalancerData() { Location = location, FrontendIPConfigurations = { new FrontendIPConfigurationData() { Name = frontendIpConfigName, PublicIPAddress = new PublicIPAddressData() { Id = lbPublicIp.Id } } }, BackendAddressPools = { new BackendAddressPoolData() { Name = backEndAddressPoolName, } }, LoadBalancingRules = { new LoadBalancingRuleData() { Name = loadBalancingRuleName, FrontendIPConfiguration = new WritableSubResource() { Id = GetChildLbResourceId(TestEnvironment.SubscriptionId, resourceGroupName, lbName, "FrontendIPConfigurations", frontendIpConfigName) }, Protocol = TransportProtocol.Tcp, FrontendPort = 80, BackendPort = 80, EnableFloatingIP = false, IdleTimeoutInMinutes = 15, BackendAddressPool = new WritableSubResource() { Id = GetChildLbResourceId(TestEnvironment.SubscriptionId, resourceGroupName, lbName, "backendAddressPools", backEndAddressPoolName) }, Probe = new WritableSubResource() { Id = GetChildLbResourceId(TestEnvironment.SubscriptionId, resourceGroupName, lbName, "probes", probeName) } } }, Probes = { new ProbeData() { Name = probeName, Protocol = ProbeProtocol.Http, Port = 80, RequestPath = "healthcheck.aspx", IntervalInSeconds = 10, NumberOfProbes = 2 } }, InboundNatRules = { new InboundNatRuleData() { Name = inboundNatRule1Name, FrontendIPConfiguration = new WritableSubResource() { Id = GetChildLbResourceId(TestEnvironment.SubscriptionId, resourceGroupName, lbName, "FrontendIPConfigurations", frontendIpConfigName) }, Protocol = TransportProtocol.Tcp, FrontendPort = 3389, BackendPort = 3389, IdleTimeoutInMinutes = 15, EnableFloatingIP = false }, new InboundNatRuleData() { Name = inboundNatRule2Name, FrontendIPConfiguration = new WritableSubResource() { Id = GetChildLbResourceId(TestEnvironment.SubscriptionId, resourceGroupName, lbName, "FrontendIPConfigurations", frontendIpConfigName) }, Protocol = TransportProtocol.Tcp, FrontendPort = 3390, BackendPort = 3389, IdleTimeoutInMinutes = 15, EnableFloatingIP = false, } } }; // Create the loadBalancer var loadBalancerCollection = resourceGroup.GetLoadBalancers(); LoadBalancer loadBalancer = (await loadBalancerCollection.CreateOrUpdateAsync(WaitUntil.Completed, lbName, loadBalancerData)).Value; // Associate the nic with LB //nic1.GetNetworkInterfaceIPConfigurations().List().First().` // TODO: where do we have the following? //nic1.IpConfigurations.First().LoadBalancerBackendAddressPools.Add(getLoadBalancer.Value.BackendAddressPools.First()); //nic1.IpConfigurations.First().LoadBalancerInboundNatRules.Add(getLoadBalancer.Value.InboundNatRules.First()); //nic2.IpConfigurations.First().LoadBalancerBackendAddressPools.Add(getLoadBalancer.Value.BackendAddressPools.First()); //nic3.IpConfigurations.First().LoadBalancerInboundNatRules.Add(getLoadBalancer.Value.InboundNatRules[1]); nic1.Data.IPConfigurations.First().LoadBalancerBackendAddressPools.Add(loadBalancer.Data.BackendAddressPools.First()); nic1.Data.IPConfigurations.First().LoadBalancerInboundNatRules.Add(loadBalancer.Data.InboundNatRules[0]); nic2.Data.IPConfigurations.First().LoadBalancerBackendAddressPools.Add(loadBalancer.Data.BackendAddressPools.First()); nic2.Data.IPConfigurations.First().LoadBalancerInboundNatRules.Add(loadBalancer.Data.InboundNatRules[1]); nic3.Data.IPConfigurations.First().LoadBalancerBackendAddressPools.Add(loadBalancer.Data.BackendAddressPools.First()); // Put Nics var networkInterfaceCollection = resourceGroup.GetNetworkInterfaces(); var createOrUpdateOperation1 = await networkInterfaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, nic1name, nic1.Data); await createOrUpdateOperation1.WaitForCompletionAsync(); var createOrUpdateOperation2 = await networkInterfaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, nic2name, nic2.Data); await createOrUpdateOperation2.WaitForCompletionAsync(); var createOrUpdateOperation3 = await networkInterfaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, nic3name, nic3.Data); await createOrUpdateOperation3.WaitForCompletionAsync(); // Get Nics await networkInterfaceCollection.GetAsync(nic1name); await networkInterfaceCollection.GetAsync(nic2name); await networkInterfaceCollection.GetAsync(nic3name); // Get lb with expanded nics from nat rules loadBalancer = await loadBalancerCollection.GetAsync(lbName, "InboundNatRules/backendIPConfiguration"); await foreach (var natRule in loadBalancer.GetInboundNatRules()) { Assert.NotNull(natRule.Data.BackendIPConfiguration); Assert.NotNull(natRule.Data.BackendIPConfiguration.Id); //Assert.NotNull(natRule.Data.BackendIPConfiguration.Name); //Assert.NotNull(natRule.Data.BackendIPConfiguration.Etag); //Assert.AreEqual(natRule.Id, natRule.Data.BackendIPConfiguration.LoadBalancerInboundNatRules[0].Id); } // Get lb with expanded nics from pools loadBalancer = await loadBalancerCollection.GetAsync(lbName, "BackendAddressPools/backendIPConfigurations"); await foreach (var pool in loadBalancer.GetBackendAddressPools()) { BackendAddressPool firstPool = await GetFirstPoolAsync(loadBalancer); foreach (var ipconfig in firstPool.Data.BackendIPConfigurations) { Assert.NotNull(ipconfig.Id); //Assert.NotNull(ipconfig.Name); //Assert.NotNull(ipconfig.Etag); //Assert.AreEqual(pool.Id, ipconfig.LoadBalancerBackendAddressPools[0].Id); } } // Get lb with expanded publicip loadBalancer = await loadBalancerCollection.GetAsync(lbName, "FrontendIPConfigurations/PublicIPAddress"); foreach (var ipconfig in loadBalancer.Data.FrontendIPConfigurations) { Assert.NotNull(ipconfig.PublicIPAddress); Assert.NotNull(ipconfig.PublicIPAddress.Id); Assert.NotNull(ipconfig.PublicIPAddress.Name); Assert.NotNull(ipconfig.PublicIPAddress.Etag); Assert.AreEqual(ipconfig.Id, ipconfig.PublicIPAddress.IPConfiguration.Id); } // Get NIC with expanded subnet nic1 = await networkInterfaceCollection.GetAsync(nic1name, "IPConfigurations/Subnet"); await foreach (NetworkInterfaceIPConfiguration ipconfig in nic1.GetNetworkInterfaceIPConfigurations()) { Assert.NotNull(ipconfig.Data.Subnet); Assert.NotNull(ipconfig.Data.Subnet.Id); //Assert.NotNull(ipconfig.Subnet.Name); //Assert.NotNull(ipconfig.Subnet.Etag); //Assert.IsNotEmpty(ipconfig.Subnet.IpConfigurations); } // Get subnet with expanded ipconfigurations Response<Subnet> subnet = await (await resourceGroup.GetVirtualNetworks().GetAsync(vnetName)).Value.GetSubnets().GetAsync( subnetName, "IPConfigurations"); foreach (IPConfiguration ipconfig in subnet.Value.Data.IPConfigurations) { Assert.NotNull(ipconfig.Id); //Assert.NotNull(ipconfig.Name); //Assert.NotNull(ipconfig.Etag); Assert.NotNull(ipconfig.PrivateIPAddress); } // Get publicIPAddress with expanded ipconfigurations Response<PublicIPAddress> publicip = await resourceGroup.GetPublicIPAddresses().GetAsync( lbPublicIpName, "IPConfiguration"); Assert.NotNull(publicip.Value.Data.IPConfiguration); Assert.NotNull(publicip.Value.Data.IPConfiguration.Id); //Assert.NotNull(publicip.Value.Data.IpConfiguration.Name); //Assert.NotNull(publicip.Value.Data.IpConfiguration.Etag); // Delete LoadBalancer Operation deleteOperation = await (await loadBalancerCollection.GetAsync(lbName)).Value.DeleteAsync(WaitUntil.Completed); await deleteOperation.WaitForCompletionResponseAsync(); // Verify Delete AsyncPageable<LoadBalancer> listLoadBalancerAP = loadBalancerCollection.GetAllAsync(); List<LoadBalancer> listLoadBalancer = await listLoadBalancerAP.ToEnumerableAsync(); Assert.IsEmpty(listLoadBalancer); // Delete all NetworkInterfaces await (await networkInterfaceCollection.GetAsync(nic1name)).Value.DeleteAsync(WaitUntil.Completed); await (await networkInterfaceCollection.GetAsync(nic2name)).Value.DeleteAsync(WaitUntil.Completed); await (await networkInterfaceCollection.GetAsync(nic3name)).Value.DeleteAsync(WaitUntil.Completed); // Delete all PublicIPAddresses await (await resourceGroup.GetPublicIPAddresses().GetAsync(lbPublicIpName)).Value.DeleteAsync(WaitUntil.Completed); }
/// <summary> /// Creates or updates a load balancer backend address pool. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='loadBalancerName'> /// The name of the load balancer. /// </param> /// <param name='backendAddressPoolName'> /// The name of the backend address pool. /// </param> /// <param name='parameters'> /// Parameters supplied to the create or update load balancer backend address /// pool operation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <BackendAddressPool> BeginCreateOrUpdateAsync(this ILoadBalancerBackendAddressPoolsOperations operations, string resourceGroupName, string loadBalancerName, string backendAddressPoolName, BackendAddressPool parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, loadBalancerName, backendAddressPoolName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates or updates a load balancer backend address pool. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='loadBalancerName'> /// The name of the load balancer. /// </param> /// <param name='backendAddressPoolName'> /// The name of the backend address pool. /// </param> /// <param name='parameters'> /// Parameters supplied to the create or update load balancer backend address /// pool operation. /// </param> public static BackendAddressPool BeginCreateOrUpdate(this ILoadBalancerBackendAddressPoolsOperations operations, string resourceGroupName, string loadBalancerName, string backendAddressPoolName, BackendAddressPool parameters) { return(operations.BeginCreateOrUpdateAsync(resourceGroupName, loadBalancerName, backendAddressPoolName, parameters).GetAwaiter().GetResult()); }