public async Task <Response <VCenterData> > GetAsync(string subscriptionId, string resourceGroupName, string vcenterName, CancellationToken cancellationToken = default) { if (subscriptionId == null) { throw new ArgumentNullException(nameof(subscriptionId)); } if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (vcenterName == null) { throw new ArgumentNullException(nameof(vcenterName)); } using var message = CreateGetRequest(subscriptionId, resourceGroupName, vcenterName); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { VCenterData value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = VCenterData.DeserializeVCenterData(document.RootElement); return(Response.FromValue(value, message.Response)); }
VCenter IOperationSource <VCenter> .CreateResult(Response response, CancellationToken cancellationToken) { using var document = JsonDocument.Parse(response.ContentStream); var data = VCenterData.DeserializeVCenterData(document.RootElement); return(new VCenter(_client, data)); }
public async Task <Response> CreateAsync(string subscriptionId, string resourceGroupName, string vcenterName, VCenterData body = null, CancellationToken cancellationToken = default) { if (subscriptionId == null) { throw new ArgumentNullException(nameof(subscriptionId)); } if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (vcenterName == null) { throw new ArgumentNullException(nameof(vcenterName)); } using var message = CreateCreateRequest(subscriptionId, resourceGroupName, vcenterName, body); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 201: return(message.Response); default: throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); } }
internal HttpMessage CreateCreateRequest(string subscriptionId, string resourceGroupName, string vcenterName, VCenterData body) { 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.ConnectedVMwarevSphere/vcenters/", false); uri.AppendPath(vcenterName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); if (body != null) { request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(body); request.Content = content; } message.SetProperty("UserAgentOverride", _userAgent); return(message); }
internal VCenter(ArmClient client, VCenterData data) : this(client, data.Id) { HasData = true; _data = data; }
public async Task <Response> CreateAsync(string subscriptionId, string resourceGroupName, string vcenterName, VCenterData data = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); Argument.AssertNotNullOrEmpty(vcenterName, nameof(vcenterName)); using var message = CreateCreateRequest(subscriptionId, resourceGroupName, vcenterName, data); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 201: return(message.Response); default: throw new RequestFailedException(message.Response); } }
public Response Create(string subscriptionId, string resourceGroupName, string vcenterName, VCenterData body = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); Argument.AssertNotNullOrEmpty(vcenterName, nameof(vcenterName)); using var message = CreateCreateRequest(subscriptionId, resourceGroupName, vcenterName, body); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { case 200: case 201: return(message.Response); default: throw new RequestFailedException(message.Response); } }
public virtual async Task <ArmOperation <VCenterResource> > CreateOrUpdateAsync(WaitUntil waitUntil, string vcenterName, VCenterData data = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(vcenterName, nameof(vcenterName)); using var scope = _vCenterClientDiagnostics.CreateScope("VCenterCollection.CreateOrUpdate"); scope.Start(); try { var response = await _vCenterRestClient.CreateAsync(Id.SubscriptionId, Id.ResourceGroupName, vcenterName, data, cancellationToken).ConfigureAwait(false); var operation = new ConnectedVMwarevSphereArmOperation <VCenterResource>(new VCenterOperationSource(Client), _vCenterClientDiagnostics, Pipeline, _vCenterRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, vcenterName, data).Request, response, OperationFinalStateVia.AzureAsyncOperation); if (waitUntil == WaitUntil.Completed) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual ArmOperation <VCenter> CreateOrUpdate(bool waitForCompletion, string vcenterName, VCenterData body = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(vcenterName, nameof(vcenterName)); using var scope = _vCenterClientDiagnostics.CreateScope("VCenterCollection.CreateOrUpdate"); scope.Start(); try { var response = _vCenterRestClient.Create(Id.SubscriptionId, Id.ResourceGroupName, vcenterName, body, cancellationToken); var operation = new ConnectedVMwarevSphereArmOperation <VCenter>(new VCenterOperationSource(Client), _vCenterClientDiagnostics, Pipeline, _vCenterRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, vcenterName, body).Request, response, OperationFinalStateVia.AzureAsyncOperation); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <VCenterCreateOrUpdateOperation> CreateOrUpdateAsync(bool waitForCompletion, string vcenterName, VCenterData body = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(vcenterName, nameof(vcenterName)); using var scope = _vCenterClientDiagnostics.CreateScope("VCenterCollection.CreateOrUpdate"); scope.Start(); try { var response = await _vCenterRestClient.CreateAsync(Id.SubscriptionId, Id.ResourceGroupName, vcenterName, body, cancellationToken).ConfigureAwait(false); var operation = new VCenterCreateOrUpdateOperation(ArmClient, _vCenterClientDiagnostics, Pipeline, _vCenterRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, vcenterName, body).Request, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }