Example #1
0
        public void PatchPool()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var netAppMgmtClient = NetAppTestUtilities.GetNetAppManagementClient(context, new RecordedDelegatingHandler {
                    StatusCodeToReturn = HttpStatusCode.OK
                });

                // create the pool
                var pool = ResourceUtils.CreatePool(netAppMgmtClient);
                Assert.Equal("Premium", pool.ServiceLevel);
                Assert.Null(pool.Tags);

                var dict = new Dictionary <string, string>();
                dict.Add("Tag1", "Value1");

                // Now try and modify it
                // set only two of the three possibles
                // size should remain unchanged
                var poolPatch = new CapacityPoolPatch()
                {
                    Tags = dict,
                };

                var resource = netAppMgmtClient.Pools.Update(poolPatch, ResourceUtils.resourceGroup, ResourceUtils.accountName1, ResourceUtils.poolName1);
                Assert.True(resource.Tags.ContainsKey("Tag1"));
                Assert.Equal("Value1", resource.Tags["Tag1"]);

                // cleanup
                ResourceUtils.DeletePool(netAppMgmtClient);
                ResourceUtils.DeleteAccount(netAppMgmtClient);
            }
        }
Example #2
0
        public void PatchPool()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var netAppMgmtClient = NetAppTestUtilities.GetNetAppManagementClient(context, new RecordedDelegatingHandler {
                    StatusCodeToReturn = HttpStatusCode.OK
                });

                // create the pool
                var pool = ResourceUtils.CreatePool(netAppMgmtClient);
                Assert.Null(pool.Tags);

                var dict = new Dictionary <string, string>();
                dict.Add("Tag1", "Value1");

                // Now try and modify it
                var poolPatch = new CapacityPoolPatch()
                {
                    Tags = dict
                };

                var resource = netAppMgmtClient.Pools.Update(poolPatch, ResourceUtils.resourceGroup, ResourceUtils.accountName1, ResourceUtils.poolName1);
                Assert.True(resource.Tags.ToString().Contains("Tag1") && resource.Tags.ToString().Contains("Value1"));

                // cleanup
                ResourceUtils.DeletePool(netAppMgmtClient);
                ResourceUtils.DeleteAccount(netAppMgmtClient);
            }
        }
        public override void ExecuteCmdlet()
        {
            IDictionary <string, string> tagPairs = null;

            if (Tag != null)
            {
                tagPairs = new Dictionary <string, string>();

                foreach (string key in Tag.Keys)
                {
                    tagPairs.Add(key, Tag[key].ToString());
                }
            }

            if (ParameterSetName == ResourceIdParameterSet)
            {
                var resourceIdentifier = new ResourceIdentifier(ResourceId);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                var parentResource = resourceIdentifier.ParentResource;
                AccountName = parentResource.Substring(parentResource.LastIndexOf('/') + 1);
                Name        = resourceIdentifier.ResourceName;
            }
            else if (ParameterSetName == ObjectParameterSet)
            {
                ResourceGroupName = InputObject.ResourceGroupName;
                Location          = InputObject.Location;
                var NameParts = InputObject.Name.Split('/');
                AccountName = NameParts[0];
                Name        = NameParts[1];
            }
            else if (ParameterSetName == ParentObjectParameterSet)
            {
                ResourceGroupName = AccountObject.ResourceGroupName;
                Location          = AccountObject.Location;
                AccountName       = AccountObject.Name;
            }

            var capacityPoolBody = new CapacityPoolPatch()
            {
                ServiceLevel = ServiceLevel,
                Size         = PoolSize,
                Location     = Location,
                Tags         = tagPairs
            };

            if (ShouldProcess(Name, string.Format(PowerShell.Cmdlets.NetAppFiles.Properties.Resources.UpdateResourceMessage, ResourceGroupName)))
            {
                var anfPool = AzureNetAppFilesManagementClient.Pools.Update(capacityPoolBody, ResourceGroupName, AccountName, Name);
                WriteObject(anfPool);
            }
        }
 /// <summary>
 /// Patch a capacity pool
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='body'>
 /// Capacity pool object supplied in the body of the operation.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='accountName'>
 /// The name of the NetApp account
 /// </param>
 /// <param name='poolName'>
 /// The name of the capacity pool
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <CapacityPool> UpdateAsync(this IPoolsOperations operations, CapacityPoolPatch body, string resourceGroupName, string accountName, string poolName, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(body, resourceGroupName, accountName, poolName, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Patch a capacity pool
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='body'>
 /// Capacity pool object supplied in the body of the operation.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='accountName'>
 /// The name of the NetApp account
 /// </param>
 /// <param name='poolName'>
 /// The name of the capacity pool
 /// </param>
 public static CapacityPool Update(this IPoolsOperations operations, CapacityPoolPatch body, string resourceGroupName, string accountName, string poolName)
 {
     return(operations.UpdateAsync(body, resourceGroupName, accountName, poolName).GetAwaiter().GetResult());
 }
        /// <summary>
        /// Executes some updates on first capacity pool and first volume listed in the configuration file (appsettings.json)
        /// </summary>
        /// <returns></returns>
        public static async Task RunUpdateOperationsSampleAsync(ProjectConfiguration config, AzureNetAppFilesManagementClient anfClient)
        {
            //
            // Capacity Pool Updates
            //
            Utils.WriteConsoleMessage("Performing size update on a Capacity Pool");

            // Get current Capacity Pool information
            CapacityPool capacityPool = null;

            try
            {
                capacityPool = await anfClient.Pools.GetAsync(
                    config.ResourceGroup,
                    config.Accounts[0].Name,
                    config.Accounts[0].CapacityPools[0].Name);
            }
            catch (Exception ex)
            {
                Utils.WriteErrorMessage($"An error occured while getting current Capacity Pool information ({config.Accounts[0].CapacityPools[0].Name}).\nError message: {ex.Message}");
                throw;
            }

            int newCapacityPoolSizeTiB = 10;

            Utils.WriteConsoleMessage($"\tChanging Capacity Pools size from {Utils.GetBytesInTiB(capacityPool.Size)}TiB to {newCapacityPoolSizeTiB}TiB");

            // New size in bytes
            long newCapacityPoolSizeBytes = Utils.GetTiBInBytes(newCapacityPoolSizeTiB);

            // Create capacity pool patch object passing required arguments and the updated size
            CapacityPoolPatch capacityPoolPatch = new CapacityPoolPatch(
                capacityPool.Location,
                size: newCapacityPoolSizeBytes);

            // Update capacity pool resource
            try
            {
                CapacityPool updatedCapacityPool = await anfClient.Pools.UpdateAsync(
                    capacityPoolPatch,
                    config.ResourceGroup,
                    config.Accounts[0].Name,
                    config.Accounts[0].CapacityPools[0].Name);

                Utils.WriteConsoleMessage($"\tCapacity Pool successfully updated, new size: {Utils.GetBytesInTiB(updatedCapacityPool.Size)}TiB, resource id: {updatedCapacityPool.Id}");
            }
            catch (Exception ex)
            {
                Utils.WriteErrorMessage($"An error occured while updating Capacity Pool {capacityPool.Id}.\nError message: {ex.Message}");
                throw;
            }

            //
            // Volume Updates
            //
            Utils.WriteConsoleMessage("Performing size and export policy update on a volume");

            // Get current Volume information
            Volume volume = null;

            try
            {
                volume = await anfClient.Volumes.GetAsync(
                    config.ResourceGroup,
                    config.Accounts[0].Name,
                    config.Accounts[0].CapacityPools[0].Name,
                    config.Accounts[0].CapacityPools[0].Volumes[0].Name);
            }
            catch (Exception ex)
            {
                Utils.WriteErrorMessage($"An error occured while getting current Volume information ({config.Accounts[0].CapacityPools[0].Volumes[0].Name}).\nError message: {ex.Message}");
                throw;
            }

            int newVolumeSizeTiB = 1;

            Utils.WriteConsoleMessage($"\tChanging Volume size from {Utils.GetBytesInTiB(volume.UsageThreshold)}TiB to {newVolumeSizeTiB}TiB. Also adding new export policy rule, current count is {volume.ExportPolicy.Rules.Count}.");

            // New size in bytes
            long newVolumeSizeBytes = Utils.GetTiBInBytes(newVolumeSizeTiB);

            // New Export Policy rule
            List <ExportPolicyRule> ruleList = volume.ExportPolicy.Rules.OrderByDescending(r => r.RuleIndex).ToList();

            // Currently, ANF's volume export policy supports up to 5 rules
            VolumePatchPropertiesExportPolicy exportPoliciesPatch = null;

            if (ruleList.Count <= 4)
            {
                ruleList.Add(new ExportPolicyRule()
                {
                    AllowedClients = "10.0.0.4/32",
                    Cifs           = false,
                    Nfsv3          = true,
                    Nfsv4          = false,
                    RuleIndex      = ruleList.ToList()[0].RuleIndex + 1,
                    UnixReadOnly   = false,
                    UnixReadWrite  = true
                });

                exportPoliciesPatch = new VolumePatchPropertiesExportPolicy()
                {
                    Rules = ruleList
                };
            }

            // Create volume patch object passing required arguments and the updated size
            VolumePatch volumePatch = null;

            if (exportPoliciesPatch != null)
            {
                volumePatch = new VolumePatch(
                    volume.Location,
                    usageThreshold: newVolumeSizeBytes,
                    exportPolicy: exportPoliciesPatch);
            }
            else
            {
                volumePatch = new VolumePatch(
                    volume.Location,
                    usageThreshold: newVolumeSizeBytes);
            }

            // Update size at volume resource
            try
            {
                Volume updatedVolume = await anfClient.Volumes.UpdateAsync(
                    volumePatch,
                    config.ResourceGroup,
                    config.Accounts[0].Name,
                    config.Accounts[0].CapacityPools[0].Name,
                    config.Accounts[0].CapacityPools[0].Volumes[0].Name);

                Utils.WriteConsoleMessage($"\tVolume successfully updated, new size: {Utils.GetBytesInTiB(updatedVolume.UsageThreshold)}TiB, export policy count: {updatedVolume.ExportPolicy.Rules.Count}, resource id: {updatedVolume.Id}");
            }
            catch (Exception ex)
            {
                Utils.WriteErrorMessage($"An error occured while updating Volume {volume.Id}.\nError message: {ex.Message}");
                throw;
            }
        }