page_type | languages | products | description | |||
---|---|---|---|---|---|---|
sample |
|
|
This project demonstrates how to deploy a volume enabled with NFS 4.1 protocol using python language and Azure NetApp Files SDK for python. |
This project demonstrates how to deploy a volume enabled with NFS 4.1 protocol using python language and Azure NetApp Files SDK for python.
In this sample application we perform the following operations:
- Creation
- NetApp Files Account
- Capacity Pool
- NFS 4.1 enabled Volume
- Clean up created resources (not enabled by default)
If you don't already have a Microsoft Azure subscription, you can get a FREE trial account here.
- Python (code was built and tested under 3.9.5 version)
- 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 Python console application work, we need to authenticate and the chosen method for this sample is using service principals.
-
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 and secure it with file system permissions
-
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 other Azure Active Directory authentication methods for Python, please refer to these samples.
-
This sample project is dedicated to demonstrate how to deploy a Volume in Azure NetApp Files that uses NFS v4.1 protocol, similar to other examples, the authentication method is based on a service principal, this project will create a single volume with a single capacity pool using standard service level tier and finally an NFS v4.1 Volume.
There is a section in the code dedicated to remove created resources, by default this script will not remove all created resources, this behavior is controlled by a variable called SHOULD_CLEANUP
, if you want cleanup right after the creation operations, just set it to True
. For a more advanced python example, please see the first item in the references section of this document.
File/folder | Description |
---|---|
media\ |
Folder that contains screenshots. |
src\ |
Sample source code folder. |
src\example.py |
Sample main file. |
src\sample_utils.py |
Sample file that contains authentication functions, all wait functions and other small functions. |
src\resource_uri_utils.py |
Sample file that contains functions to work with URIs, e.g. get resource name from URI (get_anf_capacitypool ). |
src\requirements.txt |
Sample script required modules. |
.gitignore |
Define what to ignore at commit time. |
CHANGELOG.md |
List of changes to the sample. |
CONTRIBUTING.md |
Guidelines for contributing to the sample. |
README.md |
This README file. |
LICENSE |
The license for the sample. |
CODE_OF_CONDUCT.md |
Microsoft's Open Source Code of Conduct. |
- Clone it locally
git clone https://github.com/Azure-Samples/netappfiles-python-nfs4.1-sdk-sample.git
- Change folder to .\netappfiles-python-nfs4.1-sdk-sample\src
- Install any missing dependencies as needed
pip install -r ./requirements.txt
- Make sure you have the azureauth.json and its environment variable with the path to it defined (as previously described at prerequisites)
- Edit file example.py and change the variables contents as appropriate (names are self-explanatory).
- Run the script
python ./example.py