diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1 index 35afc93066e5..a094f1351bc5 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1 @@ -26,26 +26,14 @@ function Test-VirtualMachineProfile # Network $ipname = 'hpfip' + ((Get-Random) % 10000); - $ipRefUri1 = "https://test.foo.bar/$ipname"; + $ipRefUri = "https://test.foo.bar/$ipname"; $nicName = $ipname + 'nic1'; $publicIPName = $ipname + 'name1'; - $p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri1; - - $ipname = 'hpfip' + ((Get-Random) % 10000); - $ipRefUri2 = "https://test.foo.bar/$ipname"; - $p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri2; - - # Remove all NICs - $p = $p | Remove-AzureVMNetworkInterface - Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 0; - - $p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri1; - $p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri2; - $p = Remove-AzureVMNetworkInterface -VM $p -Id $ipRefUri2; + $p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri; Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1; - Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $ipRefUri1; + Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $ipRefUri; # Storage $stoname = 'hpfteststo' + ((Get-Random) % 10000); @@ -78,23 +66,6 @@ function Test-VirtualMachineProfile Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1; Assert-AreEqual $p.StorageProfile.DataDisks[1].VirtualHardDisk.Uri $dataDiskVhdUri2; - # Remove all data disks - $p = $p | Remove-AzureVMDataDisk; - Assert-AreEqual $p.StorageProfile.DataDisks.Count 0; - - $p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri $dataDiskVhdUri1 -CreateOption Empty; - $p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $dataDiskVhdUri2 -CreateOption Empty; - - Assert-AreEqual $p.StorageProfile.DataDisks.Count 2; - Assert-AreEqual $p.StorageProfile.DataDisks[0].Caching 'ReadOnly'; - Assert-AreEqual $p.StorageProfile.DataDisks[0].DiskSizeGB 10; - Assert-AreEqual $p.StorageProfile.DataDisks[0].Lun 0; - Assert-AreEqual $p.StorageProfile.DataDisks[0].VirtualHardDisk.Uri $dataDiskVhdUri1; - Assert-AreEqual $p.StorageProfile.DataDisks[1].Caching 'ReadOnly'; - Assert-AreEqual $p.StorageProfile.DataDisks[1].DiskSizeGB 11; - Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1; - Assert-AreEqual $p.StorageProfile.DataDisks[1].VirtualHardDisk.Uri $dataDiskVhdUri2; - # Windows OS $user = "Foo12"; $password = 'BaR@000' + ((Get-Random) % 10000); diff --git a/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.format.generated.ps1xml b/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.format.generated.ps1xml index c79e0451f380..e5d31fb83a4f 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.format.generated.ps1xml +++ b/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.format.generated.ps1xml @@ -214,14 +214,6 @@ StorageProfileText - - - DataDiskNames - - - - NetworkInterfaceIds - diff --git a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs index 567609e3a15a..ad992f937933 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs @@ -33,7 +33,6 @@ public string ResourceGroupName { get { - if (string.IsNullOrEmpty(Id)) return null; Regex r = new Regex(@"(.*?)/resourcegroups/(?\S+)/providers/(.*?)", RegexOptions.IgnoreCase); Match m = r.Match(Id); return m.Success ? m.Groups["rgname"].Value : null; @@ -135,37 +134,5 @@ public string StorageProfileText { get { return JsonConvert.SerializeObject(StorageProfile, Formatting.Indented); } } - - [JsonIgnore] - public string [] DataDiskNames - { - get - { - if (this.StorageProfile == null) return null; - - var dataDiskNames = new List(); - foreach (var disk in StorageProfile.DataDisks) - { - dataDiskNames.Add(disk.Name); - } - return dataDiskNames.ToArray(); - } - } - - [JsonIgnore] - public string[] NetworkInterfaceIds - { - get - { - if (this.NetworkProfile == null) return null; - - var nicIds = new List(); - foreach (var nic in NetworkProfile.NetworkInterfaces) - { - nicIds.Add(nic.ReferenceUri); - } - return nicIds.ToArray(); - } - } } } diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMDataDiskCommand.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMDataDiskCommand.cs index cb1ded572da9..ee266482c8ce 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMDataDiskCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMDataDiskCommand.cs @@ -38,14 +38,13 @@ public class RemoveAzureVMDataDiskCommand : AzurePSCmdlet [ValidateNotNullOrEmpty] public PSVirtualMachine VM { get; set; } - [Alias("Name")] [Parameter( Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.VMDataDiskName)] [ValidateNotNullOrEmpty] - public string [] DataDiskNames { get; set; } + public string Name { get; set; } public override void ExecuteCmdlet() { @@ -55,10 +54,7 @@ public override void ExecuteCmdlet() { var disks = storageProfile.DataDisks.ToList(); var comp = StringComparison.OrdinalIgnoreCase; - foreach (var diskName in DataDiskNames) - { - disks.RemoveAll(d => string.Equals(d.Name, diskName, comp)); - } + disks.RemoveAll(d => string.Equals(d.Name, this.Name, comp)); storageProfile.DataDisks = disks; } diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs index c4bcd1c44265..f3cae6436a86 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs @@ -41,35 +41,30 @@ public class RemoveAzureVMNetworkInterfaceCommand : AzurePSCmdlet [ValidateNotNullOrEmpty] public PSVirtualMachine VM { get; set; } - [Alias("Id", "NicIds")] + [Alias("NicId", "NetworkInterfaceId")] [Parameter( Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.VMNetworkInterfaceID)] [ValidateNotNullOrEmpty] - public string[] NetworkInterfaceIds { get; set; } + public string Id { get; set; } public override void ExecuteCmdlet() { var networkProfile = this.VM.NetworkProfile; - foreach (var id in this.NetworkInterfaceIds) + if (networkProfile != null && networkProfile.NetworkInterfaces != null && networkProfile.NetworkInterfaces.Any(nic => string.Equals(nic.ReferenceUri, this.Id, StringComparison.OrdinalIgnoreCase))) { - if (networkProfile != null && - networkProfile.NetworkInterfaces != null && - networkProfile.NetworkInterfaces.Any(nic => - string.Equals(nic.ReferenceUri, id, StringComparison.OrdinalIgnoreCase))) + var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.ReferenceUri, this.Id, StringComparison.OrdinalIgnoreCase)); + networkProfile.NetworkInterfaces.Remove(nicReference); + + if (!networkProfile.NetworkInterfaces.Any()) { - var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.ReferenceUri, id, StringComparison.OrdinalIgnoreCase)); - networkProfile.NetworkInterfaces.Remove(nicReference); + networkProfile = null; } } - if (!networkProfile.NetworkInterfaces.Any()) - { - networkProfile = null; - } this.VM.NetworkProfile = networkProfile; WriteObject(this.VM);