Skip to content

Implemeted Usage cmdlet for Network; Added usage tests #4009

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 5 commits into from
Jun 4, 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
3 changes: 2 additions & 1 deletion src/ResourceManager/Network/AzureRM.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ CmdletsToExport = 'Add-AzureRmApplicationGatewayAuthenticationCertificate',
'Get-AzureRmVirtualNetwork', 'New-AzureRmVirtualNetwork',
'Get-AzureRmVirtualNetworkGatewayBgpPeerStatus',
'Get-AzureRmVirtualNetworkGatewayAdvertisedRoute',
'Get-AzureRmVirtualNetworkGatewayLearnedRoute'
'Get-AzureRmVirtualNetworkGatewayLearnedRoute',
'Get-AzureRmNetworkUsage'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
<Compile Include="ScenarioTests\RouteTableTests.cs" />
<Compile Include="ScenarioTests\NetworkSecurityGroupTests.cs" />
<Compile Include="ScenarioTests\TestDnsAvailabilityTest.cs" />
<Compile Include="ScenarioTests\UsageTests.cs" />
<Compile Include="ScenarioTests\VirtualNetworkTests.cs" />
<Compile Include="ScenarioTests\PublicIpAddressTests.cs" />
<Compile Include="ScenarioTests\VirtualNetworkGatewayTests.cs" />
Expand Down Expand Up @@ -238,6 +239,9 @@
<None Include="ScenarioTests\TestDnsAvailabilityTest.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\UsageTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\VirtualNetworkTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -457,6 +461,9 @@
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.LocalNetworkGatewayTests\TestLocalNetworkGatewayCRUD.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.UsageTests\TestNetworkUsage.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayConnectionTests\TestVirtualNetworkGatewayConnectionCRUD.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -517,4 +524,4 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.ServiceManagemenet.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using Xunit.Abstractions;

namespace Commands.Network.Test.ScenarioTests
{
public class UsageTests : Microsoft.WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
{
public UsageTests(ITestOutputHelper output)
{
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNetworkUsage()
{
NetworkResourcesController.NewInstance.RunPsTest("Test-NetworkUsage");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Tests checking usage cmdlet
#>
function Test-NetworkUsage
{
# Setup
$rgname = Get-ResourceGroupName
$vnetName = Get-ResourceName
$subnetName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/Usages"
$location = Get-ProviderLocation $resourceTypeParent

try
{
$location = $location -replace " ","";
$usage = Get-AzureRMNetworkUsage -Location $location;
$vnetCount = ($usage | Where-Object { $_.name.Value -eq "VirtualNetworks" }).currentValue;
Assert-AreNotEqual 0 $usage.Length "Usage should return non-empty array";

# Create the resource group
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation

# Create the Virtual Network
New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -DnsServer 8.8.8.8;
$usage = Get-AzureRMNetworkUsage -Location $location;
$vnetCount2 = ($usage | Where-Object { $_.name.Value -eq "VirtualNetworks" }).currentValue;

Assert-AreEqual ($vnetCount + 1) $vnetCount2 "Virtual Networks usage current value should be increased after Virtual Network was created";
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@
<Compile Include="Models\PSTroubleshootDetails.cs" />
<Compile Include="Models\PSTroubleshootRecommendedActions.cs" />
<Compile Include="Models\PSTroubleshootResult.cs" />
<Compile Include="Models\PSUsage.cs" />
<Compile Include="Models\PSUsageCustom.cs" />
<Compile Include="Models\PSUsageName.cs" />
<Compile Include="Models\PSViewNsgRules.cs" />
<Compile Include="Models\PSServiceProviderProperties.cs" />
<Compile Include="Models\PSPeering.cs" />
Expand Down Expand Up @@ -394,6 +397,7 @@
<Compile Include="NetworkWatcher\PacketCapture\StopAzureNetworkWatcherPacketCaptureCommand.cs" />
<Compile Include="NetworkWatcher\RemoveAzureNetworkWatcherCommand.cs" />
<Compile Include="ProviderWideCmdlets\GetAzureExpressRouteServiceProviderCommand.cs" />
<Compile Include="Usage\GetAzureNetworkUsageCommand.cs" />
<Compile Include="VirtualNetworkGatewayConnection\NewAzureRmIpsecPolicyCommand.cs" />
<Compile Include="RouteFilter\GetAzureRouteFilterCommand.cs" />
<Compile Include="RouteFilter\NewAzureRouteFilterCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ protected override void Configure()
Mapper.CreateMap<MNM.NetworkInterfaceDnsSettings, CNM.PSNetworkInterfaceDnsSettings>();
Mapper.CreateMap<MNM.NetworkInterfaceIPConfiguration, CNM.PSNetworkInterfaceIPConfiguration>();

// Usage
Mapper.CreateMap<CNM.PSUsage, MNM.Usage>();
Mapper.CreateMap<MNM.Usage, CNM.PSUsage>();
Mapper.CreateMap<CNM.PSUsageName, MNM.UsageName>();
Mapper.CreateMap<MNM.UsageName, CNM.PSUsageName>();

// NetworkWatcher
// CNM to MNM
Mapper.CreateMap<CNM.PSNetworkWatcher, MNM.NetworkWatcher>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>Microsoft.Azure.Commands.Network.Models.PSUsage</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.Commands.Network.Models.PSUsage</TypeName>
</ViewSelectedBy>
<ListControl>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ddefault here should be a table view - with only 3 columns, this makes the display much easier. Users can always use the list view by piping through fl

<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>ResourceType</Label>
<PropertyName>ResourceType</PropertyName>
</ListItem>
<ListItem>
<Label>CurrentValue</Label>
<PropertyName>CurrentValue</PropertyName>
</ListItem>
<ListItem>
<Label>Limit</Label>
<PropertyName>Limit</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Network.Models.PSVirtualNetwork</Name>
<ViewSelectedBy>
Expand Down
34 changes: 34 additions & 0 deletions src/ResourceManager/Network/Commands.Network/Models/PSUsage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Warning: This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

using Microsoft.Azure.Management.Network.Models;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Network.Models
{
public partial class PSUsage
{
public long CurrentValue;
public long Limit;
public string Unit;
public PSUsageName Name;
}
}
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 PSUsage
{
public string ResourceType
{
get { return Name.LocalizedValue; }
}
}
}
32 changes: 32 additions & 0 deletions src/ResourceManager/Network/Commands.Network/Models/PSUsageName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Warning: This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

using Microsoft.Azure.Management.Network.Models;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Network.Models
{
public partial class PSUsageName
{
public string Value;
public string LocalizedValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Warning: This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

using Microsoft.Azure.Commands.Network.Models;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using AutoMapper;
using CNM = Microsoft.Azure.Commands.Network.Models;

namespace Microsoft.Azure.Commands.Network.Automation
{
[Cmdlet(VerbsCommon.Get, "AzureRmNetworkUsage"), OutputType(typeof(PSUsage))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the output of this cmdlet look like on screen? Please see the help comments below and include this. You will want to make sure that the most relevant information is displayed, and extraneous information is not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markcowl, I've updated documentation. Could you please have a look?

public partial class GetAzureRmNetworkUsage : NetworkBaseCmdlet
{
[Parameter(
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Location.")]
[ValidateNotNullOrEmpty]
public string Location { get; set; }

public override void Execute()
{
base.Execute();

var vUsageList = this.NetworkClient.NetworkManagementClient.Usages.List(Location);
foreach (var vUsage in vUsageList)
{
var vUsageModel = Mapper.Map<CNM.PSUsage>(vUsage);
WriteObject(vUsageModel);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ The Add-AzureRmRouteFilterRuleConfig cmdlet adds a route filter rule to an Azure









```
PS C:\>$RouteFilter = Get-AzureRmRouteFilter -ResourceGroupName "ResourceGroup11" -Name "routefilter01"
PS C:\> Add-AzureRmRouteFilterRuleConfig -Name "rule13" -Access Allow -RouteFilterRuleType Community -RouteFilter $RouteFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ Gets a network security group.
### [Get-AzureRmNetworkSecurityRuleConfig](Get-AzureRmNetworkSecurityRuleConfig.md)
Get a network security rule configuration for a network security group.

### [Get-AzureRmNetworkUsage](Get-AzureRmNetworkUsage.md)
Lists network usages for a subscription

### [Get-AzureRmNetworkWatcher](Get-AzureRmNetworkWatcher.md)
Gets the properties of a Network Watcher

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ The Get-AzureRmApplicationGatewayBackendHealth cmdlet gets application gateway b









```
PS C:\>$BackendHealth = Get-AzureRmApplicationGatewayBackendHealth -Name ApplicationGateway01 -ResourceGroupName ResourceGroup01
```
Expand All @@ -46,6 +52,12 @@ This command gets the backend health of application gateway named ApplicationGat









```
PS C:\>$BackendHealth = Get-AzureRmApplicationGatewayBackendHealth -Name ApplicationGateway01 -ResourceGroupName ResourceGroup01 -ExpandResource "backendhealth/applicationgatewayresource"
```
Expand Down
Loading