/// <summary>
        /// Creates or updates a capacity pool
        /// </summary>
        /// <param name="client">Azure NetApp Files Management Client</param>
        /// <param name="resourceGroup">Resource Group name where capacity pool 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>
        /// <returns>CapacityPool object</returns>
        public static async Task <CapacityPool> CreateOrUpdateCapacityPoolAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool)
        {
            CapacityPool capacityPoolBody = new CapacityPool()
            {
                Location     = account.Location.ToLower(),
                ServiceLevel = pool.ServiceLevel,
                Size         = pool.Size
            };

            return(await client.Pools.CreateOrUpdateAsync(capacityPoolBody, resourceGroup, account.Name, pool.Name));
        }
        /// <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 Azure NetApp Files Account
        /// </summary>
        /// <param name="client">Azure NetApp Files Management Client</param>
        /// <param name="account">Account object generated from information contained at the appsettings.json file at Accounts section</param>
        /// <returns>NetAppAccount</returns>
        public static async Task <NetAppAccount> CreateOrUpdateAnfAccountAsync(ProjectConfiguration config, AzureNetAppFilesManagementClient client, ModelNetAppAccount account)
        {
            // Setting up NetApp Files account object
            NetAppAccount anfAccountBody = new NetAppAccount(account.Location, null, account.Name);

            // Requesting account to be created
            return(await client.Accounts.CreateOrUpdateAsync(anfAccountBody, config.ResourceGroup, account.Name));
        }
        /// <summary>
        /// Creates or updates a Azure NetApp Files Account with Active Directory information for SMB
        /// </summary>
        /// <param name="client">Azure NetApp Files Management Client</param>
        /// <param name="account">Account object generated from information contained at the appsettings.json file at Accounts section</param>
        /// <param name="activeDirectoryInfoList">Active Directory object list</param>
        /// <returns>NetAppAccount object</returns>
        public static async Task <NetAppAccount> CreateOrUpdateAnfAccountAsync(ProjectConfiguration config, AzureNetAppFilesManagementClient client, ModelNetAppAccount account, ActiveDirectory[] activeDirectories)
        {
            // Setting up NetApp Files account object and Active Directory Information
            NetAppAccount anfAccount = new NetAppAccount(account.Location.ToLower(), null, account.Name, null, null, null, activeDirectories);

            // Requesting account to be created
            return(await client.Accounts.CreateOrUpdateAsync(anfAccount, config.ResourceGroup, account.Name));
        }
예제 #5
0
        /// <summary>
        /// Creates or retrieves a Capacity Pool
        /// </summary>
        /// <param name="client">Azure NetApp Files Management Client</param>
        /// <param name="resourceGroup">Resource Group name where the capacity pool will be created</param>
        /// <param name="account">ModelNetAppAccount object that contains the data configured in the appsettings.json file for the ANF account</param>
        /// <param name="pool">ModelCapacityPool object that describes the capacity pool to be created, this information comes from appsettings.json</param>
        /// <returns>CapacityPool object</returns>
        private static async Task <CapacityPool> CreateOrRetrieveCapacityPoolAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool)
        {
            CapacityPool anfCapacityPool = await GetResourceAsync <CapacityPool>(client, resourceGroup, account.Name, pool.Name);

            if (anfCapacityPool == null)
            {
                anfCapacityPool = await CreateOrUpdateCapacityPoolAsync(client, resourceGroup, account, pool);

                Utils.WriteConsoleMessage($"\tCapacity Pool successfully created, resource id: {anfCapacityPool.Id}");
            }
            else
            {
                Utils.WriteConsoleMessage($"\tCapacity already exists, resource id: {anfCapacityPool.Id}");
            }

            return(anfCapacityPool);
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
        /// <summary>
        /// Creates or retrieves an Azure NetApp Files Account
        /// </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 <NetAppAccount> CreateOrRetrieveAccountAsync(ProjectConfiguration config, AzureNetAppFilesManagementClient client, ModelNetAppAccount account)
        {
            // Creating ANF Account
            NetAppAccount anfAccount = await GetResourceAsync <NetAppAccount>(client, config.ResourceGroup, account.Name);

            if (anfAccount == null)
            {
                anfAccount = await CreateOrUpdateAnfAccountAsync(config, client, account);

                Utils.WriteConsoleMessage($"\tAccount successfully created, resource id: {anfAccount.Id}");
            }
            else
            {
                Utils.WriteConsoleMessage($"\tAccount already exists, resource id: {anfAccount.Id}");
            }

            return(anfAccount);
        }
        /// <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)
        {
            // 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);
        }
        /// <summary>
        /// Creates or retrieves a Capacity Pool
        /// </summary>
        /// <param name="client">Azure NetApp Files Management Client</param>
        /// <param name="resourceGroup">Resource Group name where the capacity pool will be created</param>
        /// <param name="account">ModelNetAppAccount object that contains the data configured in the appsettings.json file for the ANF account</param>
        /// <param name="pool">ModelCapacityPool object that describes the capacity pool to be created, this information comes from appsettings.json</param>
        /// <returns>CapacityPool object</returns>
        private static async Task <CapacityPool> CreateOrRetrieveCapacityPoolAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool)
        {
            // Creating the ANF Account
            CapacityPool anfCapacityPool;

            try
            {
                // Checking if resource already exists
                anfCapacityPool = await client.Pools.GetAsync(resourceGroup, account.Name, pool.Name);

                Console.WriteLine($"{level1}Capacity Pool already exists, resource id: {anfCapacityPool.Id}");
            }
            catch (Exception ex)
            {
                // If account does not exist, create one
                if (ex.HResult == -2146233088)
                {
                    anfCapacityPool = await CreateOrUpdateCapacityPoolAsync(client, resourceGroup, account, pool);

                    Console.WriteLine($"{level1}Capacity Pool successfully created, resource id: {anfCapacityPool.Id}");
                }
                else
                {
                    throw;
                }
            }

            return(anfCapacityPool);
        }
        /// <summary>
        /// Creates or retrieves an Azure NetApp Files Account
        /// </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 <NetAppAccount> CreateOrRetrieveAccountAsync(ProjectConfiguration config, AzureNetAppFilesManagementClient client, ModelNetAppAccount account)
        {
            // Creating the ANF Account
            NetAppAccount anfAccount;

            try
            {
                // Checking if resource already exists
                anfAccount = await client.Accounts.GetAsync(config.ResourceGroup, account.Name);

                Console.WriteLine($"{level1}Account already exists, resource id: {anfAccount.Id}");
            }
            catch (Exception ex)
            {
                // If account does not exist, create one
                if (ex.HResult == -2146233088)
                {
                    anfAccount = await CreateOrUpdateAnfAccountAsync(config, client, account);

                    Console.WriteLine($"{level1}Account successfully created, resource id: {anfAccount.Id}");
                }
                else
                {
                    throw;
                }
            }

            return(anfAccount);
        }