Ejemplo n.º 1
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);
                }
            });
        }
Ejemplo n.º 2
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);
                }
            });
        }