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, VerbsCommon.Remove) &&
                    (this.Force.IsPresent ||
                     this.ShouldContinue(Properties.Resources.ResourceRemovalConfirmation,
                                         "Remove-AzGalleryImageDefinition operation")))
                {
                    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 result = GalleryImagesClient.DeleteWithHttpMessagesAsync(resourceGroupName, galleryName, galleryImageName).GetAwaiter().GetResult();
                    PSOperationStatusResponse output = new PSOperationStatusResponse
                    {
                        StartTime = this.StartTime,
                        EndTime   = DateTime.Now
                    };

                    if (result != null && result.Request != null && result.Request.RequestUri != null)
                    {
                        output.Name = GetOperationIdFromUrlString(result.Request.RequestUri.ToString());
                    }

                    WriteObject(output);
                }
            });
        }
示例#3
0
        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);
                }
            });
        }
示例#4
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.New))
                {
                    string resourceGroupName = this.ResourceGroupName;
                    string galleryName       = this.GalleryName;
                    string galleryImageName  = this.Name;

                    GalleryImage galleryImage = new GalleryImage();
                    galleryImage.Location     = this.Location;
                    galleryImage.Identifier   = new GalleryImageIdentifier(this.Publisher, this.Offer, this.Sku);
                    galleryImage.OsState      = this.OsState;
                    galleryImage.OsType       = this.OsType;

                    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.HyperVGeneration))
                    {
                        galleryImage.HyperVGeneration = this.HyperVGeneration;
                    }

                    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.Architecture))
                    {
                        galleryImage.Architecture = this.Architecture;
                    }

                    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;
                    }

                    if (this.IsParameterBound(c => c.Feature))
                    {
                        galleryImage.Features = this.Feature;
                    }

                    var result   = GalleryImagesClient.CreateOrUpdate(resourceGroupName, galleryName, galleryImageName, galleryImage);
                    var psObject = new PSGalleryImage();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <GalleryImage, PSGalleryImage>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }