Exemplo n.º 1
0
        public async Task GetAllInSubscription()
        {
            var collection = await GetDiskCollectionAsync();

            var diskName1 = Recording.GenerateAssetName("testDisk-");
            var diskName2 = Recording.GenerateAssetName("testDisk-");
            var input     = ResourceDataHelper.GetEmptyDiskData(DefaultLocation, new Dictionary <string, string>()
            {
                { "key", "value" }
            });

            _ = await collection.CreateOrUpdateAsync(WaitUntil.Completed, diskName1, input);

            _ = await collection.CreateOrUpdateAsync(WaitUntil.Completed, diskName2, input);

            ManagedDiskResource disk1 = null, disk2 = null;

            await foreach (var disk in DefaultSubscription.GetManagedDisksAsync())
            {
                if (disk.Data.Name == diskName1)
                {
                    disk1 = disk;
                }
                if (disk.Data.Name == diskName2)
                {
                    disk2 = disk;
                }
            }

            Assert.NotNull(disk1);
            Assert.NotNull(disk2);
        }
Exemplo n.º 2
0
        public async Task CreateDisk()
        {
            #region Snippet:Managing_Disks_CreateADisk
            ArmClient            armClient    = new ArmClient(new DefaultAzureCredential());
            SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();

            // first we need to get the resource group
            string rgName = "myRgName";
            ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);

            // Now we get the disk collection from the resource group
            ManagedDiskCollection diskCollection = resourceGroup.GetManagedDisks();
            // Use the same location as the resource group
            string diskName = "myDisk";
            var    input    = new ManagedDiskData(resourceGroup.Data.Location)
            {
                Sku = new DiskSku()
                {
                    Name = DiskStorageAccountTypes.StandardLRS
                },
                CreationData = new DiskCreationData(DiskCreateOption.Empty),
                DiskSizeGB   = 1,
            };
            ArmOperation <ManagedDiskResource> lro = await diskCollection.CreateOrUpdateAsync(WaitUntil.Completed, diskName, input);

            ManagedDiskResource disk = lro.Value;
            #endregion Snippet:Managing_Disks_CreateADisk
        }
Exemplo n.º 3
0
        public async Task Get()
        {
            var diskName = Recording.GenerateAssetName("testDisk-");
            var disk1    = await CreateDiskAsync(diskName);

            ManagedDiskResource disk2 = await disk1.GetAsync();

            ResourceDataHelper.AssertDisk(disk1.Data, disk2.Data);
        }
Exemplo n.º 4
0
        private async Task <SnapshotResource> CreateSnapshot(ManagedDiskResource disk, string name)
        {
            var snapshotCreateOperation = await _resourceGroup.GetSnapshots().CreateOrUpdateAsync(WaitUntil.Completed, name,
                                                                                                  new SnapshotData(_config.Location)
            {
                CreationData = new DiskCreationData(DiskCreateOption.Copy)
                {
                    SourceResourceId = disk.Id
                },
                Incremental = true,
            });

            return(await snapshotCreateOperation.WaitForCompletionAsync());
        }
Exemplo n.º 5
0
        public async Task Update()
        {
            var diskName = Recording.GenerateAssetName("testDisk-");
            var disk     = await CreateDiskAsync(diskName);

            var newDiskSize = 20;
            var update      = new ManagedDiskPatch()
            {
                DiskSizeGB = newDiskSize
            };
            var lro = await disk.UpdateAsync(WaitUntil.Completed, update);

            ManagedDiskResource updatedDisk = lro.Value;

            Assert.AreEqual(newDiskSize, updatedDisk.Data.DiskSizeGB);
        }
Exemplo n.º 6
0
        public async Task Get()
        {
            var collection = await GetDiskCollectionAsync();

            var diskName = Recording.GenerateAssetName("testDisk-");
            var input    = ResourceDataHelper.GetEmptyDiskData(DefaultLocation, new Dictionary <string, string>()
            {
                { "key", "value" }
            });
            var lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, diskName, input);

            ManagedDiskResource disk1 = lro.Value;
            ManagedDiskResource disk2 = await collection.GetAsync(diskName);

            ResourceDataHelper.AssertDisk(disk1.Data, disk2.Data);
        }
Exemplo n.º 7
0
        public async Task Exists()
        {
            var collection = await GetDiskCollectionAsync();

            var diskName = Recording.GenerateAssetName("testDisk-");
            var input    = ResourceDataHelper.GetEmptyDiskData(DefaultLocation, new Dictionary <string, string>()
            {
                { "key", "value" }
            });
            var lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, diskName, input);

            ManagedDiskResource disk = lro.Value;

            Assert.IsTrue(await collection.ExistsAsync(diskName));
            Assert.IsFalse(await collection.ExistsAsync(diskName + "1"));

            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await collection.ExistsAsync(null));
        }
Exemplo n.º 8
0
        public async Task DeleteDisk()
        {
            #region Snippet:Managing_Disks_DeleteDisk
            ArmClient            armClient    = new ArmClient(new DefaultAzureCredential());
            SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();

            // first we need to get the resource group
            string rgName = "myRgName";
            ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);

            // Now we get the disk collection from the resource group
            ManagedDiskCollection diskCollection = resourceGroup.GetManagedDisks();
            string diskName          = "myDisk";
            ManagedDiskResource disk = await diskCollection.GetAsync(diskName);

            await disk.DeleteAsync(WaitUntil.Completed);

            #endregion Snippet:Managing_Disks_DeleteDisk
        }