Skip to content

Commit 6aa8903

Browse files
committed
Update parameter sets for AssignIdentity.
1 parent 99fbb77 commit 6aa8903

File tree

18 files changed

+1263
-12435
lines changed

18 files changed

+1263
-12435
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineRunCommandTests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ function Test-VirtualMachineSetRunCommand
112112

113113
# Remove All VMs
114114
Get-AzureRmVM -ResourceGroupName $rgname | Remove-AzureRmVM -Force;
115+
$vms = Get-AzureRmVM -ResourceGroupName $rgname;
116+
Assert-AreEqual $vms $null;
115117
}
116118
finally
117119
{

src/ResourceManager/Compute/Commands.Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineRunCommandTests/TestVirtualMachineSetRunCommand.json

Lines changed: 1105 additions & 12346 deletions
Large diffs are not rendered by default.

src/ResourceManager/Compute/Commands.Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssConfigCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,13 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
163163

164164
[Parameter(
165165
Mandatory = false,
166+
ParameterSetName = "DefaultParameterSet",
166167
ValueFromPipelineByPropertyName = true)]
167168
public ResourceIdentityType? IdentityType { get; set; }
168169

169170
[Parameter(
170171
Mandatory = false,
172+
ParameterSetName = "DefaultParameterSet",
171173
ValueFromPipelineByPropertyName = true)]
172174
public string[] IdentityId { get; set; }
173175

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Action/RestartAzureVMCommand.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using AutoMapper;
1615
using Microsoft.Azure.Commands.Compute.Common;
1716
using Microsoft.Azure.Commands.Compute.Models;
1817
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
@@ -29,7 +28,6 @@ public class RestartAzureVMCommand : VirtualMachineBaseCmdlet
2928
protected const string RestartIdParameterSet = "RestartIdParameterSetName";
3029
protected const string PerformMaintenanceIdParameterSet = "PerformMaintenanceIdParameterSetName";
3130

32-
3331
[Parameter(
3432
Mandatory = true,
3533
Position = 0,
@@ -94,6 +92,11 @@ public override void ExecuteCmdlet()
9492
{
9593
base.ExecuteCmdlet();
9694

95+
if (this.ParameterSetName.Equals(RestartIdParameterSet) || this.ParameterSetName.Equals(PerformMaintenanceIdParameterSet))
96+
{
97+
this.ResourceGroupName = GetResourceGroupNameFromId(this.Id);
98+
}
99+
97100
if (this.PerformMaintenance.IsPresent)
98101
{
99102
ExecuteClientAction(() =>

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Action/SetAzureVMCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using AutoMapper;
1615
using Microsoft.Azure.Commands.Compute.Common;
1716
using Microsoft.Azure.Commands.Compute.Models;
1817
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
@@ -97,6 +96,11 @@ public override void ExecuteCmdlet()
9796
{
9897
base.ExecuteCmdlet();
9998

99+
if (this.ParameterSetName.Equals(GeneralizeIdParameterSet) || this.ParameterSetName.Equals(RedeployIdParameterSet))
100+
{
101+
this.ResourceGroupName = GetResourceGroupNameFromId(this.Id);
102+
}
103+
100104
if (this.Generalized.IsPresent)
101105
{
102106
ExecuteClientAction(() =>

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Action/VirtualMachineActionBaseCmdlet.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1616
using System.Management.Automation;
17-
using System.Text.RegularExpressions;
1817

1918
namespace Microsoft.Azure.Commands.Compute
2019
{
@@ -54,13 +53,5 @@ public override void ExecuteCmdlet()
5453
this.ResourceGroupName = GetResourceGroupNameFromId(this.Id);
5554
}
5655
}
57-
58-
protected string GetResourceGroupNameFromId(string idString)
59-
{
60-
var match = Regex.Match(idString, @"resourceGroups/([A-Za-z0-9\-]+)/");
61-
return (match.Success)
62-
? match.Groups[1].Value
63-
: null;
64-
}
6556
}
6657
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/NewAzureVMConfigCommand.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,24 @@ public class NewAzureVMConfigCommand : Microsoft.Azure.Commands.ResourceManager.
6161

6262
[Parameter(
6363
Position = 4,
64+
ParameterSetName = "DefaultParameterSet",
6465
ValueFromPipelineByPropertyName = false)]
6566
[ValidateNotNullOrEmpty]
6667
public ResourceIdentityType? IdentityType { get; set; }
6768

69+
[Parameter(
70+
Mandatory = false,
71+
ParameterSetName = "DefaultParameterSet",
72+
ValueFromPipelineByPropertyName = true)]
73+
public string[] IdentityId { get; set; }
74+
6875
[Parameter(
6976
Mandatory = true,
7077
ParameterSetName = "AssignIdentityParameterSet",
7178
ValueFromPipelineByPropertyName = false)]
7279
[ValidateNotNullOrEmpty]
7380
public SwitchParameter AssignIdentity { get; set; }
7481

75-
[Parameter(
76-
Mandatory = false,
77-
ValueFromPipelineByPropertyName = true)]
78-
public string[] IdentityId { get; set; }
79-
8082
[Parameter(
8183
Mandatory = false,
8284
ValueFromPipelineByPropertyName = true)]

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using AutoMapper;
1615
using Microsoft.Azure.Commands.Compute.Common;
1716
using Microsoft.Azure.Commands.Compute.Models;
17+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1818
using Microsoft.Azure.Management.Compute.Models;
1919
using System;
2020
using System.Collections;
@@ -27,8 +27,36 @@ namespace Microsoft.Azure.Commands.Compute
2727
SupportsShouldProcess = true,
2828
DefaultParameterSetName = ResourceGroupNameParameterSet)]
2929
[OutputType(typeof(PSAzureOperationResponse))]
30-
public class UpdateAzureVMCommand : VirtualMachineActionBaseCmdlet
30+
public class UpdateAzureVMCommand : VirtualMachineBaseCmdlet
3131
{
32+
private const string ResourceGroupNameParameterSet = "ResourceGroupNameParameterSetName";
33+
private const string IdParameterSet = "IdParameterSetName";
34+
private const string AssignIdentityParameterSet = "AssignIdentityParameterSet";
35+
36+
[Parameter(
37+
Mandatory = true,
38+
Position = 0,
39+
ParameterSetName = ResourceGroupNameParameterSet,
40+
ValueFromPipelineByPropertyName = true,
41+
HelpMessage = "The resource group name.")]
42+
[Parameter(
43+
Mandatory = true,
44+
Position = 0,
45+
ParameterSetName = AssignIdentityParameterSet,
46+
ValueFromPipelineByPropertyName = true,
47+
HelpMessage = "The resource group name.")]
48+
[ResourceGroupCompleter()]
49+
[ValidateNotNullOrEmpty]
50+
public string ResourceGroupName { get; set; }
51+
52+
[Parameter(
53+
Mandatory = true,
54+
Position = 0,
55+
ParameterSetName = IdParameterSet,
56+
ValueFromPipelineByPropertyName = true,
57+
HelpMessage = "The resource group name.")]
58+
public string Id { get; set; }
59+
3260
[Alias("VMProfile")]
3361
[Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
3462
[ValidateNotNullOrEmpty]
@@ -40,26 +68,45 @@ public class UpdateAzureVMCommand : VirtualMachineActionBaseCmdlet
4068
public Hashtable Tag { get; set; }
4169

4270
[Parameter(
43-
Mandatory = false,
44-
ValueFromPipelineByPropertyName = false)]
71+
Mandatory = false,
72+
ParameterSetName = ResourceGroupNameParameterSet,
73+
ValueFromPipelineByPropertyName = false)]
74+
[Parameter(
75+
Mandatory = false,
76+
ParameterSetName = IdParameterSet,
77+
ValueFromPipelineByPropertyName = false)]
4578
[ValidateNotNullOrEmpty]
4679
public ResourceIdentityType? IdentityType { get; set; }
4780

4881
[Parameter(
4982
Mandatory = false,
50-
ValueFromPipelineByPropertyName = true)]
83+
ParameterSetName = ResourceGroupNameParameterSet,
84+
ValueFromPipelineByPropertyName = false)]
85+
[Parameter(
86+
Mandatory = false,
87+
ParameterSetName = IdParameterSet,
88+
ValueFromPipelineByPropertyName = false)]
5189
public string[] IdentityId { get; set; }
5290

5391
[Parameter(
92+
Mandatory = true,
93+
ParameterSetName = AssignIdentityParameterSet,
5494
ValueFromPipelineByPropertyName = false)]
5595
[ValidateNotNullOrEmpty]
56-
[Obsolete("This parameter is obsolete. Use AssignIdentity parameter instead.", false)]
5796
public SwitchParameter AssignIdentity { get; set; }
5897

98+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
99+
public SwitchParameter AsJob { get; set; }
100+
59101
public override void ExecuteCmdlet()
60102
{
61103
base.ExecuteCmdlet();
62104

105+
if (this.ParameterSetName.Equals(IdParameterSet))
106+
{
107+
this.ResourceGroupName = GetResourceGroupNameFromId(this.Id);
108+
}
109+
63110
if (ShouldProcess(this.VM.Name, VerbsData.Update))
64111
{
65112
ExecuteClientAction(() =>

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/VirtualMachineBaseCmdlet.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System.Collections;
2222
using System.Collections.Generic;
2323
using System.Reflection;
24+
using System.Text.RegularExpressions;
2425

2526
namespace Microsoft.Azure.Commands.Compute
2627
{
@@ -66,6 +67,14 @@ public static string FormatObject(Object obj)
6667
return result;
6768
}
6869

70+
protected string GetResourceGroupNameFromId(string idString)
71+
{
72+
var match = Regex.Match(idString, @"resourceGroups/([A-Za-z0-9\-]+)/");
73+
return (match.Success)
74+
? match.Groups[1].Value
75+
: null;
76+
}
77+
6978
private static int GetTabLength(Object obj, int max, int depth, List<Tuple<string, string, int>> tupleList, bool expand = true)
7079
{
7180
var objType = obj.GetType();

src/ResourceManager/Compute/Commands.Compute/help/Add-AzureRmVMNetworkInterface.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Specifies the network interface.
9696
```yaml
9797
Type: System.Collections.Generic.List`1[Microsoft.Azure.Management.Internal.Network.Common.INetworkInterfaceReference]
9898
Parameter Sets: GetNicFromNicObject
99-
Aliases:
99+
Aliases:
100100

101101
Required: True
102102
Position: 1
@@ -111,7 +111,7 @@ Indicates that this cmdlet adds the network interface as the primary interface.
111111
```yaml
112112
Type: SwitchParameter
113113
Parameter Sets: GetNicFromNicId
114-
Aliases:
114+
Aliases:
115115

116116
Required: False
117117
Position: 2

src/ResourceManager/Compute/Commands.Compute/help/Add-AzureRmVMSecret.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ You can only specify this parameter for virtual machines that run the Windows op
6969
```yaml
7070
Type: String
7171
Parameter Sets: (All)
72-
Aliases:
72+
Aliases:
7373

7474
Required: False
7575
Position: 2
@@ -95,7 +95,7 @@ Currently, dataType accepts only .pfx files.
9595
```yaml
9696
Type: String
9797
Parameter Sets: (All)
98-
Aliases:
98+
Aliases:
9999

100100
Required: False
101101
Position: 3

src/ResourceManager/Compute/Commands.Compute/help/Add-AzureRmVmssSecret.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ This means that you can use the same value for the *SourceVaultId* parameter whe
6666
```yaml
6767
Type: String
6868
Parameter Sets: (All)
69-
Aliases:
69+
Aliases:
7070

7171
Required: False
7272
Position: 1
@@ -82,7 +82,7 @@ You can use the [New-AzureRmVmssVaultCertificateConfig](./New-AzureRmVmssVaultCe
8282
```yaml
8383
Type: VaultCertificate[]
8484
Parameter Sets: (All)
85-
Aliases:
85+
Aliases:
8686

8787
Required: False
8888
Position: 2
@@ -98,7 +98,7 @@ You can use the [New-AzureRmVmssConfig](./New-AzureRmVmssConfig.md) cmdlet to cr
9898
```yaml
9999
Type: PSVirtualMachineScaleSet
100100
Parameter Sets: (All)
101-
Aliases:
101+
Aliases:
102102

103103
Required: True
104104
Position: 0

0 commit comments

Comments
 (0)