Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

This project demonstrates how to use dotnet-core with NetApp Files SDK for Microsoft.NetApp resource provider to deploy a SMB Volume.

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

Azure-Samples/netappfiles-dotnetcore-smb-sdk-sample

page_type languages products description
sample
csharp
azure
azure-netapp-files
This project demonstrates how to use dotnet-core with NetApp Files SDK for Microsoft.NetApp resource provider to deploy a SMB Volume.

Azure NetAppFiles SDK SMB Sample .NETCore

This project demonstrates how to use dotnet-core with NetApp Files SDK for Microsoft.NetApp resource provider to deploy a SMB Volume.

In this sample application we perform the following operations:

  • Creation
    • NetApp Files Account
    • Capacity Pool
    • SMB enabled Volume
  • Clean up created resources

Note: the clean up execution is disable by default, if you want to run this end to end with the clean up, please change variable cleanup from false to true at program.cs.

If you don't already have a Microsoft Azure subscription, you can get a FREE trial account here.

Prerequisites

  1. Azure Subscription
  2. Subscription needs to have Azure NetApp Files resource provider registered. For more information, see Register for NetApp Resource Provider.
  3. Resource Group created
  4. Virtual Network with a delegated subnet to Microsoft.Netapp/volumes resource. For more information, please refer to Guidelines for Azure NetApp Files network planning
  5. For this sample console appplication work, we are using service principal based authenticate, follow these steps in order to setup authentication:
    1. 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>  
    2. 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.

    3. Copy the output content and paste it in a file called azureauth.json and secure it with file system permissions

    4. 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

  6. Active Directory infrastructure setup with one or more DNS servers from the AD domain (usually the Domain Controllers) available in the same virtual network where you're setting up Azure NetApp Files. If you want to setup an Active Directory test environment, please refer to Create a new Windows VM and create a new AD Forest, Domain and DC for a quick setup, then you can work on the vnet that gets created to setup the subnet requirements for ANF.

What is anf-dotnetcore-smb-sdk-sample.dll doing?

This sample project is dedicated to demonstrate how to deploy a Volume in Azure NetApp Files that uses SMB protocol, similar to other ANF SDK examples, the authentication method is based on a service principal, this project then will ask for the Active Directory user password and after validating that it is not null, it will create a single volume with a single capacity pool using standard service level tier and finally the SMB Volume, the resources clean up process after the sample application execution is disabled by default, if you want to perform the removal right after the creation operations, please change variable cleanup from false to true at program.cs file. For a more advanced example, for example usage of async methods (with NFS v3 and v4.1 volumes), please see the first item in the references section of this document.

SMB Volumes will require that you have an Active Directory domain available for you to use, with the DNS Servers you will define (as comma separated string) within the same virtual network (any subnet with exception of ANF Volume's delagated subnet) where your ANF service will use to setup its volumes. The username provided must be a user that has rights to domain join computers and although we setup Active Directory at NetApp Account level, the SMB server will be created only when the volume gets deployed. Finally, you will notice that the SMB server created in AD will be appended with the SMB Server prefix you configured plus a sequence of random characters, up to 15 in total name length. This application will output the final SMB server FQDN as highlighted in the screenshot.

How the project is structured

The following table describes all files within this solution:

Folder FileName Description
Root program.cs Authenticates and executes all operations
Root\Common CommonSdk.cs Static class dedicated to common operations related to ANF's SDK, in this example, it exposes GetResourceAsync and WaitForNoAnfResource methods
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\Models AzureAuthInfo.cs Class that defines an Azure AD Service Principal authentication file

How to run the console application

  1. Clone it locally
    git clone https://github.com/Azure-Samples/netappfiles-dotnetcore-smb-sdk-sample.git
  2. Make sure you change the variables located at .netappfiles-dotnetcore-smb-sdk-sample\src\anf-dotnetcore-smb-sdk-sample\program.cs in RunAsync method.
  3. Change folder to .netappfiles-dotnetcore-smb-sdk-sample\src\anf-dotnetcore-smb-sdk-sample
  4. 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)
  5. Build the console application
    dotnet build
  6. Run the console application
    dotnet run

Sample output e2e execution

References

About

This project demonstrates how to use dotnet-core with NetApp Files SDK for Microsoft.NetApp resource provider to deploy a SMB Volume.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages