/// <summary> /// Creates or updates a volume. In this process, notice that we need to create two mandatory objects, one as the export rule list and the voluome body itself before /// we request the volume creation. /// </summary> /// <param name="client">Azure NetApp Files Management Client</param> /// <param name="resourceGroup">Resource Group name where volume will be created</param> /// <param name="account">Account object generated from information contained at the appsettings.json file at Accounts section</param> /// <param name="pool">ModelCapacityPool object that describes the capacity pool to be created, this information comes from appsettings.json</param> /// <param name="volume">ModelVolume object that represents the volume to be created that is defined in appsettings.json</param> /// <returns>Volume object</returns> public static async Task <Volume> CreateOrUpdateVolumeAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool, ModelVolume volume) { List <ExportPolicyRule> ruleList = new List <ExportPolicyRule>(); foreach (ModelExportPolicyRule rule in volume.ExportPolicies) { ruleList.Add(new ExportPolicyRule() { AllowedClients = rule.AllowedClients, Cifs = rule.Cifs, Nfsv3 = rule.Nfsv3, Nfsv4 = rule.Nfsv4, RuleIndex = rule.RuleIndex, UnixReadOnly = rule.UnixReadOnly, UnixReadWrite = rule.UnixReadWrite }); } VolumePropertiesExportPolicy exportPolicies = new VolumePropertiesExportPolicy() { Rules = ruleList }; Volume volumeBody = new Volume() { ExportPolicy = exportPolicies, Location = account.Location.ToLower(), ServiceLevel = pool.ServiceLevel, CreationToken = volume.CreationToken, SubnetId = volume.SubnetId, UsageThreshold = volume.UsageThreshold }; return(await client.Volumes.CreateOrUpdateAsync(volumeBody, resourceGroup, account.Name, pool.Name, volume.Name)); }
public static void CreateSnapshot(AzureNetAppFilesManagementClient netAppMgmtClient, string snapshotName = snapshotName1, string volumeName = volumeName1, string poolName = poolName1, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location, bool snapshotOnly = false) { Volume volume = null; var snapshot = new Snapshot(); if (!snapshotOnly) { volume = CreateVolume(netAppMgmtClient, volumeName, poolName, accountName); snapshot = new Snapshot { Location = location, }; } else { // for those tests where snapshotOnly is true, no filesystem id will be available // use this opportunity to test snapshot creation with no filesystem id provided // for these cases it should use the name in the resource id snapshot = new Snapshot { Location = location, }; } if (Environment.GetEnvironmentVariable("AZURE_TEST_MODE") == "Record") { Thread.Sleep(delay); // some robustness against ARM caching } var resource = netAppMgmtClient.Snapshots.Create(snapshot, resourceGroup, accountName, poolName, volumeName, snapshotName); Assert.Equal(resource.Name, accountName + '/' + poolName + '/' + volumeName + '/' + snapshotName); }
/// <summary> /// Creates or retrieves volume /// </summary> /// <param name="config">Project Configuration file which contains the resource group needed</param> /// <param name="client">Azure NetApp Files Management Client</param> /// <param name="account">ModelNetAppAccount object that contains the data configured in the appsettings.json file for the ANF account</param> /// <returns>NetAppCount object</returns> private static async Task <Volume> CreateOrRetrieveVolumeAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool, ModelVolume volume) { // Creating or retrieving a volume Volume anfVolume; try { // Checking if resource already exists anfVolume = await client.Volumes.GetAsync(resourceGroup, account.Name, pool.Name, volume.Name); Console.WriteLine($"{level1}Volume already exists, resource id: {anfVolume.Id}"); } catch (Exception ex) { // If volume does not exist, create one if (ex.HResult == -2146233088) { anfVolume = await CreateOrUpdateVolumeAsync(client, resourceGroup, account, pool, volume); Console.WriteLine($"{level1}Volume Pool successfully created, resource id: {anfVolume.Id}"); } else { throw; } } return(anfVolume); }
/// <summary> /// Creates or retrieves a Capacity Pool /// </summary> /// <param name="client">Azure NetApp Files Management Client</param> /// <param name="resourceGroup">Resource Group name where the capacity pool will be created</param> /// <param name="account">ModelNetAppAccount object that contains the data configured in the appsettings.json file for the ANF account</param> /// <param name="pool">ModelCapacityPool object that describes the capacity pool to be created, this information comes from appsettings.json</param> /// <returns>CapacityPool object</returns> private static async Task <CapacityPool> CreateOrRetrieveCapacityPoolAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool) { // Creating the ANF Account CapacityPool anfCapacityPool; try { // Checking if resource already exists anfCapacityPool = await client.Pools.GetAsync(resourceGroup, account.Name, pool.Name); Console.WriteLine($"{level1}Capacity Pool already exists, resource id: {anfCapacityPool.Id}"); } catch (Exception ex) { // If account does not exist, create one if (ex.HResult == -2146233088) { anfCapacityPool = await CreateOrUpdateCapacityPoolAsync(client, resourceGroup, account, pool); Console.WriteLine($"{level1}Capacity Pool successfully created, resource id: {anfCapacityPool.Id}"); } else { throw; } } return(anfCapacityPool); }
/// <summary> /// Creates or Updates Azure NetApp Files Account /// </summary> /// <param name="anfClient">ANF client object</param> /// <param name="resourceGroupName">Resource group name</param> /// <param name="location">Azure location</param> /// <param name="accountName">Azure NetApp Files Account name</param> /// <param name="domainUserName">Active Directory Username</param> /// <param name="domainPassword">Active Directory Password</param> /// <param name="dnsList">DNS IP list</param> /// <param name="domainName">Domain Name</param> /// <param name="smbServerName">SMB Server Name</param> /// <param name="encodedCertContent">Encoded Certification content</param> /// <returns>NetApp Account object</returns> public static async Task <NetAppAccount> CreateOrUpdateANFAccountAsync(AzureNetAppFilesManagementClient anfClient, string resourceGroupName, string location, string accountName, string domainUserName, string domainPassword, string dnsList, string domainName, string smbServerName, string encodedCertContent) { ActiveDirectory activeDirectory = new ActiveDirectory() { Username = domainUserName, Password = domainPassword, Dns = dnsList, Domain = domainName, SmbServerName = smbServerName, ServerRootCACertificate = encodedCertContent }; NetAppAccount anfAccountBody = new NetAppAccount(location, null, accountName, null, null, null, new List <ActiveDirectory>() { activeDirectory }); return(await anfClient.Accounts.CreateOrUpdateAsync(anfAccountBody, resourceGroupName, accountName)); }
public static CapacityPool CreatePool(AzureNetAppFilesManagementClient netAppMgmtClient, string poolName = poolName1, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location, IDictionary <string, string> tags = default(IDictionary <string, string>), bool poolOnly = false, string serviceLevel = "Premium", long poolSize = 4398046511104) { if (!poolOnly) { CreateAccount(netAppMgmtClient, accountName, resourceGroup: resourceGroup, location: location, tags: tags); } var pool = new CapacityPool { Location = location, Size = poolSize, ServiceLevel = serviceLevel, Tags = tags }; CapacityPool resource; try { resource = netAppMgmtClient.Pools.CreateOrUpdate(pool, resourceGroup, accountName, poolName); } catch { // try one more time resource = netAppMgmtClient.Pools.CreateOrUpdate(pool, resourceGroup, accountName, poolName); } Assert.Equal(resource.Name, accountName + '/' + poolName); if (Environment.GetEnvironmentVariable("AZURE_TEST_MODE") == "Record") { Thread.Sleep(delay); // some robustness against ARM caching } return(resource); }
public static Volume CreateVolume(AzureNetAppFilesManagementClient netAppMgmtClient, string volumeName = volumeName1, string poolName = poolName1, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location, object tags = null, VolumePropertiesExportPolicy exportPolicy = null, bool volumeOnly = false, string snapshotId = null) { if (!volumeOnly) { CreatePool(netAppMgmtClient, poolName, accountName); } var volume = new Volume { Location = location, UsageThreshold = 100 * gibibyte, ServiceLevel = "Premium", CreationToken = volumeName, SubnetId = "/subscriptions/" + subsId + "/resourceGroups/" + resourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnet + "/subnets/default", Tags = tags, ExportPolicy = exportPolicy, SnapshotId = snapshotId }; var resource = netAppMgmtClient.Volumes.CreateOrUpdate(volume, resourceGroup, accountName, poolName, volumeName); Assert.Equal(resource.Name, accountName + '/' + poolName + '/' + volumeName); Thread.Sleep(delay); // some robustness against ARM caching return(resource); }
public static Volume CreateVolume(AzureNetAppFilesManagementClient netAppMgmtClient, string volumeName = volumeName1, string poolName = poolName1, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location, List <string> protocolTypes = null, IDictionary <string, string> tags = default(IDictionary <string, string>), VolumePropertiesExportPolicy exportPolicy = null, string vnet = vnet, bool volumeOnly = false, string snapshotId = null) { if (!volumeOnly) { CreatePool(netAppMgmtClient, poolName, accountName, resourceGroup: resourceGroup, location: location); } var defaultProtocolType = new List <string>() { "NFSv3" }; var volumeProtocolTypes = protocolTypes == null ? defaultProtocolType : protocolTypes; var volume = new Volume { Location = location, UsageThreshold = 100 * gibibyte, ProtocolTypes = volumeProtocolTypes, CreationToken = volumeName, SubnetId = "/subscriptions/" + netAppMgmtClient.SubscriptionId + "/resourceGroups/" + resourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnet + "/subnets/default", Tags = tags, ExportPolicy = exportPolicy, SnapshotId = snapshotId }; var resource = netAppMgmtClient.Volumes.CreateOrUpdate(volume, resourceGroup, accountName, poolName, volumeName); Assert.Equal(resource.Name, accountName + '/' + poolName + '/' + volumeName); Thread.Sleep(delay); // some robustness against ARM caching return(resource); }
public static void CreateSnapshot(AzureNetAppFilesManagementClient netAppMgmtClient, string snapshotName = snapshotName1, string volumeName = volumeName1, string poolName = poolName1, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location, bool snapshotOnly = false) { Volume volume = null; var snapshot = new Snapshot(); if (!snapshotOnly) { volume = CreateVolume(netAppMgmtClient, volumeName, poolName, accountName); snapshot = new Snapshot { Location = location, FileSystemId = volume?.FileSystemId }; } else { // for those tests where snapshotOnly is true, no filesystem id will be available // use this opportunity to test snapshot creation with no filesystem id provided // for these cases it should use the name in the resource id snapshot = new Snapshot { Location = location, }; } var resource = netAppMgmtClient.Snapshots.Create(snapshot, resourceGroup, accountName, poolName, volumeName, snapshotName); Assert.Equal(resource.Name, accountName + '/' + poolName + '/' + volumeName + '/' + snapshotName); }
public static NetAppAccount CreateAccount(AzureNetAppFilesManagementClient netAppMgmtClient, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location, object tags = null, ActiveDirectory activeDirectory = null) { // request reference example // az netappfiles account update -g --account-name cli-lf-acc2 --active-directories '[{"username": "******", "password": "******", "smbservername": "SMBSERVER", "dns": "1.2.3.4", "domain": "westcentralus"}]' -l westus2 var activeDirectories = new List <ActiveDirectory> { activeDirectory }; var netAppAccount = new NetAppAccount() { Location = location, Tags = tags, // current limitations of active directories make this problematic // omitting tests on active directory properties for now //ActiveDirectories = activeDirectories ActiveDirectories = null }; var resource = netAppMgmtClient.Accounts.CreateOrUpdate(netAppAccount, resourceGroup, accountName); Assert.Equal(resource.Name, accountName); Thread.Sleep(delay); // some robustness against ARM caching return(resource); }
public static void DeletePool(AzureNetAppFilesManagementClient netAppMgmtClient, string poolName = poolName1, string accountName = accountName1, string resourceGroup = resourceGroup, bool deep = false) { bool retry = true; int co = 0; if (deep) { // find and delete all nested resources - not implemented } // now delete the pool - with retry for test robustness due to // - ARM caching (ARM continues to tidy up even after the awaited async op // has returned) // - other async actions in RP/SDE/NRP // e.g. snapshot deletion might not be complete and therefore pool has child resource while (retry == true) { Thread.Sleep(delay); try { netAppMgmtClient.Pools.Delete(resourceGroup, accountName, poolName); retry = false; } catch { co++; if (co > retryAttempts) { retry = false; } } } }
private void WaitForReplicationStatus(AzureNetAppFilesManagementClient netAppMgmtClient, string targetState) { ReplicationStatus replicationStatus; int attempts = 0; do { replicationStatus = netAppMgmtClient.Volumes.ReplicationStatusMethod(ResourceUtils.remoteResourceGroup, ResourceUtils.remoteAccountName1, ResourceUtils.remotePoolName1, ResourceUtils.remoteVolumeName1); Thread.Sleep(1); } while (replicationStatus.MirrorState != targetState); //sometimes they dont sync up right away if (!replicationStatus.Healthy.Value) { do { replicationStatus = netAppMgmtClient.Volumes.ReplicationStatusMethod(ResourceUtils.remoteResourceGroup, ResourceUtils.remoteAccountName1, ResourceUtils.remotePoolName1, ResourceUtils.remoteVolumeName1); attempts++; if (Environment.GetEnvironmentVariable("AZURE_TEST_MODE") == "Record") { Thread.Sleep(100); } } while (replicationStatus.Healthy.Value || attempts == 5); } Assert.True(replicationStatus.Healthy); }
/// <summary> /// Waits for replication to become in status "Mirrored" /// </summary> /// <param name="client">ANF Client</param> /// <param name="resourceId">Resource Id of the resource being waited for being deleted</param> /// <param name="intervalInSec">Time in seconds that the sample will poll to check if the resource got deleted or not. Defaults to 10 seconds.</param> /// <param name="retries">How many retries before exting the wait for no resource function. Defaults to 60 retries.</param> /// <returns></returns> static public async Task WaitForCompleteReplicationStatus(AzureNetAppFilesManagementClient client, string resourceId, int intervalInSec = 10, int retries = 60) { using AzureEventSourceListener listener = AzureEventSourceListener.CreateTraceLogger(EventLevel.Verbose); for (int i = 0; i < retries; i++) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(intervalInSec)); try { var status = await client.Volumes.ReplicationStatusMethodAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId), ResourceUriUtils.GetAnfVolume(resourceId)); if (status.MirrorState.ToLower().Equals("mirrored")) { break; } } catch (Exception ex) { if (!(ex.Message.ToLower().Contains("creating") && ex.Message.ToLower().Contains("replication"))) { throw; } } } }
public static CapacityPool CreatePool(AzureNetAppFilesManagementClient netAppMgmtClient, string poolName = poolName1, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location, object tags = null, bool poolOnly = false) { if (!poolOnly) { CreateAccount(netAppMgmtClient, accountName); } var pool = new CapacityPool { Location = location, Size = 4398046511104, ServiceLevel = "Premium", Tags = tags }; CapacityPool resource; try { resource = netAppMgmtClient.Pools.CreateOrUpdate(pool, resourceGroup, accountName, poolName); } catch { // try one more time resource = netAppMgmtClient.Pools.CreateOrUpdate(pool, resourceGroup, accountName, poolName); } Assert.Equal(resource.Name, accountName + '/' + poolName); Thread.Sleep(delay); // some robustness against ARM caching return(resource); }
public static void DeleteSnapshot(AzureNetAppFilesManagementClient netAppMgmtClient, string snapshotName = snapshotName1, string volumeName = volumeName1, string poolName = poolName1, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location, bool deep = false) { bool retry = true; int co = 0; if (deep) { // find and delete all nested resources - not implemented } // now delete the snapshot - with retry for test robustness due to ARM caching // (arm continues to tidy up even after the awaited async op has returned) while (retry == true) { Thread.Sleep(delay); try { netAppMgmtClient.Snapshots.Delete(resourceGroup, accountName, poolName, volumeName, snapshotName); retry = false; } catch { co++; if (co > retryAttempts) { retry = false; } } } }
public static void DeleteSnapshot(AzureNetAppFilesManagementClient netAppMgmtClient, string snapshotName = snapshotName1, string volumeName = volumeName1, string poolName = poolName1, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location, bool deep = false) { bool retry = true; int co = 0; if (deep) { // find and delete all nested resources - not implemented } // now delete the snapshot - with retry for test robustness due to // - ARM caching (ARM continues to tidy up even after the awaited async op // has returned) // - other async actions in RP/SDE/NRP // e.g. snapshot deletion might fail if the actual creation is not complete at // all levels while (retry == true) { Thread.Sleep(delay); try { netAppMgmtClient.Snapshots.Delete(resourceGroup, accountName, poolName, volumeName, snapshotName); retry = false; } catch { co++; if (co > retryAttempts) { retry = false; } } } }
public static NetAppAccount CreateAccount(AzureNetAppFilesManagementClient netAppMgmtClient, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location, IDictionary <string, string> tags = default(IDictionary <string, string>), ActiveDirectory activeDirectory = null) { // request reference example // az netappfiles account update -g --account-name cli-lf-acc2 --active-directories '[{"username": "******", "password": "******", "smbservername": "SMBSERVER", "dns": "1.2.3.4", "domain": "westcentralus"}]' -l westus2 var activeDirectories = activeDirectory != null ? new List <ActiveDirectory> { activeDirectory } : new List <ActiveDirectory>(); var netAppAccount = new NetAppAccount() { Location = location, Tags = tags, ActiveDirectories = activeDirectories }; var resource = netAppMgmtClient.Accounts.CreateOrUpdate(netAppAccount, resourceGroup, accountName); Assert.Equal(resource.Name, accountName); if (Environment.GetEnvironmentVariable("AZURE_TEST_MODE") == "Record") { Thread.Sleep(delay); // some robustness against ARM caching } return(resource); }
/// <summary> /// Performs pool change for given volume /// </summary> /// <param name="anfClient">ANF object</param> /// <param name="resourceGroupName">Resource group name</param> /// <param name="accountName">Azure NetApp Files Account name</param> /// <param name="poolName">Azure NetApp Files Capacity Pool name</param> /// <param name="volumeName">Azure NetApp Files Volume name</param> /// <param name="newPoolResourceId">New Capacity Pool resource Id</param> /// <returns></returns> public static async Task ChangeVolumeCapacityPoolAsync(AzureNetAppFilesManagementClient anfClient, string resourceGroupName, string accountName, string poolName, string volumeName, string newPoolResourceId) { PoolChangeRequest changeRequestBody = new PoolChangeRequest() { NewPoolResourceId = newPoolResourceId }; await anfClient.Volumes.PoolChangeAsync(resourceGroupName, accountName, poolName, volumeName, changeRequestBody); }
/// <summary> /// Creates or Updates Azure NetApp Files Account /// </summary> /// <param name="anfClient">ANF client object</param> /// <param name="resourceGroupName">Resource group name</param> /// <param name="location">Azure location</param> /// <param name="accountName">Azure NetApp Files Account name</param> /// <returns>NetApp Account object</returns> public static async Task <NetAppAccount> CreateOrUpdateANFAccountAsync(AzureNetAppFilesManagementClient anfClient, string resourceGroupName, string location, string accountName) { NetAppAccount anfAccountBody = new NetAppAccount(location, null, accountName); return(await anfClient.Accounts.CreateOrUpdateAsync(anfAccountBody, resourceGroupName, accountName)); }
private void WaitForBackupPolicyDeleted(AzureNetAppFilesManagementClient netAppMgmtClient, string resourceGroup = ResourceUtils.resourceGroup, string accountName = ResourceUtils.accountName1) { int count = 0; do { count = netAppMgmtClient.BackupPolicies.List(resourceGroup, accountName).Count(); Thread.Sleep(5); } while (count > 0); }
private void WaitForSucceeded(AzureNetAppFilesManagementClient netAppMgmtClient, Volume sourceVolume, Volume dpVolume) { do { sourceVolume = netAppMgmtClient.Volumes.Get(ResourceUtils.repResourceGroup, ResourceUtils.accountName1, ResourceUtils.poolName1, ResourceUtils.volumeName1); dpVolume = netAppMgmtClient.Volumes.Get(ResourceUtils.remoteResourceGroup, ResourceUtils.remoteAccountName1, ResourceUtils.remotePoolName1, ResourceUtils.remoteVolumeName1); Thread.Sleep(1); } while ((sourceVolume.ProvisioningState != "Succeeded") || (dpVolume.ProvisioningState != "Succeeded")); }
public static void DeleteAccount(AzureNetAppFilesManagementClient netAppMgmtClient, string accountName = accountName1, string resourceGroup = resourceGroup, bool deep = false) { if (deep) { // find and delete all nested resources - not implemented } // now delete the account netAppMgmtClient.Accounts.Delete(resourceGroup, accountName); }
/// <summary> /// Creates or Updates Azure NetApp Files Capacity Pool /// </summary> /// <param name="anfClient">ANF client object</param> /// <param name="resourceGroupName">Resource group name</param> /// <param name="location">Azure location</param> /// <param name="accountName">Azure NetApp Files Account name</param> /// <param name="poolName">Azure NetApp Files Capacity Pool name</param> /// <param name="poolSize">Azure NetApp Files Capacity Pool size</param> /// <param name="serviceLevel">Service Level</param> /// <returns>Azure NetApp Files Capacity Pool</returns> public static async Task <CapacityPool> CreateOrUpdateANFCapacityPoolAsync(AzureNetAppFilesManagementClient anfClient, string resourceGroupName, string location, string accountName, string poolName, long poolSize, string serviceLevel) { CapacityPool primaryCapacityPoolBody = new CapacityPool() { Location = location.ToLower(), // Important: location needs to be lower case ServiceLevel = serviceLevel, //Service level can be one of three levels -> { Standard, Premium, Ultra } Size = poolSize }; return(await anfClient.Pools.CreateOrUpdateAsync(primaryCapacityPoolBody, resourceGroupName, accountName, poolName)); }
/// <summary> /// Creates or updates a capacity pool /// </summary> /// <param name="client">Azure NetApp Files Management Client</param> /// <param name="resourceGroup">Resource Group name where capacity pool will be created</param> /// <param name="account">Account object generated from information contained at the appsettings.json file at Accounts section</param> /// <param name="pool">ModelCapacityPool object that describes the capacity pool to be created, this information comes from appsettings.json</param> /// <returns>CapacityPool object</returns> public static async Task <CapacityPool> CreateOrUpdateCapacityPoolAsync(AzureNetAppFilesManagementClient client, string resourceGroup, ModelNetAppAccount account, ModelCapacityPool pool) { CapacityPool capacityPoolBody = new CapacityPool() { Location = account.Location.ToLower(), ServiceLevel = pool.ServiceLevel, Size = pool.Size }; return(await client.Pools.CreateOrUpdateAsync(capacityPoolBody, resourceGroup, account.Name, pool.Name)); }
protected void SetupManagementClients(MockContext context) { ResourceManagementClient = GetResourceManagementClient(context); NetAppFilesManagementClient = GetNetAppFilesManagementClient(context); SDKNetworkClient = GetSDKNetworkClient(context); _helper.SetupManagementClients( ResourceManagementClient, SDKNetworkClient, NetAppFilesManagementClient); }
private void WaitForReplicationStatus(AzureNetAppFilesManagementClient netAppMgmtClient, string targetState) { var replicationStatus = netAppMgmtClient.Volumes.ReplicationStatusMethod(ResourceUtils.remoteResourceGroup, ResourceUtils.remoteAccountName1, ResourceUtils.remotePoolName1, ResourceUtils.remoteVolumeName1); while (replicationStatus.MirrorState != targetState) { replicationStatus = netAppMgmtClient.Volumes.ReplicationStatusMethod(ResourceUtils.remoteResourceGroup, ResourceUtils.remoteAccountName1, ResourceUtils.remotePoolName1, ResourceUtils.remoteVolumeName1); Thread.Sleep(1); } Assert.True(replicationStatus.Healthy); }
public static void CreateAccount(AzureNetAppFilesManagementClient netAppMgmtClient, string accountName = accountName1, string resourceGroup = resourceGroup, string location = location) { var netAppAccount = new NetAppAccount() { Location = location, }; var resource = netAppMgmtClient.Accounts.CreateOrUpdate(netAppAccount, resourceGroup, accountName); Assert.Equal(resource.Name, accountName); Thread.Sleep(delay); // some robustness against ARM caching }
private void WaitForVolumesDeleted(AzureNetAppFilesManagementClient netAppMgmtClient, string resourceGroup = ResourceUtils.resourceGroup, string accountName = ResourceUtils.accountName1, string poolName = ResourceUtils.poolName1) { int count = 0; do { var volumes = netAppMgmtClient.Volumes.List(resourceGroup, accountName, poolName); var volumesList = ListNextLink <Volume> .GetAllResourcesByPollingNextLink(volumes, netAppMgmtClient.Volumes.ListNext); count = volumesList.Count; Thread.Sleep(5); } while (count > 0); }
private void WaitForPoolsDeleted(AzureNetAppFilesManagementClient netAppMgmtClient, string resourceGroup = ResourceUtils.resourceGroup, string accountName = ResourceUtils.accountName1) { int count = 0; do { var pools = netAppMgmtClient.Pools.List(resourceGroup, accountName); var poolList = ListNextLink <CapacityPool> .GetAllResourcesByPollingNextLink(pools, netAppMgmtClient.Pools.ListNext); count = poolList.Count; Thread.Sleep(5); } while (count > 0); }
/// <summary> /// Function used to wait for a specific ANF resource complete its deletion and ARM caching gets cleared /// </summary> /// <typeparam name="T">Resource Types as Snapshot, Volume, CapacityPool, and NetAppAccount</typeparam> /// <param name="client">ANF Client</param> /// <param name="resourceId">Resource Id of the resource being waited for being deleted</param> /// <param name="intervalInSec">Time in seconds that the sample will poll to check if the resource got deleted or not. Defaults to 10 seconds.</param> /// <param name="retries">How many retries before exting the wait for no resource function. Defaults to 60 retries.</param> /// <returns></returns> static public async Task WaitForAnfResource <T>(AzureNetAppFilesManagementClient client, string resourceId, int intervalInSec = 10, int retries = 60) { bool isFound = false; for (int i = 0; i < retries; i++) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(intervalInSec)); try { if (typeof(T) == typeof(NetAppAccount)) { await client.Accounts.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId)); } else if (typeof(T) == typeof(CapacityPool)) { await client.Pools.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId)); } else if (typeof(T) == typeof(Volume)) { await client.Volumes.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId), ResourceUriUtils.GetAnfVolume(resourceId)); } else if (typeof(T) == typeof(Snapshot)) { await client.Snapshots.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId), ResourceUriUtils.GetAnfVolume(resourceId), ResourceUriUtils.GetAnfSnapshot(resourceId)); } isFound = true; break; } catch { continue; } } if (!isFound) { throw new Exception($"Resource: {resourceId} is not found"); } }