static void Main(string[] args) { string token = GetAuthorizationHeader(); TokenCloudCredentials credential = new TokenCloudCredentials(subscriptionId, token); ResourceManagementClient resourcesClient = new ResourceManagementClient(credential); StorageManagementClient storageMgmtClient = new StorageManagementClient(credential); try { //Create a new resource group CreateResourceGroup(rgName, resourcesClient); //Create a new account in a specific resource group with the specified account name CreateStorageAccount(rgName, accountName, storageMgmtClient); //Get all the account properties for a given resource group and account name StorageAccount storAcct = storageMgmtClient.StorageAccounts.GetProperties(rgName, accountName).StorageAccount; //Get a list of storage accounts within a specific resource group IList <StorageAccount> storAccts = storageMgmtClient.StorageAccounts.ListByResourceGroup(rgName).StorageAccounts; //Get all the storage accounts for a given subscription IList <StorageAccount> storAcctsSub = storageMgmtClient.StorageAccounts.List().StorageAccounts; //Get the storage account keys for a given account and resource group StorageAccountKeys acctKeys = storageMgmtClient.StorageAccounts.ListKeys(rgName, accountName).StorageAccountKeys; //Regenerate the account key for a given account in a specific resource group StorageAccountKeys regenAcctKeys = storageMgmtClient.StorageAccounts.RegenerateKey(rgName, accountName, KeyName.Key1).StorageAccountKeys; //Update the storage account for a given account name and resource group UpdateStorageAccount(rgName, accountName, storageMgmtClient); //Check if the account name is available bool nameAvailable = storageMgmtClient.StorageAccounts.CheckNameAvailability(accountName).NameAvailable; //Delete a storage account with the given account name and a resource group DeleteStorageAccount(rgName, accountName, storageMgmtClient); } catch (Hyak.Common.CloudException ce) { Console.WriteLine(ce.Message); Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); } }
public static string GetKey2(this StorageAccountKeys listKeyResult) { return(listKeyResult.Key2); }
public static string GetFirstAvailableKey(this StorageAccountKeys listKeyResult) { return(!string.IsNullOrEmpty(listKeyResult.Key1) ? listKeyResult.Key1 : listKeyResult.Key2); }
private void RunAMLWebServiceTestScenario(AMLWebServiceTestDelegate actualTest, [System.Runtime.CompilerServices.CallerMemberName] string methodName = "testframework_failed") { using (var context = MockContext.Start(this.GetType().FullName, methodName)) { bool testIsSuccessfull = true; string cpRpApiVersion = string.Empty; ResourceManagementClient resourcesClient = null; StorageManagementClient storageManagementClient = null; var amlServiceName = TestUtilities.GenerateName(WebServiceTests.TestServiceNamePrefix); var resourceGroupName = TestUtilities.GenerateName(WebServiceTests.TestResourceGroupNamePrefix); var commitmentPlanName = TestUtilities.GenerateName(WebServiceTests.TestCommitmentPlanNamePrefix); var cpDeploymentName = "depl" + commitmentPlanName; var storageAccountName = TestUtilities.GenerateName(WebServiceTests.TestStorageAccountPrefix); try { // Create a resource group for the AML service resourcesClient = context.GetServiceClient <ResourceManagementClient>(); var resourceGroupDefinition = new ResourceGroup { Location = WebServiceTests.DefaultLocation }; resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, resourceGroupDefinition); // Create a support storage account for the service in this resource group storageManagementClient = context.GetServiceClient <StorageManagementClient>(); var accountParameters = new StorageAccountCreateParameters { AccountType = AccountType.StandardLRS, Location = WebServiceTests.DefaultLocation }; storageManagementClient.StorageAccounts.Create(resourceGroupName, storageAccountName, accountParameters); StorageAccountKeys accountKeys = storageManagementClient.StorageAccounts.ListKeys(resourceGroupName, storageAccountName); var storageAccountInfo = new StorageAccount(storageAccountName, accountKeys.Key1); // Create an AML commitment plan resource to associate with the services cpRpApiVersion = ResourceProvidersHelper.GetRPApiVersion(resourcesClient, WebServiceTests.MLResourceProviderNamespace, WebServiceTests.CPResourceType); var cpDeploymentItems = WebServiceTests.CreateCommitmentPlanResource(resourceGroupName, commitmentPlanName, cpDeploymentName, resourcesClient, cpRpApiVersion); var cpResource = cpDeploymentItems.Item2; // Create a client for the AML RP and run the actual test var webServicesClient = context.GetServiceClient <AzureMLWebServicesManagementClient>(); webServicesClient.LongRunningOperationRetryTimeout = WebServiceTests.AsyncOperationPollingIntervalSeconds; // Run the actual test actualTest(amlServiceName, resourceGroupName, resourcesClient, webServicesClient, cpResource.Id, storageAccountInfo); } catch (CloudException cloudEx) { Trace.TraceError("Caught unexpected exception: "); Trace.TraceError(WebServiceTests.GenerateCloudExceptionReport(cloudEx)); testIsSuccessfull = false; } finally { if (resourcesClient != null) { // Delete the deployment with the commitment plan if (cpRpApiVersion != string.Empty) { WebServiceTests.DisposeOfTestResource(() => resourcesClient.Resources.Delete(resourceGroupName, WebServiceTests.MLResourceProviderNamespace, string.Empty, WebServiceTests.CPResourceType, commitmentPlanName, cpRpApiVersion)); WebServiceTests.DisposeOfTestResource(() => resourcesClient.Deployments.Delete(resourceGroupName, cpDeploymentName)); } // Delete the created storage account WebServiceTests.DisposeOfTestResource(() => storageManagementClient.StorageAccounts.Delete(resourceGroupName, storageAccountName)); // Delete the created resource group WebServiceTests.DisposeOfTestResource(() => resourcesClient.ResourceGroups.Delete(resourceGroupName)); } } Assert.True(testIsSuccessfull); } }