public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { string resourceGroupName; string galleryName; string galleryImageName; string galleryImageVersionName; string expand = (this.ExpandReplicationStatus.IsPresent) ? "ReplicationStatus" : null; switch (this.ParameterSetName) { case "ResourceIdParameter": resourceGroupName = GetResourceGroupName(this.ResourceId); galleryName = GetResourceName(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions"); galleryImageName = GetInstanceId(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions"); galleryImageVersionName = GetVersion(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions"); break; default: resourceGroupName = this.ResourceGroupName; galleryName = this.GalleryName; galleryImageName = this.GalleryImageDefinitionName; galleryImageVersionName = this.Name; break; } if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(galleryName) && !string.IsNullOrEmpty(galleryImageName) && !string.IsNullOrEmpty(galleryImageVersionName) && !WildcardPattern.ContainsWildcardCharacters(galleryImageVersionName)) { var result = GalleryImageVersionsClient.Get(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName, expand); var psObject = new PSGalleryImageVersion(); ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImageVersion, PSGalleryImageVersion>(result, psObject); WriteObject(psObject); } else { var result = GalleryImageVersionsClient.ListByGalleryImage(resourceGroupName, galleryName, galleryImageName); var resultList = result.ToList(); var nextPageLink = result.NextPageLink; while (!string.IsNullOrEmpty(nextPageLink)) { var pageResult = GalleryImageVersionsClient.ListByGalleryImageNext(nextPageLink); foreach (var pageItem in pageResult) { resultList.Add(pageItem); } nextPageLink = pageResult.NextPageLink; } var psObject = new List <PSGalleryImageVersionList>(); foreach (var r in resultList) { psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImageVersion, PSGalleryImageVersionList>(r)); } WriteObject(SubResourceWildcardFilter(galleryImageVersionName, psObject), true); } }); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.Name, VerbsData.Update)) { string resourceGroupName; string galleryName; string galleryImageName; string galleryImageVersionName; switch (this.ParameterSetName) { case "ResourceIdParameter": resourceGroupName = GetResourceGroupName(this.ResourceId); galleryName = GetResourceName(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions"); galleryImageName = GetInstanceId(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions"); galleryImageVersionName = GetVersion(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions"); break; case "ObjectParameter": resourceGroupName = GetResourceGroupName(this.InputObject.Id); galleryName = GetResourceName(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions"); galleryImageName = GetInstanceId(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions"); galleryImageVersionName = GetVersion(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions"); break; default: resourceGroupName = this.ResourceGroupName; galleryName = this.GalleryName; galleryImageName = this.GalleryImageDefinitionName; galleryImageVersionName = this.Name; break; } var galleryImageVersion = new GalleryImageVersion(); if (this.ParameterSetName == "ObjectParameter") { ComputeAutomationAutoMapperProfile.Mapper.Map <PSGalleryImageVersion, GalleryImageVersion>(this.InputObject, galleryImageVersion); } else { galleryImageVersion = GalleryImageVersionsClient.Get(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName); } if (this.IsParameterBound(c => c.Tag)) { galleryImageVersion.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } if (this.IsParameterBound(c => c.ReplicaCount)) { if (galleryImageVersion.PublishingProfile == null) { galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile(); } galleryImageVersion.PublishingProfile.ReplicaCount = this.ReplicaCount; } if (this.IsParameterBound(c => c.PublishingProfileExcludeFromLatest)) { if (galleryImageVersion.PublishingProfile == null) { galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile(); } galleryImageVersion.PublishingProfile.ExcludeFromLatest = this.PublishingProfileExcludeFromLatest.IsPresent; } if (this.IsParameterBound(c => c.PublishingProfileEndOfLifeDate)) { if (galleryImageVersion.PublishingProfile == null) { galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile(); } galleryImageVersion.PublishingProfile.EndOfLifeDate = this.PublishingProfileEndOfLifeDate; } if (this.IsParameterBound(c => c.TargetRegion)) { if (galleryImageVersion.PublishingProfile == null) { galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile(); } galleryImageVersion.PublishingProfile.TargetRegions = new List <TargetRegion>(); foreach (var t in this.TargetRegion) { galleryImageVersion.PublishingProfile.TargetRegions.Add(new TargetRegion((string)t["Name"], (int?)t["ReplicaCount"])); } } var result = GalleryImageVersionsClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName, galleryImageVersion); var psObject = new PSGalleryImageVersion(); ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImageVersion, PSGalleryImageVersion>(result, psObject); WriteObject(psObject); } }); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.Name, VerbsData.Update)) { string resourceGroupName; string galleryName; string galleryImageName; string galleryImageVersionName; switch (this.ParameterSetName) { case "ResourceIdParameter": resourceGroupName = GetResourceGroupName(this.ResourceId); galleryName = GetResourceName(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions"); galleryImageName = GetInstanceId(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions"); galleryImageVersionName = GetVersion(this.ResourceId, "Microsoft.Compute/Galleries", "Images", "Versions"); break; case "ObjectParameter": resourceGroupName = GetResourceGroupName(this.InputObject.Id); galleryName = GetResourceName(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions"); galleryImageName = GetInstanceId(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions"); galleryImageVersionName = GetVersion(this.InputObject.Id, "Microsoft.Compute/Galleries", "Images", "Versions"); break; default: resourceGroupName = this.ResourceGroupName; galleryName = this.GalleryName; galleryImageName = this.GalleryImageDefinitionName; galleryImageVersionName = this.Name; break; } var galleryImageVersion = new GalleryImageVersion(); if (this.ParameterSetName == "ObjectParameter") { ComputeAutomationAutoMapperProfile.Mapper.Map <PSGalleryImageVersion, GalleryImageVersion>(this.InputObject, galleryImageVersion); } else { galleryImageVersion = GalleryImageVersionsClient.Get(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName); } if (this.IsParameterBound(c => c.Tag)) { galleryImageVersion.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } if (this.IsParameterBound(c => c.ReplicaCount)) { if (galleryImageVersion.PublishingProfile == null) { galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile(); } galleryImageVersion.PublishingProfile.ReplicaCount = this.ReplicaCount; } if (this.IsParameterBound(c => c.PublishingProfileExcludeFromLatest)) { if (galleryImageVersion.PublishingProfile == null) { galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile(); } galleryImageVersion.PublishingProfile.ExcludeFromLatest = this.PublishingProfileExcludeFromLatest.IsPresent; } if (this.IsParameterBound(c => c.PublishingProfileEndOfLifeDate)) { if (galleryImageVersion.PublishingProfile == null) { galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile(); } galleryImageVersion.PublishingProfile.EndOfLifeDate = this.PublishingProfileEndOfLifeDate; } if (this.IsParameterBound(c => c.TargetRegion)) { if (galleryImageVersion.PublishingProfile == null) { galleryImageVersion.PublishingProfile = new GalleryImageVersionPublishingProfile(); } galleryImageVersion.PublishingProfile.TargetRegions = new List <TargetRegion>(); foreach (var t in this.TargetRegion) { var target = new TargetRegion() { Name = (string)t["Name"], RegionalReplicaCount = (int?)t["ReplicaCount"], StorageAccountType = (string)t["StorageAccountType"], }; if (t["Encryption"] != null) { var osDiskEncryptionSetId = (string)((Hashtable)((Hashtable)t["Encryption"])["osDiskImage"])["DiskEncryptionSetId"]; var osDiskImageEncryption = new OSDiskImageEncryption(osDiskEncryptionSetId); List <DataDiskImageEncryption> dataDiskImageEncryption = null; var dataDiskImage = (object[])((Hashtable)t["Encryption"])["dataDiskImages"]; if (dataDiskImage != null) { dataDiskImageEncryption = new List <DataDiskImageEncryption>(); foreach (Hashtable dataDiskEncryptionSetId in dataDiskImage) { DataDiskImageEncryption d = new DataDiskImageEncryption((int)dataDiskEncryptionSetId["Lun"], (string)dataDiskEncryptionSetId["DiskEncryptionSetId"]); dataDiskImageEncryption.Add(d); } } target.Encryption = new EncryptionImages(osDiskImageEncryption, dataDiskImageEncryption); } galleryImageVersion.PublishingProfile.TargetRegions.Add(target); } } if (galleryImageVersion.StorageProfile != null && galleryImageVersion.StorageProfile.Source != null && galleryImageVersion.StorageProfile.Source.Id != null) { galleryImageVersion.StorageProfile.Source.Id = null; } galleryImageVersion.StorageProfile.DataDiskImages = null; galleryImageVersion.StorageProfile.OsDiskImage = null; var result = GalleryImageVersionsClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImageVersionName, galleryImageVersion); var psObject = new PSGalleryImageVersion(); ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImageVersion, PSGalleryImageVersion>(result, psObject); WriteObject(psObject); } }); }