public override void ExecuteCmdlet() { base.ExecuteCmdlet(); CheckNameAvailabilityResult checkNameAvailabilityResult = this.StorageClient.StorageAccounts.CheckNameAvailability(this.Name); if (!checkNameAvailabilityResult.NameAvailable.Value) { throw new System.ArgumentException(checkNameAvailabilityResult.Message, "Name"); } StorageAccountCreateParameters createParameters = new StorageAccountCreateParameters() { Location = this.Location, Kind = ParseAccountKind(Kind), Sku = new Sku(ParseSkuName(this.SkuName)), Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), }; if (this.CustomDomainName != null) { createParameters.CustomDomain = new CustomDomain() { Name = CustomDomainName, UseSubDomain = UseSubDomain }; } else if (UseSubDomain != null) { throw new System.ArgumentException(string.Format("UseSubDomain must be set together with CustomDomainName.")); } if (this.EnableEncryptionService != null) { createParameters.Encryption = ParseEncryption(EnableEncryptionService); } if (this.AccessTier != null) { createParameters.AccessTier = ParseAccessTier(AccessTier); } var createAccountResponse = this.StorageClient.StorageAccounts.Create( this.ResourceGroupName, this.Name, createParameters); var storageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name); this.WriteStorageAccount(storageAccount); }
public static StorageAccountCreateParameters GetDefaultStorageAccountParameters() { StorageAccountCreateParameters account = new StorageAccountCreateParameters { Location = DefaultLocation, Tags = DefaultTags, Sku = new Sku { Name = DefaultSkuName }, Kind = DefaultKind, }; return(account); }
public async Task StorageAccountRevokeUserDelegationKeys() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; //revoke user delegation keys await account.RevokeUserDelegationKeysAsync(); }
public void CreateStorageAccount() { #endif string accountName = "myaccount"; string resourceGroupName = "myResourceGroup"; ArmClient client = new ArmClient(new DefaultAzureCredential()); ResourceGroup resourceGroup = client.DefaultSubscription.GetResourceGroups().Get(resourceGroupName); StorageAccountContainer storageAccountContainer = resourceGroup.GetStorageAccounts(); Sku sku = new Sku(SkuName.PremiumLRS); StorageAccountCreateParameters parameters = new StorageAccountCreateParameters(new Sku(SkuName.StandardGRS), Kind.Storage, Location.WestUS); parameters.Tags.Add("key1", "value1"); parameters.Tags.Add("key2", "value2"); StorageAccount account = storageAccountContainer.CreateOrUpdate(accountName, parameters).Value; #endregion }
public void CreateStorageAccount() { #endif string accountName = "myaccount"; string resourceGroupName = "myResourceGroup"; ArmClient client = new ArmClient(new DefaultAzureCredential()); ResourceGroupResource resourceGroup = client.GetDefaultSubscription().GetResourceGroups().Get(resourceGroupName); StorageAccountCollection storageAccountCollection = resourceGroup.GetStorageAccounts(); StorageSku sku = new StorageSku(StorageSkuName.PremiumLRS); StorageAccountCreateParameters parameters = new StorageAccountCreateParameters(new StorageSku(StorageSkuName.StandardGRS), StorageKind.Storage, AzureLocation.WestUS); parameters.Tags.Add("key1", "value1"); parameters.Tags.Add("key2", "value2"); StorageAccountResource account = storageAccountCollection.CreateOrUpdate(WaitUntil.Completed, accountName, parameters).Value; #endregion }
public async Task CreateStorageAccountWithEncrpytion() { //create storage account with encryption settings string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(); parameters.Encryption = new Encryption(KeySource.MicrosoftStorage) { Services = new EncryptionServices { Blob = new EncryptionService { Enabled = true }, File = new EncryptionService { Enabled = true } } }; StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; VerifyAccountProperties(account, true); //verify encryption settings Assert.NotNull(account.Data.Encryption); Assert.NotNull(account.Data.Encryption.Services.Blob); Assert.True(account.Data.Encryption.Services.Blob.Enabled); Assert.NotNull(account.Data.Encryption.Services.Blob.LastEnabledTime); Assert.NotNull(account.Data.Encryption.Services.File); Assert.NotNull(account.Data.Encryption.Services.File.Enabled); Assert.NotNull(account.Data.Encryption.Services.File.LastEnabledTime); if (null != account.Data.Encryption.Services.Table) { if (account.Data.Encryption.Services.Table.Enabled.HasValue) { Assert.False(account.Data.Encryption.Services.Table.LastEnabledTime.HasValue); } } if (null != account.Data.Encryption.Services.Queue) { if (account.Data.Encryption.Services.Queue.Enabled.HasValue) { Assert.False(account.Data.Encryption.Services.Queue.LastEnabledTime.HasValue); } } }
public async Task ListStorageAccountAvailableLocations() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; //get available locations IEnumerable <Location> locationList = await account.GetAvailableLocationsAsync(); Assert.NotNull(locationList); }
public async Task CreateOrUpdate() { #region Snippet:Managing_StorageAccounts_CreateStorageAccount //first we need to define the StorageAccountCreateParameters Sku sku = new Sku(SkuName.StandardGRS); Kind kind = Kind.Storage; string location = "westus2"; StorageAccountCreateParameters parameters = new StorageAccountCreateParameters(sku, kind, location); //now we can create a storage account with defined account name and parameters StorageAccountCollection accountCollection = resourceGroup.GetStorageAccounts(); string accountName = "myAccount"; StorageAccountCreateOperation accountCreateOperation = await accountCollection.CreateOrUpdateAsync(accountName, parameters); StorageAccount storageAccount = accountCreateOperation.Value; #endregion }
public async Task GetAllPrivateLinkResources() { //create resource group and storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(sku: new Sku(SkuName.StandardLRS), kind: Kind.StorageV2); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; //get all private link resources Response <IReadOnlyList <PrivateLinkResource> > privateLinkResources = await account.GetPrivateLinkResourcesAsync(); Assert.NotNull(privateLinkResources.Value); }
public void StorageAccountCreateTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (var context = UndoContext.Current) { context.Start(); var resourcesClient = StorageManagementTestUtilities.GetResourceManagementClient(handler); var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(handler); // Create resource group var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient); // Create storage account string accountName = TestUtilities.GenerateName("sto"); StorageAccountCreateParameters parameters = StorageManagementTestUtilities.GetDefaultStorageAccountParameters(); var createRequest = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters); Assert.Equal(createRequest.StorageAccount.Location, StorageManagementTestUtilities.DefaultLocation); Assert.Equal(createRequest.StorageAccount.AccountType, AccountType.StandardGRS); Assert.Equal(createRequest.StorageAccount.Tags.Count, 2); // Make sure a second create returns immediately createRequest = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters); Assert.Equal(createRequest.StatusCode, HttpStatusCode.OK); Assert.Equal(createRequest.StorageAccount.Location, StorageManagementTestUtilities.DefaultLocation); Assert.Equal(createRequest.StorageAccount.AccountType, AccountType.StandardGRS); Assert.Equal(createRequest.StorageAccount.Tags.Count, 2); // Create storage account with only required params accountName = TestUtilities.GenerateName("sto"); parameters = new StorageAccountCreateParameters { AccountType = AccountType.StandardGRS, Location = StorageManagementTestUtilities.DefaultLocation }; createRequest = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters); Assert.Equal(createRequest.StorageAccount.Location, StorageManagementTestUtilities.DefaultLocation); Assert.Equal(createRequest.StorageAccount.AccountType, AccountType.StandardGRS); Assert.Empty(createRequest.StorageAccount.Tags); } }
public void StorageAccountCreateWithAccessTierTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { var resourcesClient = StorageManagementTestUtilities.GetResourceManagementClient(context, handler); var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler); // Create resource group var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient); // Create storage account with hot string accountName = TestUtilities.GenerateName("sto"); var parameters = new StorageAccountCreateParameters { Sku = new Sku { Name = SkuName.StandardGRS }, Kind = Kind.BlobStorage, Location = StorageManagementTestUtilities.DefaultLocation, AccessTier = AccessTier.Hot }; var account = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters); StorageManagementTestUtilities.VerifyAccountProperties(account, false); Assert.Equal(AccessTier.Hot, account.AccessTier); Assert.Equal(Kind.BlobStorage, account.Kind); // Create storage account with cool accountName = TestUtilities.GenerateName("sto"); parameters = new StorageAccountCreateParameters { Sku = new Sku { Name = SkuName.StandardGRS }, Kind = Kind.BlobStorage, Location = StorageManagementTestUtilities.DefaultLocation, AccessTier = AccessTier.Cool }; account = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters); StorageManagementTestUtilities.VerifyAccountProperties(account, false); Assert.Equal(AccessTier.Cool, account.AccessTier); Assert.Equal(Kind.BlobStorage, account.Kind); } }
/// <summary> /// Creates storage account. /// </summary> /// <param name="storageAccountName">Storage account to be created.</param> /// <param name="skuName">Storage SKU.</param> /// <param name="storageKind">Storage kind.</param> /// <returns>Stoprage account.</returns> public StorageAccount CreateStorageAccount(string storageAccountName, string skuName = null, string storageKind = null, bool blobNfs = false, string subnetUri = null) { var sku = string.IsNullOrEmpty(skuName) ? DefaultSkuName : skuName; var kind = string.IsNullOrEmpty(storageKind) ? DefaultKind : storageKind; StorageAccountCreateParameters storageAccountCreateParameters = new StorageAccountCreateParameters { Location = this.resourceGroup.Location, // Tags = DefaultTags, Sku = new Sku() { Name = sku }, Kind = kind, }; if (blobNfs == true) { storageAccountCreateParameters.IsHnsEnabled = true; storageAccountCreateParameters.Kind = "BlockBlobStorage"; storageAccountCreateParameters.Sku.Name = "Premium_LRS"; storageAccountCreateParameters.EnableHttpsTrafficOnly = false; storageAccountCreateParameters.EnableNfsV3 = true; storageAccountCreateParameters.AllowSharedKeyAccess = true; storageAccountCreateParameters.AllowBlobPublicAccess = true; //RoutingPreference rp = new RoutingPreference(); //rp.PublishMicrosoftEndpoints = true; //rp.PublishInternetEndpoints = false; //storageAccountCreateParameters.RoutingPreference = rp; VirtualNetworkRule virtualNetworkRule = new VirtualNetworkRule(); virtualNetworkRule.VirtualNetworkResourceId = subnetUri; List <VirtualNetworkRule> virtualNetworkRules = new List <VirtualNetworkRule>(); virtualNetworkRules.Add(virtualNetworkRule); NetworkRuleSet nrs = new NetworkRuleSet(); nrs.VirtualNetworkRules = virtualNetworkRules; nrs.Bypass = "******"; nrs.DefaultAction = DefaultAction.Deny; nrs.IpRules = new List <IPRule>(); storageAccountCreateParameters.NetworkRuleSet = nrs; } StorageAccount storageAccount = this.StorageManagementClient.StorageAccounts.Create(this.resourceGroup.Name, storageAccountName, storageAccountCreateParameters); return(storageAccount); }
public async Task GetAllPrivateEndPointConnections() { //create resource group and storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(sku: new Sku(SkuName.StandardLRS), kind: Kind.StorageV2); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; PrivateEndpointConnectionContainer privateEndpointConnectionContainer = account.GetPrivateEndpointConnections(); //get all private endpoint connections List <PrivateEndpointConnection> privateEndpointConnections = await privateEndpointConnectionContainer.GetAllAsync().ToEnumerableAsync(); Assert.NotNull(privateEndpointConnections); }
public void StorageAccountBeginCreateTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (var context = UndoContext.Current) { context.Start(); var resourcesClient = StorageManagementTestUtilities.GetResourceManagementClient(handler); var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(handler); // Create resource group var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient); // Create storage account string accountName = TestUtilities.GenerateName("sto"); StorageAccountCreateParameters parameters = StorageManagementTestUtilities.GetDefaultStorageAccountParameters(); StorageAccountCreateResponse response = storageMgmtClient.StorageAccounts.BeginCreate(rgname, accountName, parameters); Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); // Poll for creation while (response.StatusCode == HttpStatusCode.Accepted) { TestUtilities.Wait(response.RetryAfter * 1000); response = storageMgmtClient.GetCreateOperationStatus(response.OperationStatusLink); } // Verify create succeeded StorageAccount result = response.StorageAccount; Assert.Equal(result.Location, StorageManagementTestUtilities.DefaultLocation); Assert.Equal(result.AccountType, AccountType.StandardGRS); Assert.Equal(result.Tags.Count, 2); // Make sure a second create returns immediately response = storageMgmtClient.StorageAccounts.BeginCreate(rgname, accountName, parameters); Assert.Equal(HttpStatusCode.OK, response.StatusCode); // Verify create succeeded Assert.Equal(result.Location, StorageManagementTestUtilities.DefaultLocation); Assert.Equal(result.AccountType, AccountType.StandardGRS); Assert.Equal(result.Tags.Count, 2); } }
/// <summary> /// Create storage account /// </summary> /// <param name="resourceGroupName"></param> /// <param name="storageAccountName"></param> /// <param name="location"></param> /// <param name="storageAccountSuffix"></param> /// <param name="kind"></param> /// <returns></returns> public string CreateStorageAccount( string resourceGroupName, string storageAccountName, string location, out string storageAccountSuffix, string kind = Kind.StorageV2, bool?isHnsEnabled = default(bool?)) { var stoInput = new StorageAccountCreateParameters { Location = location, Kind = kind, Sku = new Microsoft.Azure.Management.Storage.Models.Sku { Name = Microsoft.Azure.Management.Storage.Models.SkuName.StandardGRS }, IsHnsEnabled = isHnsEnabled }; // Retrieve the storage account storageManagementClient.StorageAccounts.Create(resourceGroupName, storageAccountName, stoInput); // Retrieve the storage account primary access key var accessKey = storageManagementClient.StorageAccounts.ListKeys(resourceGroupName, storageAccountName).Keys[0].Value; ThrowIfTrue( string.IsNullOrEmpty(accessKey), "storageManagementClient.StorageAccounts.ListKeys returned null." ); // Set the storage account suffix var getResponse = storageManagementClient.StorageAccounts.GetProperties( resourceGroupName, storageAccountName ); storageAccountSuffix = getResponse.PrimaryEndpoints.Blob.ToString(); storageAccountSuffix = storageAccountSuffix.Replace("https://", "").TrimEnd('/'); storageAccountSuffix = storageAccountSuffix.Replace(storageAccountName, "").TrimStart('.'); // Remove the opening "blob." if it exists. storageAccountSuffix = storageAccountSuffix.Replace("blob.", ""); return(accessKey); }
protected static StorageAccount CreateStorageAccount(string rgName, string storageAccountName) { try { // Create the resource Group. var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate( rgName, new ResourceGroup { Location = m_location, Tags = new Dictionary <string, string>() { { rgName, DateTime.UtcNow.ToString("u") } } }); var stoInput = new StorageAccountCreateParameters { Location = m_location, Kind = Microsoft.Azure.Management.Storage.Models.Kind.StorageV2, Sku = new Microsoft.Azure.Management.Storage.Models.Sku(SkuName.StandardRAGRS), }; StorageAccount storageAccountOutput = m_SrpClient.StorageAccounts.Create(rgName, storageAccountName, stoInput); bool created = false; while (!created) { Thread.Sleep(600); var stos = m_SrpClient.StorageAccounts.ListByResourceGroup(rgName); created = stos.Any( t => StringComparer.OrdinalIgnoreCase.Equals(t.Name, storageAccountName)); } return(m_SrpClient.StorageAccounts.GetProperties(rgName, storageAccountName)); } catch { m_ResourcesClient.ResourceGroups.Delete(rgName); throw; } }
public async Task CreateStorageAccountWithEnableNfsV3() { //create storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(kind: Kind.StorageV2); parameters.EnableNfsV3 = false; StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; //validate VerifyAccountProperties(account, false); Assert.NotNull(account.Data.PrimaryEndpoints.Web); Assert.AreEqual(Kind.StorageV2, account.Data.Kind); Assert.False(account.Data.EnableNfsV3); }
/// Create a new Storage Account. If one already exists then the request still succeeds private static void CreateStorageAccount(string rgname, string acctName, StorageManagementClient storageMgmtClient) { StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(); //Check if the account name is available bool?nameAvailable = storageMgmtClient.StorageAccounts.CheckNameAvailability(acctName).NameAvailable; if (null != nameAvailable && true == (bool)nameAvailable) { Console.WriteLine("\nCreating a storage account..."); var storageAccount = storageMgmtClient.StorageAccounts.Create(rgname, acctName, parameters); Console.WriteLine("Storage account created with name " + storageAccount.Name); } else { Console.WriteLine("\nStorage account name \"{0}\" already exists.", acctName); return; } }
internal void ExecuteCommand() { ServiceManagementProfile.Initialize(); var parameters = new StorageAccountCreateParameters { Name = this.StorageAccountName, Label = this.Label, Description = this.Description, AffinityGroup = this.AffinityGroup, Location = this.Location, GeoReplicationEnabled = true }; ExecuteClientActionNewSM( parameters, CommandRuntime.ToString(), () => this.StorageClient.StorageAccounts.Create(parameters)); }
internal void ExecuteCommand() { ServiceManagementProfile.Initialize(); var parameters = new StorageAccountCreateParameters { ServiceName = this.StorageAccountName, Label = this.Label, Description = this.Description, AffinityGroup = this.AffinityGroup, Location = this.Location, GeoReplicationEnabled = true }; ExecuteClientActionNewSM( parameters, CommandRuntime.ToString(), () => this.StorageClient.StorageAccounts.Create(parameters)); }
private string CreateStandardStorageAccount(StorageManagementClient client) { string storageAccountName; var i = 0; do { storageAccountName = GetRandomStorageAccountName(i); i++; }while (i < 10 && (bool)!client.StorageAccounts.CheckNameAvailability(storageAccountName).NameAvailable); SM.ExtendedLocation extendedLocation = null; if (this.EdgeZone != null) { extendedLocation = new SM.ExtendedLocation { Name = this.EdgeZone, Type = CM.ExtendedLocationTypes.EdgeZone }; } var storaeAccountParameter = new StorageAccountCreateParameters { Location = this.Location ?? this.VM.Location, ExtendedLocation = extendedLocation }; storaeAccountParameter.SetAsStandardGRS(); try { client.StorageAccounts.Create(this.ResourceGroupName, storageAccountName, storaeAccountParameter); var getresponse = client.StorageAccounts.GetProperties(this.ResourceGroupName, storageAccountName); WriteWarning(string.Format(Properties.Resources.CreatingStorageAccountForBootDiagnostics, storageAccountName)); return(getresponse.PrimaryEndpoints.Blob); } catch (Exception e) { // Failed to create a storage account for boot diagnostics. WriteWarning(string.Format(Properties.Resources.ErrorDuringCreatingStorageAccountForBootDiagnostics, e)); return(null); } }
internal void ExecuteCommand() { ServiceManagementProfile.Initialize(); var parameters = new StorageAccountCreateParameters { Name = this.StorageAccountName, Label = this.Label, Description = this.Description, AffinityGroup = this.AffinityGroup, Location = this.Location, AccountType = string.IsNullOrEmpty(this.Type) ? StorageAccountTypes.StandardGRS : this.Type }; ExecuteClientActionNewSM( parameters, CommandRuntime.ToString(), () => this.StorageClient.StorageAccounts.Create(parameters)); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); StorageAccountCreateParameters createParameters = new StorageAccountCreateParameters() { Location = this.Location, AccountType = ParseAccountType(this.Type) }; var createAccountResponse = this.StorageClient.StorageAccounts.Create( this.ResourceGroupName, this.Name, createParameters); var getAccountResponse = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name); this.WriteStorageAccount(getAccountResponse.StorageAccount); }
protected StorageAccount CreateStorageAccount(string rgName, string storageAccountName) { try { // Create the resource Group. var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate( rgName, new ResourceGroup { Location = m_location, Tags = new Dictionary <string, string>() { { rgName, DateTime.UtcNow.ToString("u") } } }); var stoInput = new StorageAccountCreateParameters { Location = m_location, AccountType = AccountType.StandardGRS }; StorageAccount storageAccountOutput = m_SrpClient.StorageAccounts.Create(rgName, storageAccountName, stoInput); bool created = false; while (!created) { ComputeManagementTestUtilities.WaitSeconds(10); var stos = m_SrpClient.StorageAccounts.ListByResourceGroup(rgName); created = stos.Any( t => StringComparer.OrdinalIgnoreCase.Equals(t.Name, storageAccountName)); } return(m_SrpClient.StorageAccounts.GetProperties(rgName, storageAccountName)); } catch { m_ResourcesClient.ResourceGroups.Delete(rgName); throw; } }
private async Task <StorageAccount> createStorageAccount() { var name = Recording.GenerateAssetName("testsa"); var parameters = new StorageAccountCreateParameters(new StorageSku(StorageSkuName.StandardLRS), StorageKind.Storage, TestEnvironment.Location); return((await resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(WaitUntil.Completed, name, parameters)).Value); //var storageAccountId = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{resourceGroup.Data.Name}/providers/Microsoft.Storage/storageAccounts/{name}"; //var storageParameters = new Storage.Models.StorageAccountCreateParameters(new Storage.Models.Sku(Storage.Models.SkuName.StandardLRS), Storage.Models.Kind.Storage, TestEnvironment.Location); //var accountOperation = await StorageManagementClient.StorageAccounts.CreateAsync(resourceGroup.Data.Name, name, storageParameters); //Response<Storage.Models.StorageAccount> account = await accountOperation.WaitForCompletionAsync(); //return account.Value; //return (await ArmClient.DefaultSubscription.GetGenericResources().CreateOrUpdateAsync(true, storageAccountId, new GenericResourceData(TestEnvironment.Location) //{ // //Sku = new Resources.Models.Sku(), // Kind = "storage", //})).Value; }
public static async Task <Boolean> CreateStorageAccount(String authority, AutomationManagementClient automationManagementClient, string resourceGroupName, AutomationAccount account, string storageResourceGroup, string storageSubID, string storageAccount, string storageRGLocation) { try { // Get the token for the tenant on this subscription. var cloudtoken = AuthenticateHelper.RefreshTokenByAuthority(authority, Properties.Settings.Default.appIdURI); var subscriptionCreds = new TokenCloudCredentials(storageSubID, cloudtoken.AccessToken); var resourceManagementClient = new ResourceManagementClient(subscriptionCreds, new Uri(Properties.Settings.Default.appIdURI)); // Check if the resource group exists, otherwise create it. var rgExists = resourceManagementClient.ResourceGroups.CheckExistence(storageResourceGroup); if (!(rgExists.Exists)) { var resourceGroup = new ResourceGroup { Location = storageRGLocation }; await resourceManagementClient.ResourceGroups.CreateOrUpdateAsync(storageResourceGroup, resourceGroup); } // Create storage client and set subscription to work against var token = new Microsoft.Rest.TokenCredentials(cloudtoken.AccessToken); var storageManagementClient = new Microsoft.Azure.Management.Storage.StorageManagementClient(new Uri(Properties.Settings.Default.appIdURI), token); storageManagementClient.SubscriptionId = storageSubID; // Use Standard local replication as the sku since it is not critical to keep these modules replicated var storageParams = new StorageAccountCreateParameters() { Location = storageRGLocation, Kind = Kind.Storage, Sku = new Microsoft.Azure.Management.Storage.Models.Sku(SkuName.StandardLRS) }; // Create storage account CancellationToken cancelToken = new CancellationToken(); await storageManagementClient.StorageAccounts.CreateAsync(storageResourceGroup, storageAccount, storageParams, cancelToken); } catch (Exception Ex) { throw Ex; } return(true); }
protected StorageAccount CreateStorageAccount(string rgName, string storageAccountName) { try { // Create the resource Group. var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate( rgName, new ResourceGroup { Location = m_location }); var stoInput = new StorageAccountCreateParameters { Location = m_location, AccountType = AccountType.StandardGRS }; StorageAccount storageAccountOutput = m_SrpClient.StorageAccounts.Create(rgName, storageAccountName, stoInput).StorageAccount; bool created = false; while (!created) { ComputeManagementTestUtilities.WaitSeconds(10); var stos = m_SrpClient.StorageAccounts.ListByResourceGroup(rgName); created = stos.StorageAccounts.Any( t => StringComparer.OrdinalIgnoreCase.Equals(t.Name, storageAccountName)); } storageAccountOutput.Name = storageAccountName; // TODO: try to remove this in a future recording return(storageAccountOutput); } catch { var deleteRg1Response = m_ResourcesClient.ResourceGroups.Delete(rgName); Assert.True(deleteRg1Response.StatusCode == HttpStatusCode.OK); throw; } }
/// <summary> /// Creates storage account. /// </summary> /// <param name="storageAccountName">Storage account to be created.</param> /// <param name="skuName">Storage SKU.</param> /// <param name="storageKind">Storage kind.</param> /// <returns>Stoprage account.</returns> public StorageAccount CreateStorageAccount(string storageAccountName, string skuName = null, string storageKind = null) { var sku = string.IsNullOrEmpty(skuName) ? DefaultSkuName : skuName; var kind = string.IsNullOrEmpty(storageKind) ? DefaultKind : storageKind; StorageAccountCreateParameters storageAccountCreateParameters = new StorageAccountCreateParameters { Location = this.resourceGroup.Location, // Tags = DefaultTags, Sku = new Sku() { Name = sku }, Kind = kind, }; StorageAccount storageAccount = this.StorageManagementClient.StorageAccounts.Create(this.resourceGroup.Name, storageAccountName, storageAccountCreateParameters); return(storageAccount); }
protected override void ProcessRecord() { base.ProcessRecord(); StorageAccountCreateParameters createParameters = new StorageAccountCreateParameters() { Location = this.Location, AccountType = ParseAccountType(this.Type), Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true) }; var createAccountResponse = this.StorageClient.StorageAccounts.Create( this.ResourceGroupName, this.Name, createParameters); var getAccountResponse = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name); this.WriteStorageAccount(getAccountResponse.StorageAccount); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); StorageAccountCreateParameters createParameters = new StorageAccountCreateParameters() { Location = this.Location, AccountType = ParseAccountType(this.Type), Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true) }; var createAccountResponse = this.StorageClient.StorageAccounts.Create( this.ResourceGroupName, this.Name, createParameters); var storageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name).StorageAccount; this.WriteStorageAccount(storageAccount); }
protected StorageAccount CreateStorageAccount(ResourceGroup resGroup, string storageAccountName) { StorageAccount storageAccountOutput = null; string rgName = resGroup.Name; try { var storageAccountList = StorageClient.StorageAccounts.ListByResourceGroup(rgName); if (storageAccountList.Any()) { storageAccountOutput = storageAccountList.Where((sa) => sa.Name.Equals(storageAccountName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); } } catch { } if (storageAccountOutput == null) { var stoInput = new StorageAccountCreateParameters { Location = DEFAULT_LOCATION, AccountType = AccountType.StandardGRS }; storageAccountOutput = StorageClient.StorageAccounts.Create(rgName, storageAccountName, stoInput); bool created = false; while (!created) { Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(10)); var stos = StorageClient.StorageAccounts.ListByResourceGroup(rgName); created = stos.Any( t => StringComparer.OrdinalIgnoreCase.Equals(t.Name, storageAccountName)); } storageAccountOutput = StorageClient.StorageAccounts.GetProperties(rgName, storageAccountName); } return(storageAccountOutput); }
private void AddService(StorageAccountCreateParameters createParameters) { Add(a => { a.Name = createParameters.Name; }); }
/// <summary> /// Creates storage service if it does not exist. /// </summary> /// <param name="name">The storage service name</param> /// <param name="label">The storage service label</param> /// <param name="location">The location name. If not provided default one will be used</param> /// <param name="affinityGroup">The affinity group name</param> public void CreateStorageServiceIfNotExist( string name, string label = null, string location = null, string affinityGroup = null) { if (!StorageServiceExists(name)) { var createParameters = new StorageAccountCreateParameters {ServiceName = name, Label = label}; if (!string.IsNullOrEmpty(affinityGroup)) { createParameters.AffinityGroup = affinityGroup; } else { location = string.IsNullOrEmpty(location) ? GetDefaultLocation() : location; createParameters.Location = location; } TranslateException(() => StorageClient.StorageAccounts.Create(createParameters)); } }
/// <summary> /// Asynchronously creates a new storage account with the specified /// parameters. Existing accounts cannot be updated with this API and should /// instead use the Update Storage Account API. If an account is already /// created and subsequent PUT request is issued with exact same set of /// properties, then HTTP 200 would be returned. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group within the user's subscription. /// </param> /// <param name='accountName'> /// The name of the storage account within the specified resource group. /// Storage account names must be between 3 and 24 characters in length and /// use numbers and lower-case letters only. /// </param> /// <param name='parameters'> /// The parameters to provide for the created account. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task<StorageAccount> BeginCreateAsync(this IStorageAccountsOperations operations, string resourceGroupName, string accountName, StorageAccountCreateParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateWithHttpMessagesAsync(resourceGroupName, accountName, parameters, null, cancellationToken).ConfigureAwait(false)) { return _result.Body; } }
/// <summary> /// Asynchronously creates a new storage account with the specified /// parameters. Existing accounts cannot be updated with this API and should /// instead use the Update Storage Account API. If an account is already /// created and subsequent PUT request is issued with exact same set of /// properties, then HTTP 200 would be returned. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group within the user's subscription. /// </param> /// <param name='accountName'> /// The name of the storage account within the specified resource group. /// Storage account names must be between 3 and 24 characters in length and /// use numbers and lower-case letters only. /// </param> /// <param name='parameters'> /// The parameters to provide for the created account. /// </param> public static StorageAccount Create(this IStorageAccountsOperations operations, string resourceGroupName, string accountName, StorageAccountCreateParameters parameters) { return Task.Factory.StartNew(s => ((IStorageAccountsOperations)s).CreateAsync(resourceGroupName, accountName, parameters), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }