< Summary

Class:Azure.ResourceManager.Compute.VirtualMachineExtensionsRestOperations
Assembly:Azure.ResourceManager.Compute
File(s):C:\Git\azure-sdk-for-net\sdk\compute\Azure.ResourceManager.Compute\src\Generated\VirtualMachineExtensionsRestOperations.cs
Covered lines:8
Uncovered lines:236
Coverable lines:244
Total lines:539
Line coverage:3.2% (8 of 244)
Covered branches:2
Total branches:108
Branch coverage:1.8% (2 of 108)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-88.89%50%
CreateCreateOrUpdateRequest(...)-0%100%
CreateOrUpdateAsync()-0%0%
CreateOrUpdate(...)-0%0%
CreateUpdateRequest(...)-0%100%
UpdateAsync()-0%0%
Update(...)-0%0%
CreateDeleteRequest(...)-0%100%
DeleteAsync()-0%0%
Delete(...)-0%0%
CreateGetRequest(...)-0%0%
GetAsync()-0%0%
Get(...)-0%0%
CreateListRequest(...)-0%0%
ListAsync()-0%0%
List(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\compute\Azure.ResourceManager.Compute\src\Generated\VirtualMachineExtensionsRestOperations.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Azure;
 13using Azure.Core;
 14using Azure.Core.Pipeline;
 15using Azure.ResourceManager.Compute.Models;
 16
 17namespace Azure.ResourceManager.Compute
 18{
 19    internal partial class VirtualMachineExtensionsRestOperations
 20    {
 21        private string subscriptionId;
 22        private Uri endpoint;
 23        private ClientDiagnostics _clientDiagnostics;
 24        private HttpPipeline _pipeline;
 25
 26        /// <summary> Initializes a new instance of VirtualMachineExtensionsRestOperations. </summary>
 27        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 28        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 29        /// <param name="subscriptionId"> Subscription credentials which uniquely identify Microsoft Azure subscription.
 30        /// <param name="endpoint"> server parameter. </param>
 31        /// <exception cref="ArgumentNullException"> This occurs when one of the required arguments is null. </exception
 39632        public VirtualMachineExtensionsRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string
 33        {
 39634            if (subscriptionId == null)
 35            {
 036                throw new ArgumentNullException(nameof(subscriptionId));
 37            }
 39638            endpoint ??= new Uri("https://management.azure.com");
 39
 39640            this.subscriptionId = subscriptionId;
 39641            this.endpoint = endpoint;
 39642            _clientDiagnostics = clientDiagnostics;
 39643            _pipeline = pipeline;
 39644        }
 45
 46        internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string vmName, string vmExtensionName
 47        {
 048            var message = _pipeline.CreateMessage();
 049            var request = message.Request;
 050            request.Method = RequestMethod.Put;
 051            var uri = new RawRequestUriBuilder();
 052            uri.Reset(endpoint);
 053            uri.AppendPath("/subscriptions/", false);
 054            uri.AppendPath(subscriptionId, true);
 055            uri.AppendPath("/resourceGroups/", false);
 056            uri.AppendPath(resourceGroupName, true);
 057            uri.AppendPath("/providers/Microsoft.Compute/virtualMachines/", false);
 058            uri.AppendPath(vmName, true);
 059            uri.AppendPath("/extensions/", false);
 060            uri.AppendPath(vmExtensionName, true);
 061            uri.AppendQuery("api-version", "2019-12-01", true);
 062            request.Uri = uri;
 063            request.Headers.Add("Content-Type", "application/json");
 064            var content = new Utf8JsonRequestContent();
 065            content.JsonWriter.WriteObjectValue(extensionParameters);
 066            request.Content = content;
 067            return message;
 68        }
 69
 70        /// <summary> The operation to create or update the extension. </summary>
 71        /// <param name="resourceGroupName"> The name of the resource group. </param>
 72        /// <param name="vmName"> The name of the virtual machine where the extension should be created or updated. </pa
 73        /// <param name="vmExtensionName"> The name of the virtual machine extension. </param>
 74        /// <param name="extensionParameters"> Parameters supplied to the Create Virtual Machine Extension operation. </
 75        /// <param name="cancellationToken"> The cancellation token to use. </param>
 76        public async Task<Response> CreateOrUpdateAsync(string resourceGroupName, string vmName, string vmExtensionName,
 77        {
 078            if (resourceGroupName == null)
 79            {
 080                throw new ArgumentNullException(nameof(resourceGroupName));
 81            }
 082            if (vmName == null)
 83            {
 084                throw new ArgumentNullException(nameof(vmName));
 85            }
 086            if (vmExtensionName == null)
 87            {
 088                throw new ArgumentNullException(nameof(vmExtensionName));
 89            }
 090            if (extensionParameters == null)
 91            {
 092                throw new ArgumentNullException(nameof(extensionParameters));
 93            }
 94
 095            using var message = CreateCreateOrUpdateRequest(resourceGroupName, vmName, vmExtensionName, extensionParamet
 096            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 097            switch (message.Response.Status)
 98            {
 99                case 200:
 100                case 201:
 0101                    return message.Response;
 102                default:
 0103                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 104            }
 0105        }
 106
 107        /// <summary> The operation to create or update the extension. </summary>
 108        /// <param name="resourceGroupName"> The name of the resource group. </param>
 109        /// <param name="vmName"> The name of the virtual machine where the extension should be created or updated. </pa
 110        /// <param name="vmExtensionName"> The name of the virtual machine extension. </param>
 111        /// <param name="extensionParameters"> Parameters supplied to the Create Virtual Machine Extension operation. </
 112        /// <param name="cancellationToken"> The cancellation token to use. </param>
 113        public Response CreateOrUpdate(string resourceGroupName, string vmName, string vmExtensionName, VirtualMachineEx
 114        {
 0115            if (resourceGroupName == null)
 116            {
 0117                throw new ArgumentNullException(nameof(resourceGroupName));
 118            }
 0119            if (vmName == null)
 120            {
 0121                throw new ArgumentNullException(nameof(vmName));
 122            }
 0123            if (vmExtensionName == null)
 124            {
 0125                throw new ArgumentNullException(nameof(vmExtensionName));
 126            }
 0127            if (extensionParameters == null)
 128            {
 0129                throw new ArgumentNullException(nameof(extensionParameters));
 130            }
 131
 0132            using var message = CreateCreateOrUpdateRequest(resourceGroupName, vmName, vmExtensionName, extensionParamet
 0133            _pipeline.Send(message, cancellationToken);
 0134            switch (message.Response.Status)
 135            {
 136                case 200:
 137                case 201:
 0138                    return message.Response;
 139                default:
 0140                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 141            }
 0142        }
 143
 144        internal HttpMessage CreateUpdateRequest(string resourceGroupName, string vmName, string vmExtensionName, Virtua
 145        {
 0146            var message = _pipeline.CreateMessage();
 0147            var request = message.Request;
 0148            request.Method = RequestMethod.Patch;
 0149            var uri = new RawRequestUriBuilder();
 0150            uri.Reset(endpoint);
 0151            uri.AppendPath("/subscriptions/", false);
 0152            uri.AppendPath(subscriptionId, true);
 0153            uri.AppendPath("/resourceGroups/", false);
 0154            uri.AppendPath(resourceGroupName, true);
 0155            uri.AppendPath("/providers/Microsoft.Compute/virtualMachines/", false);
 0156            uri.AppendPath(vmName, true);
 0157            uri.AppendPath("/extensions/", false);
 0158            uri.AppendPath(vmExtensionName, true);
 0159            uri.AppendQuery("api-version", "2019-12-01", true);
 0160            request.Uri = uri;
 0161            request.Headers.Add("Content-Type", "application/json");
 0162            var content = new Utf8JsonRequestContent();
 0163            content.JsonWriter.WriteObjectValue(extensionParameters);
 0164            request.Content = content;
 0165            return message;
 166        }
 167
 168        /// <summary> The operation to update the extension. </summary>
 169        /// <param name="resourceGroupName"> The name of the resource group. </param>
 170        /// <param name="vmName"> The name of the virtual machine where the extension should be updated. </param>
 171        /// <param name="vmExtensionName"> The name of the virtual machine extension. </param>
 172        /// <param name="extensionParameters"> Parameters supplied to the Update Virtual Machine Extension operation. </
 173        /// <param name="cancellationToken"> The cancellation token to use. </param>
 174        public async Task<Response> UpdateAsync(string resourceGroupName, string vmName, string vmExtensionName, Virtual
 175        {
 0176            if (resourceGroupName == null)
 177            {
 0178                throw new ArgumentNullException(nameof(resourceGroupName));
 179            }
 0180            if (vmName == null)
 181            {
 0182                throw new ArgumentNullException(nameof(vmName));
 183            }
 0184            if (vmExtensionName == null)
 185            {
 0186                throw new ArgumentNullException(nameof(vmExtensionName));
 187            }
 0188            if (extensionParameters == null)
 189            {
 0190                throw new ArgumentNullException(nameof(extensionParameters));
 191            }
 192
 0193            using var message = CreateUpdateRequest(resourceGroupName, vmName, vmExtensionName, extensionParameters);
 0194            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0195            switch (message.Response.Status)
 196            {
 197                case 200:
 0198                    return message.Response;
 199                default:
 0200                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 201            }
 0202        }
 203
 204        /// <summary> The operation to update the extension. </summary>
 205        /// <param name="resourceGroupName"> The name of the resource group. </param>
 206        /// <param name="vmName"> The name of the virtual machine where the extension should be updated. </param>
 207        /// <param name="vmExtensionName"> The name of the virtual machine extension. </param>
 208        /// <param name="extensionParameters"> Parameters supplied to the Update Virtual Machine Extension operation. </
 209        /// <param name="cancellationToken"> The cancellation token to use. </param>
 210        public Response Update(string resourceGroupName, string vmName, string vmExtensionName, VirtualMachineExtensionU
 211        {
 0212            if (resourceGroupName == null)
 213            {
 0214                throw new ArgumentNullException(nameof(resourceGroupName));
 215            }
 0216            if (vmName == null)
 217            {
 0218                throw new ArgumentNullException(nameof(vmName));
 219            }
 0220            if (vmExtensionName == null)
 221            {
 0222                throw new ArgumentNullException(nameof(vmExtensionName));
 223            }
 0224            if (extensionParameters == null)
 225            {
 0226                throw new ArgumentNullException(nameof(extensionParameters));
 227            }
 228
 0229            using var message = CreateUpdateRequest(resourceGroupName, vmName, vmExtensionName, extensionParameters);
 0230            _pipeline.Send(message, cancellationToken);
 0231            switch (message.Response.Status)
 232            {
 233                case 200:
 0234                    return message.Response;
 235                default:
 0236                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 237            }
 0238        }
 239
 240        internal HttpMessage CreateDeleteRequest(string resourceGroupName, string vmName, string vmExtensionName)
 241        {
 0242            var message = _pipeline.CreateMessage();
 0243            var request = message.Request;
 0244            request.Method = RequestMethod.Delete;
 0245            var uri = new RawRequestUriBuilder();
 0246            uri.Reset(endpoint);
 0247            uri.AppendPath("/subscriptions/", false);
 0248            uri.AppendPath(subscriptionId, true);
 0249            uri.AppendPath("/resourceGroups/", false);
 0250            uri.AppendPath(resourceGroupName, true);
 0251            uri.AppendPath("/providers/Microsoft.Compute/virtualMachines/", false);
 0252            uri.AppendPath(vmName, true);
 0253            uri.AppendPath("/extensions/", false);
 0254            uri.AppendPath(vmExtensionName, true);
 0255            uri.AppendQuery("api-version", "2019-12-01", true);
 0256            request.Uri = uri;
 0257            return message;
 258        }
 259
 260        /// <summary> The operation to delete the extension. </summary>
 261        /// <param name="resourceGroupName"> The name of the resource group. </param>
 262        /// <param name="vmName"> The name of the virtual machine where the extension should be deleted. </param>
 263        /// <param name="vmExtensionName"> The name of the virtual machine extension. </param>
 264        /// <param name="cancellationToken"> The cancellation token to use. </param>
 265        public async Task<Response> DeleteAsync(string resourceGroupName, string vmName, string vmExtensionName, Cancell
 266        {
 0267            if (resourceGroupName == null)
 268            {
 0269                throw new ArgumentNullException(nameof(resourceGroupName));
 270            }
 0271            if (vmName == null)
 272            {
 0273                throw new ArgumentNullException(nameof(vmName));
 274            }
 0275            if (vmExtensionName == null)
 276            {
 0277                throw new ArgumentNullException(nameof(vmExtensionName));
 278            }
 279
 0280            using var message = CreateDeleteRequest(resourceGroupName, vmName, vmExtensionName);
 0281            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0282            switch (message.Response.Status)
 283            {
 284                case 200:
 285                case 202:
 286                case 204:
 0287                    return message.Response;
 288                default:
 0289                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 290            }
 0291        }
 292
 293        /// <summary> The operation to delete the extension. </summary>
 294        /// <param name="resourceGroupName"> The name of the resource group. </param>
 295        /// <param name="vmName"> The name of the virtual machine where the extension should be deleted. </param>
 296        /// <param name="vmExtensionName"> The name of the virtual machine extension. </param>
 297        /// <param name="cancellationToken"> The cancellation token to use. </param>
 298        public Response Delete(string resourceGroupName, string vmName, string vmExtensionName, CancellationToken cancel
 299        {
 0300            if (resourceGroupName == null)
 301            {
 0302                throw new ArgumentNullException(nameof(resourceGroupName));
 303            }
 0304            if (vmName == null)
 305            {
 0306                throw new ArgumentNullException(nameof(vmName));
 307            }
 0308            if (vmExtensionName == null)
 309            {
 0310                throw new ArgumentNullException(nameof(vmExtensionName));
 311            }
 312
 0313            using var message = CreateDeleteRequest(resourceGroupName, vmName, vmExtensionName);
 0314            _pipeline.Send(message, cancellationToken);
 0315            switch (message.Response.Status)
 316            {
 317                case 200:
 318                case 202:
 319                case 204:
 0320                    return message.Response;
 321                default:
 0322                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 323            }
 0324        }
 325
 326        internal HttpMessage CreateGetRequest(string resourceGroupName, string vmName, string vmExtensionName, string ex
 327        {
 0328            var message = _pipeline.CreateMessage();
 0329            var request = message.Request;
 0330            request.Method = RequestMethod.Get;
 0331            var uri = new RawRequestUriBuilder();
 0332            uri.Reset(endpoint);
 0333            uri.AppendPath("/subscriptions/", false);
 0334            uri.AppendPath(subscriptionId, true);
 0335            uri.AppendPath("/resourceGroups/", false);
 0336            uri.AppendPath(resourceGroupName, true);
 0337            uri.AppendPath("/providers/Microsoft.Compute/virtualMachines/", false);
 0338            uri.AppendPath(vmName, true);
 0339            uri.AppendPath("/extensions/", false);
 0340            uri.AppendPath(vmExtensionName, true);
 0341            if (expand != null)
 342            {
 0343                uri.AppendQuery("$expand", expand, true);
 344            }
 0345            uri.AppendQuery("api-version", "2019-12-01", true);
 0346            request.Uri = uri;
 0347            return message;
 348        }
 349
 350        /// <summary> The operation to get the extension. </summary>
 351        /// <param name="resourceGroupName"> The name of the resource group. </param>
 352        /// <param name="vmName"> The name of the virtual machine containing the extension. </param>
 353        /// <param name="vmExtensionName"> The name of the virtual machine extension. </param>
 354        /// <param name="expand"> The expand expression to apply on the operation. </param>
 355        /// <param name="cancellationToken"> The cancellation token to use. </param>
 356        public async Task<Response<VirtualMachineExtension>> GetAsync(string resourceGroupName, string vmName, string vm
 357        {
 0358            if (resourceGroupName == null)
 359            {
 0360                throw new ArgumentNullException(nameof(resourceGroupName));
 361            }
 0362            if (vmName == null)
 363            {
 0364                throw new ArgumentNullException(nameof(vmName));
 365            }
 0366            if (vmExtensionName == null)
 367            {
 0368                throw new ArgumentNullException(nameof(vmExtensionName));
 369            }
 370
 0371            using var message = CreateGetRequest(resourceGroupName, vmName, vmExtensionName, expand);
 0372            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0373            switch (message.Response.Status)
 374            {
 375                case 200:
 376                    {
 0377                        VirtualMachineExtension value = default;
 0378                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0379                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 380                        {
 0381                            value = null;
 382                        }
 383                        else
 384                        {
 0385                            value = VirtualMachineExtension.DeserializeVirtualMachineExtension(document.RootElement);
 386                        }
 0387                        return Response.FromValue(value, message.Response);
 388                    }
 389                default:
 0390                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 391            }
 0392        }
 393
 394        /// <summary> The operation to get the extension. </summary>
 395        /// <param name="resourceGroupName"> The name of the resource group. </param>
 396        /// <param name="vmName"> The name of the virtual machine containing the extension. </param>
 397        /// <param name="vmExtensionName"> The name of the virtual machine extension. </param>
 398        /// <param name="expand"> The expand expression to apply on the operation. </param>
 399        /// <param name="cancellationToken"> The cancellation token to use. </param>
 400        public Response<VirtualMachineExtension> Get(string resourceGroupName, string vmName, string vmExtensionName, st
 401        {
 0402            if (resourceGroupName == null)
 403            {
 0404                throw new ArgumentNullException(nameof(resourceGroupName));
 405            }
 0406            if (vmName == null)
 407            {
 0408                throw new ArgumentNullException(nameof(vmName));
 409            }
 0410            if (vmExtensionName == null)
 411            {
 0412                throw new ArgumentNullException(nameof(vmExtensionName));
 413            }
 414
 0415            using var message = CreateGetRequest(resourceGroupName, vmName, vmExtensionName, expand);
 0416            _pipeline.Send(message, cancellationToken);
 0417            switch (message.Response.Status)
 418            {
 419                case 200:
 420                    {
 0421                        VirtualMachineExtension value = default;
 0422                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0423                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 424                        {
 0425                            value = null;
 426                        }
 427                        else
 428                        {
 0429                            value = VirtualMachineExtension.DeserializeVirtualMachineExtension(document.RootElement);
 430                        }
 0431                        return Response.FromValue(value, message.Response);
 432                    }
 433                default:
 0434                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 435            }
 0436        }
 437
 438        internal HttpMessage CreateListRequest(string resourceGroupName, string vmName, string expand)
 439        {
 0440            var message = _pipeline.CreateMessage();
 0441            var request = message.Request;
 0442            request.Method = RequestMethod.Get;
 0443            var uri = new RawRequestUriBuilder();
 0444            uri.Reset(endpoint);
 0445            uri.AppendPath("/subscriptions/", false);
 0446            uri.AppendPath(subscriptionId, true);
 0447            uri.AppendPath("/resourceGroups/", false);
 0448            uri.AppendPath(resourceGroupName, true);
 0449            uri.AppendPath("/providers/Microsoft.Compute/virtualMachines/", false);
 0450            uri.AppendPath(vmName, true);
 0451            uri.AppendPath("/extensions", false);
 0452            if (expand != null)
 453            {
 0454                uri.AppendQuery("$expand", expand, true);
 455            }
 0456            uri.AppendQuery("api-version", "2019-12-01", true);
 0457            request.Uri = uri;
 0458            return message;
 459        }
 460
 461        /// <summary> The operation to get all extensions of a Virtual Machine. </summary>
 462        /// <param name="resourceGroupName"> The name of the resource group. </param>
 463        /// <param name="vmName"> The name of the virtual machine containing the extension. </param>
 464        /// <param name="expand"> The expand expression to apply on the operation. </param>
 465        /// <param name="cancellationToken"> The cancellation token to use. </param>
 466        public async Task<Response<VirtualMachineExtensionsListResult>> ListAsync(string resourceGroupName, string vmNam
 467        {
 0468            if (resourceGroupName == null)
 469            {
 0470                throw new ArgumentNullException(nameof(resourceGroupName));
 471            }
 0472            if (vmName == null)
 473            {
 0474                throw new ArgumentNullException(nameof(vmName));
 475            }
 476
 0477            using var message = CreateListRequest(resourceGroupName, vmName, expand);
 0478            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0479            switch (message.Response.Status)
 480            {
 481                case 200:
 482                    {
 0483                        VirtualMachineExtensionsListResult value = default;
 0484                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0485                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 486                        {
 0487                            value = null;
 488                        }
 489                        else
 490                        {
 0491                            value = VirtualMachineExtensionsListResult.DeserializeVirtualMachineExtensionsListResult(doc
 492                        }
 0493                        return Response.FromValue(value, message.Response);
 494                    }
 495                default:
 0496                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 497            }
 0498        }
 499
 500        /// <summary> The operation to get all extensions of a Virtual Machine. </summary>
 501        /// <param name="resourceGroupName"> The name of the resource group. </param>
 502        /// <param name="vmName"> The name of the virtual machine containing the extension. </param>
 503        /// <param name="expand"> The expand expression to apply on the operation. </param>
 504        /// <param name="cancellationToken"> The cancellation token to use. </param>
 505        public Response<VirtualMachineExtensionsListResult> List(string resourceGroupName, string vmName, string expand 
 506        {
 0507            if (resourceGroupName == null)
 508            {
 0509                throw new ArgumentNullException(nameof(resourceGroupName));
 510            }
 0511            if (vmName == null)
 512            {
 0513                throw new ArgumentNullException(nameof(vmName));
 514            }
 515
 0516            using var message = CreateListRequest(resourceGroupName, vmName, expand);
 0517            _pipeline.Send(message, cancellationToken);
 0518            switch (message.Response.Status)
 519            {
 520                case 200:
 521                    {
 0522                        VirtualMachineExtensionsListResult value = default;
 0523                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0524                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 525                        {
 0526                            value = null;
 527                        }
 528                        else
 529                        {
 0530                            value = VirtualMachineExtensionsListResult.DeserializeVirtualMachineExtensionsListResult(doc
 531                        }
 0532                        return Response.FromValue(value, message.Response);
 533                    }
 534                default:
 0535                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 536            }
 0537        }
 538    }
 539}