< Summary

Class:Azure.ResourceManager.Compute.VirtualMachineScaleSetRollingUpgradesRestOperations
Assembly:Azure.ResourceManager.Compute
File(s):C:\Git\azure-sdk-for-net\sdk\compute\Azure.ResourceManager.Compute\src\Generated\VirtualMachineScaleSetRollingUpgradesRestOperations.cs
Covered lines:8
Uncovered lines:151
Coverable lines:159
Total lines:360
Line coverage:5% (8 of 159)
Covered branches:2
Total branches:68
Branch coverage:2.9% (2 of 68)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-88.89%50%
CreateCancelRequest(...)-0%100%
CancelAsync()-0%0%
Cancel(...)-0%0%
CreateStartOSUpgradeRequest(...)-0%100%
StartOSUpgradeAsync()-0%0%
StartOSUpgrade(...)-0%0%
CreateStartExtensionUpgradeRequest(...)-0%100%
StartExtensionUpgradeAsync()-0%0%
StartExtensionUpgrade(...)-0%0%
CreateGetLatestRequest(...)-0%100%
GetLatestAsync()-0%0%
GetLatest(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\compute\Azure.ResourceManager.Compute\src\Generated\VirtualMachineScaleSetRollingUpgradesRestOperations.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 VirtualMachineScaleSetRollingUpgradesRestOperations
 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 VirtualMachineScaleSetRollingUpgradesRestOperations. </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 VirtualMachineScaleSetRollingUpgradesRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pip
 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 CreateCancelRequest(string resourceGroupName, string vmScaleSetName)
 47        {
 048            var message = _pipeline.CreateMessage();
 049            var request = message.Request;
 050            request.Method = RequestMethod.Post;
 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/virtualMachineScaleSets/", false);
 058            uri.AppendPath(vmScaleSetName, true);
 059            uri.AppendPath("/rollingUpgrades/cancel", false);
 060            uri.AppendQuery("api-version", "2019-12-01", true);
 061            request.Uri = uri;
 062            return message;
 63        }
 64
 65        /// <summary> Cancels the current virtual machine scale set rolling upgrade. </summary>
 66        /// <param name="resourceGroupName"> The name of the resource group. </param>
 67        /// <param name="vmScaleSetName"> The name of the VM scale set. </param>
 68        /// <param name="cancellationToken"> The cancellation token to use. </param>
 69        public async Task<Response> CancelAsync(string resourceGroupName, string vmScaleSetName, CancellationToken cance
 70        {
 071            if (resourceGroupName == null)
 72            {
 073                throw new ArgumentNullException(nameof(resourceGroupName));
 74            }
 075            if (vmScaleSetName == null)
 76            {
 077                throw new ArgumentNullException(nameof(vmScaleSetName));
 78            }
 79
 080            using var message = CreateCancelRequest(resourceGroupName, vmScaleSetName);
 081            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 082            switch (message.Response.Status)
 83            {
 84                case 200:
 85                case 202:
 086                    return message.Response;
 87                default:
 088                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 89            }
 090        }
 91
 92        /// <summary> Cancels the current virtual machine scale set rolling upgrade. </summary>
 93        /// <param name="resourceGroupName"> The name of the resource group. </param>
 94        /// <param name="vmScaleSetName"> The name of the VM scale set. </param>
 95        /// <param name="cancellationToken"> The cancellation token to use. </param>
 96        public Response Cancel(string resourceGroupName, string vmScaleSetName, CancellationToken cancellationToken = de
 97        {
 098            if (resourceGroupName == null)
 99            {
 0100                throw new ArgumentNullException(nameof(resourceGroupName));
 101            }
 0102            if (vmScaleSetName == null)
 103            {
 0104                throw new ArgumentNullException(nameof(vmScaleSetName));
 105            }
 106
 0107            using var message = CreateCancelRequest(resourceGroupName, vmScaleSetName);
 0108            _pipeline.Send(message, cancellationToken);
 0109            switch (message.Response.Status)
 110            {
 111                case 200:
 112                case 202:
 0113                    return message.Response;
 114                default:
 0115                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 116            }
 0117        }
 118
 119        internal HttpMessage CreateStartOSUpgradeRequest(string resourceGroupName, string vmScaleSetName)
 120        {
 0121            var message = _pipeline.CreateMessage();
 0122            var request = message.Request;
 0123            request.Method = RequestMethod.Post;
 0124            var uri = new RawRequestUriBuilder();
 0125            uri.Reset(endpoint);
 0126            uri.AppendPath("/subscriptions/", false);
 0127            uri.AppendPath(subscriptionId, true);
 0128            uri.AppendPath("/resourceGroups/", false);
 0129            uri.AppendPath(resourceGroupName, true);
 0130            uri.AppendPath("/providers/Microsoft.Compute/virtualMachineScaleSets/", false);
 0131            uri.AppendPath(vmScaleSetName, true);
 0132            uri.AppendPath("/osRollingUpgrade", false);
 0133            uri.AppendQuery("api-version", "2019-12-01", true);
 0134            request.Uri = uri;
 0135            return message;
 136        }
 137
 138        /// <summary> Starts a rolling upgrade to move all virtual machine scale set instances to the latest available P
 139        /// <param name="resourceGroupName"> The name of the resource group. </param>
 140        /// <param name="vmScaleSetName"> The name of the VM scale set. </param>
 141        /// <param name="cancellationToken"> The cancellation token to use. </param>
 142        public async Task<Response> StartOSUpgradeAsync(string resourceGroupName, string vmScaleSetName, CancellationTok
 143        {
 0144            if (resourceGroupName == null)
 145            {
 0146                throw new ArgumentNullException(nameof(resourceGroupName));
 147            }
 0148            if (vmScaleSetName == null)
 149            {
 0150                throw new ArgumentNullException(nameof(vmScaleSetName));
 151            }
 152
 0153            using var message = CreateStartOSUpgradeRequest(resourceGroupName, vmScaleSetName);
 0154            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0155            switch (message.Response.Status)
 156            {
 157                case 200:
 158                case 202:
 0159                    return message.Response;
 160                default:
 0161                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 162            }
 0163        }
 164
 165        /// <summary> Starts a rolling upgrade to move all virtual machine scale set instances to the latest available P
 166        /// <param name="resourceGroupName"> The name of the resource group. </param>
 167        /// <param name="vmScaleSetName"> The name of the VM scale set. </param>
 168        /// <param name="cancellationToken"> The cancellation token to use. </param>
 169        public Response StartOSUpgrade(string resourceGroupName, string vmScaleSetName, CancellationToken cancellationTo
 170        {
 0171            if (resourceGroupName == null)
 172            {
 0173                throw new ArgumentNullException(nameof(resourceGroupName));
 174            }
 0175            if (vmScaleSetName == null)
 176            {
 0177                throw new ArgumentNullException(nameof(vmScaleSetName));
 178            }
 179
 0180            using var message = CreateStartOSUpgradeRequest(resourceGroupName, vmScaleSetName);
 0181            _pipeline.Send(message, cancellationToken);
 0182            switch (message.Response.Status)
 183            {
 184                case 200:
 185                case 202:
 0186                    return message.Response;
 187                default:
 0188                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 189            }
 0190        }
 191
 192        internal HttpMessage CreateStartExtensionUpgradeRequest(string resourceGroupName, string vmScaleSetName)
 193        {
 0194            var message = _pipeline.CreateMessage();
 0195            var request = message.Request;
 0196            request.Method = RequestMethod.Post;
 0197            var uri = new RawRequestUriBuilder();
 0198            uri.Reset(endpoint);
 0199            uri.AppendPath("/subscriptions/", false);
 0200            uri.AppendPath(subscriptionId, true);
 0201            uri.AppendPath("/resourceGroups/", false);
 0202            uri.AppendPath(resourceGroupName, true);
 0203            uri.AppendPath("/providers/Microsoft.Compute/virtualMachineScaleSets/", false);
 0204            uri.AppendPath(vmScaleSetName, true);
 0205            uri.AppendPath("/extensionRollingUpgrade", false);
 0206            uri.AppendQuery("api-version", "2019-12-01", true);
 0207            request.Uri = uri;
 0208            return message;
 209        }
 210
 211        /// <summary> Starts a rolling upgrade to move all extensions for all virtual machine scale set instances to the
 212        /// <param name="resourceGroupName"> The name of the resource group. </param>
 213        /// <param name="vmScaleSetName"> The name of the VM scale set. </param>
 214        /// <param name="cancellationToken"> The cancellation token to use. </param>
 215        public async Task<Response> StartExtensionUpgradeAsync(string resourceGroupName, string vmScaleSetName, Cancella
 216        {
 0217            if (resourceGroupName == null)
 218            {
 0219                throw new ArgumentNullException(nameof(resourceGroupName));
 220            }
 0221            if (vmScaleSetName == null)
 222            {
 0223                throw new ArgumentNullException(nameof(vmScaleSetName));
 224            }
 225
 0226            using var message = CreateStartExtensionUpgradeRequest(resourceGroupName, vmScaleSetName);
 0227            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0228            switch (message.Response.Status)
 229            {
 230                case 200:
 231                case 202:
 0232                    return message.Response;
 233                default:
 0234                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 235            }
 0236        }
 237
 238        /// <summary> Starts a rolling upgrade to move all extensions for all virtual machine scale set instances to the
 239        /// <param name="resourceGroupName"> The name of the resource group. </param>
 240        /// <param name="vmScaleSetName"> The name of the VM scale set. </param>
 241        /// <param name="cancellationToken"> The cancellation token to use. </param>
 242        public Response StartExtensionUpgrade(string resourceGroupName, string vmScaleSetName, CancellationToken cancell
 243        {
 0244            if (resourceGroupName == null)
 245            {
 0246                throw new ArgumentNullException(nameof(resourceGroupName));
 247            }
 0248            if (vmScaleSetName == null)
 249            {
 0250                throw new ArgumentNullException(nameof(vmScaleSetName));
 251            }
 252
 0253            using var message = CreateStartExtensionUpgradeRequest(resourceGroupName, vmScaleSetName);
 0254            _pipeline.Send(message, cancellationToken);
 0255            switch (message.Response.Status)
 256            {
 257                case 200:
 258                case 202:
 0259                    return message.Response;
 260                default:
 0261                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 262            }
 0263        }
 264
 265        internal HttpMessage CreateGetLatestRequest(string resourceGroupName, string vmScaleSetName)
 266        {
 0267            var message = _pipeline.CreateMessage();
 0268            var request = message.Request;
 0269            request.Method = RequestMethod.Get;
 0270            var uri = new RawRequestUriBuilder();
 0271            uri.Reset(endpoint);
 0272            uri.AppendPath("/subscriptions/", false);
 0273            uri.AppendPath(subscriptionId, true);
 0274            uri.AppendPath("/resourceGroups/", false);
 0275            uri.AppendPath(resourceGroupName, true);
 0276            uri.AppendPath("/providers/Microsoft.Compute/virtualMachineScaleSets/", false);
 0277            uri.AppendPath(vmScaleSetName, true);
 0278            uri.AppendPath("/rollingUpgrades/latest", false);
 0279            uri.AppendQuery("api-version", "2019-12-01", true);
 0280            request.Uri = uri;
 0281            return message;
 282        }
 283
 284        /// <summary> Gets the status of the latest virtual machine scale set rolling upgrade. </summary>
 285        /// <param name="resourceGroupName"> The name of the resource group. </param>
 286        /// <param name="vmScaleSetName"> The name of the VM scale set. </param>
 287        /// <param name="cancellationToken"> The cancellation token to use. </param>
 288        public async Task<Response<RollingUpgradeStatusInfo>> GetLatestAsync(string resourceGroupName, string vmScaleSet
 289        {
 0290            if (resourceGroupName == null)
 291            {
 0292                throw new ArgumentNullException(nameof(resourceGroupName));
 293            }
 0294            if (vmScaleSetName == null)
 295            {
 0296                throw new ArgumentNullException(nameof(vmScaleSetName));
 297            }
 298
 0299            using var message = CreateGetLatestRequest(resourceGroupName, vmScaleSetName);
 0300            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0301            switch (message.Response.Status)
 302            {
 303                case 200:
 304                    {
 0305                        RollingUpgradeStatusInfo value = default;
 0306                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0307                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 308                        {
 0309                            value = null;
 310                        }
 311                        else
 312                        {
 0313                            value = RollingUpgradeStatusInfo.DeserializeRollingUpgradeStatusInfo(document.RootElement);
 314                        }
 0315                        return Response.FromValue(value, message.Response);
 316                    }
 317                default:
 0318                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 319            }
 0320        }
 321
 322        /// <summary> Gets the status of the latest virtual machine scale set rolling upgrade. </summary>
 323        /// <param name="resourceGroupName"> The name of the resource group. </param>
 324        /// <param name="vmScaleSetName"> The name of the VM scale set. </param>
 325        /// <param name="cancellationToken"> The cancellation token to use. </param>
 326        public Response<RollingUpgradeStatusInfo> GetLatest(string resourceGroupName, string vmScaleSetName, Cancellatio
 327        {
 0328            if (resourceGroupName == null)
 329            {
 0330                throw new ArgumentNullException(nameof(resourceGroupName));
 331            }
 0332            if (vmScaleSetName == null)
 333            {
 0334                throw new ArgumentNullException(nameof(vmScaleSetName));
 335            }
 336
 0337            using var message = CreateGetLatestRequest(resourceGroupName, vmScaleSetName);
 0338            _pipeline.Send(message, cancellationToken);
 0339            switch (message.Response.Status)
 340            {
 341                case 200:
 342                    {
 0343                        RollingUpgradeStatusInfo value = default;
 0344                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0345                        if (document.RootElement.ValueKind == JsonValueKind.Null)
 346                        {
 0347                            value = null;
 348                        }
 349                        else
 350                        {
 0351                            value = RollingUpgradeStatusInfo.DeserializeRollingUpgradeStatusInfo(document.RootElement);
 352                        }
 0353                        return Response.FromValue(value, message.Response);
 354                    }
 355                default:
 0356                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 357            }
 0358        }
 359    }
 360}