Skip to content

Commit 659f2cf

Browse files
committed
Block BgpPeeringAddress for VirtualNetworkGateway, minor fixes
1 parent 9782a86 commit 659f2cf

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

src/ServiceManagement/Network/Commands.Network/Gateway/NewAzureVirtualNetworkGateway.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@ public class NewAzureVirtualNetworkGatewayCommand : NetworkCmdletBase
4545
[Parameter(Position = 6, Mandatory = false, HelpMessage = "Virtual network gateway BGP speaker's ASN")]
4646
public uint Asn { get; set; }
4747

48-
[Parameter(Position = 7, Mandatory = false, HelpMessage = "Virtual network gateway BGP speaker's IP/BGP identifier")]
49-
public string BgpPeeringAddress { get; set; }
50-
51-
[Parameter(Position = 8, Mandatory = false, HelpMessage = "Weight for routes learned from this BGP speaker")]
48+
[Parameter(Position = 7, Mandatory = false, HelpMessage = "Weight for routes learned from this BGP speaker")]
5249
public int PeerWeight { get; set; }
5350

5451
public override void ExecuteCmdlet()
5552
{
56-
WriteObject(Client.CreateVirtualNetworkGateway(VNetName, GatewayName, GatewayType, GatewaySKU, Location, VnetId, Asn, BgpPeeringAddress, PeerWeight));
53+
WriteObject(Client.CreateVirtualNetworkGateway(VNetName, GatewayName, GatewayType, GatewaySKU, Location, VnetId, Asn, PeerWeight));
5754
}
5855
}
5956
}

src/ServiceManagement/Network/Commands.Network/Gateway/NewAzureVirtualNetworkGatewayConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public class NewAzureVirtualNetworkGatewayConnectionCommand : NetworkCmdletBase
4848
public string VirtualNetworkGatewayId { get; set; }
4949

5050
[Parameter(Position = 6, Mandatory = false, HelpMessage = "Whether to establish a BGP session over this connection")]
51-
public bool EnableBgp { get; set; }
51+
public string EnableBgp { get; set; }
5252

5353
public override void ExecuteCmdlet()
5454
{
55-
WriteObject(Client.CreateVirtualNetworkGatewayConnection(ConnectedEntityId, GatewayConnectionName, GatewayConnectionType, RoutingWeight, SharedKey, Guid.Parse(VirtualNetworkGatewayId), EnableBgp));
55+
WriteObject(Client.CreateVirtualNetworkGatewayConnection(ConnectedEntityId, GatewayConnectionName, GatewayConnectionType, RoutingWeight, SharedKey, Guid.Parse(VirtualNetworkGatewayId), bool.Parse(EnableBgp)));
5656
}
5757
}
5858
}

src/ServiceManagement/Network/Commands.Network/NetworkClient.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,10 +1096,14 @@ public GetVirtualNetworkGatewayContext GetVirtualNetworkGateway(string gatewayId
10961096
VnetId = response.VnetId,
10971097
SubnetId = response.SubnetId,
10981098
EnableBgp = response.EnableBgp.ToString(),
1099-
Asn = response.BgpSettings.Asn,
1100-
BgpPeeringAddress = response.BgpSettings.BgpPeeringAddress,
1101-
PeerWeight = response.BgpSettings.PeerWeight,
11021099
};
1100+
1101+
if(response.BgpSettings != null)
1102+
{
1103+
gatewayContext.Asn = response.BgpSettings.Asn;
1104+
gatewayContext.BgpPeeringAddress = response.BgpSettings.BgpPeeringAddress;
1105+
gatewayContext.PeerWeight = response.BgpSettings.PeerWeight;
1106+
}
11031107
PopulateOperationContext(response.RequestId, gatewayContext);
11041108

11051109
return gatewayContext;
@@ -1148,10 +1152,15 @@ public GetLocalNetworkGatewayContext GetLocalNetworkGateway(string gatewayId)
11481152
GatewayName = response.GatewayName,
11491153
IpAddress = response.IpAddress,
11501154
AddressSpace = response.AddressSpace.ToList(),
1151-
Asn = response.BgpSettings.Asn,
1152-
BgpPeeringAddress = response.BgpSettings.BgpPeeringAddress,
1153-
PeerWeight = response.BgpSettings.PeerWeight,
11541155
};
1156+
1157+
if(response.BgpSettings != null)
1158+
{
1159+
gatewayContext.Asn = response.BgpSettings.Asn;
1160+
gatewayContext.BgpPeeringAddress = response.BgpSettings.BgpPeeringAddress;
1161+
gatewayContext.PeerWeight = response.BgpSettings.PeerWeight;
1162+
}
1163+
11551164
PopulateOperationContext(response.RequestId, gatewayContext);
11561165

11571166
return gatewayContext;
@@ -1202,6 +1211,9 @@ public IEnumerable<GetVirtualNetworkGatewayContext> ListVirtualNetworkGateways()
12021211
VnetId = virtualNetworkGateway.VnetId,
12031212
SubnetId = virtualNetworkGateway.SubnetId,
12041213
EnableBgp = virtualNetworkGateway.EnableBgp.ToString(),
1214+
Asn = virtualNetworkGateway.BgpSettings != null ? virtualNetworkGateway.BgpSettings.Asn : 0,
1215+
BgpPeeringAddress = virtualNetworkGateway.BgpSettings != null ? virtualNetworkGateway.BgpSettings.BgpPeeringAddress : "",
1216+
PeerWeight = virtualNetworkGateway.BgpSettings != null ? virtualNetworkGateway.BgpSettings.PeerWeight : 0
12051217
};
12061218
});
12071219
PopulateOperationContext(response.RequestId, virtualNetworkGateways);
@@ -1260,7 +1272,7 @@ public SharedKeyContext GetSharedKeyV2(string gatewayId, string connectedentityI
12601272
}
12611273

12621274
public GatewayGetOperationStatusResponse CreateVirtualNetworkGateway(string vnetName, string gatewayName, string gatewayType, string gatewaySKU, string location, string vnetId,
1263-
uint Asn, string BgpPeeringAddress, int PeerWeight)
1275+
uint Asn, int PeerWeight)
12641276
{
12651277
VirtualNetworkGatewayCreateParameters parameters = new VirtualNetworkGatewayCreateParameters()
12661278
{
@@ -1269,9 +1281,9 @@ public GatewayGetOperationStatusResponse CreateVirtualNetworkGateway(string vnet
12691281
GatewayType = gatewayType,
12701282
Location = location,
12711283
VnetId = vnetId,
1272-
BgpSettings = Asn > 0?new BgpSettings {
1284+
BgpSettings = (Asn > 0 || PeerWeight > 0)?new BgpSettings {
12731285
Asn = Asn,
1274-
BgpPeeringAddress = BgpPeeringAddress,
1286+
BgpPeeringAddress = "", // We don't allow changing the gateway's BgpPeeringAddress
12751287
PeerWeight = PeerWeight
12761288
}:null,
12771289
};
@@ -1379,7 +1391,7 @@ public AzureOperationResponse UpdateLocalNetworkGateway(string gatewayId, List<s
13791391
UpdateLocalNetworkGatewayParameters parameters = new UpdateLocalNetworkGatewayParameters()
13801392
{
13811393
AddressSpace = addressSpace,
1382-
BgpSettings = Asn > 0?new BgpSettings {
1394+
BgpSettings = (Asn > 0 || PeerWeight > 0 || ! string.IsNullOrEmpty(BgpPeeringAddress))?new BgpSettings {
13831395
Asn = Asn,
13841396
BgpPeeringAddress = BgpPeeringAddress,
13851397
PeerWeight = PeerWeight,

0 commit comments

Comments
 (0)