public async Task Update() { var diskName = Recording.GenerateAssetName("testDisk-"); var disk = await CreateDiskAsync(diskName); var newDiskSize = 20; var update = new DiskPatch() { DiskSizeGB = newDiskSize }; var lro = await disk.UpdateAsync(WaitUntil.Completed, update); DiskResource updatedDisk = lro.Value; Assert.AreEqual(newDiskSize, updatedDisk.Data.DiskSizeGB); }
public virtual ArmOperation <DiskResource> Update(WaitUntil waitUntil, DiskPatch patch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(patch, nameof(patch)); using var scope = _diskClientDiagnostics.CreateScope("DiskResource.Update"); scope.Start(); try { var response = _diskRestClient.Update(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, patch, cancellationToken); var operation = new ComputeArmOperation <DiskResource>(new DiskOperationSource(Client), _diskClientDiagnostics, Pipeline, _diskRestClient.CreateUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, patch).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public Response Update(string subscriptionId, string resourceGroupName, string diskName, DiskPatch patch, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); Argument.AssertNotNullOrEmpty(diskName, nameof(diskName)); Argument.AssertNotNull(patch, nameof(patch)); using var message = CreateUpdateRequest(subscriptionId, resourceGroupName, diskName, patch); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { case 200: case 202: return(message.Response); default: throw new RequestFailedException(message.Response); } }
internal HttpMessage CreateUpdateRequest(string subscriptionId, string resourceGroupName, string diskName, DiskPatch patch) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Patch; var uri = new RawRequestUriBuilder(); uri.Reset(_endpoint); uri.AppendPath("/subscriptions/", false); uri.AppendPath(subscriptionId, true); uri.AppendPath("/resourceGroups/", false); uri.AppendPath(resourceGroupName, true); uri.AppendPath("/providers/Microsoft.Compute/disks/", false); uri.AppendPath(diskName, true); uri.AppendQuery("api-version", _apiVersion, true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(patch); request.Content = content; _userAgent.Apply(message); return(message); }