public async Task createStorageAccountAndGetFileShareCollection()
        {
            ArmClient            armClient    = new ArmClient(new DefaultAzureCredential());
            SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();

            string        rgName   = "myRgName";
            AzureLocation location = AzureLocation.WestUS2;
            ArmOperation <ResourceGroupResource> operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location));

            ResourceGroupResource resourceGroup = operation.Value;

            this.resourceGroup = resourceGroup;
            StorageSku  sku         = new StorageSku(StorageSkuName.StandardGRS);
            StorageKind kind        = StorageKind.Storage;
            string      locationStr = "westus2";
            StorageAccountCreateOrUpdateContent parameters        = new StorageAccountCreateOrUpdateContent(sku, kind, locationStr);
            StorageAccountCollection            accountCollection = resourceGroup.GetStorageAccounts();
            string accountName = "myAccount";
            ArmOperation <StorageAccountResource> accountCreateOperation = await accountCollection.CreateOrUpdateAsync(WaitUntil.Started, accountName, parameters);

            storageAccount = await accountCreateOperation.WaitForCompletionAsync();

            #region Snippet:Managing_FileShares_GetFileService
            FileServiceResource fileService = await storageAccount.GetFileService().GetAsync();

            #endregion
            this.fileService = fileService;
        }
        public async Task CreateEventhubWithParameter()
        {
            //prepare a storage account
            string     accountName = Recording.GenerateAssetName("storage");
            StorageSku sku         = new StorageSku("Standard_LRS");
            var        storageAccountCreateParameters = new StorageAccountCreateOrUpdateContent(sku, StorageKind.StorageV2, "eastus2")
            {
                AccessTier = AccessTier.Hot
            };
            StorageAccountResource account = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(WaitUntil.Completed, accountName, storageAccountCreateParameters)).Value;

            if (Mode != RecordedTestMode.Playback)
            {
                await Task.Delay(5000);
            }

            //create eventhub
            string       eventHubName = Recording.GenerateAssetName("eventhub");
            EventHubData parameter    = new EventHubData()
            {
                MessageRetentionInDays = 4,
                PartitionCount         = 4,
                Status             = EntityStatus.Active,
                CaptureDescription = new CaptureDescription()
                {
                    Enabled           = true,
                    Encoding          = EncodingCaptureDescription.Avro,
                    IntervalInSeconds = 120,
                    SizeLimitInBytes  = 10485763,
                    Destination       = new EventHubDestination()
                    {
                        Name                     = "EventHubArchive.AzureBlockBlob",
                        BlobContainer            = "container",
                        ArchiveNameFormat        = "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}",
                        StorageAccountResourceId = account.Id.ToString()
                    }
                }
            };
            EventHubResource eventHub = (await _eventHubCollection.CreateOrUpdateAsync(WaitUntil.Completed, eventHubName, parameter)).Value;

            //validate
            Assert.NotNull(eventHub);
            Assert.AreEqual(eventHub.Id.Name, eventHubName);
            Assert.AreEqual(eventHub.Data.Status, parameter.Status);
            Assert.AreEqual(eventHub.Data.MessageRetentionInDays, parameter.MessageRetentionInDays);
            Assert.AreEqual(eventHub.Data.PartitionCount, parameter.PartitionCount);
            Assert.AreEqual(eventHub.Data.CaptureDescription.IntervalInSeconds, parameter.CaptureDescription.IntervalInSeconds);
            Assert.AreEqual(eventHub.Data.CaptureDescription.SizeLimitInBytes, parameter.CaptureDescription.SizeLimitInBytes);
            Assert.AreEqual(eventHub.Data.CaptureDescription.Destination.Name, parameter.CaptureDescription.Destination.Name);
            Assert.AreEqual(eventHub.Data.CaptureDescription.Destination.BlobContainer, parameter.CaptureDescription.Destination.BlobContainer);
            Assert.AreEqual(eventHub.Data.CaptureDescription.Destination.StorageAccountResourceId, parameter.CaptureDescription.Destination.StorageAccountResourceId);
            Assert.AreEqual(eventHub.Data.CaptureDescription.Destination.ArchiveNameFormat, parameter.CaptureDescription.Destination.ArchiveNameFormat);

            await account.DeleteAsync(WaitUntil.Completed);
        }
        public static StorageAccountCreateOrUpdateContent GetDefaultStorageAccountParameters(StorageSku sku = null, StorageKind?kind = null, string location = null, ManagedServiceIdentity identity = null)
        {
            StorageSku  skuParameters      = sku ?? DefaultSkuNameStandardGRS;
            StorageKind kindParameters     = kind ?? DefaultKindStorage;
            string      locationParameters = location ?? DefaultLocationString;
            StorageAccountCreateOrUpdateContent parameters = new StorageAccountCreateOrUpdateContent(skuParameters, kindParameters, locationParameters);

            parameters.Tags.InitializeFrom(DefaultTags);
            parameters.Identity = identity;
            return(parameters);
        }
Esempio n. 4
0
        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);
StorageAccountCreateOrUpdateContent parameters = new StorageAccountCreateOrUpdateContent(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 CreateOrUpdate()
        {
            #region Snippet:Managing_StorageAccounts_CreateStorageAccount
            //first we need to define the StorageAccountCreateParameters
            StorageSku  sku      = new StorageSku(StorageSkuName.StandardGRS);
            StorageKind kind     = StorageKind.Storage;
            string      location = "westus2";
            StorageAccountCreateOrUpdateContent parameters = new StorageAccountCreateOrUpdateContent(sku, kind, location);
            //now we can create a storage account with defined account name and parameters
            StorageAccountCollection accountCollection = resourceGroup.GetStorageAccounts();
            string accountName = "myAccount";
            ArmOperation <StorageAccountResource> accountCreateOperation = await accountCollection.CreateOrUpdateAsync(WaitUntil.Completed, accountName, parameters);

            StorageAccountResource storageAccount = accountCreateOperation.Value;
            #endregion
        }
Esempio n. 6
0
        public void ValidateStorageAccountCreateOrUpdateContent()
        {
            var data = new StorageAccountCreateOrUpdateContent(new StorageSku(StorageSkuName.StandardGRS), StorageKind.Storage, AzureLocation.AustraliaCentral);

            Assert.IsNull(data.KeyPolicy);
            Assert.IsNull(data.KeyExpirationPeriodInDays);

            data.KeyExpirationPeriodInDays = 5;

            Assert.IsNotNull(data.KeyPolicy);
            Assert.AreEqual(5, data.KeyExpirationPeriodInDays);

            data.KeyExpirationPeriodInDays = null;

            Assert.IsNull(data.KeyPolicy);
            Assert.IsNull(data.KeyExpirationPeriodInDays);
        }
        private async Task <StorageAccountResource> createStorageAccount()
        {
            var name       = Recording.GenerateAssetName("testsa");
            var parameters = new StorageAccountCreateOrUpdateContent(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.StorageAccountResource> 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;
        }
Esempio n. 8
0
        public virtual async Task <ArmOperation <StorageAccountResource> > CreateOrUpdateAsync(WaitUntil waitUntil, string accountName, StorageAccountCreateOrUpdateContent content, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(accountName, nameof(accountName));
            Argument.AssertNotNull(content, nameof(content));

            using var scope = _storageAccountClientDiagnostics.CreateScope("StorageAccountCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response = await _storageAccountRestClient.CreateAsync(Id.SubscriptionId, Id.ResourceGroupName, accountName, content, cancellationToken).ConfigureAwait(false);

                var operation = new StorageArmOperation <StorageAccountResource>(new StorageAccountOperationSource(Client), _storageAccountClientDiagnostics, Pipeline, _storageAccountRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, accountName, content).Request, response, OperationFinalStateVia.Location);
                if (waitUntil == WaitUntil.Completed)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public async Task CreateGetDeleteObjectReplicationPolicy()
        {
            //create 2 storage accounts
            string accountName1 = await CreateValidAccountNameAsync("teststoragemgmt");

            string accountName2 = await CreateValidAccountNameAsync("teststoragemgmt");

            StorageAccountCreateOrUpdateContent createParameters = GetDefaultStorageAccountParameters(kind: StorageKind.StorageV2);
            StorageAccountResource sourceAccount = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(WaitUntil.Completed, accountName1, createParameters)).Value;
            StorageAccountResource destAccount   = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(WaitUntil.Completed, accountName2, createParameters)).Value;

            //update 2 accounts properties
            var updateparameter = new StorageAccountPatch
            {
                AllowCrossTenantReplication = true,
                EnableHttpsTrafficOnly      = true
            };

            destAccount = await destAccount.UpdateAsync(updateparameter);

            sourceAccount = await sourceAccount.UpdateAsync(updateparameter);

            BlobServiceResource blobService1 = await destAccount.GetBlobService().GetAsync();

            BlobContainerCollection blobContainerCollection1 = blobService1.GetBlobContainers();
            BlobServiceResource     blobService2             = await destAccount.GetBlobService().GetAsync();

            BlobContainerCollection blobContainerCollection2 = blobService2.GetBlobContainers();

            //enable changefeed and versoning
            blobService1.Data.IsVersioningEnabled = true;
            await blobService1.CreateOrUpdateAsync(WaitUntil.Completed, blobService1.Data);

            //create 2 pairs of source and dest blob containers
            string containerName1            = Recording.GenerateAssetName("testblob1");
            string containerName2            = Recording.GenerateAssetName("testblob2");
            string containerName3            = Recording.GenerateAssetName("testblob3");
            string containerName4            = Recording.GenerateAssetName("testblob4");
            BlobContainerResource container1 = (await blobContainerCollection1.CreateOrUpdateAsync(WaitUntil.Completed, containerName1, new BlobContainerData())).Value;
            BlobContainerResource container2 = (await blobContainerCollection2.CreateOrUpdateAsync(WaitUntil.Completed, containerName2, new BlobContainerData())).Value;
            BlobContainerResource container3 = (await blobContainerCollection1.CreateOrUpdateAsync(WaitUntil.Completed, containerName3, new BlobContainerData())).Value;
            BlobContainerResource container4 = (await blobContainerCollection2.CreateOrUpdateAsync(WaitUntil.Completed, containerName4, new BlobContainerData())).Value;

            //prepare rules and policy
            ObjectReplicationPolicyData parameter = new ObjectReplicationPolicyData()
            {
                SourceAccount      = sourceAccount.Id.Name,
                DestinationAccount = destAccount.Id.Name
            };
            List <string> prefix = new List <string>();

            prefix.Add("aa");
            prefix.Add("bc d");
            prefix.Add("123");
            string minCreationTime = "2021-03-19T16:06:00Z";
            List <ObjectReplicationPolicyRule> rules = new List <ObjectReplicationPolicyRule>();

            parameter.Rules.Add(
                new ObjectReplicationPolicyRule(containerName1, containerName2)
            {
                Filters = new ObjectReplicationPolicyFilter(prefix, minCreationTime),
            }
                );
            parameter.Rules.Add(
                new ObjectReplicationPolicyRule(containerName3, containerName4)
                );

            //create policy
            ObjectReplicationPolicyCollection objectReplicationPolicyCollection = destAccount.GetObjectReplicationPolicies();
            ObjectReplicationPolicyResource   objectReplicationPolicy           = (await objectReplicationPolicyCollection.CreateOrUpdateAsync(WaitUntil.Completed, "default", parameter)).Value;

            Assert.NotNull(objectReplicationPolicy);
            Assert.AreEqual(objectReplicationPolicy.Data.DestinationAccount, destAccount.Id.Name);
            Assert.AreEqual(objectReplicationPolicy.Data.SourceAccount, sourceAccount.Id.Name);

            //get policy
            List <ObjectReplicationPolicyResource> policies = await objectReplicationPolicyCollection.GetAllAsync().ToEnumerableAsync();

            objectReplicationPolicy = policies[0];
            Assert.NotNull(objectReplicationPolicy);
            Assert.AreEqual(objectReplicationPolicy.Data.DestinationAccount, destAccount.Id.Name);
            Assert.AreEqual(objectReplicationPolicy.Data.SourceAccount, sourceAccount.Id.Name);

            //delete policy
            await objectReplicationPolicy.DeleteAsync(WaitUntil.Completed);
        }