Skip to content

Commit 768d789

Browse files
committed
Merge pull request #438 from hyonholee/dev3
Reverting the fix for piping issue
2 parents e8e0578 + 5978c66 commit 768d789

File tree

5 files changed

+13
-92
lines changed

5 files changed

+13
-92
lines changed

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

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,14 @@ function Test-VirtualMachineProfile
2626

2727
# Network
2828
$ipname = 'hpfip' + ((Get-Random) % 10000);
29-
$ipRefUri1 = "https://test.foo.bar/$ipname";
29+
$ipRefUri = "https://test.foo.bar/$ipname";
3030
$nicName = $ipname + 'nic1';
3131
$publicIPName = $ipname + 'name1';
3232

33-
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri1;
34-
35-
$ipname = 'hpfip' + ((Get-Random) % 10000);
36-
$ipRefUri2 = "https://test.foo.bar/$ipname";
37-
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri2;
38-
39-
# Remove all NICs
40-
$p = $p | Remove-AzureVMNetworkInterface
41-
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 0;
42-
43-
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri1;
44-
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri2;
45-
$p = Remove-AzureVMNetworkInterface -VM $p -Id $ipRefUri2;
33+
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri;
4634

4735
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
48-
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $ipRefUri1;
36+
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $ipRefUri;
4937

5038
# Storage
5139
$stoname = 'hpfteststo' + ((Get-Random) % 10000);
@@ -78,23 +66,6 @@ function Test-VirtualMachineProfile
7866
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1;
7967
Assert-AreEqual $p.StorageProfile.DataDisks[1].VirtualHardDisk.Uri $dataDiskVhdUri2;
8068

81-
# Remove all data disks
82-
$p = $p | Remove-AzureVMDataDisk;
83-
Assert-AreEqual $p.StorageProfile.DataDisks.Count 0;
84-
85-
$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
86-
$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $dataDiskVhdUri2 -CreateOption Empty;
87-
88-
Assert-AreEqual $p.StorageProfile.DataDisks.Count 2;
89-
Assert-AreEqual $p.StorageProfile.DataDisks[0].Caching 'ReadOnly';
90-
Assert-AreEqual $p.StorageProfile.DataDisks[0].DiskSizeGB 10;
91-
Assert-AreEqual $p.StorageProfile.DataDisks[0].Lun 0;
92-
Assert-AreEqual $p.StorageProfile.DataDisks[0].VirtualHardDisk.Uri $dataDiskVhdUri1;
93-
Assert-AreEqual $p.StorageProfile.DataDisks[1].Caching 'ReadOnly';
94-
Assert-AreEqual $p.StorageProfile.DataDisks[1].DiskSizeGB 11;
95-
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1;
96-
Assert-AreEqual $p.StorageProfile.DataDisks[1].VirtualHardDisk.Uri $dataDiskVhdUri2;
97-
9869
# Windows OS
9970
$user = "Foo12";
10071
$password = 'BaR@000' + ((Get-Random) % 10000);

src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.format.generated.ps1xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,6 @@
214214
<Label>StorageProfile</Label>
215215
<PropertyName>StorageProfileText</PropertyName>
216216
</ListItem>
217-
<ListItem>
218-
<Label>DataDiskNames</Label>
219-
<PropertyName>DataDiskNames</PropertyName>
220-
</ListItem>
221-
<ListItem>
222-
<Label>NetworkInterfaceIds</Label>
223-
<PropertyName>NetworkInterfaceIds</PropertyName>
224-
</ListItem>
225217
</ListItems>
226218
</ListEntry>
227219
</ListEntries>

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)