@@ -18,6 +18,176 @@ namespace Microsoft.Azure.Management.Compute
1818 /// </summary>
1919 internal partial class VirtualMachineScaleSetVMsOperations : IServiceOperations < ComputeManagementClient > , IVirtualMachineScaleSetVMsOperations
2020 {
21+ public async Task < AzureOperationResponse > ReimageWithHttpMessagesAsync ( string resourceGroupName , string vmScaleSetName , string instanceId , bool ? tempDisk , Dictionary < string , List < string > > customHeaders = null , CancellationToken cancellationToken = default ( CancellationToken ) )
22+ {
23+ AzureOperationResponse _response = await BeginReimageWithHttpMessagesAsync ( resourceGroupName , vmScaleSetName , instanceId , tempDisk , customHeaders , cancellationToken ) . ConfigureAwait ( false ) ;
24+ return await Client . GetPostOrDeleteOperationResultAsync ( _response , customHeaders , cancellationToken ) . ConfigureAwait ( false ) ;
25+ }
26+
27+ public async Task < AzureOperationResponse > BeginReimageWithHttpMessagesAsync ( string resourceGroupName , string vmScaleSetName , string instanceId , bool ? tempDisk , Dictionary < string , List < string > > customHeaders = null , CancellationToken cancellationToken = default ( CancellationToken ) )
28+ {
29+ if ( resourceGroupName == null )
30+ {
31+ throw new ValidationException ( ValidationRules . CannotBeNull , "resourceGroupName" ) ;
32+ }
33+ if ( vmScaleSetName == null )
34+ {
35+ throw new ValidationException ( ValidationRules . CannotBeNull , "vmScaleSetName" ) ;
36+ }
37+ if ( instanceId == null )
38+ {
39+ throw new ValidationException ( ValidationRules . CannotBeNull , "instanceId" ) ;
40+ }
41+ if ( Client . SubscriptionId == null )
42+ {
43+ throw new ValidationException ( ValidationRules . CannotBeNull , "this.Client.SubscriptionId" ) ;
44+ }
45+ string apiVersion = "2022-11-01" ;
46+ // Tracing
47+ VirtualMachineScaleSetVMReimageParameters vmScaleSetVMReimageInput = default ( VirtualMachineScaleSetVMReimageParameters ) ;
48+ if ( tempDisk != null )
49+ {
50+ vmScaleSetVMReimageInput = new VirtualMachineScaleSetVMReimageParameters ( ) ;
51+ vmScaleSetVMReimageInput . TempDisk = tempDisk ;
52+ }
53+ bool _shouldTrace = ServiceClientTracing . IsEnabled ;
54+ string _invocationId = null ;
55+ if ( _shouldTrace )
56+ {
57+ _invocationId = ServiceClientTracing . NextInvocationId . ToString ( ) ;
58+ Dictionary < string , object > tracingParameters = new Dictionary < string , object > ( ) ;
59+ tracingParameters . Add ( "resourceGroupName" , resourceGroupName ) ;
60+ tracingParameters . Add ( "vmScaleSetName" , vmScaleSetName ) ;
61+ tracingParameters . Add ( "instanceId" , instanceId ) ;
62+ tracingParameters . Add ( "vmScaleSetVMReimageInput" , vmScaleSetVMReimageInput ) ;
63+ tracingParameters . Add ( "apiVersion" , apiVersion ) ;
64+ tracingParameters . Add ( "cancellationToken" , cancellationToken ) ;
65+ ServiceClientTracing . Enter ( _invocationId , this , "BeginReimage" , tracingParameters ) ;
66+ }
67+ // Construct URL
68+ var _baseUrl = Client . BaseUri . AbsoluteUri ;
69+ var _url = new System . Uri ( new System . Uri ( _baseUrl + ( _baseUrl . EndsWith ( "/" ) ? "" : "/" ) ) , "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/virtualMachines/{instanceId}/reimage" ) . ToString ( ) ;
70+ _url = _url . Replace ( "{resourceGroupName}" , System . Uri . EscapeDataString ( resourceGroupName ) ) ;
71+ _url = _url . Replace ( "{vmScaleSetName}" , System . Uri . EscapeDataString ( vmScaleSetName ) ) ;
72+ _url = _url . Replace ( "{instanceId}" , System . Uri . EscapeDataString ( instanceId ) ) ;
73+ _url = _url . Replace ( "{subscriptionId}" , System . Uri . EscapeDataString ( Client . SubscriptionId ) ) ;
74+ List < string > _queryParameters = new List < string > ( ) ;
75+ if ( apiVersion != null )
76+ {
77+ _queryParameters . Add ( string . Format ( "api-version={0}" , System . Uri . EscapeDataString ( apiVersion ) ) ) ;
78+ }
79+ if ( _queryParameters . Count > 0 )
80+ {
81+ _url += ( _url . Contains ( "?" ) ? "&" : "?" ) + string . Join ( "&" , _queryParameters ) ;
82+ }
83+ // Create HTTP transport objects
84+ var _httpRequest = new HttpRequestMessage ( ) ;
85+ HttpResponseMessage _httpResponse = null ;
86+ _httpRequest . Method = new HttpMethod ( "POST" ) ;
87+ _httpRequest . RequestUri = new System . Uri ( _url ) ;
88+ // Set Headers
89+ if ( Client . GenerateClientRequestId != null && Client . GenerateClientRequestId . Value )
90+ {
91+ _httpRequest . Headers . TryAddWithoutValidation ( "x-ms-client-request-id" , System . Guid . NewGuid ( ) . ToString ( ) ) ;
92+ }
93+ if ( Client . AcceptLanguage != null )
94+ {
95+ if ( _httpRequest . Headers . Contains ( "accept-language" ) )
96+ {
97+ _httpRequest . Headers . Remove ( "accept-language" ) ;
98+ }
99+ _httpRequest . Headers . TryAddWithoutValidation ( "accept-language" , Client . AcceptLanguage ) ;
100+ }
101+
102+
103+ if ( customHeaders != null )
104+ {
105+ foreach ( var _header in customHeaders )
106+ {
107+ if ( _httpRequest . Headers . Contains ( _header . Key ) )
108+ {
109+ _httpRequest . Headers . Remove ( _header . Key ) ;
110+ }
111+ _httpRequest . Headers . TryAddWithoutValidation ( _header . Key , _header . Value ) ;
112+ }
113+ }
114+
115+ // Serialize Request
116+ string _requestContent = null ;
117+ if ( vmScaleSetVMReimageInput != null )
118+ {
119+ _requestContent = Rest . Serialization . SafeJsonConvert . SerializeObject ( vmScaleSetVMReimageInput , Client . SerializationSettings ) ;
120+ _httpRequest . Content = new StringContent ( _requestContent , System . Text . Encoding . UTF8 ) ;
121+ _httpRequest . Content . Headers . ContentType = System . Net . Http . Headers . MediaTypeHeaderValue . Parse ( "application/json; charset=utf-8" ) ;
122+ }
123+ // Set Credentials
124+ if ( Client . Credentials != null )
125+ {
126+ cancellationToken . ThrowIfCancellationRequested ( ) ;
127+ await Client . Credentials . ProcessHttpRequestAsync ( _httpRequest , cancellationToken ) . ConfigureAwait ( false ) ;
128+ }
129+ // Send Request
130+ if ( _shouldTrace )
131+ {
132+ ServiceClientTracing . SendRequest ( _invocationId , _httpRequest ) ;
133+ }
134+ cancellationToken . ThrowIfCancellationRequested ( ) ;
135+ _httpResponse = await Client . HttpClient . SendAsync ( _httpRequest , cancellationToken ) . ConfigureAwait ( false ) ;
136+ if ( _shouldTrace )
137+ {
138+ ServiceClientTracing . ReceiveResponse ( _invocationId , _httpResponse ) ;
139+ }
140+ HttpStatusCode _statusCode = _httpResponse . StatusCode ;
141+ cancellationToken . ThrowIfCancellationRequested ( ) ;
142+ string _responseContent = null ;
143+ if ( ( int ) _statusCode != 200 && ( int ) _statusCode != 202 )
144+ {
145+ var ex = new CloudException ( string . Format ( "Operation returned an invalid status code '{0}'" , _statusCode ) ) ;
146+ try
147+ {
148+ _responseContent = await _httpResponse . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
149+ CloudError _errorBody = Rest . Serialization . SafeJsonConvert . DeserializeObject < CloudError > ( _responseContent , Client . DeserializationSettings ) ;
150+ if ( _errorBody != null )
151+ {
152+ ex = new CloudException ( _errorBody . Message ) ;
153+ ex . Body = _errorBody ;
154+ }
155+ }
156+ catch ( JsonException )
157+ {
158+ // Ignore the exception
159+ }
160+ ex . Request = new HttpRequestMessageWrapper ( _httpRequest , _requestContent ) ;
161+ ex . Response = new HttpResponseMessageWrapper ( _httpResponse , _responseContent ) ;
162+ if ( _httpResponse . Headers . Contains ( "x-ms-request-id" ) )
163+ {
164+ ex . RequestId = _httpResponse . Headers . GetValues ( "x-ms-request-id" ) . FirstOrDefault ( ) ;
165+ }
166+ if ( _shouldTrace )
167+ {
168+ ServiceClientTracing . Error ( _invocationId , ex ) ;
169+ }
170+ _httpRequest . Dispose ( ) ;
171+ if ( _httpResponse != null )
172+ {
173+ _httpResponse . Dispose ( ) ;
174+ }
175+ throw ex ;
176+ }
177+ // Create Result
178+ var _result = new AzureOperationResponse ( ) ;
179+ _result . Request = _httpRequest ;
180+ _result . Response = _httpResponse ;
181+ if ( _httpResponse . Headers . Contains ( "x-ms-request-id" ) )
182+ {
183+ _result . RequestId = _httpResponse . Headers . GetValues ( "x-ms-request-id" ) . FirstOrDefault ( ) ;
184+ }
185+ if ( _shouldTrace )
186+ {
187+ ServiceClientTracing . Exit ( _invocationId , _result ) ;
188+ }
189+ return _result ;
190+ }
21191 /// <summary>
22192 /// Deletes a virtual machine from a VM scale set.
23193 /// </summary>
0 commit comments