/// <summary> /// Creates or updates a volume. In this process, notice that we need to create two mandatory objects, one as the export rule list and the voluome body itself before /// we request the volume creation. /// </summary> /// <param name="client">Azure NetApp Files Management Client</param> /// <param name="resourceGroup">Resource Group name where volume will be created</param> /// <param name="account">Account object generated from information contained at the appsettings.json file at Accounts section</param> /// <param name="pool">ModelCapacityPool object that describes the capacity pool to be created, this information comes from appsettings.json</param> /// <param name="volume">ModelVolume object that represents the volume to be created that is defined in appsettings.json</param> /// <returns>Volume object</returns> public static async Task <Volume> CreateOrUpdateVolumeAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool, ModelVolume volume) { List <ExportPolicyRule> ruleList = new List <ExportPolicyRule>(); foreach (ModelExportPolicyRule rule in volume.ExportPolicies) { ruleList.Add(new ExportPolicyRule() { AllowedClients = rule.AllowedClients, Cifs = rule.Cifs, Nfsv3 = rule.Nfsv3, Nfsv41 = rule.Nfsv41, RuleIndex = rule.RuleIndex, UnixReadOnly = rule.UnixReadOnly, UnixReadWrite = rule.UnixReadWrite }); } VolumePropertiesExportPolicy exportPolicies = new VolumePropertiesExportPolicy() { Rules = ruleList }; Volume volumeBody = new Volume() { ExportPolicy = exportPolicies, Location = account.Location.ToLower(), ServiceLevel = pool.ServiceLevel, CreationToken = volume.CreationToken, SubnetId = volume.SubnetId, UsageThreshold = volume.UsageThreshold, ProtocolTypes = new List <string> { "NFSv3" } // If NFS 4.1 is required, use NFSv41 value instead, at this moment only one protocol is supported in a single volume }; return(await client.Volumes.CreateOrUpdateAsync(volumeBody, resourceGroup, account.Name, pool.Name, volume.Name)); }
/// <summary> /// Creates or updates a capacity pool /// </summary> /// <param name="client">Azure NetApp Files Management Client</param> /// <param name="resourceGroup">Resource Group name where volume will be created</param> /// <param name="account">Account object generated from information contained at the appsettings.json file at Accounts section</param> /// <param name="pool">ModelCapacityPool object that describes the capacity pool to be created, this information comes from appsettings.json</param> /// <param name="volume">ModelVolume object that represents the volume to be created that is defined in appsettings.json</param> /// <returns>Volume object</returns> private static async Task <Volume> CreateOrUpdateVolumeAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool, ModelVolume volume) { List <ExportPolicyRule> ruleList = new List <ExportPolicyRule>(); foreach (ModelExportPolicyRule rule in volume.ExportPolicies) { ruleList.Add(new ExportPolicyRule() { AllowedClients = rule.AllowedClients, Cifs = rule.Cifs, Nfsv3 = rule.Nfsv3, Nfsv4 = rule.Nfsv4, RuleIndex = rule.RuleIndex, UnixReadOnly = rule.UnixReadOnly, UnixReadWrite = rule.UnixReadWrite }); } VolumePropertiesExportPolicy exportPolicies = new VolumePropertiesExportPolicy() { Rules = ruleList }; Volume volumeBody = new Volume() { ExportPolicy = exportPolicies, Location = account.Location.ToLower(), ServiceLevel = pool.ServiceLevel, CreationToken = volume.CreationToken, SubnetId = volume.SubnetId, UsageThreshold = volume.UsageThreshold }; return(await client.Volumes.CreateOrUpdateAsync(volumeBody, resourceGroup, account.Name, pool.Name, volume.Name)); }
/// <summary> /// Creates or retrieves volume /// </summary> /// <param name="config">Project Configuration file which contains the resource group needed</param> /// <param name="client">Azure NetApp Files Management Client</param> /// <param name="account">ModelNetAppAccount object that contains the data configured in the appsettings.json file for the ANF account</param> /// <returns>NetAppCount object</returns> private static async Task <Volume> CreateOrRetrieveVolumeAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool, ModelVolume volume) { Volume anfVolume = await GetResourceAsync <Volume>(client, resourceGroup, account.Name, pool.Name, volume.Name); if (anfVolume == null) { anfVolume = await CreateOrUpdateVolumeAsync(client, resourceGroup, account, pool, volume); Utils.WriteConsoleMessage($"\tVolume successfully created, resource id: {anfVolume.Id}"); } else { Utils.WriteConsoleMessage($"\tVolume already exists, resource id: {anfVolume.Id}"); } return(anfVolume); }
/// <summary> /// Creates or retrieves volume /// </summary> /// <param name="config">Project Configuration file which contains the resource group needed</param> /// <param name="client">Azure NetApp Files Management Client</param> /// <param name="account">ModelNetAppAccount object that contains the data configured in the appsettings.json file for the ANF account</param> /// <returns>NetAppCount object</returns> private static async Task <Volume> CreateOrRetrieveVolumeAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool, ModelVolume volume) { // Creating or retrieving a volume Volume anfVolume; try { // Checking if resource already exists anfVolume = await client.Volumes.GetAsync(resourceGroup, account.Name, pool.Name, volume.Name); Console.WriteLine($"{level1}Volume already exists, resource id: {anfVolume.Id}"); } catch (Exception ex) { // If volume does not exist, create one if (ex.HResult == -2146233088) { anfVolume = await CreateOrUpdateVolumeAsync(client, resourceGroup, account, pool, volume); Console.WriteLine($"{level1}Volume Pool successfully created, resource id: {anfVolume.Id}"); } else { throw; } } return(anfVolume); }