public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { string resourceGroupName; string hostGroupName; string hostName; switch (this.ParameterSetName) { case "ResourceIdParameter": resourceGroupName = GetResourceGroupName(this.ResourceId); hostGroupName = GetResourceName(this.ResourceId, "Microsoft.Compute/hosts", "hosts"); hostName = GetResourceName(this.ResourceId, "Microsoft.Compute/hosts", "hosts"); break; default: resourceGroupName = this.ResourceGroupName; hostGroupName = this.HostGroupName; hostName = this.Name; break; } if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(hostGroupName) && !string.IsNullOrEmpty(hostName)) { InstanceViewTypes?expand = null; if (this.InstanceView.IsPresent) { expand = InstanceViewTypes.InstanceView; } var result = DedicatedHostsClient.Get(resourceGroupName, hostGroupName, hostName, expand); var psObject = new PSHost(); ComputeAutomationAutoMapperProfile.Mapper.Map <DedicatedHost, PSHost>(result, psObject); WriteObject(psObject); } else { var result = DedicatedHostsClient.ListByHostGroup(resourceGroupName, hostGroupName); var resultList = result.ToList(); var nextPageLink = result.NextPageLink; while (!string.IsNullOrEmpty(nextPageLink)) { var pageResult = DedicatedHostsClient.ListByHostGroupNext(nextPageLink); foreach (var pageItem in pageResult) { resultList.Add(pageItem); } nextPageLink = pageResult.NextPageLink; } var psObject = new List <PSHostList>(); foreach (var r in resultList) { psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <DedicatedHost, PSHostList>(r)); } WriteObject(psObject, true); } }); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.Name, VerbsCommon.Remove)) { string resourceGroupName; string hostGroupName; string hostName; switch (this.ParameterSetName) { case ResourceIdParamSet: resourceGroupName = GetResourceGroupName(this.ResourceId); hostGroupName = GetResourceName(this.ResourceId, "Microsoft.Compute/hostGroups", "hosts"); hostName = GetInstanceId(this.ResourceId, "Microsoft.Compute/hostGroups", "hosts"); break; case ObjectParamSet: resourceGroupName = GetResourceGroupName(this.InputObject.Id); hostGroupName = GetResourceName(this.InputObject.Id, "Microsoft.Compute/hostGroups", "hosts"); hostName = GetInstanceId(this.InputObject.Id, "Microsoft.Compute/hostGroups", "hosts"); break; default: resourceGroupName = this.ResourceGroupName; hostGroupName = this.HostGroupName; hostName = this.Name; break; } var result = DedicatedHostsClient.RestartWithHttpMessagesAsync(resourceGroupName, hostGroupName, hostName).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); } }); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.Name, VerbsCommon.New)) { string resourceGroupName = this.ResourceGroupName; string hostGroupName = this.HostGroupName; string hostName = this.Name; DedicatedHost parameters = new DedicatedHost(); parameters.Location = this.Location; parameters.Sku = new Sku(this.Sku, null, null);; if (this.IsParameterBound(c => c.PlatformFaultDomain)) { parameters.PlatformFaultDomain = this.PlatformFaultDomain; } if (this.IsParameterBound(c => c.AutoReplaceOnFailure)) { parameters.AutoReplaceOnFailure = this.AutoReplaceOnFailure; } if (this.IsParameterBound(c => c.LicenseType)) { parameters.LicenseType = this.LicenseType; } if (this.MyInvocation.BoundParameters.ContainsKey("Tag")) { parameters.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } var result = DedicatedHostsClient.CreateOrUpdate(resourceGroupName, hostGroupName, hostName, parameters); var psObject = new PSHost(); ComputeAutomationAutoMapperProfile.Mapper.Map <DedicatedHost, PSHost>(result, psObject); WriteObject(psObject); } }); }