From 7edfeeeb97dccb7036f404cb61a5034a9c28b44d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 May 2015 23:21:23 -0700 Subject: [PATCH 1/7] Add Force parameter to Remove-AzureAvailabilitySet --- .../ScenarioTests/AvailabilitySetTests.ps1 | 4 +++- .../RemoveAzureAvailabilitySetCommand.cs | 16 +++++++++++++--- .../Properties/Resources.Designer.cs | 18 ++++++++++++++++++ .../Commands.Compute/Properties/Resources.resx | 6 ++++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AvailabilitySetTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AvailabilitySetTests.ps1 index 2df972e56a33..89a4fbfe6149 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AvailabilitySetTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AvailabilitySetTests.ps1 @@ -43,7 +43,9 @@ function Test-AvailabilitySet Assert-AreEqual $aset.PlatformUpdateDomainCount $nonDefaultUD; Assert-AreEqual $aset.PlatformFaultDomainCount $nonDefaultFD; - Remove-AzureAvailabilitySet -ResourceGroupName $rgname -Name $asetName; + Assert-ThrowsContains { Remove-AzureAvailabilitySet -ResourceGroupName $rgname -Name $asetName; } "This cmdlet will remove the specified availability set. Do you want to continue?" + + Remove-AzureAvailabilitySet -ResourceGroupName $rgname -Name $asetName -Force; $asets = Get-AzureAvailabilitySet -ResourceGroupName $rgname; Assert-AreEqual $asets $null; diff --git a/src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs b/src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs index b61ab1473155..0951913d6320 100644 --- a/src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs @@ -37,13 +37,23 @@ public class RemoveAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet [ValidateNotNullOrEmpty] public string Name { get; set; } + [Parameter( + Position = 2, + HelpMessage = "To force the removal.")] + [ValidateNotNullOrEmpty] + public SwitchParameter Force { get; set; } + public override void ExecuteCmdlet() { base.ExecuteCmdlet(); - var op = this.AvailabilitySetClient.Delete(this.ResourceGroupName, this.Name); - - WriteObject(op); + if (this.Force.IsPresent + || this.ShouldContinue(Properties.Resources.AvailabilitySetRemovalConfirmation, + Properties.Resources.AvailabilitySetRemovalCaption)) + { + var op = this.AvailabilitySetClient.Delete(this.ResourceGroupName, this.Name); + WriteObject(op); + } } } } diff --git a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs index c7605bac79fa..230e4a350c03 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs @@ -60,6 +60,24 @@ internal Resources() { } } + /// + /// Looks up a localized string similar to Availability set removal operation. + /// + public static string AvailabilitySetRemovalCaption { + get { + return ResourceManager.GetString("AvailabilitySetRemovalCaption", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to This cmdlet will remove the specified availability set. Do you want to continue?. + /// + public static string AvailabilitySetRemovalConfirmation { + get { + return ResourceManager.GetString("AvailabilitySetRemovalConfirmation", resourceCulture); + } + } + /// /// Looks up a localized string similar to Cannot specify both Windows and Linux configurations.. /// diff --git a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx index c14a2af5faf2..ed628b2289c2 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx +++ b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx @@ -117,6 +117,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Availability set removal operation + + + This cmdlet will remove the specified availability set. Do you want to continue? + Cannot specify both Windows and Linux configurations. From 58fcb412e284b1e2c64c32851fd2ecab716d0ce5 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 May 2015 23:26:17 -0700 Subject: [PATCH 2/7] Combine Get-AzureVMImage and Get-AzureVMImageDetail cmdlets Combine Get-AzureVMExtensionImage and Get-AzureVMExtensionImageDetail --- .../ScenarioTests/VirtualMachineTests.ps1 | 3 +- .../GetAzureVMExtensionImageCommand.cs | 100 +++++++++---- .../Images/GetAzureVMImageCommand.cs | 137 ++++++++++++++---- .../Images/GetAzureVMImageDetailCommand.cs | 9 +- .../Models/PSVirtualMachineImage.cs | 2 - 5 files changed, 186 insertions(+), 65 deletions(-) diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 index 268994d5a1b6..436155cbe30b 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 @@ -260,7 +260,8 @@ function Test-VirtualMachineImageList foreach ($ver in $versions) { if ($ver -eq $null -or $ver -eq '') { continue; } - $s6 = Get-AzureVMImageDetail -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -Version $ver; + #$s6 = Get-AzureVMImageDetail -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -Version $ver; + $s6 = Get-AzureVMImage -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -Version $ver; Assert-NotNull $s6; $s6; diff --git a/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs b/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs index fc142923423f..806766de0c46 100644 --- a/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs @@ -21,10 +21,18 @@ namespace Microsoft.Azure.Commands.Compute { - [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineExtensionImage)] - [OutputType(typeof(PSVirtualMachineExtensionImage))] + [Cmdlet(VerbsCommon.Get, + ProfileNouns.VirtualMachineExtensionImage, + DefaultParameterSetName = ListVMImageExtensionParamSetName)] + [OutputType(typeof(PSVirtualMachineExtensionImage), + ParameterSetName = new[] { ListVMImageExtensionParamSetName })] + [OutputType(typeof(PSVirtualMachineExtensionImageDetails), + ParameterSetName = new[] { GetVMImageExtensionDetailParamSetName })] public class GetAzureVMExtensionImageCommand : VirtualMachineExtensionImageBaseCmdlet { + protected const string ListVMImageExtensionParamSetName = "ListVMImageExtension"; + protected const string GetVMImageExtensionDetailParamSetName = "GetVMImageExtensionDetail"; + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] public string Location { get; set; } @@ -37,34 +45,76 @@ public class GetAzureVMExtensionImageCommand : VirtualMachineExtensionImageBaseC [Parameter, ValidateNotNullOrEmpty] public string FilterExpression { get; set; } + [Parameter(ParameterSetName = GetVMImageExtensionDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true), + ValidateNotNullOrEmpty] + public string Version { get; set; } + public override void ExecuteCmdlet() { base.ExecuteCmdlet(); - var parameters = new VirtualMachineExtensionImageListVersionsParameters + if (this.PagingParameters.Equals(ListVMImageExtensionParamSetName)) + { + var parameters = new VirtualMachineExtensionImageListVersionsParameters + { + Location = Location.Canonicalize(), + PublisherName = PublisherName, + Type = Type, + FilterExpression = FilterExpression + }; + + VirtualMachineImageResourceList result = this.VirtualMachineExtensionImageClient.ListVersions(parameters); + + var images = from r in result.Resources + select new PSVirtualMachineExtensionImage + { + RequestId = result.RequestId, + StatusCode = result.StatusCode, + Id = r.Id, + Location = r.Location, + Version = r.Name, + PublisherName = this.PublisherName, + Type = this.Type, + FilterExpression = this.FilterExpression + }; + + WriteObject(images, true); + } + else { - Location = Location.Canonicalize(), - PublisherName = PublisherName, - Type = Type, - FilterExpression = FilterExpression - }; - - VirtualMachineImageResourceList result = this.VirtualMachineExtensionImageClient.ListVersions(parameters); - - var images = from r in result.Resources - select new PSVirtualMachineExtensionImage - { - RequestId = result.RequestId, - StatusCode = result.StatusCode, - Id = r.Id, - Location = r.Location, - Version = r.Name, - PublisherName = this.PublisherName, - Type = this.Type, - FilterExpression = this.FilterExpression - }; - - WriteObject(images, true); + + var parameters = new VirtualMachineExtensionImageGetParameters + { + Location = Location.Canonicalize(), + PublisherName = PublisherName, + Type = Type, + FilterExpression = FilterExpression, + Version = Version + }; + + VirtualMachineExtensionImageGetResponse result = this.VirtualMachineExtensionImageClient.Get(parameters); + + var image = new PSVirtualMachineExtensionImageDetails + { + RequestId = result.RequestId, + StatusCode = result.StatusCode, + Id = result.VirtualMachineExtensionImage.Id, + Location = result.VirtualMachineExtensionImage.Location, + Name = result.VirtualMachineExtensionImage.Name, + HandlerSchema = result.VirtualMachineExtensionImage.HandlerSchema, + OperatingSystem = result.VirtualMachineExtensionImage.OperatingSystem, + ComputeRole = result.VirtualMachineExtensionImage.ComputeRole, + SupportsMultipleExtensions = result.VirtualMachineExtensionImage.SupportsMultipleExtensions, + VMScaleSetEnabled = result.VirtualMachineExtensionImage.VMScaleSetEnabled, + PublisherName = this.PublisherName, + Type = this.Type, + Version = this.Version + }; + + WriteObject(image); + } } } } diff --git a/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageCommand.cs b/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageCommand.cs index 68a1454a256c..d4158110aeda 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageCommand.cs @@ -21,55 +21,128 @@ namespace Microsoft.Azure.Commands.Compute { - [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineImage)] - [OutputType(typeof(PSVirtualMachineImage))] + [Cmdlet(VerbsCommon.Get, + ProfileNouns.VirtualMachineImage, + DefaultParameterSetName = ListVMImageParamSetName)] + [OutputType(typeof(PSVirtualMachineImage), + ParameterSetName = new [] {ListVMImageParamSetName})] + [OutputType(typeof(PSVirtualMachineImageDetail), + ParameterSetName = new [] {GetVMImageDetailParamSetName})] public class GetAzureVMImageCommand : VirtualMachineImageBaseCmdlet { - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + protected const string ListVMImageParamSetName = "ListVMImage"; + protected const string GetVMImageDetailParamSetName = "GetVMImageDetail"; + + [Parameter(ParameterSetName = ListVMImageParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = GetVMImageDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] public string Location { get; set; } - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + [Parameter(ParameterSetName = ListVMImageParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = GetVMImageDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] public string PublisherName { get; set; } - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + [Parameter(ParameterSetName = ListVMImageParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = GetVMImageDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] public string Offer { get; set; } - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] + [Parameter(ParameterSetName = ListVMImageParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = GetVMImageDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] public string Skus { get; set; } - [Parameter, ValidateNotNullOrEmpty] + [Parameter(ParameterSetName = ListVMImageParamSetName, + ValueFromPipelineByPropertyName = true), + ValidateNotNullOrEmpty] public string FilterExpression { get; set; } + [Parameter(ParameterSetName = GetVMImageDetailParamSetName, + Mandatory = true, + ValueFromPipelineByPropertyName = true), + ValidateNotNullOrEmpty] + public string Version { get; set; } + public override void ExecuteCmdlet() { base.ExecuteCmdlet(); - var parameters = new VirtualMachineImageListParameters + if (this.ParameterSetName.Equals(ListVMImageParamSetName)) { - Location = Location.Canonicalize(), - Offer = Offer, - PublisherName = PublisherName, - Skus = Skus, - FilterExpression = FilterExpression - }; - - VirtualMachineImageResourceList result = this.VirtualMachineImageClient.List(parameters); - - var images = from r in result.Resources - select new PSVirtualMachineImage - { - RequestId = result.RequestId, - StatusCode = result.StatusCode, - Id = r.Id, - Location = r.Location, - Version = r.Name, - PublisherName = this.PublisherName, - Offer = this.Offer, - Skus = this.Skus, - FilterExpression = this.FilterExpression - }; - - WriteObject(images, true); + var parameters = new VirtualMachineImageListParameters + { + Location = Location.Canonicalize(), + Offer = Offer, + PublisherName = PublisherName, + Skus = Skus, + FilterExpression = FilterExpression + }; + + VirtualMachineImageResourceList result = this.VirtualMachineImageClient.List(parameters); + + var images = from r in result.Resources + select new PSVirtualMachineImage + { + RequestId = result.RequestId, + StatusCode = result.StatusCode, + Id = r.Id, + Location = r.Location, + Version = r.Name, + PublisherName = this.PublisherName, + Offer = this.Offer, + Skus = this.Skus, + FilterExpression = this.FilterExpression + }; + + WriteObject(images, true); + } + else + { + var parameters = new VirtualMachineImageGetParameters + { + Location = Location.Canonicalize(), + PublisherName = PublisherName, + Offer = Offer, + Skus = Skus, + Version = Version + }; + + VirtualMachineImageGetResponse response = this.VirtualMachineImageClient.Get(parameters); + + var image = new PSVirtualMachineImageDetail + { + RequestId = response.RequestId, + StatusCode = response.StatusCode, + Id = response.VirtualMachineImage.Id, + Location = response.VirtualMachineImage.Location, + Version = response.VirtualMachineImage.Name, + PublisherName = this.PublisherName, + Offer = this.Offer, + Skus = this.Skus, + OSDiskImage = response.VirtualMachineImage.OSDiskImage, + DataDiskImages = response.VirtualMachineImage.DataDiskImages, + PurchasePlan = response.VirtualMachineImage.PurchasePlan, + }; + + WriteObject(image); + } } } } diff --git a/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageDetailCommand.cs b/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageDetailCommand.cs index 867c6640f71c..ef3cf2dddbc4 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageDetailCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageDetailCommand.cs @@ -61,14 +61,13 @@ public override void ExecuteCmdlet() StatusCode = response.StatusCode, Id = response.VirtualMachineImage.Id, Location = response.VirtualMachineImage.Location, - Name = response.VirtualMachineImage.Name, - OSDiskImage = response.VirtualMachineImage.OSDiskImage, - DataDiskImages = response.VirtualMachineImage.DataDiskImages, - PurchasePlan = response.VirtualMachineImage.PurchasePlan, + Version = response.VirtualMachineImage.Name, PublisherName = this.PublisherName, Offer = this.Offer, Skus = this.Skus, - Version = this.Version + OSDiskImage = response.VirtualMachineImage.OSDiskImage, + DataDiskImages = response.VirtualMachineImage.DataDiskImages, + PurchasePlan = response.VirtualMachineImage.PurchasePlan, }; WriteObject(image); diff --git a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachineImage.cs b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachineImage.cs index 7687533ce7e3..675559e88694 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachineImage.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachineImage.cs @@ -49,8 +49,6 @@ public class PSVirtualMachineImage : PSVirtualMachineImageSku public class PSVirtualMachineImageDetail : PSVirtualMachineImage { - public string Name { get; set; } - public OSDiskImage OSDiskImage { get; set; } public PurchasePlan PurchasePlan { get; set; } From 39d57bf4e2dd7f740692ff9cbdf7520cabae8d5a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 May 2015 23:29:00 -0700 Subject: [PATCH 3/7] Fix piping issue for Remove-AzureVMDataDisk and Remove-AzureVMNetworkInterface --- .../Models/PSVirtualMachine.cs | 33 +++++++++++++++++++ .../Config/RemoveAzureVMDataDiskCommand.cs | 8 +++-- .../RemoveAzureVMNetworkInterfaceCommand.cs | 21 +++++++----- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs index ad992f937933..4a4a9187113c 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs @@ -33,6 +33,7 @@ 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; @@ -134,5 +135,37 @@ 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[] NicIds + { + 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 ee266482c8ce..cb1ded572da9 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMDataDiskCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMDataDiskCommand.cs @@ -38,13 +38,14 @@ 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 Name { get; set; } + public string [] DataDiskNames { get; set; } public override void ExecuteCmdlet() { @@ -54,7 +55,10 @@ public override void ExecuteCmdlet() { var disks = storageProfile.DataDisks.ToList(); var comp = StringComparison.OrdinalIgnoreCase; - disks.RemoveAll(d => string.Equals(d.Name, this.Name, comp)); + foreach (var diskName in DataDiskNames) + { + disks.RemoveAll(d => string.Equals(d.Name, diskName, 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 f3cae6436a86..61c0b9a5420c 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs @@ -41,30 +41,35 @@ public class RemoveAzureVMNetworkInterfaceCommand : AzurePSCmdlet [ValidateNotNullOrEmpty] public PSVirtualMachine VM { get; set; } - [Alias("NicId", "NetworkInterfaceId")] + [Alias("Id", "NetworkInterfaceId")] [Parameter( Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.VMNetworkInterfaceID)] [ValidateNotNullOrEmpty] - public string Id { get; set; } + public string [] NicIds { get; set; } public override void ExecuteCmdlet() { var networkProfile = this.VM.NetworkProfile; - if (networkProfile != null && networkProfile.NetworkInterfaces != null && networkProfile.NetworkInterfaces.Any(nic => string.Equals(nic.ReferenceUri, this.Id, StringComparison.OrdinalIgnoreCase))) + foreach (var id in this.NicIds) { - var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.ReferenceUri, this.Id, StringComparison.OrdinalIgnoreCase)); - networkProfile.NetworkInterfaces.Remove(nicReference); - - if (!networkProfile.NetworkInterfaces.Any()) + if (networkProfile != null && + networkProfile.NetworkInterfaces != null && + networkProfile.NetworkInterfaces.Any(nic => + string.Equals(nic.ReferenceUri, id, StringComparison.OrdinalIgnoreCase))) { - networkProfile = null; + var nicReference = networkProfile.NetworkInterfaces.First(nic => string.Equals(nic.ReferenceUri, id, StringComparison.OrdinalIgnoreCase)); + networkProfile.NetworkInterfaces.Remove(nicReference); } } + if (!networkProfile.NetworkInterfaces.Any()) + { + networkProfile = null; + } this.VM.NetworkProfile = networkProfile; WriteObject(this.VM); From 9f910dd574122c23ec2be7c13b54e283ecfff883 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 22 May 2015 03:37:28 -0700 Subject: [PATCH 4/7] Fix for combining image and imagedetails --- .../ScenarioTests/ComputeTestCommon.ps1 | 2 +- .../ScenarioTests/VirtualMachineTests.ps1 | 25 +++++++++---------- .../GetAzureVMExtensionImageCommand.cs | 18 +++---------- .../GetAzureVMExtensionImageDetailCommand.cs | 2 ++ .../Images/GetAzureVMImageCommand.cs | 6 ++--- .../Images/GetAzureVMImageDetailCommand.cs | 11 +++++--- .../Models/PSVirtualMachineImage.cs | 2 ++ .../Properties/Resources.Designer.cs | 18 +++++++++++++ .../Properties/Resources.resx | 6 +++++ 9 files changed, 55 insertions(+), 35 deletions(-) diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ComputeTestCommon.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ComputeTestCommon.ps1 index 90abbbb09ee6..5411137fed4c 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ComputeTestCommon.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ComputeTestCommon.ps1 @@ -211,7 +211,7 @@ function Get-DefaultCRPImage $defaultVersion = $result[0]; } - $vmimg = Get-AzureVMImageDetail -Location $loc -Offer $defaultOffer -PublisherName $defaultPublisher -Skus $defaultSku -Version $defaultVersion; + $vmimg = Get-AzureVMImage -Location $loc -Offer $defaultOffer -PublisherName $defaultPublisher -Skus $defaultSku -Version $defaultVersion; return $vmimg; } diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 index b723cc3f89e2..11f4adf28017 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 @@ -252,16 +252,15 @@ function Test-VirtualMachineImageList { $versions = $s4 | select -ExpandProperty Version; - $s6 = Get-AzureVMImage -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -FilterExpression ('name -eq *'); - Assert-NotNull $s6; - Assert-NotNull $s6.Count -gt 0; - $verNames = $s6 | select -ExpandProperty Version; + $s5 = Get-AzureVMImage -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -FilterExpression ('name -eq *'); + Assert-NotNull $s5; + Assert-NotNull $s5.Count -gt 0; + $verNames = $s5 | select -ExpandProperty Version; foreach ($ver in $versions) { if ($ver -eq $null -or $ver -eq '') { continue; } - #$s6 = Get-AzureVMImageDetail -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -Version $ver; - $s6 = Get-AzureVMImage -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -Version $ver; + $s6 = Get-AzureVMImage -Location $locStr -PublisherName $pub -Offer $offer -Sku $sku -Version $ver; Assert-NotNull $s6; $s6; @@ -300,7 +299,7 @@ function Test-VirtualMachineImageList $versions = $s2 | select -ExpandProperty Version; foreach ($ver in $versions) { - $s3 = Get-AzureVMExtensionImageDetail -Location $locStr -PublisherName $pub -Type $type -Version $ver -FilterExpression '*'; + $s3 = Get-AzureVMExtensionImage -Location $locStr -PublisherName $pub -Type $type -Version $ver -FilterExpression '*'; Assert-NotNull $s3; Assert-True { $s3.Version -eq $ver; } @@ -317,11 +316,11 @@ function Test-VirtualMachineImageList # Test Piping $pubNameFilter = '*Microsoft*Windows*Server*'; - $imgs = Get-AzureVMImagePublisher -Location $locStr | where { $_.PublisherName -like $pubNameFilter } | Get-AzureVMImageOffer | Get-AzureVMImageSku | Get-AzureVMImage | Get-AzureVMImageDetail; + $imgs = Get-AzureVMImagePublisher -Location $locStr | where { $_.PublisherName -like $pubNameFilter } | Get-AzureVMImageOffer | Get-AzureVMImageSku | Get-AzureVMImage | Get-AzureVMImage; Assert-True { $imgs.Count -gt 0 }; $pubNameFilter = '*Microsoft.Compute*'; - $extimgs = Get-AzureVMImagePublisher -Location $locStr | where { $_.PublisherName -like $pubNameFilter } | Get-AzureVMExtensionImageType | Get-AzureVMExtensionImage | Get-AzureVMExtensionImageDetail; + $extimgs = Get-AzureVMImagePublisher -Location $locStr | where { $_.PublisherName -like $pubNameFilter } | Get-AzureVMExtensionImageType | Get-AzureVMExtensionImage | Get-AzureVMExtensionImage; Assert-True { $extimgs.Count -gt 0 }; # Negative Tests @@ -342,12 +341,12 @@ function Test-VirtualMachineImageList Assert-ThrowsContains { $s5 = Get-AzureVMImage -Location $locStr -PublisherName $publisherName -Offer $offerName -Skus $skusName -FilterExpression $filter; } "was not found"; $version = '1.0.0'; - Assert-ThrowsContains { $s6 = Get-AzureVMImageDetail -Location $locStr -PublisherName $publisherName -Offer $offerName -Skus $skusName -Version $version; } "was not found"; + Assert-ThrowsContains { $s6 = Get-AzureVMImage -Location $locStr -PublisherName $publisherName -Offer $offerName -Skus $skusName -Version $version; } "was not found"; # Extension Images $type = Get-ComputeTestResourceName; - Assert-ThrowsContains { $s7 = Get-AzureVMExtensionImageDetail -Location $locStr -PublisherName $publisherName -Type $type -FilterExpression $filter -Version $version; } "was not found"; - + Assert-ThrowsContains { $s7 = Get-AzureVMExtensionImage -Location $locStr -PublisherName $publisherName -Type $type -FilterExpression $filter -Version $version; } "was not found"; + Assert-ThrowsContains { $s8 = Get-AzureVMExtensionImageType -Location $locStr -PublisherName $publisherName; } "was not found"; Assert-ThrowsContains { $s9 = Get-AzureVMExtensionImage -Location $locStr -PublisherName $publisherName -Type $type -FilterExpression $filter; } "was not found"; @@ -988,7 +987,7 @@ function Test-VirtualMachinePlan2 $vmmImgOfferName = 'a10-vthunder-adc'; $vmmImgSkusName = 'vthunder_byol'; $vmmImgVerName = '1.0.0'; - $imgRef = Get-AzureVMImageDetail -PublisherName $vmmImgPubName -Location $loc -Offer $vmmImgOfferName -Skus $vmmImgSkusName -Version $vmmImgVerName; + $imgRef = Get-AzureVMImage -PublisherName $vmmImgPubName -Location $loc -Offer $vmmImgOfferName -Skus $vmmImgSkusName -Version $vmmImgVerName; $plan = $imgRef.PurchasePlan; $p = Set-AzureVMSourceImage -VM $p -PublisherName $imgRef.PublisherName -Offer $imgRef.Offer -Skus $imgRef.Skus -Version $imgRef.Version; $p.Plan = New-Object Microsoft.Azure.Management.Compute.Models.Plan; diff --git a/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs b/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs index 806766de0c46..4bbb0241c38e 100644 --- a/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs @@ -22,17 +22,10 @@ namespace Microsoft.Azure.Commands.Compute { [Cmdlet(VerbsCommon.Get, - ProfileNouns.VirtualMachineExtensionImage, - DefaultParameterSetName = ListVMImageExtensionParamSetName)] - [OutputType(typeof(PSVirtualMachineExtensionImage), - ParameterSetName = new[] { ListVMImageExtensionParamSetName })] - [OutputType(typeof(PSVirtualMachineExtensionImageDetails), - ParameterSetName = new[] { GetVMImageExtensionDetailParamSetName })] + ProfileNouns.VirtualMachineExtensionImage)] + [OutputType(typeof(PSVirtualMachineExtensionImageDetails))] public class GetAzureVMExtensionImageCommand : VirtualMachineExtensionImageBaseCmdlet { - protected const string ListVMImageExtensionParamSetName = "ListVMImageExtension"; - protected const string GetVMImageExtensionDetailParamSetName = "GetVMImageExtensionDetail"; - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] public string Location { get; set; } @@ -45,17 +38,14 @@ public class GetAzureVMExtensionImageCommand : VirtualMachineExtensionImageBaseC [Parameter, ValidateNotNullOrEmpty] public string FilterExpression { get; set; } - [Parameter(ParameterSetName = GetVMImageExtensionDetailParamSetName, - Mandatory = true, - ValueFromPipelineByPropertyName = true), - ValidateNotNullOrEmpty] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true)] public string Version { get; set; } public override void ExecuteCmdlet() { base.ExecuteCmdlet(); - if (this.PagingParameters.Equals(ListVMImageExtensionParamSetName)) + if (string.IsNullOrEmpty(this.Version)) { var parameters = new VirtualMachineExtensionImageListVersionsParameters { diff --git a/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageDetailCommand.cs b/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageDetailCommand.cs index 0a0e51b03fac..26f9a810bf3c 100644 --- a/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageDetailCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageDetailCommand.cs @@ -43,6 +43,8 @@ public override void ExecuteCmdlet() { base.ExecuteCmdlet(); + WriteWarning(Properties.Resources.DeprecationOfGetAzureVMExtensionImageDetail); + var parameters = new VirtualMachineExtensionImageGetParameters { Location = Location.Canonicalize(), diff --git a/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageCommand.cs b/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageCommand.cs index d4158110aeda..bea3d2cf91bd 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageCommand.cs @@ -22,8 +22,7 @@ namespace Microsoft.Azure.Commands.Compute { [Cmdlet(VerbsCommon.Get, - ProfileNouns.VirtualMachineImage, - DefaultParameterSetName = ListVMImageParamSetName)] + ProfileNouns.VirtualMachineImage)] [OutputType(typeof(PSVirtualMachineImage), ParameterSetName = new [] {ListVMImageParamSetName})] [OutputType(typeof(PSVirtualMachineImageDetail), @@ -70,7 +69,7 @@ public class GetAzureVMImageCommand : VirtualMachineImageBaseCmdlet public string Skus { get; set; } [Parameter(ParameterSetName = ListVMImageParamSetName, - ValueFromPipelineByPropertyName = true), + ValueFromPipelineByPropertyName = false), ValidateNotNullOrEmpty] public string FilterExpression { get; set; } @@ -132,6 +131,7 @@ public override void ExecuteCmdlet() StatusCode = response.StatusCode, Id = response.VirtualMachineImage.Id, Location = response.VirtualMachineImage.Location, + Name = response.VirtualMachineImage.Name, Version = response.VirtualMachineImage.Name, PublisherName = this.PublisherName, Offer = this.Offer, diff --git a/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageDetailCommand.cs b/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageDetailCommand.cs index ef3cf2dddbc4..098e7879fcd4 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageDetailCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Images/GetAzureVMImageDetailCommand.cs @@ -44,6 +44,8 @@ public override void ExecuteCmdlet() { base.ExecuteCmdlet(); + WriteWarning(Properties.Resources.DeprecationOfGetAzureVMImageDetail); + var parameters = new VirtualMachineImageGetParameters { Location = Location.Canonicalize(), @@ -61,13 +63,14 @@ public override void ExecuteCmdlet() StatusCode = response.StatusCode, Id = response.VirtualMachineImage.Id, Location = response.VirtualMachineImage.Location, - Version = response.VirtualMachineImage.Name, - PublisherName = this.PublisherName, - Offer = this.Offer, - Skus = this.Skus, + Name = response.VirtualMachineImage.Name, OSDiskImage = response.VirtualMachineImage.OSDiskImage, DataDiskImages = response.VirtualMachineImage.DataDiskImages, PurchasePlan = response.VirtualMachineImage.PurchasePlan, + PublisherName = this.PublisherName, + Offer = this.Offer, + Skus = this.Skus, + Version = this.Version }; WriteObject(image); diff --git a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachineImage.cs b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachineImage.cs index 675559e88694..7687533ce7e3 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachineImage.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachineImage.cs @@ -49,6 +49,8 @@ public class PSVirtualMachineImage : PSVirtualMachineImageSku public class PSVirtualMachineImageDetail : PSVirtualMachineImage { + public string Name { get; set; } + public OSDiskImage OSDiskImage { get; set; } public PurchasePlan PurchasePlan { get; set; } diff --git a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs index 230e4a350c03..c1b6347ff8d3 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs @@ -96,6 +96,24 @@ public static string CustomScriptExtensionTryToUseTheFirstSpecifiedFileAsRunScri } } + /// + /// Looks up a localized string similar to Get-AzureVMExtensionImageDetail cmdlet will be deprecated in a future release of Azure PowerShell. The functionality is merged into Get-AzureVMExtensionImage cmdlet.. + /// + public static string DeprecationOfGetAzureVMExtensionImageDetail { + get { + return ResourceManager.GetString("DeprecationOfGetAzureVMExtensionImageDetail", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Get-AzureVMImageDetail cmdlet will be deprecated in a future release of Azure PowerShell. The functionality is merged into Get-AzureVMImage cmdlet.. + /// + public static string DeprecationOfGetAzureVMImageDetail { + get { + return ResourceManager.GetString("DeprecationOfGetAzureVMImageDetail", resourceCulture); + } + } + /// /// Looks up a localized string similar to Virtual machine extension removal operation. /// diff --git a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx index ed628b2289c2..246fc5627a0c 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx +++ b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx @@ -129,6 +129,12 @@ No Run File has been assigned, and the Custom Script extension will try to use the first specified File Name as the Run File. + + Get-AzureVMExtensionImageDetail cmdlet will be deprecated in a future release of Azure PowerShell. The functionality is merged into Get-AzureVMExtensionImage cmdlet. + + + Get-AzureVMImageDetail cmdlet will be deprecated in a future release of Azure PowerShell. The functionality is merged into Get-AzureVMImage cmdlet. + Virtual machine extension removal operation From 4eaf626f84e2f86a3ceec479d7ba7c868ea8cc50 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 22 May 2015 03:39:06 -0700 Subject: [PATCH 5/7] Update the output of Remove-AzureAvailabilitySet cmdlet --- .../RemoveAzureAvailabilitySetCommand.cs | 8 +- .../Commands.Compute/Commands.Compute.csproj | 1 + .../Common/ComputeAutoMapperProfile.cs | 2 +- ...osoft.Azure.Commands.Compute.format.ps1xml | 85 +++++++++++++++++-- .../Models/PSOperationResponse.cs | 27 ++++++ 5 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 src/ResourceManager/Compute/Commands.Compute/Models/PSOperationResponse.cs diff --git a/src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs b/src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs index 0951913d6320..e2936fe4b619 100644 --- a/src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs @@ -12,13 +12,16 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using AutoMapper; using Microsoft.Azure.Commands.Compute.Common; +using Microsoft.Azure.Commands.Compute.Models; using Microsoft.Azure.Management.Compute; using System.Management.Automation; namespace Microsoft.Azure.Commands.Compute { [Cmdlet(VerbsCommon.Remove, ProfileNouns.AvailabilitySet)] + [OutputType(typeof(PSOperationResponse))] public class RemoveAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet { [Parameter( @@ -51,8 +54,9 @@ public override void ExecuteCmdlet() || this.ShouldContinue(Properties.Resources.AvailabilitySetRemovalConfirmation, Properties.Resources.AvailabilitySetRemovalCaption)) { - var op = this.AvailabilitySetClient.Delete(this.ResourceGroupName, this.Name); - WriteObject(op); + AzureOperationResponse op = this.AvailabilitySetClient.Delete(this.ResourceGroupName, this.Name); + var result = Mapper.Map(op); + WriteObject(result); } } } diff --git a/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj b/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj index 533b475004d3..89d0f8c77f05 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj +++ b/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj @@ -177,6 +177,7 @@ + diff --git a/src/ResourceManager/Compute/Commands.Compute/Common/ComputeAutoMapperProfile.cs b/src/ResourceManager/Compute/Commands.Compute/Common/ComputeAutoMapperProfile.cs index c621b8ed69c1..e387f9001e46 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Common/ComputeAutoMapperProfile.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Common/ComputeAutoMapperProfile.cs @@ -72,8 +72,8 @@ protected override void Configure() Mapper.CreateMap(); Mapper.CreateMap(); Mapper.CreateMap(); - Mapper.CreateMap(); + Mapper.CreateMap(); } } } \ No newline at end of file diff --git a/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.format.ps1xml b/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.format.ps1xml index 10a34543f006..e74b2ea3694c 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.format.ps1xml +++ b/src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.format.ps1xml @@ -60,10 +60,6 @@ - - - TrackingOperationId - Status @@ -72,6 +68,10 @@ Output + + + ErrorText + StartTime @@ -81,8 +81,81 @@ EndTime - - ErrorText + + TrackingOperationId + + + + + + + + Microsoft.Azure.Commands.Compute.Models.PSOperationResponse + + Microsoft.Azure.Commands.Compute.Models.PSOperationResponse + + + + + + + + StatusCode + + + + RequestId + + + + + + + + Microsoft.Azure.Management.Compute.Models.DataDisk + + Microsoft.Azure.Management.Compute.Models.DataDisk + + + + + + + + Name + + + + DiskSizeGB + + + + Lun + + + + Caching + + + + CreateOption + + + + SourceImage + + + + + if ($_.VirtualHardDisk -ne $null) + { + $_.VirtualHardDisk.Uri; + } + else + { + $_.VirtualHardDisk; + } + diff --git a/src/ResourceManager/Compute/Commands.Compute/Models/PSOperationResponse.cs b/src/ResourceManager/Compute/Commands.Compute/Models/PSOperationResponse.cs new file mode 100644 index 000000000000..a3a633e2918e --- /dev/null +++ b/src/ResourceManager/Compute/Commands.Compute/Models/PSOperationResponse.cs @@ -0,0 +1,27 @@ +// +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System.Net; + +namespace Microsoft.Azure.Commands.Compute.Models +{ + public class PSOperationResponse + { + public string RequestId { get; set; } + + public HttpStatusCode StatusCode { get; set; } + } +} From 0bcc52d67eabc5dc9eb45e37093bcea3a01ced2d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 22 May 2015 03:40:13 -0700 Subject: [PATCH 6/7] Add test for piping of Remove-AzureVMDataDisk and Remove-AzureVMNetworkInterface --- .../VirtualMachineProfileTests.ps1 | 35 +++++++++++++++++-- ...e.Commands.Compute.format.generated.ps1xml | 8 +++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1 index a094f1351bc5..35afc93066e5 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1 @@ -26,14 +26,26 @@ function Test-VirtualMachineProfile # Network $ipname = 'hpfip' + ((Get-Random) % 10000); - $ipRefUri = "https://test.foo.bar/$ipname"; + $ipRefUri1 = "https://test.foo.bar/$ipname"; $nicName = $ipname + 'nic1'; $publicIPName = $ipname + 'name1'; - $p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri; + $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; Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1; - Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $ipRefUri; + Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $ipRefUri1; # Storage $stoname = 'hpfteststo' + ((Get-Random) % 10000); @@ -66,6 +78,23 @@ 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 e5d31fb83a4f..73ec490b8d45 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,6 +214,14 @@ StorageProfileText + + + DataDiskNames + + + + NicIds + From 57579722c45d6315e6e7b5ad1cc7c2b876b8e8c4 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 22 May 2015 11:05:58 -0700 Subject: [PATCH 7/7] Change NicIds to NetworkInterfaceIds --- .../Compute/Commands.Compute/Models/PSVirtualMachine.cs | 2 +- .../Config/RemoveAzureVMNetworkInterfaceCommand.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs index 4a4a9187113c..567609e3a15a 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs @@ -153,7 +153,7 @@ public string [] DataDiskNames } [JsonIgnore] - public string[] NicIds + public string[] NetworkInterfaceIds { get { diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs index 61c0b9a5420c..c4bcd1c44265 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/RemoveAzureVMNetworkInterfaceCommand.cs @@ -41,20 +41,20 @@ public class RemoveAzureVMNetworkInterfaceCommand : AzurePSCmdlet [ValidateNotNullOrEmpty] public PSVirtualMachine VM { get; set; } - [Alias("Id", "NetworkInterfaceId")] + [Alias("Id", "NicIds")] [Parameter( Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.VMNetworkInterfaceID)] [ValidateNotNullOrEmpty] - public string [] NicIds { get; set; } + public string[] NetworkInterfaceIds { get; set; } public override void ExecuteCmdlet() { var networkProfile = this.VM.NetworkProfile; - foreach (var id in this.NicIds) + foreach (var id in this.NetworkInterfaceIds) { if (networkProfile != null && networkProfile.NetworkInterfaces != null &&