public VirtualNetworkGateway(IVirtualNetworkGateway virtualNetworkGateway, TargetSettings targetSettings) { this._SourceVirtualNetworkGateway = virtualNetworkGateway; this.SetTargetName(this.SourceName, targetSettings); }
/** * Azure Network sample for managing virtual network gateway. * - Create a virtual network with subnets * - Create virtual network gateway * - Update virtual network gateway with Point-to-Site connection configuration * - Generate and download VPN client configuration package. Now it can be used to create VPN connection to Azure. * - Revoke a client certificate * * Please note: in order to run this sample, you need to have: * - pre-generated root certificate and public key exported to $CERT_PATH file * For more details please see https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-certificates-point-to-site for PowerShell instructions * and https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-certificates-point-to-site-makecert for Makecert instructions. * - client certificate generated for this root certificate installed on your machine. * Please see: https://docs.microsoft.com/en-us/azure/vpn-gateway/point-to-site-how-to-vpn-client-install-azure-cert * - thumbprint for client certificate saved to $CLIENT_CERT_THUMBPRINT */ 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 certPath = Environment.GetEnvironmentVariable("CERT_PATH"); string clientCertThumbprint = Environment.GetEnvironmentVariable("CLIENT_CERT_THUMBPRINT"); try { //============================================================ // Create virtual network with address spaces 192.168.0.0/16 and 10.254.0.0/16 and 3 subnets Utilities.Log("Creating virtual network..."); INetwork network = azure.Networks.Define(vnetName) .WithRegion(region) .WithNewResourceGroup(rgName) .WithAddressSpace("192.168.0.0/16") .WithAddressSpace("10.254.0.0/16") .WithSubnet("GatewaySubnet", "192.168.200.0/24") .WithSubnet("FrontEnd", "192.168.1.0/24") .WithSubnet("BackEnd", "10.254.1.0/24") .Create(); Utilities.Log("Created network"); // Print the virtual network Utilities.Log(network); //============================================================ // Create virtual network gateway Utilities.Log("Creating virtual network gateway..."); IVirtualNetworkGateway vngw1 = azure.VirtualNetworkGateways.Define(vpnGatewayName) .WithRegion(region) .WithExistingResourceGroup(rgName) .WithExistingNetwork(network) .WithRouteBasedVpn() .WithSku(VirtualNetworkGatewaySkuName.VpnGw1) .Create(); Utilities.Log("Created virtual network gateway"); //============================================================ // Update virtual network gateway with Point-to-Site connection configuration Utilities.Log("Creating Point-to-Site configuration..."); vngw1.Update() .DefinePointToSiteConfiguration() .WithAddressPool("172.16.201.0/24") .WithAzureCertificateFromFile("p2scert.cer", new FileInfo(certPath)) .Attach() .Apply(); Utilities.Log("Created Point-to-Site configuration"); //============================================================ // Generate and download VPN client configuration package. Now it can be used to create VPN connection to Azure. Utilities.Log("Generating VPN profile..."); String profile = vngw1.GenerateVpnProfile(); Utilities.Log(String.Format("Profile generation is done. Please download client package at: %s", profile)); // At this point vpn client package can be downloaded from provided link. Unzip it and run the configuration corresponding to your OS. // For Windows machine, VPN client .exe can be run. For non-Windows, please use configuration from downloaded VpnSettings.xml //============================================================ // Revoke a client certificate. After this command, you will no longer available to connect with the corresponding client certificate. Utilities.Log("Revoking client certificate..."); vngw1.Update().UpdatePointToSiteConfiguration() .WithRevokedCertificate("p2sclientcert.cer", clientCertThumbprint) .Parent() .Apply(); Utilities.Log("Revoked client certificate"); } 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); } } }
/** * 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, INetworkManager networkManager) { 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 = networkManager.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); } } }
public VirtualNetworkGateway(IVirtualNetworkGateway virtualNetworkGateway, TargetSettings targetSettings) : base(ArmConst.MicrosoftNetwork, ArmConst.LoadBalancers) { this._SourceVirtualNetworkGateway = virtualNetworkGateway; this.SetTargetName(this.SourceName, targetSettings); }