Skip to content

Commit aa7bd12

Browse files
Adding Virtual Network Usage cmdlet
1 parent 4b49871 commit aa7bd12

20 files changed

+1588
-17
lines changed

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.14.0.0-prerelease\lib\net45\Microsoft.Azure.Management.Compute.dll</HintPath>
8484
<Private>True</Private>
8585
</Reference>
86-
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
87-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
86+
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
87+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.2-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
8888
<Private>True</Private>
8989
</Reference>
9090
<Reference Include="Microsoft.Azure.Management.Storage">

src/ResourceManager/Compute/Commands.Compute/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
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" />
1111
<package id="Microsoft.Azure.Management.Compute" version="14.0.0-prerelease" targetFramework="net45" />
12-
<package id="Microsoft.Azure.Management.Network" version="10.1.0-preview" targetFramework="net452" />
12+
<package id="Microsoft.Azure.Management.Network" version="10.1.2-preview" targetFramework="net452" />
1313
<package id="Microsoft.Azure.Management.Storage" version="4.1.0-preview" targetFramework="net45" />
1414
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
1515
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />

src/ResourceManager/Network/AzureRM.Network.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ CmdletsToExport = 'Add-AzureRmApplicationGatewayAuthenticationCertificate',
291291
'Get-AzureRmVirtualNetworkGatewayBgpPeerStatus',
292292
'Get-AzureRmVirtualNetworkGatewayAdvertisedRoute',
293293
'Get-AzureRmVirtualNetworkGatewayLearnedRoute',
294-
'Get-AzureRmNetworkUsage'
294+
'Get-AzureRmNetworkUsage',
295+
'Get-AzureRmVirtualNetworkUsageList'
295296

296297
# Variables to export from this module
297298
# VariablesToExport = @()

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
<Reference Include="Microsoft.Azure.Management.Authorization">
6464
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
6565
</Reference>
66-
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
67-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
66+
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
67+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.2-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
6868
<Private>True</Private>
6969
</Reference>
7070
<Reference Include="Microsoft.Azure.Management.ResourceManager">
@@ -110,7 +110,7 @@
110110
<Private>True</Private>
111111
</Reference>
112112
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
113-
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.5\lib\net45\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
113+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.7\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
114114
<Private>True</Private>
115115
</Reference>
116116
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.TestFramework">
@@ -466,7 +466,7 @@
466466
</None>
467467
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.UsageTests\TestNetworkUsage.json">
468468
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
469-
</None>
469+
</None>
470470
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayConnectionTests\TestVirtualNetworkGatewayConnectionCRUD.json">
471471
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
472472
</None>
@@ -527,4 +527,4 @@
527527
</ItemGroup>
528528
<ItemGroup />
529529
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
530-
</Project>
530+
</Project>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,12 @@ public void TestResourceNavigationLinksOnSubnetCRUD()
5353
{
5454
NetworkResourcesController.NewInstance.RunPsTest("Test-ResourceNavigationLinksCRUD");
5555
}
56+
57+
[Fact]
58+
[Trait(Category.AcceptanceType, Category.CheckIn)]
59+
public void TestVirtualNetworkUsage()
60+
{
61+
NetworkResourcesController.NewInstance.RunPsTest("Test-VirtualNetworkUsage");
62+
}
5663
}
5764
}

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

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,55 @@ function Test-ResourceNavigationLinksCRUD
348348
# Cleanup
349349
Clean-ResourceGroup $rgname
350350
}
351-
}
351+
}
352+
353+
<#
354+
.SYNOPSIS
355+
Tests checking Virtual Network Usage feature.
356+
#>
357+
function Test-VirtualNetworkUsage
358+
{
359+
# Setup
360+
$rgname = Get-ResourceGroupName
361+
$vnetName = Get-ResourceName
362+
$subnetName = Get-ResourceName
363+
$subnet2Name = Get-ResourceName
364+
$nicName = Get-ResourceName
365+
$domainNameLabel = Get-ResourceName
366+
$rglocation = Get-ProviderLocation ResourceManagement
367+
$resourceTypeParent = "Microsoft.Network/virtualNetworks"
368+
$location = Get-ProviderLocation $resourceTypeParent
369+
370+
try
371+
{
372+
# Create the resource group
373+
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
374+
375+
# Create the Virtual Network
376+
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24
377+
New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
378+
$vnet = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
379+
380+
Assert-NotNull $vnet;
381+
Assert-NotNull $vnet.Subnets;
382+
383+
$subnetId = $vnet.Subnets[0].Id;
384+
385+
$usage = Get-AzureRMVirtualNetworkUsageList -ResourceGroupName $rgname -Name $vnetName;
386+
387+
Assert-NotNull $usage;
388+
$currentUsage = $usage.CurrentValue;
389+
390+
# Add Network Interface to change usage current value
391+
New-AzureRmNetworkInterface -Location $location -Name $nicName -ResourceGroupName $rgname -SubnetId $subnetId;
392+
$usage = Get-AzureRMVirtualNetworkUsageList -ResourceGroupName $rgname -Name $vnetName;
393+
$currentUsageNew = $usage.CurrentValue;
394+
395+
Assert-AreEqual $currentUsage $($currentUsageNew - 1);
396+
}
397+
finally
398+
{
399+
# Cleanup
400+
Clean-ResourceGroup $rgname
401+
}
402+
}

src/ResourceManager/Network/Commands.Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.VirtualNetworkTests/TestVirtualNetworkUsage.json

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<package id="Microsoft.Azure.Insights" version="0.13.1-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.Compute" version="14.0.0-prerelease" targetFramework="net45" />
11-
<package id="Microsoft.Azure.Management.Network" version="10.1.0-preview" targetFramework="net452" />
11+
<package id="Microsoft.Azure.Management.Network" version="10.1.2-preview" targetFramework="net452" />
1212
<package id="Microsoft.Azure.Management.Redis" version="3.1.1-preview" targetFramework="net45" />
1313
<package id="Microsoft.Azure.Management.ResourceManager" version="1.6.0-preview" targetFramework="net452" />
1414
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
@@ -21,7 +21,7 @@
2121
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net45" />
2222
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
2323
<package id="Microsoft.Rest.ClientRuntime" version="2.3.8" targetFramework="net452" />
24-
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.5" targetFramework="net45" />
24+
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.7" targetFramework="net452" />
2525
<package id="Microsoft.Rest.ClientRuntime.Azure.TestFramework" version="1.5.2" targetFramework="net45" />
2626
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
2727
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
<SpecificVersion>False</SpecificVersion>
7474
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
7575
</Reference>
76-
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
77-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
76+
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
77+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.2-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
7878
<Private>True</Private>
7979
</Reference>
8080
<Reference Include="Microsoft.Data.Edm">
@@ -275,6 +275,7 @@
275275
<Compile Include="ExpressRouteCircuit\RemoveAzureExpressRouteCircuitCommand.cs" />
276276
<Compile Include="ExpressRouteCircuit\SetAzureExpressRouteCircuitCommand.cs" />
277277
<Compile Include="ExpressRouteCircuit\ExpressRouteCircuitBaseCmdlet.cs" />
278+
<Compile Include="Models\PSVirtualNetworkUsage.cs" />
278279
<Compile Include="Models\PSApplicationGatewayBackendHealth.cs" />
279280
<Compile Include="Models\PSApplicationGatewayBackendHealthHttpSettings.cs" />
280281
<Compile Include="Models\PSApplicationGatewayBackendHealthPool.cs" />
@@ -368,6 +369,7 @@
368369
<Compile Include="Models\PSTopologyResource.cs" />
369370
<Compile Include="Models\PSVirtualNetworkPeering.cs" />
370371
<Compile Include="Models\PSTunnelConnectionHealth.cs" />
372+
<Compile Include="Models\PSVirtualNetworkUsageCustom.cs" />
371373
<Compile Include="NetworkInterface\EffectiveResources\GetAzureEffectiveNetworkSecurityGroupCommand.cs" />
372374
<Compile Include="NetworkInterface\EffectiveResources\GetAzureEffectiveRouteTableCommand.cs" />
373375
<Compile Include="NetworkInterface\IpConfiguration\AddAzureNetworkInterfaceIpConfigCommand.cs" />
@@ -577,6 +579,7 @@
577579
<Compile Include="VirtualNetwork\GetAzureVirtualNetworkCommand.cs" />
578580
<Compile Include="VirtualNetwork\NewAzureVirtualNetworkCommand.cs" />
579581
<Compile Include="VirtualNetwork\VirtualNetworkBaseCmdlet.cs" />
582+
<Compile Include="VirtualNetwork\VirtualNetworkListUsageMethod.cs" />
580583
</ItemGroup>
581584
<ItemGroup>
582585
<ProjectReference Include="..\..\..\Common\Commands.Common.Authentication.Abstractions\Commands.Common.Authentication.Abstractions.csproj">
@@ -604,7 +607,9 @@
604607
<Name>Commands.Tags</Name>
605608
</ProjectReference>
606609
</ItemGroup>
607-
<ItemGroup />
610+
<ItemGroup>
611+
<Folder Include="Microsoft\Azure\Commands\Network\Models\" />
612+
</ItemGroup>
608613
<ItemGroup>
609614
<None Include="..\AzureRM.Network.psd1">
610615
<Link>AzureRM.Network.psd1</Link>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ public static void Initialize()
7676
// CNM to MNM
7777
cfg.CreateMap<CNM.PSAddressSpace, MNM.AddressSpace>();
7878
cfg.CreateMap<CNM.PSVirtualNetwork, MNM.VirtualNetwork>();
79+
cfg.CreateMap<CNM.PSVirtualNetworkUsage, MNM.VirtualNetworkUsage>();
80+
cfg.CreateMap<CNM.PSUsageName, MNM.VirtualNetworkUsageName>();
7981

8082
// MNM to CNM
8183
cfg.CreateMap<MNM.AddressSpace, CNM.PSAddressSpace>();
8284
cfg.CreateMap<MNM.VirtualNetwork, CNM.PSVirtualNetwork>();
85+
cfg.CreateMap<MNM.VirtualNetworkUsage, CNM.PSVirtualNetworkUsage>();
86+
cfg.CreateMap<MNM.VirtualNetworkUsageName, CNM.PSUsageName>();
8387

8488
// PublicIpAddress
8589
// CNM to MNM

src/ResourceManager/Network/Commands.Network/Microsoft.Azure.Commands.Network.format.ps1xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,40 @@
2727
</ListEntries>
2828
</ListControl>
2929
</View>
30+
<View>
31+
<Name>Microsoft.Azure.Commands.Network.Models.PSVirtualNetworkUsage</Name>
32+
<ViewSelectedBy>
33+
<TypeName>Microsoft.Azure.Commands.Network.Models.PSVirtualNetworkUsage</TypeName>
34+
</ViewSelectedBy>
35+
<ListControl>
36+
<ListEntries>
37+
<ListEntry>
38+
<ListItems>
39+
<ListItem>
40+
<Label>Name</Label>
41+
<PropertyName>NameText</PropertyName>
42+
</ListItem>
43+
<ListItem>
44+
<Label>Id</Label>
45+
<PropertyName>Id</PropertyName>
46+
</ListItem>
47+
<ListItem>
48+
<Label>CurrentValue</Label>
49+
<PropertyName>CurrentValue</PropertyName>
50+
</ListItem>
51+
<ListItem>
52+
<Label>Limit</Label>
53+
<PropertyName>Limit</PropertyName>
54+
</ListItem>
55+
<ListItem>
56+
<Label>Unit</Label>
57+
<PropertyName>Unit</PropertyName>
58+
</ListItem>
59+
</ListItems>
60+
</ListEntry>
61+
</ListEntries>
62+
</ListControl>
63+
</View>
3064
<View>
3165
<Name>Microsoft.Azure.Commands.Network.Models.PSVirtualNetwork</Name>
3266
<ViewSelectedBy>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Microsoft.Azure.Commands.Network.Models
2+
{
3+
public partial class PSVirtualNetworkUsage
4+
{
5+
public string Id;
6+
public long CurrentValue;
7+
public long Limit;
8+
public string Unit;
9+
public PSUsageName Name;
10+
}
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.Azure.Commands.Network.Models
8+
{
9+
public partial class PSVirtualNetworkUsage
10+
{
11+
public string NameText
12+
{
13+
get { return Name.LocalizedValue; }
14+
}
15+
}
16+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// Copyright (c) Microsoft and contributors. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
// Warning: This code was generated by a tool.
18+
//
19+
// Changes to this file may cause incorrect behavior and will be lost if the
20+
// code is regenerated.
21+
22+
using Microsoft.Azure.Commands.Network.Models;
23+
using Microsoft.Azure.Management.Network;
24+
using Microsoft.Azure.Management.Network.Models;
25+
using System;
26+
using System.Collections;
27+
using System.Collections.Generic;
28+
using System.Linq;
29+
using System.Management.Automation;
30+
using AutoMapper;
31+
using CNM = Microsoft.Azure.Commands.Network.Models;
32+
33+
namespace Microsoft.Azure.Commands.Network.Automation
34+
{
35+
[Cmdlet(VerbsCommon.Get, "AzureRmVirtualNetworkUsageList"), OutputType(typeof(PSVirtualNetworkUsage))]
36+
public partial class GetAzureRmVirtualNetworkUsageList : NetworkBaseCmdlet
37+
{
38+
[Parameter(
39+
Mandatory = true,
40+
ValueFromPipelineByPropertyName = true)]
41+
[ValidateNotNullOrEmpty]
42+
public string ResourceGroupName { get; set; }
43+
[Parameter(
44+
Mandatory = true,
45+
ValueFromPipelineByPropertyName = true)]
46+
[ValidateNotNullOrEmpty]
47+
public string Name { get; set; }
48+
49+
public override void Execute()
50+
{
51+
base.Execute();
52+
53+
var vVirtualNetworkList = this.NetworkClient.NetworkManagementClient.VirtualNetworks.ListUsage(ResourceGroupName, Name);
54+
foreach (var vVirtualNetwork in vVirtualNetworkList)
55+
{
56+
var vVirtualNetworkModel = Mapper.Map<CNM.PSVirtualNetworkUsage>(vVirtualNetwork);
57+
WriteObject(vVirtualNetworkModel);
58+
}
59+
}
60+
}
61+
}

src/ResourceManager/Network/Commands.Network/help/Add-AzureRmRouteFilterRuleConfig.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ The Add-AzureRmRouteFilterRuleConfig cmdlet adds a route filter rule to an Azure
3535

3636

3737

38+
39+
3840
```
3941
PS C:\>$RouteFilter = Get-AzureRmRouteFilter -ResourceGroupName "ResourceGroup11" -Name "routefilter01"
4042
PS C:\> Add-AzureRmRouteFilterRuleConfig -Name "rule13" -Access Allow -RouteFilterRuleType Community -RouteFilter $RouteFilter

src/ResourceManager/Network/Commands.Network/help/Get-AzureRmApplicationGatewayBackendHealth.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ The Get-AzureRmApplicationGatewayBackendHealth cmdlet gets application gateway b
3737

3838

3939

40+
41+
4042
```
4143
PS C:\>$BackendHealth = Get-AzureRmApplicationGatewayBackendHealth -Name ApplicationGateway01 -ResourceGroupName ResourceGroup01
4244
```
@@ -58,6 +60,8 @@ This command gets the backend health of application gateway named ApplicationGat
5860

5961

6062

63+
64+
6165
```
6266
PS C:\>$BackendHealth = Get-AzureRmApplicationGatewayBackendHealth -Name ApplicationGateway01 -ResourceGroupName ResourceGroup01 -ExpandResource "backendhealth/applicationgatewayresource"
6367
```

0 commit comments

Comments
 (0)