示例#1
0
 public SetConfigApplicationGateway(IApplicationGatewayOperations applicationGatewayClient,
                                    string gatewayName, ApplicationGatewaySetConfiguration config)
 {
     this.applicationGatewayClient = applicationGatewayClient;
     this.gatewayName = gatewayName;
     this.config      = config;
 }
示例#2
0
        public void CreateApplicationGateway()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                ApplicationGatewayOperationResponse result = new ApplicationGatewayOperationResponse();

                //CREATE gateway
                var createParams = new CreateApplicationGatewayParameters
                {
                    Name        = gatewayName,
                    Description = gatewayDescription,
                    VnetName    = vnet,
                    Subnets     = new List <string>()
                    {
                        subnet
                    }
                };

                result = networkTestClient.ApplicationGateways.CreateApplicationGateway(createParams);
                Assert.Equal(result.StatusCode, HttpStatusCode.OK);

                //SET gateway config
                ApplicationGatewaySetConfiguration config = GenerateConfig();

                result = networkTestClient.ApplicationGateways.SetConfigApplicationGateway(gatewayName, config);
                Assert.Equal(result.StatusCode, HttpStatusCode.OK);

                //START gateway
                result = networkTestClient.ApplicationGateways.StartApplicationGateway(gatewayName);
                Assert.Equal(result.StatusCode, HttpStatusCode.OK);
            }
        }
        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);
        }
        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))));
            }
        }
示例#5
0
 /// <summary>
 /// The Begin Set Application Gateway Config operation  sets the
 /// specified config on the application gateway  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ApplicationGateway.IL7GatewayOperations.
 /// </param>
 /// <param name='gatewayName'>
 /// Required. Gateway name
 /// </param>
 /// <param name='config'>
 /// Required. Parameters supplied to Set Application Gateway config
 /// request.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is inprogress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself.  If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request.  If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request, and also includes error
 /// information regarding the failure.
 /// </returns>
 public static Task <ApplicationGatewayOperationResponse> SetConfigAsync(this IL7GatewayOperations operations, string gatewayName, ApplicationGatewaySetConfiguration config)
 {
     return(operations.SetConfigAsync(gatewayName, config, CancellationToken.None));
 }
示例#6
0
 /// <summary>
 /// The Begin Set Application Gateway Config operation  sets the
 /// specified config on the application gateway  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ApplicationGateway.IL7GatewayOperations.
 /// </param>
 /// <param name='gatewayName'>
 /// Required. Gateway name
 /// </param>
 /// <param name='config'>
 /// Required. Parameters supplied to Set Application Gateway config
 /// request.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is inprogress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself.  If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request.  If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request, and also includes error
 /// information regarding the failure.
 /// </returns>
 public static ApplicationGatewayOperationResponse SetConfig(this IL7GatewayOperations operations, string gatewayName, ApplicationGatewaySetConfiguration config)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IL7GatewayOperations)s).SetConfigAsync(gatewayName, config);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
示例#7
0
        public ApplicationGatewayOperationResponse SetConfigApplicationGateway(string gatewayName, ApplicationGatewaySetConfiguration config)
        {
            SetConfigApplicationGateway operation = new SetConfigApplicationGateway(applicationGatewayClient, gatewayName, config);

            testClient.InvokeTestOperation(operation);

            return(operation.InvokeResponse);
        }
示例#8
0
        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))));
            }
        }
示例#9
0
        private ApplicationGatewaySetConfiguration HydraConfigFromPowerShellConfig(PowerShellAppGwModel.ApplicationGatewayConfiguration config)
        {
            ApplicationGatewaySetConfiguration outConfig = new ApplicationGatewaySetConfiguration();

            //Frontend IPs
            outConfig.FrontendIPConfigurations = new List <FrontendIPConfiguration>();

            //Config without Frontend IPs is also valid
            if (null != config.FrontendIPConfigurations)
            {
                foreach (PowerShellAppGwModel.FrontendIPConfiguration fip in config.FrontendIPConfigurations)
                {
                    outConfig.FrontendIPConfigurations.Add(new FrontendIPConfiguration
                    {
                        Name            = fip.Name,
                        Type            = fip.Type,
                        StaticIPAddress = fip.StaticIPAddress
                    });
                }
            }

            //Frontend Port
            outConfig.FrontendPorts = new List <FrontendPort>();
            foreach (PowerShellAppGwModel.FrontendPort fp in config.FrontendPorts)
            {
                outConfig.FrontendPorts.Add(new FrontendPort
                {
                    Name = fp.Name,
                    Port = fp.Port
                });
            }

            //Backend Address Pools
            outConfig.BackendAddressPools = new List <BackendAddressPool>();
            foreach (PowerShellAppGwModel.BackendAddressPool pool in config.BackendAddressPools)
            {
                List <BackendServer> servers = new List <BackendServer>();
                foreach (string server in pool.BackendServers)
                {
                    servers.Add(new BackendServer
                    {
                        IPAddress = server
                    });
                }

                outConfig.BackendAddressPools.Add(new BackendAddressPool
                {
                    Name           = pool.Name,
                    BackendServers = servers
                });
            }

            //Backend Http Settings List
            outConfig.BackendHttpSettingsList = new List <BackendHttpSettings>();
            foreach (PowerShellAppGwModel.BackendHttpSettings setting in config.BackendHttpSettingsList)
            {
                outConfig.BackendHttpSettingsList.Add(new BackendHttpSettings
                {
                    Name                = setting.Name,
                    Port                = setting.Port,
                    Protocol            = (Protocol)setting.Protocol,
                    CookieBasedAffinity = setting.CookieBasedAffinity
                });
            }

            //Http Listeners
            outConfig.HttpListeners = new List <AGHttpListener>();
            foreach (PowerShellAppGwModel.HttpListener listener in config.HttpListeners)
            {
                outConfig.HttpListeners.Add(new AGHttpListener
                {
                    Name         = listener.Name,
                    FrontendIP   = listener.FrontendIP,
                    FrontendPort = listener.FrontendPort,
                    Protocol     = (Protocol)listener.Protocol,
                    SslCert      = listener.SslCert
                });
            }

            //Http Load Balancing Rules
            outConfig.HttpLoadBalancingRules = new List <HttpLoadBalancingRule>();
            foreach (PowerShellAppGwModel.HttpLoadBalancingRule rule in config.HttpLoadBalancingRules)
            {
                outConfig.HttpLoadBalancingRules.Add(new HttpLoadBalancingRule
                {
                    Name = rule.Name,
                    Type = rule.Type,
                    BackendHttpSettings = rule.BackendHttpSettings,
                    Listener            = rule.Listener,
                    BackendAddressPool  = rule.BackendAddressPool
                });
            }

            return(outConfig);
        }