public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.New))
                {
                    CapacityReservationGroup capacityReservationGroup = new CapacityReservationGroup();
                    capacityReservationGroup.Location = this.Location;

                    if (this.IsParameterBound(c => c.Tag))
                    {
                        capacityReservationGroup.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
                    }
                    if (this.IsParameterBound(c => c.Zone))
                    {
                        capacityReservationGroup.Zones = this.Zone;
                    }

                    var result   = CapacityReservationGroupClient.CreateOrUpdate(this.ResourceGroupName, this.Name, capacityReservationGroup);
                    var psObject = new PSCapacityReservationGroup();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <CapacityReservationGroup, PSCapacityReservationGroup>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
Exemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName;
                string name;

                switch (this.ParameterSetName)
                {
                case ResourceIDParameterSet:
                    resourceGroupName = GetResourceGroupName(this.ResourceId);
                    name = GetResourceName(this.ResourceId, "Microsoft.Compute/capacityReservationGroups");
                    break;

                case InputObjectParameterSet:
                    resourceGroupName = GetResourceGroupName(this.CapacityReservationGroup.Id);
                    name = GetResourceName(this.CapacityReservationGroup.Id, "Microsoft.Compute/capacityReservationGroups");
                    break;

                default:
                    resourceGroupName = this.ResourceGroupName;
                    name = this.Name;
                    break;
                }

                CapacityReservationGroup result;

                if (this.IsParameterBound(c => c.Tag))
                {
                    var tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
                    result   = CapacityReservationGroupClient.Update(resourceGroupName, name, tags);
                }
                else
                {
                    result = CapacityReservationGroupClient.Update(resourceGroupName, name);
                }

                var psObject = new PSCapacityReservationGroup();
                ComputeAutomationAutoMapperProfile.Mapper.Map <CapacityReservationGroup, PSCapacityReservationGroup>(result, psObject);
                WriteObject(psObject);
            });
        }
Exemplo n.º 3
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName;
                string capacityReservationGroupName;

                if (this.ParameterSetName == ResourceIDParameterSet)
                {
                    resourceGroupName            = GetResourceGroupName(this.ResourceId);
                    capacityReservationGroupName = GetResourceName(this.ResourceId, "Microsoft.Compute/capacityReservationGroups");
                }
                else
                {
                    resourceGroupName            = this.ResourceGroupName;
                    capacityReservationGroupName = this.Name;
                }

                if (ShouldGetByName(resourceGroupName, capacityReservationGroupName))
                {
                    CapacityReservationGroup result = new CapacityReservationGroup();
                    if (this.InstanceView.IsPresent)
                    {
                        result = CapacityReservationGroupClient.Get(resourceGroupName, capacityReservationGroupName, "InstanceView");
                    }
                    else
                    {
                        result = CapacityReservationGroupClient.Get(resourceGroupName, capacityReservationGroupName);
                    }
                    var psObject = new PSCapacityReservationGroup();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <CapacityReservationGroup, PSCapacityReservationGroup>(result, psObject);
                    WriteObject(psObject);
                }
                else if (ShouldListByResourceGroup(resourceGroupName, capacityReservationGroupName))
                {
                    var result       = CapacityReservationGroupClient.ListByResourceGroup(resourceGroupName);
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = CapacityReservationGroupClient.ListByResourceGroupNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSCapacityReservationGroupList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <CapacityReservationGroup, PSCapacityReservationGroupList>(r));
                    }
                    WriteObject(TopLevelWildcardFilter(resourceGroupName, capacityReservationGroupName, psObject), true);
                }
                else
                {
                    var result       = CapacityReservationGroupClient.ListBySubscription();
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = CapacityReservationGroupClient.ListBySubscriptionNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSCapacityReservationGroupList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <CapacityReservationGroup, PSCapacityReservationGroupList>(r));
                    }
                    WriteObject(TopLevelWildcardFilter(resourceGroupName, capacityReservationGroupName, psObject), true);
                }
            });
        }