-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Changes from all commits
e7ce6d9
3e470a3
91d358e
f995b34
fc6f0f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -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; } | ||
} | ||
} | ||
} |
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))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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