Git Product home page Git Product logo

netappfiles-dotnetcore-snapshot-policy-sdk-sample's Introduction

Error in user YAML: (<unknown>): found unexpected end of stream while scanning a quoted scalar at line 7 column 14
---
page_type: sample
languages:
- csharp
products:
- azure
- azure-netapp-files
description: "This project demonstrates how to create a Snapshot Policy for Microsoft.NetApp resource provider using .NETCore SDK.
---

Azure NetAppFiles SDK Sample - Snapshot Policy for .NETCore

This project demonstrates how to use a Java sample application to create a Snapshot Policy for the Microsoft.NetApp resource provider.

In this sample application we perform the following operations:

  • Creations
    • NetApp Files Account
    • Snapshot Policy
    • Capacity Pool
    • Volume
  • Updates
    • Snapshot Policy
  • Deletions
    • Volume
    • Snapshot Policy
    • Capacity Pool
    • Account

Note: The cleanup execution is disabled by default. If you want to run this end to end with the cleanup, please change value of boolean variable 'shouldCleanup' in 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 be enabled for Azure NetApp Files. For more information, please refer to this document.
  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, 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.

    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

What is netappfiles-dontnetcore-snapshot-policy-sdk-sample doing?

This sample is dedicated to demonstrate how to create a Snapshot Policy using an ANF Account name in Azure NetApp Files. Similar to other ANF SDK examples, the authentication method is based on a service principal. This project will first create an ANF Account and then a Snapshot Policy that is tied to that Account. Afterwards it will create a Capacity Pool within the Account and finally a single Volume that uses the newly created Snapshot Policy.

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 boolean variable called 'shouldCleanup' in the program.cs class. If you want to erase all resources right after the creation operations, set this variable to 'true'. If any of the earlier operations fail for any reason, the cleanup of resources will have to be done manually.

A Snapshot Policy uses schedules to create snapshots of Volumes that can be hourly, daily, weekly, monthly. The Snapshot Policy will also determine how many snapshots to keep. The sample will create a Snapshot Policy with all schedules and then update a single schedule within the policy, changing the value of the schedule's snapshots to keep.

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 Creation.cs Performs the creation operations of resources
Root Deletion.cs Performs the delete operations of the created resources
Root Update.cs Performs update operations on created resources
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

How to run the console application

  1. Clone it locally
    git clone https://github.com/Azure-Samples/netappfiles-dotnetcore-dual-protocol-sdk-sample.git
  2. Make sure you change the variables located at netappfiles-dotnetcore-dual-protocol-sdk-sample\src\anf-dotnetcore-dual-protocol-sdk-sample\program.cs at RunAsync method.
  3. Change folder to netappfiles-dotnetcore-dual-protocol-sdk-sample\src\anf-dotnetcore-dual-protocol-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

netappfiles-dotnetcore-snapshot-policy-sdk-sample's People

Contributors

adelghabb avatar adelghabboun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.