示例#1
0
        public async Task <Response <TemplateSpecData> > CreateOrUpdateAsync(string subscriptionId, string resourceGroupName, string templateSpecName, TemplateSpecData templateSpec, CancellationToken cancellationToken = default)
        {
            if (subscriptionId == null)
            {
                throw new ArgumentNullException(nameof(subscriptionId));
            }
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (templateSpecName == null)
            {
                throw new ArgumentNullException(nameof(templateSpecName));
            }
            if (templateSpec == null)
            {
                throw new ArgumentNullException(nameof(templateSpec));
            }

            using var message = CreateCreateOrUpdateRequest(subscriptionId, resourceGroupName, templateSpecName, templateSpec);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            case 201:
            {
                TemplateSpecData value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                value = TemplateSpecData.DeserializeTemplateSpecData(document.RootElement);
                return(Response.FromValue(value, message.Response));
            }
示例#2
0
 internal TemplateSpec(ArmResource options, TemplateSpecData resource) : base(options, resource.Id)
 {
     HasData                  = true;
     _data                    = resource;
     _clientDiagnostics       = new ClientDiagnostics(ClientOptions);
     _templateSpecsRestClient = new TemplateSpecsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri);
 }
        public virtual async Task <ArmOperation <TemplateSpecResource> > CreateOrUpdateAsync(WaitUntil waitUntil, string templateSpecName, TemplateSpecData data, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(templateSpecName, nameof(templateSpecName));
            Argument.AssertNotNull(data, nameof(data));

            using var scope = _templateSpecClientDiagnostics.CreateScope("TemplateSpecCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response = await _templateSpecRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, templateSpecName, data, cancellationToken).ConfigureAwait(false);

                var operation = new ResourcesArmOperation <TemplateSpecResource>(Response.FromValue(new TemplateSpecResource(Client, response), response.GetRawResponse()));
                if (waitUntil == WaitUntil.Completed)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
示例#4
0
        internal Azure.Core.HttpMessage CreateCreateOrUpdateRequest(string subscriptionId, string resourceGroupName, string templateSpecName, TemplateSpecData templateSpec)
        {
            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/templateSpecs/", false);
            uri.AppendPath(templateSpecName, 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(templateSpec);
            request.Content = content;
            message.SetProperty("SDKUserAgent", _userAgent);
            return(message);
        }
 internal TemplateSpecResource(ArmClient client, TemplateSpecData data) : this(client, data.Id)
 {
     HasData = true;
     _data   = data;
 }
示例#6
0
 internal TemplateSpec(ArmClient armClient, TemplateSpecData data) : this(armClient, data.Id)
 {
     HasData = true;
     _data   = data;
 }
示例#7
0
        public async virtual Task <TemplateSpecCreateOrUpdateOperation> CreateOrUpdateAsync(string templateSpecName, TemplateSpecData templateSpec, bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            if (templateSpecName == null)
            {
                throw new ArgumentNullException(nameof(templateSpecName));
            }
            if (templateSpec == null)
            {
                throw new ArgumentNullException(nameof(templateSpec));
            }

            using var scope = _clientDiagnostics.CreateScope("TemplateSpecCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response = await _templateSpecsRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, templateSpecName, templateSpec, cancellationToken).ConfigureAwait(false);

                var operation = new TemplateSpecCreateOrUpdateOperation(Parent, response);
                if (waitForCompletion)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public virtual TemplateSpecCreateOrUpdateOperation CreateOrUpdate(bool waitForCompletion, string templateSpecName, TemplateSpecData templateSpec, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(templateSpecName, nameof(templateSpecName));
            if (templateSpec == null)
            {
                throw new ArgumentNullException(nameof(templateSpec));
            }

            using var scope = _templateSpecClientDiagnostics.CreateScope("TemplateSpecCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response  = _templateSpecRestClient.CreateOrUpdate(Id.SubscriptionId, Id.ResourceGroupName, templateSpecName, templateSpec, cancellationToken);
                var operation = new TemplateSpecCreateOrUpdateOperation(ArmClient, response);
                if (waitForCompletion)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
示例#9
0
        public virtual TemplateSpecCreateOrUpdateOperation CreateOrUpdate(string templateSpecName, TemplateSpecData templateSpec, bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            if (templateSpecName == null)
            {
                throw new ArgumentNullException(nameof(templateSpecName));
            }
            if (templateSpec == null)
            {
                throw new ArgumentNullException(nameof(templateSpec));
            }

            using var scope = _clientDiagnostics.CreateScope("TemplateSpecContainer.CreateOrUpdate");
            scope.Start();
            try
            {
                var response  = _restClient.CreateOrUpdate(Id.ResourceGroupName, templateSpecName, templateSpec, cancellationToken);
                var operation = new TemplateSpecCreateOrUpdateOperation(Parent, response);
                if (waitForCompletion)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }