internal Snapshot(ArmResource options, SnapshotData resource) : base(options, resource.Id) { HasData = true; _data = resource; _clientDiagnostics = new ClientDiagnostics(ClientOptions); _restClient = new SnapshotsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Id.SubscriptionId, BaseUri); }
SnapshotResource IOperationSource <SnapshotResource> .CreateResult(Response response, CancellationToken cancellationToken) { using var document = JsonDocument.Parse(response.ContentStream); var data = SnapshotData.DeserializeSnapshotData(document.RootElement); return(new SnapshotResource(_client, data)); }
internal Snapshot(ArmResource options, SnapshotData data) : base(options, data.Id) { HasData = true; _data = data; _clientDiagnostics = new ClientDiagnostics(ClientOptions); _snapshotsRestClient = new SnapshotsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); #if DEBUG ValidateResourceId(Id); #endif }
internal Snapshot(ArmResource options, SnapshotData data) : base(options, data.Id) { HasData = true; _data = data; _clientDiagnostics = new ClientDiagnostics(ClientOptions); ClientOptions.TryGetApiVersion(ResourceType, out string apiVersion); _snapshotsRestClient = new SnapshotsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri, apiVersion); #if DEBUG ValidateResourceId(Id); #endif }
public async Task <Response <SnapshotData> > GetAsync(string resourceGroupName, string snapshotName, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (snapshotName == null) { throw new ArgumentNullException(nameof(snapshotName)); } using var message = CreateGetRequest(resourceGroupName, snapshotName); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { SnapshotData value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = SnapshotData.DeserializeSnapshotData(document.RootElement); return(Response.FromValue(value, message.Response)); }
internal Snapshot(ArmClient client, SnapshotData data) : this(client, data.Id) { HasData = true; _data = data; }
public async virtual Task <SnapshotCreateOrUpdateOperation> CreateOrUpdateAsync(bool waitForCompletion, string snapshotName, SnapshotData snapshot, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(snapshotName, nameof(snapshotName)); if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } using var scope = _snapshotClientDiagnostics.CreateScope("SnapshotCollection.CreateOrUpdate"); scope.Start(); try { var response = await _snapshotRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, snapshotName, snapshot, cancellationToken).ConfigureAwait(false); var operation = new SnapshotCreateOrUpdateOperation(ArmClient, _snapshotClientDiagnostics, Pipeline, _snapshotRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, snapshotName, snapshot).Request, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual SnapshotCreateOrUpdateOperation CreateOrUpdate(string snapshotName, SnapshotData snapshot, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (snapshotName == null) { throw new ArgumentNullException(nameof(snapshotName)); } if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } using var scope = _clientDiagnostics.CreateScope("SnapshotCollection.CreateOrUpdate"); scope.Start(); try { var response = _restClient.CreateOrUpdate(Id.ResourceGroupName, snapshotName, snapshot, cancellationToken); var operation = new SnapshotCreateOrUpdateOperation(Parent, _clientDiagnostics, Pipeline, _restClient.CreateCreateOrUpdateRequest(Id.ResourceGroupName, snapshotName, snapshot).Request, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual ArmOperation <Snapshot> CreateOrUpdate(bool waitForCompletion, string snapshotName, SnapshotData snapshot, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(snapshotName, nameof(snapshotName)); if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } using var scope = _snapshotClientDiagnostics.CreateScope("SnapshotCollection.CreateOrUpdate"); scope.Start(); try { var response = _snapshotRestClient.CreateOrUpdate(Id.SubscriptionId, Id.ResourceGroupName, snapshotName, snapshot, cancellationToken); var operation = new ComputeArmOperation <Snapshot>(new SnapshotOperationSource(Client), _snapshotClientDiagnostics, Pipeline, _snapshotRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, snapshotName, snapshot).Request, response, OperationFinalStateVia.Location); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual async Task <ArmOperation <SnapshotResource> > CreateOrUpdateAsync(WaitUntil waitUntil, string snapshotName, SnapshotData data, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(snapshotName, nameof(snapshotName)); Argument.AssertNotNull(data, nameof(data)); using var scope = _snapshotClientDiagnostics.CreateScope("SnapshotCollection.CreateOrUpdate"); scope.Start(); try { var response = await _snapshotRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, snapshotName, data, cancellationToken).ConfigureAwait(false); var operation = new ComputeArmOperation <SnapshotResource>(new SnapshotOperationSource(Client), _snapshotClientDiagnostics, Pipeline, _snapshotRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, snapshotName, data).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async Task <Response> CreateOrUpdateAsync(string resourceGroupName, string snapshotName, SnapshotData snapshot, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (snapshotName == null) { throw new ArgumentNullException(nameof(snapshotName)); } if (snapshot == null) { throw new ArgumentNullException(nameof(snapshot)); } using var message = CreateCreateOrUpdateRequest(resourceGroupName, snapshotName, snapshot); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 202: return(message.Response); default: throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); } }
internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string snapshotName, SnapshotData snapshot) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Put; 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/snapshots/", false); uri.AppendPath(snapshotName, true); uri.AppendQuery("api-version", "2020-12-01", true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(snapshot); request.Content = content; message.SetProperty("UserAgentOverride", _userAgent); return(message); }