public void CreateUpdate()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                string circuitName = SdkContext.RandomResourceName("erc", 10);
                var    groupName   = SdkContext.RandomResourceName("rg", 6);
                var    manager     = TestHelper.CreateNetworkManager();

                // create Express Route Circuit
                IExpressRouteCircuit erc = manager.ExpressRouteCircuits.Define(circuitName)
                                           .WithRegion(REGION)
                                           .WithNewResourceGroup(groupName)
                                           .WithServiceProvider("Microsoft ER Test")
                                           .WithPeeringLocation("Area51")
                                           .WithBandwidthInMbps(50)
                                           .WithSku(ExpressRouteCircuitSkuType.StandardMeteredData)
                                           .WithTag("tag1", "value1")
                                           .Create();
                erc.Update()
                .WithTag("tag2", "value2")
                .WithoutTag("tag1")
                .WithBandwidthInMbps(200)
                .WithSku(ExpressRouteCircuitSkuType.PremiumUnlimitedData)
                .Apply();
                erc.Refresh();
                Assert.True(erc.Tags.ContainsKey("tag2"));
                Assert.True(!erc.Tags.ContainsKey("tag1"));
                Assert.Equal(200, erc.ServiceProviderProperties.BandwidthInMbps);
                Assert.Equal(ExpressRouteCircuitSkuType.PremiumUnlimitedData, erc.Sku);
                manager.ExpressRouteCircuits.DeleteById(erc.Id);
                manager.ResourceManager.ResourceGroups.DeleteByName(groupName);
            }
        }
Exemplo n.º 2
0
        public void CanCreatePeering()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                string circuitName = SdkContext.RandomResourceName("erc", 10);
                var    groupName   = SdkContext.RandomResourceName("rg", 6);
                var    manager     = TestHelper.CreateNetworkManager();

                try
                {
                    // create Express Route Circuit
                    IExpressRouteCircuit erc = manager.ExpressRouteCircuits.Define(circuitName)
                                               .WithRegion(REGION)
                                               .WithNewResourceGroup(groupName)
                                               .WithServiceProvider("Microsoft ER Test")
                                               .WithPeeringLocation("Area51")
                                               .WithBandwidthInMbps(50)
                                               .WithSku(ExpressRouteCircuitSkuType.PremiumMeteredData)
                                               .WithTag("tag1", "value1")
                                               .Create();
                    erc.Peerings.DefineMicrosoftPeering()
                    .WithAdvertisedPublicPrefixes("124.1.0.0/24")
                    .WithPrimaryPeerAddressPrefix("124.0.0.0/30")
                    .WithSecondaryPeerAddressPrefix("124.0.0.4/30")
                    .WithVlanId(200)
                    .WithPeerAsn(100)
                    .Create();
                    Assert.Equal(1, erc.PeeringsMap.Count);
                    Assert.True(erc.PeeringsMap.ContainsKey(ExpressRoutePeeringType.MicrosoftPeering.ToString()));
                    var peering = erc.PeeringsMap[ExpressRoutePeeringType.MicrosoftPeering.ToString()]
                                  .Update()
                                  .WithVlanId(300)
                                  .WithPeerAsn(101)
                                  .WithSecondaryPeerAddressPrefix("124.0.0.8/30")
                                  .Apply();
                    Assert.Equal(300, peering.VlanId);
                    Assert.Equal(101, peering.PeerAsn);
                    Assert.Equal("124.0.0.8/30", peering.SecondaryPeerAddressPrefix);
                    manager.ResourceManager.ResourceGroups.BeginDeleteByName(groupName);
                }
                finally
                {
                    try
                    {
                        TestHelper.CreateResourceManager().ResourceGroups.DeleteByName(groupName);
                    }
                    catch { }
                }
            }
        }
 ///GENMHASH:6C56ED8B9268C869E730DCC2AA432590:E6D2C0ECA74E9925CAF40C55749D0EB1
 public VirtualNetworkGatewayConnectionImpl WithExpressRoute(IExpressRouteCircuit circuit)
 {
     return(WithExpressRoute(circuit.Id));
 }
        /**
         * Azure Network sample for managing express route circuits.
         *  - Create Express Route circuit
         *  - Create Express Route circuit peering. Please note: express route circuit should be provisioned by connectivity provider before this step.
         *  - Adding authorization to express route circuit
         *  - Create virtual network to be associated with virtual network gateway
         *  - Create virtual network gateway
         *  - Create virtual network gateway connection
         */
        public static void RunSample(IAzure azure)
        {
            string rgName         = SdkContext.RandomResourceName("rg", 20);
            string ercName        = SdkContext.RandomResourceName("erc", 20);
            string vnetName       = SdkContext.RandomResourceName("vnet", 20);
            string gatewayName    = SdkContext.RandomResourceName("gtw", 20);
            string connectionName = SdkContext.RandomResourceName("con", 20);

            try
            {
                //============================================================
                // create Express Route Circuit
                Utilities.Log("Creating express route circuit...");
                IExpressRouteCircuit erc = azure.ExpressRouteCircuits.Define(ercName)
                                           .WithRegion(region)
                                           .WithNewResourceGroup(rgName)
                                           .WithServiceProvider("Equinix")
                                           .WithPeeringLocation("Silicon Valley")
                                           .WithBandwidthInMbps(50)
                                           .WithSku(ExpressRouteCircuitSkuType.PremiumMeteredData)
                                           .Create();
                Utilities.Log("Created express route circuit");

                //============================================================
                // Create Express Route circuit peering. Please note: express route circuit should be provisioned by connectivity provider before this step.
                Utilities.Log("Creating express route circuit peering...");
                erc.Peerings.DefineAzurePrivatePeering()
                .WithPrimaryPeerAddressPrefix("123.0.0.0/30")
                .WithSecondaryPeerAddressPrefix("123.0.0.4/30")
                .WithVlanId(200)
                .WithPeerAsn(100)
                .Create();
                Utilities.Log("Created express route circuit peering");

                //============================================================
                // Adding authorization to express route circuit
                erc.Update()
                .WithAuthorization("myAuthorization")
                .Apply();

                //============================================================
                // Create virtual network to be associated with virtual network gateway
                Utilities.Log("Creating virtual network...");
                INetwork network = azure.Networks.Define(vnetName)
                                   .WithRegion(region)
                                   .WithExistingResourceGroup(rgName)
                                   .WithAddressSpace("192.168.0.0/16")
                                   .WithSubnet("GatewaySubnet", "192.168.200.0/26")
                                   .WithSubnet("FrontEnd", "192.168.1.0/24")
                                   .Create();

                //============================================================
                // Create virtual network gateway
                Utilities.Log("Creating virtual network gateway...");
                IVirtualNetworkGateway vngw1 = azure.VirtualNetworkGateways.Define(gatewayName)
                                               .WithRegion(region)
                                               .WithNewResourceGroup(rgName)
                                               .WithExistingNetwork(network)
                                               .WithExpressRoute()
                                               .WithSku(VirtualNetworkGatewaySkuName.Standard)
                                               .Create();
                Utilities.Log("Created virtual network gateway");

                //============================================================
                // Create virtual network gateway connection
                Utilities.Log("Creating virtual network gateway connection...");
                vngw1.Connections.Define(connectionName)
                .WithExpressRoute(erc)
                // Note: authorization key is required only in case express route circuit and virtual network gateway are in different subscriptions
                // .WithAuthorization(erc.Inner.Authorizations.First().AuthorizationKey)
                .Create();
                Utilities.Log("Created virtual network gateway connection");
            }
            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
 /// <summary>
 /// Create Express Route connection.
 /// </summary>
 /// <param name="circuit">Express Route circuit used for connection.</param>
 /// <return>The next stage of the definition.</return>
 VirtualNetworkGatewayConnection.Definition.IWithCreate VirtualNetworkGatewayConnection.Definition.IWithConnectionType.WithExpressRoute(IExpressRouteCircuit circuit)
 {
     return(this.WithExpressRoute(circuit));
 }