|
| 1 | +// ---------------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// Copyright Microsoft Corporation |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | +// ---------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +using Microsoft.Azure.Commands.Compute.Common; |
| 16 | +using Microsoft.Azure.Commands.Compute.Models; |
| 17 | +using Microsoft.Azure.Management.Compute; |
| 18 | +using Microsoft.Azure.Management.Compute.Models; |
| 19 | +using System.Linq; |
| 20 | +using System.Management.Automation; |
| 21 | + |
| 22 | +namespace Microsoft.Azure.Commands.Compute |
| 23 | +{ |
| 24 | + [Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineExtensionImage)] |
| 25 | + [OutputType(typeof(PSVirtualMachineExtensionImage))] |
| 26 | + [OutputType(typeof(PSVirtualMachineExtensionImageDetails))] |
| 27 | + public class GetAzureVMExtensionImageCommand : VirtualMachineExtensionImageBaseCmdlet |
| 28 | + { |
| 29 | + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] |
| 30 | + public string Location { get; set; } |
| 31 | + |
| 32 | + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] |
| 33 | + public string PublisherName { get; set; } |
| 34 | + |
| 35 | + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty] |
| 36 | + public string Type { get; set; } |
| 37 | + |
| 38 | + [Parameter, ValidateNotNullOrEmpty] |
| 39 | + public string FilterExpression { get; set; } |
| 40 | + |
| 41 | + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true)] |
| 42 | + public string Version { get; set; } |
| 43 | + |
| 44 | + protected override void ProcessRecord() |
| 45 | + { |
| 46 | + base.ProcessRecord(); |
| 47 | + |
| 48 | + ExecuteClientAction(() => |
| 49 | + { |
| 50 | + if (string.IsNullOrEmpty(this.Version)) |
| 51 | + { |
| 52 | + // TODO, FilterExpression |
| 53 | + var result = this.VirtualMachineExtensionImageClient.ListVersions(Location.Canonicalize(), PublisherName, Type); |
| 54 | + |
| 55 | + var images = from r in result |
| 56 | + select new PSVirtualMachineExtensionImage |
| 57 | + { |
| 58 | + Id = r.Id, |
| 59 | + Location = r.Location, |
| 60 | + Version = r.Name, |
| 61 | + PublisherName = this.PublisherName, |
| 62 | + Type = this.Type, |
| 63 | + FilterExpression = this.FilterExpression |
| 64 | + }; |
| 65 | + |
| 66 | + WriteObject(result, true); |
| 67 | + // TODO: Cannot Write the Result from Linq Select. |
| 68 | + //WriteObject(images, true); |
| 69 | + } |
| 70 | + else |
| 71 | + { |
| 72 | + var result = this.VirtualMachineExtensionImageClient.Get(Location.Canonicalize(), PublisherName, Type, Version); |
| 73 | + |
| 74 | + var image = new PSVirtualMachineExtensionImageDetails |
| 75 | + { |
| 76 | + Id = result.Id, |
| 77 | + Location = result.Location, |
| 78 | + HandlerSchema = result.HandlerSchema, |
| 79 | + OperatingSystem = result.OperatingSystem, |
| 80 | + ComputeRole = result.ComputeRole, |
| 81 | + SupportsMultipleExtensions = result.SupportsMultipleExtensions, |
| 82 | + VMScaleSetEnabled = result.VmScaleSetEnabled, |
| 83 | + Version = result.Name, |
| 84 | + PublisherName = this.PublisherName, |
| 85 | + Type = this.Type, |
| 86 | + FilterExpression = this.FilterExpression |
| 87 | + }; |
| 88 | + |
| 89 | + WriteObject(image); |
| 90 | + } |
| 91 | + }); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments