예제 #1
0
        public async Task <Response <PublicIPPrefix> > GetAsync(string resourceGroupName, string publicIpPrefixName, string expand = null, CancellationToken cancellationToken = default)
        {
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (publicIpPrefixName == null)
            {
                throw new ArgumentNullException(nameof(publicIpPrefixName));
            }

            using var message = CreateGetRequest(resourceGroupName, publicIpPrefixName, expand);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

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

                if (document.RootElement.ValueKind == JsonValueKind.Null)
                {
                    value = null;
                }
                else
                {
                    value = PublicIPPrefix.DeserializePublicIPPrefix(document.RootElement);
                }
                return(Response.FromValue(value, message.Response));
            }
예제 #2
0
        public PSPublicIpPrefix ToPsPublicIpPrefix(PublicIPPrefix publicIpPrefix)
        {
            var psPublicIpPrefix = NetworkResourceManagerProfile.Mapper.Map <PSPublicIpPrefix>(publicIpPrefix);

            psPublicIpPrefix.Tag = TagsConversionHelper.CreateTagHashtable(publicIpPrefix.Tags);

            if (string.IsNullOrEmpty(psPublicIpPrefix.IPPrefix))
            {
                psPublicIpPrefix.IPPrefix = "Not Assigned";
            }
            return(psPublicIpPrefix);
        }
 /// <summary>
 /// Creates or updates a static or dynamic public IP prefix.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='publicIpPrefixName'>
 /// The name of the public IP prefix.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the create or update public IP prefix operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <PublicIPPrefix> BeginCreateOrUpdateAsync(this IPublicIPPrefixesOperations operations, string resourceGroupName, string publicIpPrefixName, PublicIPPrefix parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, publicIpPrefixName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates or updates a static or dynamic public IP prefix.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='publicIpPrefixName'>
 /// The name of the public IP prefix.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the create or update public IP prefix operation.
 /// </param>
 public static PublicIPPrefix BeginCreateOrUpdate(this IPublicIPPrefixesOperations operations, string resourceGroupName, string publicIpPrefixName, PublicIPPrefix parameters)
 {
     return(operations.BeginCreateOrUpdateAsync(resourceGroupName, publicIpPrefixName, parameters).GetAwaiter().GetResult());
 }
        public async Task PublicIpPrefixApiTest()
        {
            var container = await GetCollection();
            var name = Recording.GenerateAssetName("test_public_ip_prefix_");

            // create
            PublicIPPrefix prefix = await container.CreateOrUpdate(name, new PublicIPPrefixData()
            {
                Location = TestEnvironment.Location,
                PrefixLength = 28,
                Sku = new PublicIPPrefixSku()
                {
                    Name = PublicIPPrefixSkuName.Standard,
                }
            }).WaitForCompletionAsync();

            Assert.True(await container.CheckIfExistsAsync(name));

            var prefixData = prefix.Data;
            ValidateCommon(prefixData, name);
            Assert.IsEmpty(prefixData.Tags);

            prefixData.Tags.Add("tag1", "value1");
            prefixData.Tags.Add("tag2", "value2");

            // update
            prefix = await container.CreateOrUpdate(name, prefixData).WaitForCompletionAsync();
            prefixData = prefix.Data;

            ValidateCommon(prefixData, name);
            Assert.That(prefixData.Tags, Has.Count.EqualTo(2));
            Assert.That(prefixData.Tags, Does.ContainKey("tag1").WithValue("value1"));
            Assert.That(prefixData.Tags, Does.ContainKey("tag2").WithValue("value2"));

            // get
            prefix = await container.GetAsync(name);
            prefixData = prefix.Data;

            ValidateCommon(prefixData, name);
            Assert.That(prefixData.Tags, Has.Count.EqualTo(2));
            Assert.That(prefixData.Tags, Does.ContainKey("tag1").WithValue("value1"));
            Assert.That(prefixData.Tags, Does.ContainKey("tag2").WithValue("value2"));

            // update tags
            var tags = new TagsObject();
            tags.Tags.Add("tag2", "value2");
            prefixData = (await prefix.UpdateAsync(tags)).Value.Data;

            ValidateCommon(prefixData, name);
            Assert.That(prefixData.Tags, Has.Count.EqualTo(1));
            Assert.That(prefixData.Tags, Does.ContainKey("tag2").WithValue("value2"));

            // list
            var prefixes = await container.GetAllAsync().ToEnumerableAsync();
            Assert.That(prefixes, Has.Count.EqualTo(1));
            prefix = prefixes[0];
            prefixData = prefix.Data;

            ValidateCommon(prefixData, name);
            Assert.That(prefixData.Tags, Has.Count.EqualTo(1));
            Assert.That(prefixData.Tags, Does.ContainKey("tag2").WithValue("value2"));

            // delete
            await prefix.DeleteAsync();

            Assert.False(await container.CheckIfExistsAsync(name));

            prefixes = await container.GetAllAsync().ToEnumerableAsync();
            Assert.IsEmpty(prefixes);
        }
        public virtual PublicIPPrefixesCreateOrUpdateOperation StartCreateOrUpdate(string resourceGroupName, string publicIpPrefixName, PublicIPPrefix parameters, CancellationToken cancellationToken = default)
        {
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (publicIpPrefixName == null)
            {
                throw new ArgumentNullException(nameof(publicIpPrefixName));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using var scope = _clientDiagnostics.CreateScope("PublicIPPrefixesOperations.StartCreateOrUpdate");
            scope.Start();
            try
            {
                var originalResponse = RestClient.CreateOrUpdate(resourceGroupName, publicIpPrefixName, parameters, cancellationToken);
                return(new PublicIPPrefixesCreateOrUpdateOperation(_clientDiagnostics, _pipeline, RestClient.CreateCreateOrUpdateRequest(resourceGroupName, publicIpPrefixName, parameters).Request, originalResponse));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }