public PowerShellAppGwModel.ApplicationGatewayConfigContext GetApplicationGatewayConfig(string gatewayName) { ApplicationGatewayGetConfiguration hydraConfig = client.ApplicationGateways.GetConfig(gatewayName); PowerShellAppGwModel.ApplicationGatewayConfiguration psConfig = PowerShellConfigFromHydraConfig(hydraConfig); return(new PowerShellAppGwModel.ApplicationGatewayConfigContext { OperationDescription = "Get-ApplicationGatewayConfig", OperationId = hydraConfig.RequestId, OperationStatus = hydraConfig.StatusCode.ToString(), Config = psConfig, XMLConfiguration = PowerShellAppGwModel.ApplicationGatewayConfiguration.Print(psConfig) }); }
private static void VerifyGetApplicationGatewayConfigDetails( ApplicationGatewaySetConfiguration setConfig, ApplicationGatewayGetConfiguration getConfig) { Assert.Equal(setConfig.FrontendIPConfigurations.Count, getConfig.FrontendIPConfigurations.Count); foreach (var getVar in setConfig.FrontendIPConfigurations) { Assert.True(getConfig.FrontendIPConfigurations.Any(setVar => (String.Equals(setVar.Name, getVar.Name, StringComparison.InvariantCultureIgnoreCase) && setVar.StaticIPAddress == getVar.StaticIPAddress && setVar.Type == getVar.Type))); } Assert.Equal(setConfig.FrontendPorts.Count, getConfig.FrontendPorts.Count); foreach (var getVar in setConfig.FrontendPorts) { Assert.True(getConfig.FrontendPorts.Any(setVar => (String.Equals(setVar.Name, getVar.Name, StringComparison.InvariantCultureIgnoreCase) && setVar.Port == getVar.Port))); } Assert.Equal(setConfig.Probes.Count, getConfig.Probes.Count); foreach (var getVar in setConfig.Probes) { Assert.True(getConfig.Probes.Any(setVar => (String.Equals(setVar.Name, getVar.Name, StringComparison.InvariantCultureIgnoreCase) && (String.Equals(setVar.Protocol, getVar.Protocol, StringComparison.InvariantCultureIgnoreCase)) && (String.Equals(setVar.Path, getVar.Path, StringComparison.InvariantCultureIgnoreCase)) && (String.Equals(setVar.Host, getVar.Host, StringComparison.InvariantCultureIgnoreCase)) && (String.Equals(setVar.Path, getVar.Path, StringComparison.InvariantCultureIgnoreCase)) && (setVar.Interval == getVar.Interval) && (setVar.Timeout == getVar.Timeout) && (setVar.UnhealthyThreshold == getVar.UnhealthyThreshold)))); } Assert.Equal(setConfig.BackendAddressPools.Count, getConfig.BackendAddressPools.Count); foreach (var getVar in setConfig.BackendAddressPools) { var setVar = getConfig.BackendAddressPools.FirstOrDefault(addrPool => (String.Equals(addrPool.Name, getVar.Name, StringComparison.InvariantCultureIgnoreCase))); Assert.NotNull(setVar); Assert.Equal(getVar.BackendServers.Count, setVar.BackendServers.Count); foreach (var getPool in getVar.BackendServers) { Assert.True(getVar.BackendServers.Any(setPool => (String.Equals(setPool.IPAddress, getPool.IPAddress, StringComparison.InvariantCultureIgnoreCase)))); } } Assert.Equal(setConfig.BackendHttpSettingsList.Count, getConfig.BackendHttpSettingsList.Count); foreach (var getVar in setConfig.BackendHttpSettingsList) { Assert.True(getConfig.BackendHttpSettingsList.Any(setVar => (String.Equals(setVar.Name, getVar.Name, StringComparison.InvariantCultureIgnoreCase)) && (setVar.Port == getVar.Port) && (setVar.Protocol == getVar.Protocol) && (String.Equals(setVar.CookieBasedAffinity, getVar.CookieBasedAffinity, StringComparison.InvariantCultureIgnoreCase)) && (setVar.RequestTimeout == getVar.RequestTimeout) && (String.Equals(setVar.Probe, getVar.Probe, StringComparison.InvariantCultureIgnoreCase)))); } Assert.Equal(setConfig.HttpListeners.Count, getConfig.HttpListeners.Count); foreach (var getVar in setConfig.HttpListeners) { Assert.True(getConfig.HttpListeners.Any(setVar => (String.Equals(setVar.Name, getVar.Name, StringComparison.InvariantCultureIgnoreCase)) && (String.Equals(setVar.FrontendPort, getVar.FrontendPort, StringComparison.InvariantCultureIgnoreCase)) && (setVar.Protocol == getVar.Protocol) && (String.Equals(setVar.SslCert, getVar.SslCert, StringComparison.InvariantCultureIgnoreCase)))); } Assert.Equal(setConfig.HttpLoadBalancingRules.Count, getConfig.HttpLoadBalancingRules.Count); foreach (var getVar in setConfig.HttpLoadBalancingRules) { Assert.True(getConfig.HttpLoadBalancingRules.Any(setVar => (String.Equals(setVar.Name, getVar.Name, StringComparison.InvariantCultureIgnoreCase)) && (String.Equals(setVar.Type, getVar.Type, StringComparison.InvariantCultureIgnoreCase)) && (String.Equals(setVar.BackendHttpSettings, getVar.BackendHttpSettings, StringComparison.InvariantCultureIgnoreCase)) && (String.Equals(setVar.Listener, getVar.Listener, StringComparison.InvariantCultureIgnoreCase)) && (String.Equals(setVar.BackendAddressPool, getVar.BackendAddressPool, StringComparison.InvariantCultureIgnoreCase)))); } }
private static void VerifyGetApplicationGatewayConfigDetails( ApplicationGatewaySetConfiguration setConfig, ApplicationGatewayGetConfiguration getConfig) { Assert.Equal(setConfig.FrontendIPConfigurations.Count, getConfig.FrontendIPConfigurations.Count); foreach (var getVar in setConfig.FrontendIPConfigurations) { Assert.True(getConfig.FrontendIPConfigurations.Any(setVar => (string.Equals(setVar.Name, getVar.Name) && setVar.StaticIPAddress == getVar.StaticIPAddress && setVar.Type == getVar.Type))); } Assert.Equal(setConfig.FrontendPorts.Count, getConfig.FrontendPorts.Count); foreach (var getVar in setConfig.FrontendPorts) { Assert.True(getConfig.FrontendPorts.Any(setVar => (string.Equals(setVar.Name, getVar.Name) && setVar.Port == getVar.Port))); } Assert.Equal(setConfig.BackendAddressPools.Count, getConfig.BackendAddressPools.Count); foreach (var getVar in setConfig.BackendAddressPools) { var setVar = getConfig.BackendAddressPools.FirstOrDefault(addrPool => (string.Equals(addrPool.Name, getVar.Name))); Assert.NotNull(setVar); Assert.Equal(getVar.BackendServers.Count, setVar.BackendServers.Count); foreach (var getPool in getVar.BackendServers) { Assert.True(getVar.BackendServers.Any(setPool => (string.Equals(setPool.IPAddress, getPool.IPAddress)))); } } Assert.Equal(setConfig.BackendHttpSettingsList.Count, getConfig.BackendHttpSettingsList.Count); foreach (var getVar in setConfig.BackendHttpSettingsList) { Assert.True(getConfig.BackendHttpSettingsList.Any(setVar => (string.Equals(setVar.Name, getVar.Name)) && (setVar.Port == getVar.Port) && (setVar.Protocol == getVar.Protocol) && (string.Equals(setVar.CookieBasedAffinity, getVar.CookieBasedAffinity)))); } Assert.Equal(setConfig.HttpListeners.Count, getConfig.HttpListeners.Count); foreach (var getVar in setConfig.HttpListeners) { Assert.True(getConfig.HttpListeners.Any(setVar => (string.Equals(setVar.Name, getVar.Name)) && (string.Equals(setVar.FrontendPort, getVar.FrontendPort)) && (setVar.Protocol == getVar.Protocol) && (string.Equals(setVar.SslCert, getVar.SslCert)))); } Assert.Equal(setConfig.HttpLoadBalancingRules.Count, getConfig.HttpLoadBalancingRules.Count); foreach (var getVar in setConfig.HttpLoadBalancingRules) { Assert.True(getConfig.HttpLoadBalancingRules.Any(setVar => (string.Equals(setVar.Name, getVar.Name)) && (string.Equals(setVar.Type, getVar.Type)) && (string.Equals(setVar.BackendHttpSettings, getVar.BackendHttpSettings)) && (string.Equals(setVar.Listener, getVar.Listener)) && (string.Equals(setVar.BackendAddressPool, getVar.BackendAddressPool)))); } }
private PowerShellAppGwModel.ApplicationGatewayConfiguration PowerShellConfigFromHydraConfig(ApplicationGatewayGetConfiguration config) { PowerShellAppGwModel.ApplicationGatewayConfiguration outConfig = new PowerShellAppGwModel.ApplicationGatewayConfiguration(); //Frontend IPs List <PowerShellAppGwModel.FrontendIPConfiguration> fips = new List <PowerShellAppGwModel.FrontendIPConfiguration>(); //Config without Frontend IPs is also valid if (null != config.FrontendIPConfigurations) { foreach (FrontendIPConfiguration fip in config.FrontendIPConfigurations) { fips.Add(new PowerShellAppGwModel.FrontendIPConfiguration { Name = fip.Name, Type = fip.Type, StaticIPAddress = fip.StaticIPAddress }); } } //Frontend Port List <PowerShellAppGwModel.FrontendPort> fps = new List <PowerShellAppGwModel.FrontendPort>(); foreach (FrontendPort fp in config.FrontendPorts) { fps.Add(new PowerShellAppGwModel.FrontendPort { Name = fp.Name, Port = fp.Port }); } //Backend Address Pools List <PowerShellAppGwModel.BackendAddressPool> pools = new List <PowerShellAppGwModel.BackendAddressPool>(); foreach (BackendAddressPool pool in config.BackendAddressPools) { PowerShellAppGwModel.BackendServerCollection servers = new PowerShellAppGwModel.BackendServerCollection(); foreach (BackendServer server in pool.BackendServers) { servers.Add(server.IPAddress); } pools.Add(new PowerShellAppGwModel.BackendAddressPool { Name = pool.Name, BackendServers = servers }); } //Backend Http Settings List List <PowerShellAppGwModel.BackendHttpSettings> settings = new List <PowerShellAppGwModel.BackendHttpSettings>(); foreach (BackendHttpSettings setting in config.BackendHttpSettingsList) { settings.Add(new PowerShellAppGwModel.BackendHttpSettings { Name = setting.Name, Port = setting.Port, Protocol = (PowerShellAppGwModel.Protocol)setting.Protocol, CookieBasedAffinity = setting.CookieBasedAffinity }); } //Http Listeners List <PowerShellAppGwModel.HttpListener> listeners = new List <PowerShellAppGwModel.HttpListener>(); foreach (AGHttpListener listener in config.HttpListeners) { listeners.Add(new PowerShellAppGwModel.HttpListener { Name = listener.Name, FrontendIP = listener.FrontendIP, FrontendPort = listener.FrontendPort, Protocol = (PowerShellAppGwModel.Protocol)listener.Protocol, SslCert = listener.SslCert }); } //Http Load Balancing Rules List <PowerShellAppGwModel.HttpLoadBalancingRule> rules = new List <PowerShellAppGwModel.HttpLoadBalancingRule>(); foreach (HttpLoadBalancingRule rule in config.HttpLoadBalancingRules) { rules.Add(new PowerShellAppGwModel.HttpLoadBalancingRule { Name = rule.Name, Type = rule.Type, BackendHttpSettings = rule.BackendHttpSettings, Listener = rule.Listener, BackendAddressPool = rule.BackendAddressPool }); } outConfig.FrontendIPConfigurations = fips; outConfig.FrontendPorts = fps; outConfig.BackendAddressPools = pools; outConfig.BackendHttpSettingsList = settings; outConfig.HttpListeners = listeners; outConfig.HttpLoadBalancingRules = rules; return(outConfig); }