Skip to content

Commit 7d6bed8

Browse files
Merge pull request #3 from Azure/network-september
Network september merge
2 parents be27293 + cc4de26 commit 7d6bed8

File tree

9 files changed

+1583
-5
lines changed

9 files changed

+1583
-5
lines changed

src/Network/Network.Test/ScenarioTests/VirtualNetworkTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public void TestVirtualNetworkSubnetCRUD()
5050
TestRunner.RunTestScript("Test-subnetCRUD");
5151
}
5252

53+
[Fact]
54+
[Trait(Category.AcceptanceType, Category.CheckIn)]
55+
[Trait(Category.Owner, NrpTeamAlias.sdnnrp)]
56+
public void TestVirtualNetworkBgpCommunitiesCRUD()
57+
{
58+
TestRunner.RunTestScript("Test-bgpCommunitiesCRUD");
59+
}
60+
5361
[Fact]
5462
[Trait(Category.AcceptanceType, Category.CheckIn)]
5563
[Trait(Category.Owner, NrpTeamAlias.sdnnrp)]

src/Network/Network.Test/ScenarioTests/VirtualNetworkTests.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,48 @@ function Test-subnetCRUD
201201
}
202202
}
203203

204+
<#
205+
.SYNOPSIS
206+
Tests creating, updating & deleting a virtualNetwork with BGP Communities.
207+
.DESCRIPTION
208+
SmokeTest
209+
#>
210+
function Test-bgpCommunitiesCRUD
211+
{
212+
# Setup
213+
$rgname = Get-ResourceGroupName
214+
$vnetName = Get-ResourceName
215+
$rglocation = Get-ProviderLocation ResourceManagement
216+
$resourceTypeParent = "Microsoft.Network/virtualNetworks"
217+
$location = Get-ProviderLocation $resourceTypeParent "eastus2euap"
218+
219+
try
220+
{
221+
# Create the resource group
222+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
223+
224+
# Create q virtual network with a BGP community
225+
New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -BgpCommunity 12076:61234
226+
227+
# Get the virtual network and verify that the community is set to the expected value
228+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
229+
Assert-AreEqual "12076:61234" $vnet.BgpCommunities.VirtualNetworkCommunity
230+
231+
# Update the virtual network with a different BGP community
232+
$vnet.BgpCommunities.VirtualNetworkCommunity = "12076:64321"
233+
$vnet | Set-AzVirtualNetwork
234+
235+
# Get the virtual network and verify that the community is set to the new value
236+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
237+
Assert-AreEqual "12076:64321" $vnet.BgpCommunities.VirtualNetworkCommunity
238+
}
239+
finally
240+
{
241+
# Cleanup
242+
Clean-ResourceGroup $rgname
243+
}
244+
}
245+
204246
<#
205247
.SYNOPSIS
206248
Tests creating new virtualNetwork w/ delegated subnets.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.VirtualNetworkTests/TestVirtualNetworkBgpCommunitiesCRUD.json

Lines changed: 1467 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ private static void Initialize()
168168
// Subnet
169169
// CNM to MNM
170170
cfg.CreateMap<CNM.PSDhcpOptions, MNM.DhcpOptions>();
171+
cfg.CreateMap<CNM.PSVirtualNetworkBgpCommunities, MNM.VirtualNetworkBgpCommunities>();
171172
cfg.CreateMap<CNM.PSSubnet, MNM.Subnet>()
172173
.ForMember(dest => dest.AddressPrefix, opt => opt.Ignore())
173174
.ForMember(dest=> dest.AddressPrefixes, opt => opt.Ignore())
@@ -190,6 +191,7 @@ private static void Initialize()
190191

191192
// MNM to CNM
192193
cfg.CreateMap<MNM.DhcpOptions, CNM.PSDhcpOptions>();
194+
cfg.CreateMap<MNM.VirtualNetworkBgpCommunities, CNM.PSVirtualNetworkBgpCommunities>();
193195
cfg.CreateMap<MNM.Subnet, CNM.PSSubnet>()
194196
.ForMember(dest => dest.AddressPrefix, opt => opt.Ignore())
195197
.AfterMap((src, dest) =>

src/Network/Network/Models/PSVirtualNetwork.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class PSVirtualNetwork : PSTopLevelResource, IResourceReference, IVirtual
2828

2929
public List<PSSubnet> Subnets { get; set; }
3030

31+
public PSVirtualNetworkBgpCommunities BgpCommunities { get; set; }
32+
3133
public List<PSVirtualNetworkPeering> VirtualNetworkPeerings { get; set; }
3234

3335
[Ps1Xml(Target = ViewControl.Table)]
@@ -56,6 +58,12 @@ public string SubnetsText
5658
get { return JsonConvert.SerializeObject(Subnets, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
5759
}
5860

61+
[JsonIgnore]
62+
public string BgpCommunitiesText
63+
{
64+
get { return JsonConvert.SerializeObject(BgpCommunities, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
65+
}
66+
5967
[JsonIgnore]
6068
public string VirtualNetworkPeeringsText
6169
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Microsoft.Azure.Commands.Network.Models
4+
{
5+
public class PSVirtualNetworkBgpCommunities
6+
{
7+
public string VirtualNetworkCommunity { get; set; }
8+
9+
public string RegionalCommunity { get; set; }
10+
11+
public bool ShouldSerializeRegionalCommunity()
12+
{
13+
return !string.IsNullOrWhiteSpace(this.RegionalCommunity);
14+
}
15+
}
16+
}

src/Network/Network/Network.format.ps1xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@
114114
<Label>Subnets</Label>
115115
<PropertyName>SubnetsText</PropertyName>
116116
</ListItem>
117+
<ListItem>
118+
<Label>BgpCommunities</Label>
119+
<PropertyName>BgpCommunitiesText</PropertyName>
120+
<ItemSelectionCondition>
121+
<ScriptBlock>
122+
!($_.BgpCommunities -eq $null)
123+
</ScriptBlock>
124+
</ItemSelectionCondition>
125+
</ListItem>
117126
<ListItem>
118127
<Label>VirtualNetworkPeerings</Label>
119128
<PropertyName>VirtualNetworkPeeringsText</PropertyName>

src/Network/Network/VirtualNetwork/NewAzureVirtualNetworkCommand.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ public class NewAzureVirtualNetworkCommand : VirtualNetworkBaseCmdlet
7272
HelpMessage = "The list of subnets")]
7373
public PSSubnet[] Subnet { get; set; }
7474

75+
[Parameter(
76+
Mandatory = false,
77+
ValueFromPipelineByPropertyName = true,
78+
HelpMessage = "The BGP Community advertised over ExpressRoute.")]
79+
public string BgpCommunity { get; set; }
80+
7581
[Parameter(
7682
Mandatory = false,
7783
ValueFromPipelineByPropertyName = true,
@@ -137,8 +143,13 @@ private PSVirtualNetwork CreateVirtualNetwork()
137143
vnet.DdosProtectionPlan = new PSResourceId {Id = DdosProtectionPlanId};
138144
}
139145

146+
if (!string.IsNullOrWhiteSpace(BgpCommunity))
147+
{
148+
vnet.BgpCommunities = new PSVirtualNetworkBgpCommunities {VirtualNetworkCommunity = this.BgpCommunity};
149+
}
150+
140151
// Map to the sdk object
141-
var vnetModel = NetworkResourceManagerProfile.Mapper.Map<MNM.VirtualNetwork>(vnet);
152+
var vnetModel = NetworkResourceManagerProfile.Mapper.Map<MNM.VirtualNetwork>(vnet);
142153
vnetModel.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true);
143154

144155
// Execute the Create VirtualNetwork call

src/Network/Network/help/New-AzVirtualNetwork.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Creates a virtual network.
1515

1616
```
1717
New-AzVirtualNetwork -Name <String> -ResourceGroupName <String> -Location <String> -AddressPrefix <String[]>
18-
[-DnsServer <String[]>] [-Subnet <PSSubnet[]>] [-Tag <Hashtable>] [-EnableDdosProtection]
19-
[-DdosProtectionPlanId <String>] [-Force] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
20-
[-Confirm] [<CommonParameters>]
18+
[-DnsServer <String[]>] [-Subnet <PSSubnet[]>] [-BgpCommunity <String>] [-Tag <Hashtable>]
19+
[-EnableDdosProtection] [-DdosProtectionPlanId <String>] [-Force] [-AsJob]
20+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2121
```
2222

2323
## DESCRIPTION
@@ -103,6 +103,21 @@ Accept pipeline input: False
103103
Accept wildcard characters: False
104104
```
105105
106+
### -BgpCommunity
107+
The BGP Community advertised over ExpressRoute.
108+
109+
```yaml
110+
Type: System.String
111+
Parameter Sets: (All)
112+
Aliases:
113+
114+
Required: False
115+
Position: Named
116+
Default value: None
117+
Accept pipeline input: True (ByPropertyName)
118+
Accept wildcard characters: False
119+
```
120+
106121
### -DdosProtectionPlanId
107122
Reference to the DDoS protection plan resource associated with the virtual network.
108123
@@ -286,7 +301,7 @@ Accept wildcard characters: False
286301
```
287302
288303
### CommonParameters
289-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
304+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
290305
291306
## INPUTS
292307

0 commit comments

Comments
 (0)