Last active
July 8, 2016 15:17
-
-
Save devigned/57fb9f85d73fe87d62be36862f0c82a8 to your computer and use it in GitHub Desktop.
quick sample of network related functionality to get some feedback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write("Creating a public IP address for the load balancer"); | |
var publicIpCreateParams = new PublicIPAddress { | |
Location = westus, | |
PublicIPAllocationMethod = IPAllocationMethod.Dynamic, | |
DnsSettings = new PublicIPAddressDnsSettings{ DomainNameLabel = "sample-dotnet-domain-name-label" } | |
}; | |
var pubIp = networkClient.PublicIPAddresses.CreateOrUpdate(resourceGroupName, "sample-dotnet-pubip", publicIpCreateParams); | |
Write("Building the frontend IP configuration to expose the public IP"); | |
var frontendIPConfig = new FrontendIPConfiguration{ | |
Name = "sample-frontend-config", | |
PrivateIPAllocationMethod = IPAllocationMethod.Dynamic, | |
PublicIPAddress = new PublicIPAddress{ | |
Id = pubIp.Id | |
} | |
}; | |
Write("Building the backend IP address pool for the load balancer"); | |
var backendAddressPool = new BackendAddressPool{Name = "sample-backend-pool"}; | |
Write("Building the health probe for the load balancer, which will probe the http://publicIPAddress/canary to determine the health of the applicaiton."); | |
var probe = new Probe{ | |
Name = "sample-probe", | |
Protocol = ProbeProtocol.Http, | |
Port = 80, | |
IntervalInSeconds = 15, | |
NumberOfProbes = 4, | |
RequestPath = "/canary" | |
}; | |
Write("Creating a load balancer exposing port 80 with inbound nat rules for port 21, 23 mapping back to port 22 on two backend VMs"); | |
var lb = networkClient.LoadBalancers.CreateOrUpdate(resourceGroupName, "sample-loadbalancer", new LoadBalancer{ | |
Location = westus, | |
FrontendIPConfigurations = new List<FrontendIPConfiguration>{frontendIPConfig}, | |
BackendAddressPools = new List<BackendAddressPool>{backendAddressPool}, | |
Probes = new List<Probe>{probe}, | |
LoadBalancingRules = new List<LoadBalancingRule>{ | |
new LoadBalancingRule{ | |
Name = "sample-http-rule", | |
Protocol = ProbeProtocol.Tcp, | |
FrontendPort = 80, | |
BackendPort = 80, | |
IdleTimeoutInMinutes = 4, | |
EnableFloatingIP = false, | |
LoadDistribution = LoadDistribution.Default, | |
FrontendIPConfiguration = frontendIPConfig, | |
BackendAddressPool = backendAddressPool, | |
Probe = probe | |
} | |
}, | |
InboundNatRules = new List<InboundNatRule>{ | |
new InboundNatRule{ | |
Name = "sample-inbound-ssh-rule", | |
Protocol = ProbeProtocol.Tcp, | |
FrontendPort = 21, | |
BackendPort = 22, | |
EnableFloatingIP = false, | |
IdleTimeoutInMinutes = 4, | |
FrontendIPConfiguration = frontendIPConfig, | |
}, | |
new InboundNatRule{ | |
Name = "sample-inbound-ssh-rule", | |
Protocol = ProbeProtocol.Tcp, | |
FrontendPort = 23, | |
BackendPort = 22, | |
EnableFloatingIP = false, | |
IdleTimeoutInMinutes = 4, | |
FrontendIPConfiguration = frontendIPConfig, | |
} | |
} | |
}); | |
/* | |
"{\r\n \"error\": {\r\n \"code\": \"InvalidRequestFormat\",\r\n \"message\": \"Cannot parse the request.\",\r\n | |
\"details\": [\r\n {\r\n \"code\": \"MissingJsonReferenceId\",\r\n | |
\"message\": \"Value for reference id is missing. Path properties.loadBalancingRules[0].properties.frontendIPConfiguration.\"\r\n },\r\n | |
{\r\n \"code\": \"MissingJsonReferenceId\",\r\n | |
\"message\": \"Value for reference id is missing. Path properties.loadBalancingRules[0].properties.backendAddressPool.\"\r\n },\r\n | |
{\r\n \"code\": \"MissingJsonReferenceId\",\r\n | |
\"message\": \"Value for reference id is missing. Path properties.loadBalancingRules[0].properties.probe.\"\r\n },\r\n | |
{\r\n \"code\": \"MissingJsonReferenceId\",\r\n | |
\"message\": \"Value for reference id is missing. Path properties.inboundNatRules[0].properties.frontendIPConfiguration.\"\r\n },\r\n | |
{\r\n \"code\": \"MissingJsonReferenceId\",\r\n | |
\"message\": \"Value for reference id is missing. Path properties.inboundNatRules[1].properties.frontendIPConfiguration.\"\r\n },\r\n | |
{\r\n \"code\": \"DuplicateResourceName\",\r\n | |
\"message\": \"Resource /subscriptions//resourceGroups//providers/Microsoft.Network/loadBalancers/ has two child resources | |
with the same name (sample-inbound-ssh-rule).\"\r\n }\r\n ]\r\n }\r\n}" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment