static private async Task RunAsync()
        {
            // Getting project configuration
            ProjectConfiguration config = GetConfiguration("appsettings.json");

            // Authenticating using service principal, refer to README.md file for requirement details
            var credentials = await ServicePrincipalAuth.GetServicePrincipalCredential("AZURE_AUTH_LOCATION");

            //// Authenticating using Device Login flow - uncomment following 4 lines for this type of authentication and
            //// comment the lines related to service principal authentication, refer to README.md file for requirement details
            //Console.ForegroundColor = ConsoleColor.Yellow;
            //AuthenticationResult authenticationResult = await AuthenticateAsync(config.PublicClientApplicationOptions);
            //TokenCredentials credentials = new TokenCredentials(authenticationResult.AccessToken);
            //Console.ResetColor();

            // Instantiating a new ANF management client
            Utils.WriteConsoleMessage("Instantiating a new Azure NetApp Files management client...");
            AzureNetAppFilesManagementClient anfClient = new AzureNetAppFilesManagementClient(credentials)
            {
                SubscriptionId = config.SubscriptionId
            };

            Utils.WriteConsoleMessage($"\tApi Version: {anfClient.ApiVersion}");

            // Creating ANF resources (Account, Pool, Volumes)
            await Creation.RunCreationSampleAsync(config, anfClient);

            // Creating and restoring snapshots
            await Snapshots.RunSnapshotOperationsSampleAsync(config, anfClient);

            // Performing updates on Capacity Pools and Volumes
            await Updates.RunUpdateOperationsSampleAsync(config, anfClient);

            // WARNING: destructive operations at this point, you can uncomment these lines to clean up all resources created in this example.
            // Deletion operations (snapshots, volumes, capacity pools and accounts)
            //Utils.WriteConsoleMessage($"Waiting for 1 minute to let the snapshot used to create a new volume to complete the split operation therefore not being locked...");
            //System.Threading.Thread.Sleep(TimeSpan.FromMinutes(1));
            //await Cleanup.RunCleanupTasksSampleAsync(config, anfClient);
        }
예제 #2
0
        private static async Task CreateANFAsync()
        {
            //----------------------------------------------------------------------------------------
            // Authenticating using service principal, refer to README.md file for requirement details
            //----------------------------------------------------------------------------------------
            WriteConsoleMessage("Authenticating...");
            Credentials = await ServicePrincipalAuth.GetServicePrincipalCredential("AZURE_AUTH_LOCATION");

            //------------------------------------------
            // Instantiating a new ANF management client
            //------------------------------------------
            WriteConsoleMessage("Instantiating a new Azure NetApp Files management client...");
            AzureNetAppFilesManagementClient anfClient = new AzureNetAppFilesManagementClient(Credentials)
            {
                SubscriptionId = subscriptionId
            };

            WriteConsoleMessage($"\tApi Version: {anfClient.ApiVersion}");


            //----------------------------
            // Get Certification encoding
            //----------------------------
            var bytes = Encoding.UTF8.GetBytes(Utils.GetFileContent(rootCACertFullFilePath));
            var encodedCertContent = Convert.ToBase64String(bytes);

            //----------------------
            // Creating ANF Account
            //----------------------
            WriteConsoleMessage($"Requesting ANF Account to be created in {location}");
            var newAccount = await Creation.CreateOrUpdateANFAccountAsync(anfClient,
                                                                          resourceGroupName,
                                                                          location,
                                                                          anfAccountName,
                                                                          domainJoinUsername,
                                                                          domainJoinPassword,
                                                                          dnsList,
                                                                          adFQDN,
                                                                          smbServerNamePrefix,
                                                                          encodedCertContent);

            WriteConsoleMessage($"\tAccount Resource Id: {newAccount.Id}");

            //----------------------
            // Creating ANF Capacity Pool
            //----------------------
            WriteConsoleMessage($"Requesting ANF Primary Capacity Pool to be created in {location}");
            var newPrimaryPool = await Creation.CreateOrUpdateANFCapacityPoolAsync(anfClient, resourceGroupName, location, anfAccountName, capacityPoolName, capacitypoolSize, capacityPoolServiceLevel);

            WriteConsoleMessage($"\tCapacity Pool Resource Id: {newPrimaryPool.Id}");

            //----------------------
            // Creating ANF Volume
            //----------------------
            WriteConsoleMessage($"Requesting ANF Volume to be created in {location}");
            var newVolume = await Creation.CreateOrUpdateANFVolumeAsync(anfClient, resourceGroupName, location, anfAccountName, capacityPoolName, capacityPoolServiceLevel, anfVolumeName, subnetId, volumeSize);

            WriteConsoleMessage($"\tVolume Resource Id: {newVolume.Id}");

            WriteConsoleMessage($"Waiting for {newVolume.Id} to be available...");
            await ResourceUriUtils.WaitForAnfResource <Volume>(anfClient, newVolume.Id);

            //--------------------
            // Clean Up Resources
            //--------------------

            if (shouldCleanUp)
            {
                WriteConsoleMessage("-------------------------");
                WriteConsoleMessage("Cleaning up ANF resources");
                WriteConsoleMessage("-------------------------");

                // Deleting Volume in the secondary pool first
                WriteConsoleMessage("Deleting Dual-Protocol Volume...");
                await Deletion.DeleteANFVolumeAsync(anfClient, resourceGroupName, anfAccountName, capacityPoolName, anfVolumeName);

                await ResourceUriUtils.WaitForNoAnfResource <Volume>(anfClient, newVolume.Id);

                // Deleting Primary Pool
                WriteConsoleMessage("Deleting Capacity Pool...");
                await Deletion.DeleteANFCapacityPoolAsync(anfClient, resourceGroupName, anfAccountName, capacityPoolName);

                await ResourceUriUtils.WaitForNoAnfResource <CapacityPool>(anfClient, newPrimaryPool.Id);

                //Deleting Account
                WriteConsoleMessage("Deleting Account ...");
                await Deletion.DeleteANFAccountAsync(anfClient, resourceGroupName, anfAccountName);

                await ResourceUriUtils.WaitForNoAnfResource <NetAppAccount>(anfClient, newAccount.Id);
            }
        }
예제 #3
0
        private static async Task CreateANFAsync()
        {
            //----------------------------------------------------------------------------------------
            // Authenticating using service principal, refer to README.md file for requirement details
            //----------------------------------------------------------------------------------------
            WriteConsoleMessage("Authenticating...");
            Credentials = await ServicePrincipalAuth.GetServicePrincipalCredential("AZURE_AUTH_LOCATION");

            //------------------------------------------
            // Instantiating a new ANF management client
            //------------------------------------------
            WriteConsoleMessage("Instantiating a new Azure NetApp Files management client...");
            AzureNetAppFilesManagementClient anfClient = new AzureNetAppFilesManagementClient(Credentials)
            {
                SubscriptionId = subscriptionId
            };

            WriteConsoleMessage($"\tApi Version: {anfClient.ApiVersion}");

            //----------------------
            // Creating ANF Account
            //----------------------
            WriteConsoleMessage($"Requesting ANF Account to be created in {location}");
            var newAccount = await Creation.CreateOrUpdateANFAccountAsync(anfClient,
                                                                          resourceGroupName,
                                                                          location,
                                                                          anfAccountName);

            WriteConsoleMessage($"\tAccount Resource Id: {newAccount.Id}");

            //----------------------
            // Creating Snapshot Policy
            //----------------------
            WriteConsoleMessage("Creating Snapshot policy ...");
            var newSnapshotPolicy = await Creation.CreateANFSnapshotPolicy(anfClient,
                                                                           resourceGroupName,
                                                                           location,
                                                                           anfAccountName,
                                                                           snapshotPolicyName);

            WriteConsoleMessage($"\tSnapshot resource Id: {newSnapshotPolicy.Id}");

            //----------------------
            // Creating ANF Capacity Pool
            //----------------------
            WriteConsoleMessage($"Requesting ANF Primary Capacity Pool to be created in {location}");
            var newPool = await Creation.CreateOrUpdateANFCapacityPoolAsync(anfClient, resourceGroupName, location, anfAccountName, capacityPoolName, capacitypoolSize, capacityPoolServiceLevel);

            WriteConsoleMessage($"\tCapacity Pool Resource Id: {newPool.Id}");

            //----------------------
            // Creating ANF Volume
            //----------------------
            WriteConsoleMessage($"Requesting ANF Volume to be created in {location} with Snapshot Policy {snapshotPolicyName} attached");
            var newVolume = await Creation.CreateOrUpdateANFVolumeAsync(anfClient, resourceGroupName, location, anfAccountName, capacityPoolName, capacityPoolServiceLevel, anfVolumeName, subnetId, volumeSize, newSnapshotPolicy.Id);

            WriteConsoleMessage($"\tVolume Resource Id: {newVolume.Id}");

            WriteConsoleMessage($"Waiting for {newVolume.Id} to be available...");
            await ResourceUriUtils.WaitForAnfResource <Volume>(anfClient, newVolume.Id);

            //----------------------
            // Updating Snapshot Policy
            //----------------------
            WriteConsoleMessage("Updating Snapshot policy ...");
            var currentSnapshotPolicy = await Update.UpdateANFSnapshotPolicy(anfClient,
                                                                             resourceGroupName,
                                                                             location,
                                                                             anfAccountName,
                                                                             snapshotPolicyName,
                                                                             newSnapshotPolicy.HourlySchedule);

            WriteConsoleMessage($"\tSnapshot resource has been updating successfully. Id: {currentSnapshotPolicy.Id}");

            if (shouldCleanUp)
            {
                WriteConsoleMessage("-------------------------");
                WriteConsoleMessage("Cleaning up ANF resources");
                WriteConsoleMessage("-------------------------");

                WriteConsoleMessage("waiting for snapshot policy to complete updating before start cleaning up resources.");
                Thread.Sleep(5000);

                // Deleting Volume in the secondary pool first
                WriteConsoleMessage("Deleting Volume...");
                await Deletion.DeleteANFVolumeAsync(anfClient, resourceGroupName, anfAccountName, capacityPoolName, anfVolumeName);

                await ResourceUriUtils.WaitForNoAnfResource <Volume>(anfClient, newVolume.Id);

                // Deleting Primary Pool
                WriteConsoleMessage("Deleting Capacity Pool...");
                await Deletion.DeleteANFCapacityPoolAsync(anfClient, resourceGroupName, anfAccountName, capacityPoolName);

                await ResourceUriUtils.WaitForNoAnfResource <CapacityPool>(anfClient, newPool.Id);

                //Deleting Snapshot Policy
                WriteConsoleMessage("Deleting Snapshot Policy ...");
                await Deletion.DeleteANFSnapshotPolicy(anfClient, resourceGroupName, anfAccountName, snapshotPolicyName);

                //Deleting Account
                WriteConsoleMessage("Deleting Account ...");
                await Deletion.DeleteANFAccountAsync(anfClient, resourceGroupName, anfAccountName);

                await ResourceUriUtils.WaitForNoAnfResource <NetAppAccount>(anfClient, newAccount.Id);
            }
        }
        private static async Task CreateANFAsync()
        {
            //----------------------------------------------------------------------------------------
            // Authenticating using service principal, refer to README.md file for requirement details
            //----------------------------------------------------------------------------------------
            WriteConsoleMessage("Authenticating...");
            Credentials = await ServicePrincipalAuth.GetServicePrincipalCredential("AZURE_AUTH_LOCATION");

            //------------------------------------------
            // Instantiating a new ANF management client
            //------------------------------------------
            WriteConsoleMessage("Instantiating a new Azure NetApp Files management client...");
            AzureNetAppFilesManagementClient anfClient = new AzureNetAppFilesManagementClient(Credentials)
            {
                SubscriptionId = subscriptionId
            };

            WriteConsoleMessage($"\tApi Version: {anfClient.ApiVersion}");

            //----------------------
            // Creating ANF Account
            //----------------------
            WriteConsoleMessage($"Requesting ANF Account to be created in {location}");
            var newAccount = await Creation.CreateOrUpdateANFAccountAsync(anfClient, resourceGroupName, location, anfAccountName);

            WriteConsoleMessage($"\tAccount Resource Id: {newAccount.Id}");

            //----------------------
            // Creating ANF Primary Capacity Pool
            //----------------------
            WriteConsoleMessage($"Requesting ANF Primary Capacity Pool to be created in {location}");
            var newPrimaryPool = await Creation.CreateOrUpdateANFCapacityPoolAsync(anfClient, resourceGroupName, location, anfAccountName, primaryCapacityPoolName, capacitypoolSize, primaryCapacityPoolServiceLevel);

            WriteConsoleMessage($"\tAccount Resource Id: {newPrimaryPool.Id}");

            //----------------------
            // Creating ANF Secondary Capacity Pool
            //----------------------
            WriteConsoleMessage($"Requesting ANF Secondary Capacity Pool to be created in {location}");
            var newSecondaryPool = await Creation.CreateOrUpdateANFCapacityPoolAsync(anfClient, resourceGroupName, location, anfAccountName, secondaryCapacityPoolName, capacitypoolSize, SecondaryCapacityPoolServiceLevel);

            WriteConsoleMessage($"\tAccount Resource Id: {newSecondaryPool.Id}");

            //----------------------
            // Creating ANF Volume
            //----------------------
            WriteConsoleMessage($"Requesting ANF Volume to be created in {location}");
            var newVolume = await Creation.CreateOrUpdateANFVolumeAsync(anfClient, resourceGroupName, location, anfAccountName, primaryCapacityPoolName, primaryCapacityPoolServiceLevel, anfVolumeName, subnetId, volumeSize);

            WriteConsoleMessage($"\tAccount Resource Id: {newVolume.Id}");

            WriteConsoleMessage($"Waiting for {newVolume.Id} to be available...");
            await ResourceUriUtils.WaitForAnfResource <Volume>(anfClient, newVolume.Id);

            //----------------------------------
            // Change ANF Volume's Capacity Pool
            //----------------------------------
            WriteConsoleMessage("Performing Pool Change. Updating volume...");
            await Update.ChangeVolumeCapacityPoolAsync(anfClient, resourceGroupName, anfAccountName, primaryCapacityPoolName, anfVolumeName, newSecondaryPool.Id);

            WriteConsoleMessage($"\tPool change is successful. Moved volume from {primaryCapacityPoolName} to {secondaryCapacityPoolName}");

            //--------------------
            // Clean Up Resources
            //--------------------

            if (shouldCleanUp)
            {
                WriteConsoleMessage("-------------------------");
                WriteConsoleMessage("Cleaning up ANF resources");
                WriteConsoleMessage("-------------------------");

                // Deleting Volume in the secondary pool first
                WriteConsoleMessage("Deleting Volume in the secondary Pool...");
                var volume = await anfClient.Volumes.GetAsync(resourceGroupName, anfAccountName, secondaryCapacityPoolName, anfVolumeName);

                await Deletion.DeleteANFVolumeAsync(anfClient, resourceGroupName, anfAccountName, secondaryCapacityPoolName, anfVolumeName);

                await ResourceUriUtils.WaitForNoAnfResource <Volume>(anfClient, volume.Id);

                // Deleting Primary Pool
                WriteConsoleMessage("Deleting primary Pool...");
                await Deletion.DeleteANFCapacityPoolAsync(anfClient, resourceGroupName, anfAccountName, primaryCapacityPoolName);

                await ResourceUriUtils.WaitForNoAnfResource <CapacityPool>(anfClient, newPrimaryPool.Id);

                // Deleting Secondary pool
                WriteConsoleMessage("Deleting secondary Pool...");
                await Deletion.DeleteANFCapacityPoolAsync(anfClient, resourceGroupName, anfAccountName, secondaryCapacityPoolName);

                await ResourceUriUtils.WaitForNoAnfResource <CapacityPool>(anfClient, newSecondaryPool.Id);

                //Deleting Account
                WriteConsoleMessage("Deleting Account ...");
                await Deletion.DeleteANFAccountAsync(anfClient, resourceGroupName, anfAccountName);

                await ResourceUriUtils.WaitForNoAnfResource <NetAppAccount>(anfClient, newAccount.Id);
            }
        }