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.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/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.Test/ScenarioTests/VirtualMachineTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 index 3d8c91f93b70..11f4adf28017 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 @@ -252,15 +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; Assert-NotNull $s6; $s6; @@ -299,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; } @@ -316,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 @@ -341,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"; @@ -987,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/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs b/src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs index b61ab1473155..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( @@ -37,13 +40,24 @@ 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)) + { + 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/ExtensionImages/GetAzureVMExtensionImageCommand.cs b/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs index fc142923423f..4bbb0241c38e 100644 --- a/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/ExtensionImages/GetAzureVMExtensionImageCommand.cs @@ -21,8 +21,9 @@ namespace Microsoft.Azure.Commands.Compute { - [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineExtensionImage)] - [OutputType(typeof(PSVirtualMachineExtensionImage))] + [Cmdlet(VerbsCommon.Get, + ProfileNouns.VirtualMachineExtensionImage)] + [OutputType(typeof(PSVirtualMachineExtensionImageDetails))] public class GetAzureVMExtensionImageCommand : VirtualMachineExtensionImageBaseCmdlet { [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] @@ -37,34 +38,73 @@ public class GetAzureVMExtensionImageCommand : VirtualMachineExtensionImageBaseC [Parameter, ValidateNotNullOrEmpty] public string FilterExpression { get; set; } + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true)] + public string Version { get; set; } + public override void ExecuteCmdlet() { base.ExecuteCmdlet(); - var parameters = new VirtualMachineExtensionImageListVersionsParameters + if (string.IsNullOrEmpty(this.Version)) + { + 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 parameters = new VirtualMachineExtensionImageGetParameters + { + Location = Location.Canonicalize(), + PublisherName = PublisherName, + Type = Type, + FilterExpression = FilterExpression, + Version = Version + }; + + VirtualMachineExtensionImageGetResponse result = this.VirtualMachineExtensionImageClient.Get(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 - }; + 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(images, true); + WriteObject(image); + } } } } 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 68a1454a256c..bea3d2cf91bd 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)] + [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 = false), + 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, + Name = response.VirtualMachineImage.Name, + 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..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(), 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 + 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; } + } +} diff --git a/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs b/src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachine.cs index ad992f937933..567609e3a15a 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[] 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/Properties/Resources.Designer.cs b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs index c7605bac79fa..c1b6347ff8d3 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.. /// @@ -78,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 c14a2af5faf2..246fc5627a0c 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx +++ b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx @@ -117,12 +117,24 @@ 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. 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 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..c4bcd1c44265 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", "NicIds")] [Parameter( Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true, HelpMessage = HelpMessages.VMNetworkInterfaceID)] [ValidateNotNullOrEmpty] - public string Id { get; set; } + public string[] NetworkInterfaceIds { 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.NetworkInterfaceIds) { - 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);