Skip to content

Commit c4d82a3

Browse files
unknownunknown
authored andcommitted
Revert "Fix piping issue for Remove-AzureVMDataDisk"
This reverts commit 39d57bf. Conflicts: src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs
1 parent f231a6c commit c4d82a3

File tree

3 files changed

+10
-52
lines changed

3 files changed

+10
-52
lines changed

src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public string ResourceGroupName
3333
{
3434
get
3535
{
36-
if (string.IsNullOrEmpty(Id)) return null;
3736
Regex r = new Regex(@"(.*?)/resourcegroups/(?<rgname>\S+)/providers/(.*?)", RegexOptions.IgnoreCase);
3837
Match m = r.Match(Id);
3938
return m.Success ? m.Groups["rgname"].Value : null;
@@ -135,37 +134,5 @@ public string StorageProfileText
135134
{
136135
get { return JsonConvert.SerializeObject(StorageProfile, Formatting.Indented); }
137136
}
138-
139-
[JsonIgnore]
140-
public string [] DataDiskNames
141-
{
142-
get
143-
{
144-
if (this.StorageProfile == null) return null;
145-
146-
var dataDiskNames = new List<string>();
147-
foreach (var disk in StorageProfile.DataDisks)
148-
{
149-
dataDiskNames.Add(disk.Name);
150-
}
151-
return dataDiskNames.ToArray();
152-
}
153-
}
154-
155-
[JsonIgnore]
156-
public string[] NetworkInterfaceIds
157-
{
158-
get
159-
{
160-
if (this.NetworkProfile == null) return null;
161-
162-
var nicIds = new List<string>();
163-
foreach (var nic in NetworkProfile.NetworkInterfaces)
164-
{
165-
nicIds.Add(nic.ReferenceUri);
166-
}
167-
return nicIds.ToArray();
168-
}
169-
}
170137
}
171138
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ public class RemoveAzureVMDataDiskCommand : AzurePSCmdlet
3838
[ValidateNotNullOrEmpty]
3939
public PSVirtualMachine VM { get; set; }
4040

41-
[Alias("Name")]
4241
[Parameter(
4342
Mandatory = true,
4443
Position = 1,
4544
ValueFromPipelineByPropertyName = true,
4645
HelpMessage = HelpMessages.VMDataDiskName)]
4746
[ValidateNotNullOrEmpty]
48-
public string [] DataDiskNames { get; set; }
47+
public string Name { get; set; }
4948

5049
public override void ExecuteCmdlet()
5150
{
@@ -55,10 +54,7 @@ public override void ExecuteCmdlet()
5554
{
5655
var disks = storageProfile.DataDisks.ToList();
5756
var comp = StringComparison.OrdinalIgnoreCase;
58-
foreach (var diskName in DataDiskNames)
59-
{
60-
disks.RemoveAll(d => string.Equals(d.Name, diskName, comp));
61-
}
57+
disks.RemoveAll(d => string.Equals(d.Name, this.Name, comp));
6258
storageProfile.DataDisks = disks;
6359
}
6460

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,30 @@ public class RemoveAzureVMNetworkInterfaceCommand : AzurePSCmdlet
4141
[ValidateNotNullOrEmpty]
4242
public PSVirtualMachine VM { get; set; }
4343

44-
[Alias("Id", "NicIds")]
44+
[Alias("NicId", "NetworkInterfaceId")]
4545
[Parameter(
4646
Mandatory = true,
4747
Position = 1,
4848
ValueFromPipelineByPropertyName = true,
4949
HelpMessage = HelpMessages.VMNetworkInterfaceID)]
5050
[ValidateNotNullOrEmpty]
51-
public string[] NetworkInterfaceIds { get; set; }
51+
public string Id { get; set; }
5252

5353
public override void ExecuteCmdlet()
5454
{
5555
var networkProfile = this.VM.NetworkProfile;
5656

57-
foreach (var id in this.NetworkInterfaceIds)
57+
if (networkProfile != null && networkProfile.NetworkInterfaces != null && networkProfile.NetworkInterfaces.Any(nic => string.Equals(nic.ReferenceUri, this.Id, StringComparison.OrdinalIgnoreCase)))
5858
{
59-
if (networkProfile != null &&
60-
networkProfile.NetworkInterfaces != null &&
61-
networkProfile.NetworkInterfaces.Any(nic =>
62-
string.Equals(nic.ReferenceUri, id, StringComparison.OrdinalIgnoreCase)))
59+
var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.ReferenceUri, this.Id, StringComparison.OrdinalIgnoreCase));
60+
networkProfile.NetworkInterfaces.Remove(nicReference);
61+
62+
if (!networkProfile.NetworkInterfaces.Any())
6363
{
64-
var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.ReferenceUri, id, StringComparison.OrdinalIgnoreCase));
65-
networkProfile.NetworkInterfaces.Remove(nicReference);
64+
networkProfile = null;
6665
}
6766
}
6867

69-
if (!networkProfile.NetworkInterfaces.Any())
70-
{
71-
networkProfile = null;
72-
}
7368
this.VM.NetworkProfile = networkProfile;
7469

7570
WriteObject(this.VM);

0 commit comments

Comments
 (0)