page_type | languages | products | description | |||
---|---|---|---|---|---|---|
sample |
|
|
This project demonstrates how to use dotnet-core with NetApp Files SDK for Microsoft.NetApp resource provider to deploy a cross-region replication for NFS 4.1 Volume. |
This project demonstrates how to deploy a cross-region replication with enabled with NFS 4.1 protocol volume using dotnet-core language and Azure NetApp Files SDK.
In this sample application we perform the following operations:
- Creation
- Primary NetApp account
- Primary capacity pool
- Primary NFS v3 volume
- Primary capacity pool
- Secondary NetApp account
- Secondary capacity pool
- Secondary NFS v3 Data Replication volume with reference to the primary volume Resource ID
- Secondary capacity pool
- Primary NetApp account
- Authorize primary volume with secondary volume Resource ID
- Finally, the clean up process takes place (not enabled by default, please change the variable shouldCleanUp to true at program.cs file if you want the clean up code to take a place),deleting all resources in the reverse order following the hierarchy otherwise we can't remove resources that have nested resources still live. You will also notice that the clean up process uses a function called WaitForNoANFResource, at this moment this is required so we can workaround a current ARM behavior of reporting that the object was deleted when in fact its deletion is still in progress.
If you don't already have a Microsoft Azure subscription, you can get a FREE trial account here.
- Azure Subscription
- Subscription needs to have Azure NetApp Files resource provider registered. For more information, see Register for NetApp Resource Provider.
- Resource Group created
- Virtual Network with a delegated subnet to Microsoft.Netapp/volumes resource. For more information, please refer to Guidelines for Azure NetApp Files network planning
- For this sample console appplication work, we are using service principal based authenticate, follow these steps in order to setup authentication:
-
Within an Azure Cloud Shell session, make sure you're logged on at the subscription where you want to be associated with the service principal by default:
az account show
If this is not the correct subscription, use
az account set -s <subscription name or id>
-
Create a service principal using Azure CLI
az ad sp create-for-rbac --sdk-auth
Note: this command will automatically assign RBAC contributor role to the service principal at subscription level, you can narrow down the scope to the specific resource group where your tests will create the resources.
-
Copy the output content and paste it in a file called azureauth.json, secure it with file system permissions and save it outside the tree related of your local git repo folder so the file doesn't get commited.
-
Set an environment variable pointing to the file path you just created, here is an example with Powershell and bash: Powershell
[Environment]::SetEnvironmentVariable("AZURE_AUTH_LOCATION", "C:\sdksample\azureauth.json", "User")
Bash
export AZURE_AUTH_LOCATION=/sdksamples/azureauth.json
Note: for more information on service principal authentication with dotnet, please refer to Authenticate with the Azure Libraries for .NET
-
This sample project is dedicated to demonstrate how to enable cross-region replication in Azure NetApp Files for a NFS v4.1 enabled volume, similar to other examples, the authentication method is based on a service principal, this project will create two ANF Accounts in different regions with capacity pool. A single volume using Premium service level tier in the Source ANF, and Data Replication Volume with Standard service level tier in the destination region.
The following table describes all files within this solution:
Folder | FileName | Description |
---|---|---|
Root | program.cs | Authenticates and executes all operations |
Root\Common | ResourceUriUtils.cs | Static class that exposes some methods that helps parsing Uris, building a new Uris or getting a resource name from Uri for example |
Root\Common | ServicePrincipalAuth.cs | Small static class used when working with Service Principal based authentication |
Root\Common | Utils.cs | Static class that exposes a few methods that helps on various tasks, like writting a log to the console for example. |
Root\Model | AzureAuthInfo.cs | Class that defines an Azure AD Service Principal authentication file |
- Clone it locally
git clone https://github.com/Azure-Samples/netappfiles-dotnetcore-nfs4.1-sdk-sample.git
- Make sure you change the variables located at .netappfiles-dotnetcore-crr-sdk-sample\src\anf-dotnetcore-crr-sdk-sample\program.cs at RunAsync method.
- Change folder to .netappfiles-dotnetcore-crr-sdk-sample\src\anf-dotnetcore-crr-sdk-sample
- Since we're using service principal authentication flow, make sure you have the azureauth.json and its environment variable with the path to it defined (as previously described)
- Build the console application
dotnet build
- Run the console application
dotnet run