Skip to content

Adding Virtual Network Usage cmdlet #4159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.14.0.0-prerelease\lib\net45\Microsoft.Azure.Management.Compute.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.1-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.Storage, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand All @@ -94,11 +94,11 @@
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.5\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.8\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.5\lib\net45\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.7\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.TestFramework">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<package id="Microsoft.Azure.Graph.RBAC" version="3.4.0-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Compute" version="14.0.0-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Network" version="10.1.0-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Network" version="10.1.1-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Storage" version="4.1.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Test.Framework" version="1.0.6179.26854-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.7-preview" targetFramework="net45" />
Expand All @@ -16,8 +16,8 @@
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.5" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.5" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.8" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.7" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure.TestFramework" version="1.5.0-preview" targetFramework="net45" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.14.0.0-prerelease\lib\net45\Microsoft.Azure.Management.Compute.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.1-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.Storage">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Compute" version="14.0.0-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Network" version="10.1.0-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Network" version="10.1.1-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Storage" version="4.1.0-preview" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
Expand Down
3 changes: 2 additions & 1 deletion src/ResourceManager/Network/AzureRM.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ CmdletsToExport = 'Add-AzureRmApplicationGatewayAuthenticationCertificate',
'Get-AzureRmVirtualNetworkGatewayBgpPeerStatus',
'Get-AzureRmVirtualNetworkGatewayAdvertisedRoute',
'Get-AzureRmVirtualNetworkGatewayLearnedRoute',
'Get-AzureRmNetworkUsage'
'Get-AzureRmNetworkUsage',
'Get-AzureRmVirtualNetworkUsageList'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
<Reference Include="Microsoft.Azure.Management.Authorization">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.1-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.ResourceManager">
Expand Down Expand Up @@ -110,7 +110,7 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.5\lib\net45\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.7\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.TestFramework">
Expand Down Expand Up @@ -466,7 +466,7 @@
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.UsageTests\TestNetworkUsage.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayConnectionTests\TestVirtualNetworkGatewayConnectionCRUD.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand All @@ -491,6 +491,9 @@
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkTests\TestVirtualNetworkSubnetCRUD.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkTests\TestVirtualNetworkUsage.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Common\Commands.Common.Authentication.Abstractions\Commands.Common.Authentication.Abstractions.csproj">
Expand Down Expand Up @@ -527,4 +530,4 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,12 @@ public void TestResourceNavigationLinksOnSubnetCRUD()
{
NetworkResourcesController.NewInstance.RunPsTest("Test-ResourceNavigationLinksCRUD");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualNetworkUsage()
{
NetworkResourcesController.NewInstance.RunPsTest("Test-VirtualNetworkUsage");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,55 @@ function Test-ResourceNavigationLinksCRUD
# Cleanup
Clean-ResourceGroup $rgname
}
}
}

<#
.SYNOPSIS
Tests checking Virtual Network Usage feature.
#>
function Test-VirtualNetworkUsage
{
# Setup
$rgname = Get-ResourceGroupName
$vnetName = Get-ResourceName
$subnetName = Get-ResourceName
$subnet2Name = Get-ResourceName
$nicName = Get-ResourceName
$domainNameLabel = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/virtualNetworks"
$location = Get-ProviderLocation $resourceTypeParent

try
{
# Create the resource group
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }

# Create the Virtual Network
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24
New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
$vnet = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname

Assert-NotNull $vnet;
Assert-NotNull $vnet.Subnets;

$subnetId = $vnet.Subnets[0].Id;

$usage = Get-AzureRMVirtualNetworkUsageList -ResourceGroupName $rgname -Name $vnetName;

Assert-NotNull $usage;
$currentUsage = $usage.CurrentValue;

# Add Network Interface to change usage current value
New-AzureRmNetworkInterface -Location $location -Name $nicName -ResourceGroupName $rgname -SubnetId $subnetId;
$usage = Get-AzureRMVirtualNetworkUsageList -ResourceGroupName $rgname -Name $vnetName;
$currentUsageNew = $usage.CurrentValue;

Assert-AreEqual $currentUsage $($currentUsageNew - 1);
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<package id="Microsoft.Azure.Insights" version="0.13.1-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Compute" version="14.0.0-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Network" version="10.1.0-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Network" version="10.1.1-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Redis" version="3.1.1-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.ResourceManager" version="1.6.0-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
Expand All @@ -21,7 +21,7 @@
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.8" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.5" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.7" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure.TestFramework" version="1.5.2" targetFramework="net45" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
<Reference Include="Microsoft.Azure.Management.Network, Version=10.1.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.10.1.1-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Data.Edm">
Expand Down Expand Up @@ -275,6 +275,7 @@
<Compile Include="ExpressRouteCircuit\RemoveAzureExpressRouteCircuitCommand.cs" />
<Compile Include="ExpressRouteCircuit\SetAzureExpressRouteCircuitCommand.cs" />
<Compile Include="ExpressRouteCircuit\ExpressRouteCircuitBaseCmdlet.cs" />
<Compile Include="Models\PSVirtualNetworkUsage.cs" />
<Compile Include="Models\PSApplicationGatewayBackendHealth.cs" />
<Compile Include="Models\PSApplicationGatewayBackendHealthHttpSettings.cs" />
<Compile Include="Models\PSApplicationGatewayBackendHealthPool.cs" />
Expand Down Expand Up @@ -368,6 +369,7 @@
<Compile Include="Models\PSTopologyResource.cs" />
<Compile Include="Models\PSVirtualNetworkPeering.cs" />
<Compile Include="Models\PSTunnelConnectionHealth.cs" />
<Compile Include="Models\PSVirtualNetworkUsageCustom.cs" />
<Compile Include="NetworkInterface\EffectiveResources\GetAzureEffectiveNetworkSecurityGroupCommand.cs" />
<Compile Include="NetworkInterface\EffectiveResources\GetAzureEffectiveRouteTableCommand.cs" />
<Compile Include="NetworkInterface\IpConfiguration\AddAzureNetworkInterfaceIpConfigCommand.cs" />
Expand Down Expand Up @@ -577,6 +579,7 @@
<Compile Include="VirtualNetwork\GetAzureVirtualNetworkCommand.cs" />
<Compile Include="VirtualNetwork\NewAzureVirtualNetworkCommand.cs" />
<Compile Include="VirtualNetwork\VirtualNetworkBaseCmdlet.cs" />
<Compile Include="VirtualNetwork\VirtualNetworkListUsageMethod.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Common\Commands.Common.Authentication.Abstractions\Commands.Common.Authentication.Abstractions.csproj">
Expand Down Expand Up @@ -604,7 +607,9 @@
<Name>Commands.Tags</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Microsoft\Azure\Commands\Network\Models\" />
</ItemGroup>
<ItemGroup>
<None Include="..\AzureRM.Network.psd1">
<Link>AzureRM.Network.psd1</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ public static void Initialize()
// CNM to MNM
cfg.CreateMap<CNM.PSAddressSpace, MNM.AddressSpace>();
cfg.CreateMap<CNM.PSVirtualNetwork, MNM.VirtualNetwork>();
cfg.CreateMap<CNM.PSVirtualNetworkUsage, MNM.VirtualNetworkUsage>();
cfg.CreateMap<CNM.PSUsageName, MNM.VirtualNetworkUsageName>();

// MNM to CNM
cfg.CreateMap<MNM.AddressSpace, CNM.PSAddressSpace>();
cfg.CreateMap<MNM.VirtualNetwork, CNM.PSVirtualNetwork>();
cfg.CreateMap<MNM.VirtualNetworkUsage, CNM.PSVirtualNetworkUsage>();
cfg.CreateMap<MNM.VirtualNetworkUsageName, CNM.PSUsageName>();

// PublicIpAddress
// CNM to MNM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@
</ListEntries>
</ListControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Network.Models.PSVirtualNetworkUsage</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.Commands.Network.Models.PSVirtualNetworkUsage</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>Name</Label>
<PropertyName>NameText</PropertyName>
</ListItem>
<ListItem>
<Label>Id</Label>
<PropertyName>Id</PropertyName>
</ListItem>
<ListItem>
<Label>CurrentValue</Label>
<PropertyName>CurrentValue</PropertyName>
</ListItem>
<ListItem>
<Label>Limit</Label>
<PropertyName>Limit</PropertyName>
</ListItem>
<ListItem>
<Label>Unit</Label>
<PropertyName>Unit</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Network.Models.PSVirtualNetwork</Name>
<ViewSelectedBy>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Microsoft.Azure.Commands.Network.Models
{
public partial class PSVirtualNetworkUsage
{
public string Id { get; set; }
public long CurrentValue { get; set; }
public long Limit { get; set; }
public string Unit { get; set; }
public PSUsageName Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Azure.Commands.Network.Models
{
public partial class PSVirtualNetworkUsage
{
public string NameText
{
get { return Name.LocalizedValue; }
}
}
}
Loading