Skip to content

Commit f8d9d10

Browse files
authored
Merge pull request #5223 from maddieclayton/AsJobStorage
Add -AsJob parameter to Storage cmdlets
2 parents c6d5c96 + d61cd24 commit f8d9d10

19 files changed

+195
-80
lines changed

src/ResourceManager/Storage/ChangeLog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
- Set-AzureRmStorageAccount
2525
* Added Location Completer to -Location parameters allowing tab completion through valid Locations
2626
* Added ResourceGroup Completer to -ResourceGroup parameters allowing tab completion through resource groups in current subscription
27+
* Added -AsJob support for long-running Storage cmdlets. Allows selected cmdlets to run in the background and return a job to track and control progress.
28+
- Affected cmdlets are New-, Remove-, Add-, and Update- for Storage Account and Storage Account Network Rule.
2729
## Version 4.0.1
2830
* Fixed assembly loading issue that caused some cmdlets to fail when executing
2931

@@ -80,4 +82,4 @@
8082

8183
## Version 2.4.0
8284

83-
## Version 2.3.0
85+
## Version 2.3.0

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ function Test-StorageAccount
3737

3838
New-AzureRmResourceGroup -Name $rgname -Location $loc;
3939

40-
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype -Kind $kind -AccessTier $accessTier -EnableEncryptionService $encryptionServiceBF;
40+
$job = New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype -Kind $kind -AccessTier $accessTier -EnableEncryptionService $encryptionServiceBF -AsJob
41+
$job | Wait-Job
4142
$stos = Get-AzureRmStorageAccount -ResourceGroupName $rgname;
4243

4344
$stotype = 'StandardGRS';
@@ -565,22 +566,25 @@ function Test-NetworkRule
565566
Assert-AreEqual $stoacl.IpRules[1].IPAddressOrRange $ip4;
566567
Assert-AreEqual $stoacl.VirtualNetworkRules $null
567568

568-
Remove-AzureRmStorageAccountNetworkRule -ResourceGroupName $rgname -Name $stoname -IPAddressOrRange "$ip3"
569+
$job = Remove-AzureRmStorageAccountNetworkRule -ResourceGroupName $rgname -Name $stoname -IPAddressOrRange "$ip3" -AsJob
570+
$job | Wait-Job
569571
$stoacl = Get-AzureRmStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname
570572
Assert-AreEqual $stoacl.Bypass 6;
571573
Assert-AreEqual $stoacl.DefaultAction Allow;
572574
Assert-AreEqual $stoacl.IpRules.Count 1
573575
Assert-AreEqual $stoacl.IpRules[0].IPAddressOrRange $ip4;
574576
Assert-AreEqual $stoacl.VirtualNetworkRules $null
575577

576-
Update-AzureRmStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname -IpRule @() -DefaultAction Deny -Bypass None
578+
$job = Update-AzureRmStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname -IpRule @() -DefaultAction Deny -Bypass None -AsJob
579+
$job | Wait-Job
577580
$stoacl = Get-AzureRmStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname
578581
Assert-AreEqual $stoacl.Bypass 0;
579582
Assert-AreEqual $stoacl.DefaultAction Deny;
580583
Assert-AreEqual $stoacl.IpRules $null
581584
Assert-AreEqual $stoacl.VirtualNetworkRules $null
582585

583-
$stoacliprule | Add-AzureRmStorageAccountNetworkRule -ResourceGroupName $rgname -Name $stoname
586+
$job = $stoacliprule | Add-AzureRmStorageAccountNetworkRule -ResourceGroupName $rgname -Name $stoname -AsJob
587+
$job | Wait-Job
584588
$stoacl = Get-AzureRmStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname
585589
Assert-AreEqual $stoacl.Bypass 0;
586590
Assert-AreEqual $stoacl.DefaultAction Deny;
@@ -589,10 +593,11 @@ function Test-NetworkRule
589593
Assert-AreEqual $stoacl.IpRules[1].IPAddressOrRange $ip4;
590594
Assert-AreEqual $stoacl.VirtualNetworkRules $null
591595

592-
Set-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -NetworkRuleSet (@{bypass="AzureServices";
596+
$job = Set-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -AsJob -NetworkRuleSet (@{bypass="AzureServices";
593597
ipRules=(@{IPAddressOrRange="$ip1";Action="allow"},
594598
@{IPAddressOrRange="$ip2";Action="allow"});
595599
defaultAction="Allow"})
600+
$job | Wait-Job
596601

597602
$stoacl = Get-AzureRmStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname
598603
Assert-AreEqual $stoacl.Bypass 4;
@@ -602,7 +607,8 @@ function Test-NetworkRule
602607
Assert-AreEqual $stoacl.IpRules[1].IPAddressOrRange $ip2;
603608
Assert-AreEqual $stoacl.VirtualNetworkRules $null
604609

605-
Remove-AzureRmStorageAccount -Force -ResourceGroupName $rgname -Name $stoname;
610+
$job = Remove-AzureRmStorageAccount -Force -ResourceGroupName $rgname -Name $stoname -AsJob
611+
$job | Wait-Job
606612
}
607613
finally
608614
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public class AddAzureStorageAccountNetworkRuleCommand : StorageAccountBaseCmdlet
9292
[Alias("SubnetId", "VirtualNetworkId")]
9393
public string[] VirtualNetworkResourceId { get; set; }
9494

95+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
96+
public SwitchParameter AsJob { get; set; }
97+
9598

9699
public override void ExecuteCmdlet()
97100
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ public PSNetworkRuleSet NetworkRuleSet
138138
get; set;
139139
}
140140

141+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
142+
public SwitchParameter AsJob { get; set; }
143+
141144
public override void ExecuteCmdlet()
142145
{
143146
base.ExecuteCmdlet();

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,18 @@ public class RemoveAzureStorageAccountCommand : StorageAccountBaseCmdlet
4343
public string Name { get; set; }
4444

4545
[Parameter(HelpMessage = "Force to Delete the Storage Account")]
46-
public SwitchParameter Force
47-
{
48-
get { return force; }
49-
set { force = value; }
50-
}
51-
private bool force = false;
46+
public SwitchParameter Force { get; set; }
47+
48+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
49+
public SwitchParameter AsJob { get; set; }
5250

5351
public override void ExecuteCmdlet()
5452
{
5553
base.ExecuteCmdlet();
5654

5755
if (ShouldProcess(this.Name, "Remove Storage Account"))
5856
{
59-
if (this.force || ShouldContinue(string.Format("Remove Storage Account '{0}' and all content in it", this.Name), ""))
57+
if (this.Force || ShouldContinue(string.Format("Remove Storage Account '{0}' and all content in it", this.Name), ""))
6058
{
6159
this.StorageClient.StorageAccounts.Delete(
6260
this.ResourceGroupName,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public class RemoveAzureStorageAccountNetworkRuleCommand : StorageAccountBaseCmd
9393
[Alias("SubnetId", "VirtualNetworkId")]
9494
public string[] VirtualNetworkResourceId { get; set; }
9595

96+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
97+
public SwitchParameter AsJob { get; set; }
98+
9699
public override void ExecuteCmdlet()
97100
{
98101
base.ExecuteCmdlet();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ public PSNetworkRuleSet NetworkRuleSet
193193
HelpMessage = "Upgrade Storage Account Kind to StorageV2.")]
194194
public SwitchParameter UpgradeToStorageV2 { get; set; }
195195

196+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
197+
public SwitchParameter AsJob { get; set; }
198+
196199
public override void ExecuteCmdlet()
197200
{
198201
base.ExecuteCmdlet();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public PSVirtualNetworkRule[] VirtualNetworkRule
118118
private bool isIpRuleSet = false;
119119
private bool isNetworkRuleSet = false;
120120

121+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
122+
public SwitchParameter AsJob { get; set; }
123+
121124

122125
public override void ExecuteCmdlet()
123126
{

src/ResourceManager/Storage/Commands.Management.Storage/help/Add-AzureRmStorageAccountNetworkRule.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ schema: 2.0.0
1515
### NetWorkRuleString (Default)
1616
```
1717
Add-AzureRmStorageAccountNetworkRule [-ResourceGroupName] <String> [-Name] <String>
18-
-VirtualNetworkResourceId <String[]> [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
18+
-VirtualNetworkResourceId <String[]> [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
1919
[<CommonParameters>]
2020
```
2121

2222
### IpRuleObject
2323
```
2424
Add-AzureRmStorageAccountNetworkRule [-ResourceGroupName] <String> [-Name] <String> -IPRule <PSIpRule[]>
25-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
25+
[-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2626
```
2727

2828
### NetworkRuleObject
2929
```
3030
Add-AzureRmStorageAccountNetworkRule [-ResourceGroupName] <String> [-Name] <String>
31-
-VirtualNetworkRule <PSVirtualNetworkRule[]> [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
32-
[<CommonParameters>]
31+
-VirtualNetworkRule <PSVirtualNetworkRule[]> [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
32+
[-Confirm] [<CommonParameters>]
3333
```
3434

3535
### IpRuleString
3636
```
3737
Add-AzureRmStorageAccountNetworkRule [-ResourceGroupName] <String> [-Name] <String>
38-
-IPAddressOrRange <String[]> [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
38+
-IPAddressOrRange <String[]> [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
3939
[<CommonParameters>]
4040
```
4141

@@ -76,6 +76,21 @@ This command add several IpRule with IpRule objects, input with JSON.
7676

7777
## PARAMETERS
7878

79+
### -AsJob
80+
Run cmdlet in the background
81+
82+
```yaml
83+
Type: SwitchParameter
84+
Parameter Sets: (All)
85+
Aliases:
86+
87+
Required: False
88+
Position: Named
89+
Default value: None
90+
Accept pipeline input: False
91+
Accept wildcard characters: False
92+
```
93+
7994
### -DefaultProfile
8095
The credentials, account, tenant, and subscription used for communication with Azure.
8196
@@ -97,7 +112,7 @@ The Array of IpAddressOrRange, add IpRules with the input IpAddressOrRange and d
97112
```yaml
98113
Type: String[]
99114
Parameter Sets: IpRuleString
100-
Aliases:
115+
Aliases:
101116

102117
Required: True
103118
Position: Named
@@ -112,7 +127,7 @@ The Array of IpRule objects to add to the NetworkRule Property.
112127
```yaml
113128
Type: PSIpRule[]
114129
Parameter Sets: IpRuleObject
115-
Aliases:
130+
Aliases:
116131

117132
Required: True
118133
Position: Named
@@ -142,7 +157,7 @@ Specifies the name of the resource group contains the Storage account.
142157
```yaml
143158
Type: String
144159
Parameter Sets: (All)
145-
Aliases:
160+
Aliases:
146161

147162
Required: True
148163
Position: 0
@@ -172,7 +187,7 @@ The Array of VirtualNetworkRule objects to add to the NetworkRule Property.
172187
```yaml
173188
Type: PSVirtualNetworkRule[]
174189
Parameter Sets: NetworkRuleObject
175-
Aliases:
190+
Aliases:
176191

177192
Required: True
178193
Position: Named
@@ -229,3 +244,4 @@ Microsoft.Azure.Commands.Management.Storage.Models.PSIpRule
229244
## NOTES
230245
231246
## RELATED LINKS
247+

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Specifies the name of the resource group that contains the Storage account to ge
8989
```yaml
9090
Type: String
9191
Parameter Sets: ResourceGroupParameterSet
92-
Aliases:
92+
Aliases:
9393

9494
Required: False
9595
Position: 0
@@ -101,7 +101,7 @@ Accept wildcard characters: False
101101
```yaml
102102
Type: String
103103
Parameter Sets: AccountNameParameterSet
104-
Aliases:
104+
Aliases:
105105

106106
Required: True
107107
Position: 0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Specifies the name of the resource group that contains the Storage account.
7777
```yaml
7878
Type: String
7979
Parameter Sets: (All)
80-
Aliases:
80+
Aliases:
8181

8282
Required: True
8383
Position: 0

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Specifies the name of the resource group contains the Storage account.
6767
```yaml
6868
Type: String
6969
Parameter Sets: (All)
70-
Aliases:
70+
Aliases:
7171

7272
Required: True
7373
Position: 0
@@ -90,3 +90,4 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
9090
## NOTES
9191
9292
## RELATED LINKS
93+

0 commit comments

Comments
 (0)