public async Task PlacementGroupId() { var asetName = Recording.GenerateAssetName("aset-"); AvailabilitySet aset = await CreateAvailabilitySetAsync(asetName); var beforeAdd = aset.Data.ProximityPlacementGroupId; ResourceGroup rg = Client.GetResourceGroup(ResourceGroup.CreateResourceIdentifier(aset.Id.SubscriptionId, aset.Id.ResourceGroupName)); var proxGrpName = Recording.GenerateAssetName("proxGrp-"); ProximityPlacementGroup proxGrp = (await rg.GetProximityPlacementGroups().CreateOrUpdateAsync(true, proxGrpName, new ProximityPlacementGroupData(DefaultLocation))).Value; AvailabilitySetUpdateOptions updateOptions = new AvailabilitySetUpdateOptions(); updateOptions.ProximityPlacementGroupId = proxGrp.Id; aset = await aset.UpdateAsync(updateOptions); var addIdResult = aset.Data.ProximityPlacementGroupId; updateOptions.ProximityPlacementGroupId = null; aset = await aset.UpdateAsync(updateOptions); var removeIdResult = aset.Data.ProximityPlacementGroupId; var asetName2 = Recording.GenerateAssetName("aset-"); AvailabilitySet aset2 = await CreateAvailabilitySetAsync(asetName2); var newBeforeAdd = aset2.Data.ProximityPlacementGroup?.Id; AvailabilitySetUpdateOptions updateOptions2 = new AvailabilitySetUpdateOptions(); updateOptions2.ProximityPlacementGroup = new Resources.Models.WritableSubResource(); updateOptions2.ProximityPlacementGroup.Id = proxGrp.Id; aset2 = await aset2.UpdateAsync(updateOptions2); var newAddIdResult = aset2.Data.ProximityPlacementGroup.Id; updateOptions2.ProximityPlacementGroup.Id = null; aset2 = await aset2.UpdateAsync(updateOptions2); var newRemoveIdResult = aset2.Data.ProximityPlacementGroup?.Id; updateOptions2.ProximityPlacementGroup.Id = proxGrp.Id; aset2 = await aset2.UpdateAsync(updateOptions2); Assert.NotNull(aset2.Data.ProximityPlacementGroup.Id); updateOptions2.ProximityPlacementGroup = null; aset2 = await aset2.UpdateAsync(updateOptions2); var newRemoveOuterIdResult = aset2.Data.ProximityPlacementGroup?.Id; Assert.AreEqual(beforeAdd, newBeforeAdd); Assert.AreEqual(addIdResult, newAddIdResult); Assert.AreEqual(removeIdResult, newRemoveIdResult); Assert.AreEqual(removeIdResult, newRemoveOuterIdResult); }
public async Task UpdateAvailabilitySet() { #region Snippet:Managing_Availability_Set_UpdateAnAvailabilitySet // First, initialize the ArmClient and get the default subscription ArmClient armClient = new ArmClient(new DefaultAzureCredential()); // Now we get a ResourceGroup collection for that subscription Subscription subscription = await armClient.GetDefaultSubscriptionAsync(); ResourceGroupCollection rgCollection = subscription.GetResourceGroups(); // With the collection, we can create a new resource group with an specific name string rgName = "myRgName"; ResourceGroup resourceGroup = await rgCollection.GetAsync(rgName); AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets(); string availabilitySetName = "myAvailabilitySet"; AvailabilitySet availabilitySet = await availabilitySetCollection.GetAsync(availabilitySetName); // availabilitySet is an AvailabilitySet instance created above AvailabilitySetUpdate update = new AvailabilitySetUpdate() { PlatformFaultDomainCount = 3 }; AvailabilitySet updatedAvailabilitySet = await availabilitySet.UpdateAsync(update); #endregion Snippet:Managing_Availability_Set_UpdateAnAvailabilitySet }