Exemple #1
0
        public virtual SubscriptionPolicySetDefinitionCreateOrUpdateOperation CreateOrUpdate(bool waitForCompletion, string policySetDefinitionName, PolicySetDefinitionData parameters, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(policySetDefinitionName, nameof(policySetDefinitionName));
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using var scope = _subscriptionPolicySetDefinitionPolicySetDefinitionsClientDiagnostics.CreateScope("SubscriptionPolicySetDefinitionCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response  = _subscriptionPolicySetDefinitionPolicySetDefinitionsRestClient.CreateOrUpdate(Id.SubscriptionId, policySetDefinitionName, parameters, cancellationToken);
                var operation = new SubscriptionPolicySetDefinitionCreateOrUpdateOperation(ArmClient, response);
                if (waitForCompletion)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        protected async Task <SubscriptionPolicySetDefinition> CreatePolicySetDefinitionAtSubscription(Subscription subscription, SubscriptionPolicyDefinition policyDefinition, string policySetDefinitionName)
        {
            PolicySetDefinitionData input = new PolicySetDefinitionData
            {
                DisplayName       = $"Test ${policySetDefinitionName}",
                PolicyDefinitions = { new PolicyDefinitionReference(policyDefinition.Id) }
            };
            SubscriptionPolicySetDefinitionCreateOrUpdateOperation lro = await subscription.GetSubscriptionPolicySetDefinitions().CreateOrUpdateAsync(true, policySetDefinitionName, input);

            return(lro.Value);
        }