public void CreateUpdate()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                string testId            = SdkContext.RandomResourceName("", 9);
                string resourceGroupName = "rg" + testId;
                string lngwName          = "lngw" + testId;
                Region region            = Region.USSouthCentral;

                var manager = TestHelper.CreateNetworkManager();

                try
                {
                    ILocalNetworkGateway gateway = manager.LocalNetworkGateways.Define(lngwName)
                                                   .WithRegion(region)
                                                   .WithNewResourceGroup(resourceGroupName)
                                                   .WithIPAddress("40.71.184.214")
                                                   .WithAddressSpace("192.168.3.0/24")
                                                   .WithAddressSpace("192.168.4.0/27")
                                                   .Create();
                    Assert.Equal("40.71.184.214", gateway.IPAddress);
                    Assert.Equal(2, gateway.AddressSpaces.Count);
                    Assert.True(gateway.AddressSpaces.Contains("192.168.4.0/27"));

                    gateway.Update()
                    .WithoutAddressSpace("192.168.3.0/24")
                    .WithIPAddress("40.71.184.216")
                    .WithTag("tag2", "value2")
                    .WithoutTag("tag1")
                    .Apply();
                    Assert.False(gateway.AddressSpaces.Contains("192.168.3.0/24"));
                    Assert.Equal("40.71.184.216", gateway.IPAddress);
                    Assert.True(gateway.Tags.ContainsKey("tag2"));
                    Assert.False(gateway.Tags.ContainsKey("tag1"));
                    gateway.UpdateTags()
                    .WithoutTag("tag2")
                    .WithTag("tag3", "value3")
                    .ApplyTags();
                    Assert.False(gateway.Tags.ContainsKey("tag2"));
                    string value3;
                    gateway.Tags.TryGetValue("tag3", out value3);
                    Assert.Equal("value3", value3);

                    manager.LocalNetworkGateways.DeleteById(gateway.Id);
                    manager.ResourceManager.ResourceGroups.DeleteByName(gateway.ResourceGroupName);
                }
                finally
                {
                    try
                    {
                        TestHelper.CreateResourceManager().ResourceGroups.DeleteByName(resourceGroupName);
                    }
                    catch { }
                }
            }
        }
        ///GENMHASH:04D6D858FF61D37F76DA127C20A5ABF9:DFC8C1E6C2A0BC0C3178B00DC329D6B7
        public VirtualNetworkGatewayConnectionImpl WithLocalNetworkGateway(ILocalNetworkGateway localNetworkGateway)
        {
            SubResource localNetworkGatewayRef = new SubResource()
            {
                Id = localNetworkGateway.Id
            };

            Inner.LocalNetworkGateway2 = localNetworkGatewayRef;
            return(this);
        }
Exemplo n.º 3
0
 VirtualNetworkGatewayConnection.Definition.IWithSharedKey VirtualNetworkGatewayConnection.Definition.IWithLocalNetworkGateway.WithLocalNetworkGateway(ILocalNetworkGateway localNetworkGateway)
 {
     return(this.WithLocalNetworkGateway(localNetworkGateway) as VirtualNetworkGatewayConnection.Definition.IWithSharedKey);
 }
        /**
         * Azure Network sample for managing virtual network gateway.
         *  - Create virtual network with gateway subnet
         *  - Create VPN gateway
         *  - Create local network gateway
         *  - Create VPN Site-to-Site connection
         *  - List VPN Gateway connections for particular gateway
         *  - Reset virtual network gateway
         */
        public static void RunSample(IAzure azure)
        {
            string rgName           = SdkContext.RandomResourceName("rgNEMV", 24);
            string vnetName         = SdkContext.RandomResourceName("vnet", 20);
            string vpnGatewayName   = SdkContext.RandomResourceName("vngw", 20);
            string localGatewayName = SdkContext.RandomResourceName("lngw", 20);
            string connectionName   = SdkContext.RandomResourceName("con", 20);

            try
            {
                //============================================================
                // Create virtual network
                Utilities.Log("Creating virtual network...");
                INetwork network = azure.Networks.Define(vnetName)
                                   .WithRegion(region)
                                   .WithNewResourceGroup(rgName)
                                   .WithAddressSpace("10.11.0.0/16")
                                   .WithSubnet("GatewaySubnet", "10.11.255.0/27")
                                   .Create();
                Utilities.Log("Created network");
                // Print the virtual network
                Utilities.PrintVirtualNetwork(network);

                //============================================================
                // Create VPN gateway
                Utilities.Log("Creating virtual network gateway...");
                IVirtualNetworkGateway vngw = azure.VirtualNetworkGateways.Define(vpnGatewayName)
                                              .WithRegion(region)
                                              .WithExistingResourceGroup(rgName)
                                              .WithExistingNetwork(network)
                                              .WithRouteBasedVpn()
                                              .WithSku(VirtualNetworkGatewaySkuName.VpnGw1)
                                              .Create();
                Utilities.Log("Created virtual network gateway");

                //============================================================
                // Create local network gateway
                Utilities.Log("Creating virtual network gateway...");
                ILocalNetworkGateway lngw = azure.LocalNetworkGateways.Define(localGatewayName)
                                            .WithRegion(region)
                                            .WithExistingResourceGroup(rgName)
                                            .WithIPAddress("40.71.184.214")
                                            .WithAddressSpace("192.168.3.0/24")
                                            .Create();
                Utilities.Log("Created virtual network gateway");

                //============================================================
                // Create VPN Site-to-Site connection
                Utilities.Log("Creating virtual network gateway connection...");
                vngw.Connections
                .Define(connectionName)
                .WithSiteToSite()
                .WithLocalNetworkGateway(lngw)
                .WithSharedKey("MySecretKey")
                .Create();
                Utilities.Log("Created virtual network gateway connection");

                //============================================================
                // List VPN Gateway connections for particular gateway
                var connections = vngw.ListConnections();
                foreach (var connection in connections)
                {
                    Utilities.Print(connection);
                }
                //============================================================
                // Reset virtual network gateway
                vngw.Reset();
            }
            finally
            {
                try
                {
                    Utilities.Log("Deleting Resource Group: " + rgName);
                    azure.ResourceGroups.BeginDeleteByName(rgName);
                }
                catch (NullReferenceException)
                {
                    Utilities.Log("Did not create any resources in Azure. No clean up is necessary");
                }
                catch (Exception ex)
                {
                    Utilities.Log(ex);
                }
            }
        }
Exemplo n.º 5
0
 public LocalNetworkGateway(ILocalNetworkGateway localNetworkGateway, TargetSettings targetSettings, ILogProvider logProvider) : base(ArmConst.MicrosoftNetwork, ArmConst.LocalNetworkGateways, logProvider)
 {
     this._SourceLocalNetworkGateway = localNetworkGateway;
     this.SetTargetName(this.SourceName, targetSettings);
 }
Exemplo n.º 6
0
 public LocalNetworkGateway(ILocalNetworkGateway localNetworkGateway, TargetSettings targetSettings)
 {
     this._SourceLocalNetworkGateway = localNetworkGateway;
     this.SetTargetName(this.SourceName, targetSettings);
 }