Skip to content

This project demonstrates how to perform CRUD management operations for Microsoft.NetApp resource provider using Go.

License

Notifications You must be signed in to change notification settings

Azure-Samples/netappfiles-go-sdk-sample

page_type languages products description
sample
go
azure
azure-netapp-files
This project demonstrates how to use a to perform management CRUD operations for Microsoft.NetApp resource provider using Go SDK.

Azure NetAppFiles SDK Sample for Go

This project demonstrates how to perform management CRUD operations for Microsoft.NetApp resource provider using GoLang.

In this sample application we perform the following operations:

  • Creation
    • NetApp Files Account
    • Capacity Pool
    • Volumes (one NFSv3 and one NFSv4.1)
    • Snapshot NFSv3 volume
    • Volume from Snapshot (NFSv3)
  • Updates
    • Change the NFSv4.1 Volume size from 100GiB to 200GiB
  • Deletions (when cleanup variable is set to true)
    • Snapshot
    • Volumes
    • Capacity Pools
    • Accounts

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

Prerequisites

  1. Go installed (if not installed yet, follow the official instructions)
  2. Azure Subscription.
  3. Subscription needs to be whitelisted for Azure NetApp Files. For more information, please refer to this document.
  4. Resource Group created
  5. Virtual Network with a delegated subnet to Microsoft.Netapp/volumes resource. For more information, please refer to Guidelines for Azure NetApp Files network planning
  6. Adjust variable contents within var() block at example.go file to match your environment
  7. For this sample Go console application work, we need to authenticate through az cli.
    1. From terminal perform login to your Azure account: bash az login and Set the subscription to be used, use bash az account set -s <subscription name or id>

    2. Set the subscription ID environment variable:

      # PowerShell example
      $env:AZURE_SUBSCRIPTION_ID="<your subscription id>"
      # Bash example
      export AZURE_SUBSCRIPTION_ID="<your subscription id>"

      Note: for other Azure Active Directory authentication methods for Go, please refer to Authentication methods in the Azure SDK for Go.

What is example.go doing

Currently, Azure NetApp Files SDK exposes control plane management operations, CRUD operations for its resources like accounts, capacity pools, volumes and snapshots. We start this execution by defining some basic variables that will be used throughout the code to define resource group name, location, account name, virtual network, subnet names, etc.

Note: Please refer to Resource limits for Azure NetApp Files to understand ANF's most current limits.

Next, it will move forward and obtain the subscription ID for the test we perform to check if the subnet provided exists before starting creating any ANF resource. Authentication is made on each operation where we obtain an authorizer to pass to each client we instantiate (in Azure Go SDK for NetAppFiles each resource has its own client). For more information about the authentication process used, refer to Authentication methods in the Azure SDK for Go document.

Then, it will start the CRUD operations by creating one account, then capacity pool, volumes, snapshot and volume from snapshot, in this exact sequence (for more information about Azure NetApp Files storage hierarchy please refer to this document). After all resources are created, it will perform an update to a volume by changing its usage threshold (size) doubling its size in this example.

Finally, the clean up process takes place (not enabled by default, please change variable shouldCleanUp to true at example.go file if you want clean up to take 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. We will also notice some functions called GetANF<resource type>, these were also created in this sample to be able to get the name of the resource without its hierarchy represented in the <resource type>.name property, which cannot be used directly in other methods of Azure NetApp Files client like get.

Contents

File/folder Description
media\ Folder that contains screenshots.
netappfiles-go-sdk-sample\ Sample source code folder.
netappfiles-go-sdk-sample\example.go Sample main file.
netappfiles-go-sdk-sample\go.mod The go.mod file defines the module’s module path, which is also the import path used for the root directory, and its dependency requirements, which are the other modules needed for a successful build.
netappfiles-go-sdk-sample\go.sum The go.sum file contains hashes for each of the modules and it's versions used in this sample
netappfiles-go-sdk-sample\internal\ Folder that contains all internal packages dedicated to this sample.
netappfiles-go-sdk-sample\internal\iam\iam.go Package that allows us to get the authorizer object from Azure Active Directory by using the NewAuthorizerFromFile function.
netappfiles-go-sdk-sample\internal\models\models.go Provides models for this sample, e.g. AzureAuthInfo models the authorization file.
netappfiles-go-sdk-sample\internal\sdkutils\sdkutils.go Contains all functions that directly uses the SDK and some helper functions.
netappfiles-go-sdk-sample\internal\uri\uri.go Provides various functions to parse resource IDs and get information or perform validations.
netappfiles-go-sdk-sample\internal\utils\utils.go Provides generic functions.
.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.

How to run

  1. Go to your GOPATH folder and create the following path

    # PowerShell example
    cd $env:GOPATH/src
    mkdir ./github.com/Azure-Samples
    # Bash example
    cd $GOPATH/src
    mkdir -p ./github.com/Azure-Samples
  2. Clone it locally

    cd github.com/Azure-Samples
    git clone https://github.com/Azure-Samples/netappfiles-go-sdk-sample.git
  3. Change folder to netappfiles-go-sdk-sample/netappfiles-go-sdk-sample

    cd netappfiles-go-sdk-sample/netappfiles-go-sdk-sample
  4. Make sure you have the azureauth.json and its environment variable with the path to it defined (as previously described at prerequisites)

  5. Edit file example.go var() block and change the variables contents as appropriate (names are self-explanatory).

  6. Run the sample

    go run .

Sample output e2e execution

References

About

This project demonstrates how to perform CRUD management operations for Microsoft.NetApp resource provider using Go.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 9

Languages