Exemple #1
0
        public async Task DiskPoolCrudOperations()
        {
            var diskPoolName       = Recording.GenerateAssetName("diskpool-");
            var diskPoolCollection = _resourceGroup.GetDiskPools();

            var sku            = new StoragePoolSku("Standard_S1");
            var diskPoolCreate = new DiskPoolCreate(sku, DefaultLocation, SubnetResourceId)
            {
            };

            diskPoolCreate.AvailabilityZones.Add("1");
            // the following additional capability is not needed for non-test disk pools
            diskPoolCreate.AdditionalCapabilities.Add("DiskPool.SkipInfrastructureDeployment");

            // create disk pool
            var response = await diskPoolCollection.CreateOrUpdateAsync(WaitUntil.Completed, diskPoolName, diskPoolCreate);

            var diskPool = response.Value;

            Assert.AreEqual(diskPoolName, diskPool.Data.Name);
            Assert.AreEqual(ProvisioningStates.Succeeded, diskPool.Data.ProvisioningState);

            // update disk pool -- by adding a new tag
            diskPoolCreate.Tags.Add("tag2", "value2");
            var updateResponse = await diskPoolCollection.CreateOrUpdateAsync(WaitUntil.Completed, diskPoolName, diskPoolCreate);

            diskPool = updateResponse.Value;
            Assert.AreEqual(diskPoolCreate.Tags, diskPool.Data.Tags);
            Assert.AreEqual(ProvisioningStates.Succeeded, diskPool.Data.ProvisioningState);

            // stop disk pool
            var deallocateResponse = await diskPool.DeallocateAsync(WaitUntil.Completed);

            // start disk pool
            var startResponse = await diskPool.StartAsync(WaitUntil.Completed);

            // delete disk pool
            var deleteResponse = await diskPool.DeleteAsync(WaitUntil.Completed);

            try
            {
                var getResponse = await diskPoolCollection.GetAsync(diskPoolName);
            } catch (RequestFailedException e)
            {
                Assert.AreEqual(StatusCodes.Status404NotFound, e.Status);
            }
        }
 public static Response <DiskPoolResource> GetDiskPool(this ResourceGroupResource resourceGroupResource, string diskPoolName, CancellationToken cancellationToken = default)
 {
     return(resourceGroupResource.GetDiskPools().Get(diskPoolName, cancellationToken));
 }
        public async Task IscsiTargetCrudOperations()
        {
            var diskPoolName       = Recording.GenerateAssetName("diskpool-");
            var diskPoolCollection = _resourceGroup.GetDiskPools();

            var sku            = new StoragePoolSku("Standard_S1");
            var diskPoolCreate = new DiskPoolCreate(sku, DefaultLocation, SubnetResourceId)
            {
            };

            diskPoolCreate.AvailabilityZones.Add("1");

            // create disk pool
            var response = await diskPoolCollection.CreateOrUpdateAsync(WaitUntil.Completed, diskPoolName, diskPoolCreate);

            var diskPool = response.Value;

            Assert.AreEqual(diskPoolName, diskPool.Data.Name);
            Assert.AreEqual(ProvisioningStates.Succeeded, diskPool.Data.ProvisioningState);

            // create iSCSI target
            var targetCollection  = diskPool.GetIscsiTargets();
            var iscsiTargetName   = Recording.GenerateAssetName("target-");
            var iscsiTargetCreate = new IscsiTargetCreate(IscsiTargetAclMode.Dynamic);

            var targetCreateResponse = await targetCollection.CreateOrUpdateAsync(WaitUntil.Completed, iscsiTargetName, iscsiTargetCreate);

            var iscsiTarget = targetCreateResponse.Value;

            Assert.AreEqual(iscsiTargetName, iscsiTarget.Data.Name);
            Assert.AreEqual(ProvisioningStates.Succeeded, iscsiTarget.Data.ProvisioningState);

            // update iSCSI target -- by updating the managed by property
            var dataStoreId = "/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/myResourceGroup/providers/Microsoft.AVS/privateClouds/myPrivateCloud/clusters/Cluster-1/datastores/datastore1";

            iscsiTargetCreate.ManagedBy = dataStoreId;
            iscsiTargetCreate.ManagedByExtended.Add(dataStoreId);
            var targetUpdateResponse = await targetCollection.CreateOrUpdateAsync(WaitUntil.Completed, iscsiTargetName, iscsiTargetCreate);

            iscsiTarget = targetUpdateResponse.Value;

            Assert.AreEqual(dataStoreId, iscsiTarget.Data.ManagedBy);
            Assert.AreEqual(ProvisioningStates.Succeeded, iscsiTarget.Data.ProvisioningState);

            // remove managed by reference
            iscsiTargetCreate.ManagedBy = "";
            iscsiTargetCreate.ManagedByExtended.Remove(dataStoreId);
            targetUpdateResponse = await targetCollection.CreateOrUpdateAsync(WaitUntil.Completed, iscsiTargetName, iscsiTargetCreate);

            iscsiTarget = targetUpdateResponse.Value;

            Assert.AreEqual(null, iscsiTarget.Data.ManagedBy);
            Assert.AreEqual(ProvisioningStates.Succeeded, iscsiTarget.Data.ProvisioningState);

            // delete iSCSI target
            var targetDeleteResponse = await iscsiTarget.DeleteAsync(WaitUntil.Completed);

            try
            {
                var getResponse = await targetCollection.GetAsync(iscsiTargetName);
            }
            catch (RequestFailedException e)
            {
                Assert.AreEqual(StatusCodes.Status404NotFound, e.Status);
            }
        }
 public static async Task <Response <DiskPoolResource> > GetDiskPoolAsync(this ResourceGroupResource resourceGroupResource, string diskPoolName, CancellationToken cancellationToken = default)
 {
     return(await resourceGroupResource.GetDiskPools().GetAsync(diskPoolName, cancellationToken).ConfigureAwait(false));
 }