internal DeploymentScript(ArmResource options, DeploymentScriptData resource) : base(options, resource.Id) { HasData = true; _data = resource; _clientDiagnostics = new ClientDiagnostics(ClientOptions); _deploymentScriptsRestClient = new DeploymentScriptsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
public Response Create(string resourceGroupName, string scriptName, DeploymentScriptData deploymentScript, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (scriptName == null) { throw new ArgumentNullException(nameof(scriptName)); } if (deploymentScript == null) { throw new ArgumentNullException(nameof(deploymentScript)); } using var message = CreateCreateRequest(resourceGroupName, scriptName, deploymentScript); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { case 200: case 201: return(message.Response); default: throw _clientDiagnostics.CreateRequestFailedException(message.Response); } }
DeploymentScript IOperationSource <DeploymentScript> .CreateResult(Response response, CancellationToken cancellationToken) { using var document = JsonDocument.Parse(response.ContentStream); var data = DeploymentScriptData.DeserializeDeploymentScriptData(document.RootElement); return(new DeploymentScript(_client, data)); }
public async Task <Response <DeploymentScriptData> > UpdateAsync(string subscriptionId, string resourceGroupName, string scriptName, PatchableDeploymentScriptData data, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); Argument.AssertNotNullOrEmpty(scriptName, nameof(scriptName)); Argument.AssertNotNull(data, nameof(data)); using var message = CreateUpdateRequest(subscriptionId, resourceGroupName, scriptName, data); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { DeploymentScriptData value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = DeploymentScriptData.DeserializeDeploymentScriptData(document.RootElement); return(Response.FromValue(value, message.Response)); }
public async Task <Response <DeploymentScriptData> > UpdateAsync(string resourceGroupName, string scriptName, IDictionary <string, string> tags = null, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (scriptName == null) { throw new ArgumentNullException(nameof(scriptName)); } using var message = CreateUpdateRequest(resourceGroupName, scriptName, tags); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { DeploymentScriptData value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = DeploymentScriptData.DeserializeDeploymentScriptData(document.RootElement); return(Response.FromValue(value, message.Response)); }
internal DeploymentScript(ArmClient client, DeploymentScriptData data) : this(client, data.Id) { HasData = true; _data = data; }
public async virtual Task <ArmOperation <DeploymentScript> > CreateOrUpdateAsync(bool waitForCompletion, string scriptName, DeploymentScriptData deploymentScript, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(scriptName, nameof(scriptName)); Argument.AssertNotNull(deploymentScript, nameof(deploymentScript)); using var scope = _deploymentScriptClientDiagnostics.CreateScope("DeploymentScriptCollection.CreateOrUpdate"); scope.Start(); try { var response = await _deploymentScriptRestClient.CreateAsync(Id.SubscriptionId, Id.ResourceGroupName, scriptName, deploymentScript, cancellationToken).ConfigureAwait(false); var operation = new ResourcesArmOperation <DeploymentScript>(new DeploymentScriptOperationSource(Client), _deploymentScriptClientDiagnostics, Pipeline, _deploymentScriptRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, scriptName, deploymentScript).Request, response, OperationFinalStateVia.Location); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <DeploymentScriptCreateOperation> CreateOrUpdateAsync(string scriptName, DeploymentScriptData deploymentScript, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (scriptName == null) { throw new ArgumentNullException(nameof(scriptName)); } if (deploymentScript == null) { throw new ArgumentNullException(nameof(deploymentScript)); } using var scope = _clientDiagnostics.CreateScope("DeploymentScriptCollection.CreateOrUpdate"); scope.Start(); try { var response = await _deploymentScriptsRestClient.CreateAsync(Id.SubscriptionId, Id.ResourceGroupName, scriptName, deploymentScript, cancellationToken).ConfigureAwait(false); var operation = new DeploymentScriptCreateOperation(Parent, _clientDiagnostics, Pipeline, _deploymentScriptsRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, scriptName, deploymentScript).Request, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async Task <Response> CreateAsync(string subscriptionId, string resourceGroupName, string scriptName, DeploymentScriptData deploymentScript, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); Argument.AssertNotNullOrEmpty(scriptName, nameof(scriptName)); Argument.AssertNotNull(deploymentScript, nameof(deploymentScript)); using var message = CreateCreateRequest(subscriptionId, resourceGroupName, scriptName, deploymentScript); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 201: return(message.Response); default: throw new RequestFailedException(message.Response); } }
internal Azure.Core.HttpMessage CreateCreateRequest(string subscriptionId, string resourceGroupName, string scriptName, DeploymentScriptData deploymentScript) { 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.Resources/deploymentScripts/", false); uri.AppendPath(scriptName, 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(deploymentScript); request.Content = content; _userAgent.Apply(message); return(message); }
public virtual DeploymentScriptCreateOperation CreateOrUpdate(string scriptName, DeploymentScriptData deploymentScript, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (scriptName == null) { throw new ArgumentNullException(nameof(scriptName)); } if (deploymentScript == null) { throw new ArgumentNullException(nameof(deploymentScript)); } using var scope = _clientDiagnostics.CreateScope("DeploymentScriptContainer.CreateOrUpdate"); scope.Start(); try { var response = _restClient.Create(Id.ResourceGroupName, scriptName, deploymentScript, cancellationToken); var operation = new DeploymentScriptCreateOperation(Parent, _clientDiagnostics, Pipeline, _restClient.CreateCreateRequest(Id.ResourceGroupName, scriptName, deploymentScript).Request, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual DeploymentScriptCreateOrUpdateOperation CreateOrUpdate(bool waitForCompletion, string scriptName, DeploymentScriptData deploymentScript, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(scriptName, nameof(scriptName)); if (deploymentScript == null) { throw new ArgumentNullException(nameof(deploymentScript)); } using var scope = _deploymentScriptClientDiagnostics.CreateScope("DeploymentScriptCollection.CreateOrUpdate"); scope.Start(); try { var response = _deploymentScriptRestClient.Create(Id.SubscriptionId, Id.ResourceGroupName, scriptName, deploymentScript, cancellationToken); var operation = new DeploymentScriptCreateOrUpdateOperation(ArmClient, _deploymentScriptClientDiagnostics, Pipeline, _deploymentScriptRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, scriptName, deploymentScript).Request, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }