Skip to content

Commit a465602

Browse files
committed
Add parameters for BGP with VPN gateways
1 parent befdfac commit a465602

File tree

11 files changed

+110
-4
lines changed

11 files changed

+110
-4
lines changed

src/ResourceManager/Network/Commands.Network.Test/Commands.Network.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
6565
</Reference>
6666
<Reference Include="Microsoft.Azure.Management.Network, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
67-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.3.2.0-preview\lib\net45\Microsoft.Azure.Management.Network.dll</HintPath>
67+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.3.3.0-preview\lib\net45\Microsoft.Azure.Management.Network.dll</HintPath>
6868
<Private>True</Private>
6969
</Reference>
7070
<Reference Include="Microsoft.Azure.ResourceManager">

src/ResourceManager/Network/Commands.Network.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
77
<package id="Microsoft.Azure.Graph.RBAC" version="1.9.0-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
9-
<package id="Microsoft.Azure.Management.Network" version="3.2.0-preview" targetFramework="net45" />
9+
<package id="Microsoft.Azure.Management.Network" version="3.3.0-preview" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.Resources" version="2.19.0-preview" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Test.Framework" version="1.0.5896.19355-prerelease" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.0-preview" targetFramework="net45" />

src/ResourceManager/Network/Commands.Network/Commands.Network.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
7474
</Reference>
7575
<Reference Include="Microsoft.Azure.Management.Network, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
76-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.3.2.0-preview\lib\net45\Microsoft.Azure.Management.Network.dll</HintPath>
76+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.3.3.0-preview\lib\net45\Microsoft.Azure.Management.Network.dll</HintPath>
7777
<Private>True</Private>
7878
</Reference>
7979
<Reference Include="Microsoft.Data.Edm">
@@ -262,6 +262,7 @@
262262
<Compile Include="ExpressRouteCircuit\RemoveAzureExpressRouteCircuitCommand.cs" />
263263
<Compile Include="ExpressRouteCircuit\SetAzureExpressRouteCircuitCommand.cs" />
264264
<Compile Include="ExpressRouteCircuit\ExpressRouteCircuitBaseCmdlet.cs" />
265+
<Compile Include="Models\PSBgpSettings.cs" />
265266
<Compile Include="Models\PSApplicationGateway.cs" />
266267
<Compile Include="Models\PSApplicationGatewayBackendAddress.cs" />
267268
<Compile Include="Models\PSApplicationGatewayBackendAddressPool.cs" />

src/ResourceManager/Network/Commands.Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ protected override void Configure()
243243
Mapper.CreateMap<CNM.PSVpnClientParameters, MNM.VpnClientParameters>();
244244
Mapper.CreateMap<CNM.PSVpnClientRevokedCertificate, MNM.VpnClientRevokedCertificate>();
245245
Mapper.CreateMap<CNM.PSVpnClientRootCertificate, MNM.VpnClientRootCertificate>();
246+
Mapper.CreateMap<CNM.PSBgpSettings, MNM.BgpSettings>();
246247

247248
// MNM to CNM
248249
Mapper.CreateMap<MNM.VirtualNetworkGateway, CNM.PSVirtualNetworkGateway>();
@@ -256,6 +257,7 @@ protected override void Configure()
256257
Mapper.CreateMap<MNM.VpnClientParameters, CNM.PSVpnClientParameters>();
257258
Mapper.CreateMap<MNM.VpnClientRevokedCertificate, CNM.PSVpnClientRevokedCertificate>();
258259
Mapper.CreateMap<MNM.VpnClientRootCertificate, CNM.PSVpnClientRootCertificate>();
260+
Mapper.CreateMap<MNM.BgpSettings, CNM.PSBgpSettings>();
259261

260262
// Application Gateways
261263
// CNM to MNM

src/ResourceManager/Network/Commands.Network/LocalNetworkGateway/NewAzureLocalNetworkGatewayCommand.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ public class NewAzureLocalNetworkGatewayCommand : LocalNetworkGatewayBaseCmdlet
6262
[ValidateNotNullOrEmpty]
6363
public List<string> AddressPrefix { get; set; }
6464

65+
[Parameter(
66+
Mandatory = false,
67+
ValueFromPipelineByPropertyName = true,
68+
HelpMessage = "The local network gateway's ASN")]
69+
public uint Asn { get; set; }
70+
71+
[Parameter(
72+
Mandatory = false,
73+
ValueFromPipelineByPropertyName =true,
74+
HelpMessage = "The IP address of the local network gateway's BGP speaker")]
75+
public string BgpPeeringAddress { get; set; }
76+
77+
[Parameter(
78+
Mandatory = false,
79+
ValueFromPipelineByPropertyName =true,
80+
HelpMessage = "Weight added to BGP routes learned from this local network gateway")]
81+
public int PeerWeight { get; set; }
82+
6583
[Parameter(
6684
Mandatory = false,
6785
ValueFromPipelineByPropertyName = true,
@@ -106,6 +124,25 @@ private PSLocalNetworkGateway CreateLocalNetworkGateway()
106124
localnetGateway.LocalNetworkAddressSpace.AddressPrefixes = this.AddressPrefix;
107125
localnetGateway.GatewayIpAddress = this.GatewayIpAddress;
108126

127+
if(this.PeerWeight < 0)
128+
{
129+
throw new PSArgumentException("PeerWeight cannot be negative");
130+
}
131+
132+
if(this.Asn > 0 && !string.IsNullOrEmpty(this.BgpPeeringAddress))
133+
{
134+
localnetGateway.BgpSettings = new PSBgpSettings()
135+
{
136+
Asn = this.Asn,
137+
BgpPeeringAddress = this.BgpPeeringAddress,
138+
PeerWeight = this.PeerWeight
139+
};
140+
}else if((!string.IsNullOrEmpty(this.BgpPeeringAddress) && this.Asn == 0) ||
141+
(string.IsNullOrEmpty(this.BgpPeeringAddress) && this.Asn > 0))
142+
{
143+
throw new PSArgumentException("For a BGP session to be established over IPsec, the local network gateway's ASN and BgpPeeringAddress must both be specified.");
144+
}
145+
109146
// Map to the sdk object
110147
var localnetGatewayModel = Mapper.Map<MNM.LocalNetworkGateway>(localnetGateway);
111148
localnetGatewayModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

src/ResourceManager/Network/Commands.Network/Models/PSLocalNetworkGateway.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ public class PSLocalNetworkGateway : PSTopLevelResource
2626

2727
public string ProvisioningState { get; set; }
2828

29+
public PSBgpSettings BgpSettings { get; set; }
30+
2931
[JsonIgnore]
3032
public string AddressSpaceText
3133
{
3234
get { return JsonConvert.SerializeObject(LocalNetworkAddressSpace, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
3335
}
36+
37+
[JsonIgnore]
38+
public string BgpSettingsText
39+
{
40+
get { return JsonConvert.SerializeObject(BgpSettings, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
41+
}
3442
}
3543
}

src/ResourceManager/Network/Commands.Network/Models/PSVirtualNetworkGateway.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class PSVirtualNetworkGateway : PSTopLevelResource
3535

3636
public PSVpnClientConfiguration VpnClientConfiguration { get; set; }
3737

38+
public PSBgpSettings BgpSettings { get; set; }
39+
3840
[JsonIgnore]
3941
public string IpConfigurationsText
4042
{
@@ -58,5 +60,11 @@ public string VpnClientConfigurationText
5860
{
5961
get { return JsonConvert.SerializeObject(VpnClientConfiguration, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
6062
}
63+
64+
[JsonIgnore]
65+
public string BgpSettingsText
66+
{
67+
get { return JsonConvert.SerializeObject(BgpSettings, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
68+
}
6169
}
6270
}

src/ResourceManager/Network/Commands.Network/Models/PSVirtualNetworkGatewayConnection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class PSVirtualNetworkGatewayConnection : PSTopLevelResource
3333

3434
public string SharedKey { get; set; }
3535

36+
public bool EnableBgp { get; set; }
37+
3638
public string ConnectionStatus { get; set; }
3739

3840
public ulong EgressBytesTransferred { get; set; }

src/ResourceManager/Network/Commands.Network/VirtualNetworkGateway/NewAzureVirtualNetworkGatewayCommand.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ public class NewAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmd
120120
HelpMessage = "The list of VpnClientCertificates to be revoked.")]
121121
public List<PSVpnClientRevokedCertificate> VpnClientRevokedCertificates { get; set; }
122122

123+
[Parameter(
124+
Mandatory = false,
125+
ValueFromPipelineByPropertyName = true,
126+
HelpMessage = "The virtual network gateway's ASN for BGP over VPN")]
127+
public uint Asn { get; set; }
128+
129+
[Parameter(
130+
Mandatory = false,
131+
ValueFromPipelineByPropertyName = true,
132+
HelpMessage = "The weight added to routes learned over BGP from this virtual network gateway")]
133+
public int PeerWeight { get; set; }
134+
123135
[Parameter(
124136
Mandatory = false,
125137
ValueFromPipelineByPropertyName = true,
@@ -223,6 +235,26 @@ private PSVirtualNetworkGateway CreateVirtualNetworkGateway()
223235
vnetGateway.VpnClientConfiguration = null;
224236
}
225237

238+
if(this.Asn > 0 || this.PeerWeight > 0)
239+
{
240+
vnetGateway.BgpSettings = new PSBgpSettings();
241+
vnetGateway.BgpSettings.BgpPeeringAddress = null; // We block modifying the gateway's BgpPeeringAddress (CA)
242+
243+
if(this.Asn > 0)
244+
{
245+
vnetGateway.BgpSettings.Asn = this.Asn;
246+
}
247+
248+
if(this.PeerWeight > 0)
249+
{
250+
vnetGateway.BgpSettings.PeerWeight = this.PeerWeight;
251+
}
252+
else if(this.PeerWeight < 0)
253+
{
254+
throw new ArgumentException("PeerWeight must be a positive integer");
255+
}
256+
}
257+
226258
// Map to the sdk object
227259
var vnetGatewayModel = Mapper.Map<MNM.VirtualNetworkGateway>(vnetGateway);
228260
vnetGatewayModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

src/ResourceManager/Network/Commands.Network/VirtualNetworkGatewayConnection/NewAzureVirtualNetworkGatewayConnectionCommand.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ public class NewAzureVirtualNetworkGatewayConnectionCommand : VirtualNetworkGate
113113
HelpMessage = "Peer")]
114114
public PSPeering Peer { get; set; }
115115

116+
[Parameter(
117+
Mandatory = false,
118+
ValueFromPipelineByPropertyName =true,
119+
HelpMessage = "Whether to establish a BGP session over a S2S VPN tunnel")]
120+
public string EnableBgp { get; set; }
121+
116122
[Parameter(
117123
Mandatory = false,
118124
ValueFromPipelineByPropertyName = true,
@@ -159,6 +165,16 @@ private PSVirtualNetworkGatewayConnection CreateVirtualNetworkGatewayConnection(
159165
vnetGatewayConnection.ConnectionType = this.ConnectionType;
160166
vnetGatewayConnection.RoutingWeight = this.RoutingWeight;
161167
vnetGatewayConnection.SharedKey = this.SharedKey;
168+
169+
if (!string.IsNullOrEmpty(this.EnableBgp))
170+
{
171+
vnetGatewayConnection.EnableBgp = bool.Parse(this.EnableBgp);
172+
}
173+
else
174+
{
175+
vnetGatewayConnection.EnableBgp = false;
176+
}
177+
162178
if (!string.IsNullOrEmpty(this.AuthorizationKey))
163179
{
164180
vnetGatewayConnection.AuthorizationKey = this.AuthorizationKey;

src/ResourceManager/Network/Commands.Network/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<package id="Microsoft.Azure.Graph.RBAC" version="1.9.0-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
11-
<package id="Microsoft.Azure.Management.Network" version="3.2.0-preview" targetFramework="net45" />
11+
<package id="Microsoft.Azure.Management.Network" version="3.3.0-preview" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Management.Resources" version="2.19.0-preview" targetFramework="net45" />
1313
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
1414
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />

0 commit comments

Comments
 (0)