public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { string resourceGroupName; string galleryName; string galleryImageName; switch (this.ParameterSetName) { case "ResourceIdParameter": resourceGroupName = GetResourceGroupName(this.ResourceId); galleryName = GetResourceName(this.ResourceId, "Microsoft.Compute/Galleries", "Images"); galleryImageName = GetInstanceId(this.ResourceId, "Microsoft.Compute/Galleries", "Images"); break; case "SharedGalleryParameterSet": SharedGalleryGet(); return; default: resourceGroupName = this.ResourceGroupName; galleryName = this.GalleryName; galleryImageName = this.Name; break; } if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(galleryName) && !string.IsNullOrEmpty(galleryImageName) && !WildcardPattern.ContainsWildcardCharacters(galleryImageName)) { var result = GalleryImagesClient.Get(resourceGroupName, galleryName, galleryImageName); var psObject = new PSGalleryImage(); ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImage, PSGalleryImage>(result, psObject); WriteObject(psObject); } else { var result = GalleryImagesClient.ListByGallery(resourceGroupName, galleryName); var resultList = result.ToList(); var nextPageLink = result.NextPageLink; while (!string.IsNullOrEmpty(nextPageLink)) { var pageResult = GalleryImagesClient.ListByGalleryNext(nextPageLink); foreach (var pageItem in pageResult) { resultList.Add(pageItem); } nextPageLink = pageResult.NextPageLink; } var psObject = new List <PSGalleryImageList>(); foreach (var r in resultList) { psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImage, PSGalleryImageList>(r)); } WriteObject(SubResourceWildcardFilter(galleryImageName, psObject), true); } }); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.Name, VerbsData.Update)) { string resourceGroupName; string galleryName; string galleryImageName; switch (this.ParameterSetName) { case "ResourceIdParameter": resourceGroupName = GetResourceGroupName(this.ResourceId); galleryName = GetResourceName(this.ResourceId, "Microsoft.Compute/Galleries", "Images"); galleryImageName = GetInstanceId(this.ResourceId, "Microsoft.Compute/Galleries", "Images"); break; case "ObjectParameter": resourceGroupName = GetResourceGroupName(this.InputObject.Id); galleryName = GetResourceName(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images"); galleryImageName = GetInstanceId(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images"); break; default: resourceGroupName = this.ResourceGroupName; galleryName = this.GalleryName; galleryImageName = this.Name; break; } var galleryImage = new GalleryImage(); if (this.ParameterSetName == "ObjectParameter") { ComputeAutomationAutoMapperProfile.Mapper.Map <PSGalleryImage, GalleryImage>(this.InputObject, galleryImage); } else { galleryImage = GalleryImagesClient.Get(resourceGroupName, galleryName, galleryImageName); } if (this.IsParameterBound(c => c.Description)) { galleryImage.Description = this.Description; } if (this.IsParameterBound(c => c.Eula)) { galleryImage.Eula = this.Eula; } if (this.IsParameterBound(c => c.PrivacyStatementUri)) { galleryImage.PrivacyStatementUri = this.PrivacyStatementUri; } if (this.IsParameterBound(c => c.ReleaseNoteUri)) { galleryImage.ReleaseNoteUri = this.ReleaseNoteUri; } if (this.IsParameterBound(c => c.EndOfLifeDate)) { galleryImage.EndOfLifeDate = this.EndOfLifeDate; } if (this.IsParameterBound(c => c.Tag)) { galleryImage.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } if (this.IsParameterBound(c => c.MinimumVCPU)) { if (galleryImage.Recommended == null) { galleryImage.Recommended = new RecommendedMachineConfiguration(); } if (galleryImage.Recommended.VCPUs == null) { galleryImage.Recommended.VCPUs = new ResourceRange(); } galleryImage.Recommended.VCPUs.Min = this.MinimumVCPU; } if (this.IsParameterBound(c => c.MaximumVCPU)) { if (galleryImage.Recommended == null) { galleryImage.Recommended = new RecommendedMachineConfiguration(); } if (galleryImage.Recommended.VCPUs == null) { galleryImage.Recommended.VCPUs = new ResourceRange(); } galleryImage.Recommended.VCPUs.Max = this.MaximumVCPU; } if (this.IsParameterBound(c => c.MinimumMemory)) { if (galleryImage.Recommended == null) { galleryImage.Recommended = new RecommendedMachineConfiguration(); } if (galleryImage.Recommended.Memory == null) { galleryImage.Recommended.Memory = new ResourceRange(); } galleryImage.Recommended.Memory.Min = this.MinimumMemory; } if (this.IsParameterBound(c => c.MaximumMemory)) { if (galleryImage.Recommended == null) { galleryImage.Recommended = new RecommendedMachineConfiguration(); } if (galleryImage.Recommended.Memory == null) { galleryImage.Recommended.Memory = new ResourceRange(); } galleryImage.Recommended.Memory.Max = this.MaximumMemory; } if (this.IsParameterBound(c => c.DisallowedDiskType)) { if (galleryImage.Disallowed == null) { galleryImage.Disallowed = new Disallowed(); } galleryImage.Disallowed.DiskTypes = this.DisallowedDiskType; } if (this.IsParameterBound(c => c.PurchasePlanName)) { if (galleryImage.PurchasePlan == null) { galleryImage.PurchasePlan = new ImagePurchasePlan(); } galleryImage.PurchasePlan.Name = this.PurchasePlanName; } if (this.IsParameterBound(c => c.PurchasePlanPublisher)) { if (galleryImage.PurchasePlan == null) { galleryImage.PurchasePlan = new ImagePurchasePlan(); } galleryImage.PurchasePlan.Publisher = this.PurchasePlanPublisher; } if (this.IsParameterBound(c => c.PurchasePlanProduct)) { if (galleryImage.PurchasePlan == null) { galleryImage.PurchasePlan = new ImagePurchasePlan(); } galleryImage.PurchasePlan.Product = this.PurchasePlanProduct; } var result = GalleryImagesClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImage); var psObject = new PSGalleryImage(); ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImage, PSGalleryImage>(result, psObject); WriteObject(psObject); } }); }