public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.New))
                {
                    string resourceGroupName            = this.ResourceGroupName;
                    string hostGroupName                = this.Name;
                    DedicatedHostGroup parameters       = new DedicatedHostGroup();
                    parameters.Location                 = this.Location;
                    parameters.PlatformFaultDomainCount = this.PlatformFaultDomain;

                    if (this.IsParameterBound(c => c.Zone))
                    {
                        parameters.Zones = this.Zone;
                    }

                    if (this.IsParameterBound(c => c.SupportAutomaticPlacement))
                    {
                        parameters.SupportAutomaticPlacement = this.SupportAutomaticPlacement;
                    }

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

                    var result   = DedicatedHostGroupsClient.CreateOrUpdate(resourceGroupName, hostGroupName, parameters);
                    var psObject = new PSHostGroup();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <DedicatedHostGroup, PSHostGroup>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
Ejemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName;
                string hostGroupName;
                switch (this.ParameterSetName)
                {
                case "ResourceIdParameter":
                    resourceGroupName = GetResourceGroupName(this.ResourceId);
                    hostGroupName     = GetResourceName(this.ResourceId, "Microsoft.Compute/hostGroups");
                    break;

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

                if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(hostGroupName))
                {
                    DedicatedHostGroup result;
                    if (this.InstanceView.IsPresent)
                    {
                        result = DedicatedHostGroupsClient.Get(resourceGroupName, hostGroupName, InstanceViewTypes.InstanceView);
                    }
                    else
                    {
                        result = DedicatedHostGroupsClient.Get(resourceGroupName, hostGroupName);
                    }
                    var psObject = new PSHostGroup();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <DedicatedHostGroup, PSHostGroup>(result, psObject);
                    WriteObject(psObject);
                }
                else if (!string.IsNullOrEmpty(resourceGroupName))
                {
                    var result       = DedicatedHostGroupsClient.ListByResourceGroup(resourceGroupName);
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = DedicatedHostGroupsClient.ListByResourceGroupNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSHostGroupList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <DedicatedHostGroup, PSHostGroupList>(r));
                    }
                    WriteObject(psObject, true);
                }
                else
                {
                    var result       = DedicatedHostGroupsClient.ListBySubscription();
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = DedicatedHostGroupsClient.ListBySubscriptionNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSHostGroupList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <DedicatedHostGroup, PSHostGroupList>(r));
                    }
                    WriteObject(psObject, true);
                }
            });
        }