internal GalleryImage(ArmClient client, GalleryImageData data) : this(client, data.Id) { HasData = true; _data = data; }
internal HttpMessage CreateCreateOrUpdateRequest(string subscriptionId, string resourceGroupName, string galleryName, string galleryImageName, GalleryImageData galleryImage) { 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/galleries/", false); uri.AppendPath(galleryName, true); uri.AppendPath("/images/", false); uri.AppendPath(galleryImageName, 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(galleryImage); request.Content = content; message.SetProperty("SDKUserAgent", _userAgent); return(message); }
public async Task <Response> CreateOrUpdateAsync(string subscriptionId, string resourceGroupName, string galleryName, string galleryImageName, GalleryImageData galleryImage, CancellationToken cancellationToken = default) { if (subscriptionId == null) { throw new ArgumentNullException(nameof(subscriptionId)); } if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (galleryName == null) { throw new ArgumentNullException(nameof(galleryName)); } if (galleryImageName == null) { throw new ArgumentNullException(nameof(galleryImageName)); } if (galleryImage == null) { throw new ArgumentNullException(nameof(galleryImage)); } using var message = CreateCreateOrUpdateRequest(subscriptionId, resourceGroupName, galleryName, galleryImageName, galleryImage); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 201: case 202: return(message.Response); default: throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); } }
public virtual async Task <ArmOperation <GalleryImage> > CreateOrUpdateAsync(WaitUntil waitUntil, string galleryImageName, GalleryImageData galleryImage, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(galleryImageName, nameof(galleryImageName)); Argument.AssertNotNull(galleryImage, nameof(galleryImage)); using var scope = _galleryImageClientDiagnostics.CreateScope("GalleryImageCollection.CreateOrUpdate"); scope.Start(); try { var response = await _galleryImageRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, galleryImageName, galleryImage, cancellationToken).ConfigureAwait(false); var operation = new ComputeArmOperation <GalleryImage>(new GalleryImageOperationSource(Client), _galleryImageClientDiagnostics, Pipeline, _galleryImageRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, galleryImageName, galleryImage).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }