Skip to content

Commit 43bad4c

Browse files
authored
Merge pull request #7311 from wastoresh/locationusage
[Storage] Support get Storage Location Usage
2 parents 49f399b + 3490793 commit 43bad4c

File tree

6 files changed

+150
-2
lines changed

6 files changed

+150
-2
lines changed

src/ResourceManager/Storage/Commands.Management.Storage.Test/ScenarioTests/StorageAccountTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,12 @@ public void TestSetAzureStorageAccountStorageV2()
121121
{
122122
TestController.NewInstance.RunPsTest(_logger, "Test-SetAzureStorageAccountStorageV2");
123123
}
124+
125+
[Fact]
126+
[Trait(Category.AcceptanceType, Category.CheckIn)]
127+
public void TestGetAzureStorageLocationUsage()
128+
{
129+
TestController.NewInstance.RunPsTest(_logger, "Test-GetAzureStorageLocationUsage");
130+
}
124131
}
125132
}

src/ResourceManager/Storage/Commands.Management.Storage.Test/ScenarioTests/StorageAccountTests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,19 @@ function Test-SetAzureStorageAccountStorageV2
657657
Clean-ResourceGroup $rgname
658658
}
659659
}
660+
661+
<#
662+
.SYNOPSIS
663+
Test GetAzureStorageUsage with current Location
664+
.Description
665+
AzureAutomationTest
666+
#>
667+
function Test-GetAzureStorageLocationUsage
668+
{
669+
# Test
670+
$loc = Get-ProviderLocation_Stage ResourceManagement;
671+
672+
$usage = Get-AzureRmStorageUsage -Location $loc
673+
Assert-AreNotEqual 0 $usage.Limit;
674+
Assert-AreNotEqual 0 $usage.CurrentValue;
675+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/subscriptions/ce4a7590-4722-4bcf-a2c6-e473e9f11778/providers/Microsoft.Storage/locations/eastus2(stage)/usages?api-version=2018-03-01-preview",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvY2U0YTc1OTAtNDcyMi00YmNmLWEyYzYtZTQ3M2U5ZjExNzc4L3Byb3ZpZGVycy9NaWNyb3NvZnQuU3RvcmFnZS9sb2NhdGlvbnMvZWFzdHVzMiUyOHN0YWdlJTI5L3VzYWdlcz9hcGktdmVyc2lvbj0yMDE4LTAzLTAxLXByZXZpZXc=",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"x-ms-client-request-id": [
10+
"a9a430c2-5ecf-4f95-ad41-90e0b9977ac2"
11+
],
12+
"accept-language": [
13+
"en-US"
14+
],
15+
"User-Agent": [
16+
"FxVersion/4.7.3163.0",
17+
"OSName/Windows10Enterprise",
18+
"OSVersion/6.3.17134",
19+
"Microsoft.Azure.Management.Storage.StorageManagementClient/8.1.0.0"
20+
]
21+
},
22+
"ResponseBody": "{\r\n \"value\": [\r\n {\r\n \"unit\": \"Count\",\r\n \"currentValue\": 16,\r\n \"limit\": 250,\r\n \"name\": {\r\n \"value\": \"StorageAccounts\",\r\n \"localizedValue\": \"Storage Accounts\"\r\n }\r\n }\r\n ]\r\n}",
23+
"ResponseHeaders": {
24+
"Content-Length": [
25+
"129"
26+
],
27+
"Content-Type": [
28+
"application/json"
29+
],
30+
"Expires": [
31+
"-1"
32+
],
33+
"Pragma": [
34+
"no-cache"
35+
],
36+
"x-ms-request-id": [
37+
"0c699dac-d2a0-4c63-8707-2ff8c39e1980"
38+
],
39+
"Strict-Transport-Security": [
40+
"max-age=31536000; includeSubDomains"
41+
],
42+
"x-ms-ratelimit-remaining-subscription-reads": [
43+
"11999"
44+
],
45+
"x-ms-correlation-request-id": [
46+
"96f88cf3-b6ed-41f4-84bb-f30350aa6106"
47+
],
48+
"x-ms-routing-request-id": [
49+
"SOUTHEASTASIA:20180920T091605Z:96f88cf3-b6ed-41f4-84bb-f30350aa6106"
50+
],
51+
"X-Content-Type-Options": [
52+
"nosniff"
53+
],
54+
"Cache-Control": [
55+
"no-cache"
56+
],
57+
"Date": [
58+
"Thu, 20 Sep 2018 09:16:05 GMT"
59+
],
60+
"Server": [
61+
"Microsoft-Azure-Storage-Resource-Provider/1.0,Microsoft-HTTPAPI/2.0 Microsoft-HTTPAPI/2.0"
62+
]
63+
},
64+
"StatusCode": 200
65+
}
66+
],
67+
"Names": {},
68+
"Variables": {
69+
"SubscriptionId": "ce4a7590-4722-4bcf-a2c6-e473e9f11778"
70+
}
71+
}

src/ResourceManager/Storage/Commands.Management.Storage/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Support get the Storage resource usage of a specific location
22+
- Get-AzureRmStorageUsage
2123

2224
## Version 5.1.0
2325
* Upgrade to Azure Storage Client Library 9.3.0

src/ResourceManager/Storage/Commands.Management.Storage/StorageAccount/GetAzureStorageUsage.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,41 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.Management.Storage.Models;
16+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1617
using Microsoft.Azure.Management.Storage;
18+
using Microsoft.Azure.Management.Storage.Models;
19+
using System.Collections.Generic;
1720
using System.Management.Automation;
1821

1922
namespace Microsoft.Azure.Commands.Management.Storage.StorageAccount
2023
{
2124
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "StorageUsage"), OutputType(typeof(PSUsage))]
2225
public class GetAzureStorageUsageCommand : StorageAccountBaseCmdlet
2326
{
27+
[Parameter(
28+
Mandatory = false,
29+
ValueFromPipelineByPropertyName = true,
30+
HelpMessage = "Storage Accounts Location.")]
31+
[LocationCompleter("Microsoft.Storage/storageAccounts")]
32+
[ValidateNotNullOrEmpty]
33+
public string Location { get; set; }
2434
public override void ExecuteCmdlet()
2535
{
2636
base.ExecuteCmdlet();
2737

28-
foreach (var usage in this.StorageClient.Usages.List())
38+
//Get usage
39+
IEnumerable<Usage> usages;
40+
if (Location == null)
41+
{
42+
usages = this.StorageClient.Usages.List();
43+
}
44+
else
45+
{
46+
usages = this.StorageClient.Usages.ListByLocation(Location);
47+
}
48+
49+
//Output usage
50+
foreach (var usage in usages)
2951
{
3052
WriteObject(new PSUsage()
3153
{

src/ResourceManager/Storage/Commands.Management.Storage/help/Get-AzureRmStorageUsage.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gets the Storage resource usage of the current subscription.
1414
## SYNTAX
1515

1616
```
17-
Get-AzureRmStorageUsage [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
17+
Get-AzureRmStorageUsage [-Location <String>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1818
```
1919

2020
## DESCRIPTION
@@ -28,6 +28,20 @@ PS C:\>Get-AzureRmStorageUsage
2828
```
2929

3030
This command gets the Storage resources usage of the current subscription.
31+
32+
33+
### Example 2: Get the storage resources usage of specified location
34+
```
35+
PS C:\>Get-AzureRmStorageUsage -Location 'West US'
36+
37+
LocalizedName : Storage Accounts
38+
Name : StorageAccounts
39+
Unit : Count
40+
CurrentValue : 18
41+
Limit : 250
42+
```
43+
44+
This command gets the Storage resources usage of of specified location under the current subscription.
3145

3246
## PARAMETERS
3347

@@ -46,6 +60,22 @@ Accept pipeline input: False
4660
Accept wildcard characters: False
4761
```
4862
63+
### -Location
64+
Indicate to get Storage resources usage on the specified location.
65+
If not specified, will get Storage resources usage on all locations under the subscription.
66+
67+
```yaml
68+
Type: System.String
69+
Parameter Sets: (All)
70+
Aliases:
71+
72+
Required: False
73+
Position: Named
74+
Default value: None
75+
Accept pipeline input: True (ByPropertyName)
76+
Accept wildcard characters: False
77+
```
78+
4979
### CommonParameters
5080
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).
5181

0 commit comments

Comments
 (0)