Exemplo n.º 1
0
        public async Task CreateDisk()
        {
            #region Snippet:Managing_Disks_CreateADisk
            ArmClient    armClient    = new ArmClient(new DefaultAzureCredential());
            Subscription subscription = armClient.DefaultSubscription;
            // first we need to get the resource group
            string        rgName        = "myRgName";
            ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);

            // Now we get the virtual machine container from the resource group
            DiskContainer diskContainer = resourceGroup.GetDisks();
            // Use the same location as the resource group
            string diskName = "myDisk";
            var    input    = new DiskData(resourceGroup.Data.Location)
            {
                Sku = new DiskSku()
                {
                    Name = DiskStorageAccountTypes.StandardLRS
                },
                CreationData = new CreationData(DiskCreateOption.Empty),
                DiskSizeGB   = 1,
            };
            DiskCreateOrUpdateOperation lro = await diskContainer.CreateOrUpdateAsync(diskName, input);

            Disk disk = lro.Value;
            #endregion Snippet:Managing_Disks_CreateADisk
        }
Exemplo n.º 2
0
        public async Task DeleteDisk()
        {
            #region Snippet:Managing_Disks_DeleteDisk
            ArmClient    armClient    = new ArmClient(new DefaultAzureCredential());
            Subscription subscription = armClient.DefaultSubscription;
            // first we need to get the resource group
            string        rgName        = "myRgName";
            ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);

            // Now we get the virtual machine container from the resource group
            DiskContainer diskContainer = resourceGroup.GetDisks();
            string        diskName      = "myDisk";
            Disk          disk          = await diskContainer.GetAsync(diskName);

            await disk.DeleteAsync();

            #endregion Snippet:Managing_Disks_DeleteDisk
        }
Exemplo n.º 3
0
        public async Task ListDisks()
        {
            #region Snippet:Managing_Disks_ListAllDisks
            ArmClient    armClient    = new ArmClient(new DefaultAzureCredential());
            Subscription subscription = armClient.DefaultSubscription;
            // first we need to get the resource group
            string        rgName        = "myRgName";
            ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);

            // Now we get the virtual machine container from the resource group
            DiskContainer diskContainer = resourceGroup.GetDisks();
            // With ListAsync(), we can get a list of the virtual machines in the container
            AsyncPageable <Disk> response = diskContainer.GetAllAsync();
            await foreach (Disk disk in response)
            {
                Console.WriteLine(disk.Data.Name);
            }
            #endregion Snippet:Managing_Disks_ListAllDisks
        }