コード例 #1
0
        protected void CleanupResourceGroups()
        {
            if (Mode != RecordedTestMode.Playback)
            {
                Parallel.ForEach(ResourceGroupCleanupPolicy.ResourceGroupsCreated, resourceGroup =>
                {
                    try
                    {
                        SubscriptionResource sub = _cleanupClient.GetSubscriptions().Exists(TestEnvironment.SubscriptionId)
                            ? _cleanupClient.GetSubscriptions().Get(TestEnvironment.SubscriptionId)
                            : null;
                        sub?.GetResourceGroups().Get(resourceGroup).Value.Delete(_waitForCleanup);
                    }
                    catch (RequestFailedException e) when(e.Status == 404)
                    {
                        //we assume the test case cleaned it up if it no longer exists.
                    }
                });

                Parallel.ForEach(ManagementGroupCleanupPolicy.ManagementGroupsCreated, mgmtGroupId =>
                {
                    try
                    {
                        _cleanupClient.GetManagementGroupResource(new ResourceIdentifier(mgmtGroupId)).Delete(_waitForCleanup);
                    }
                    catch (RequestFailedException e) when(e.Status == 404 || e.Status == 403)
                    {
                        //we assume the test case cleaned it up if it no longer exists.
                    }
                });
            }
        }
コード例 #2
0
        protected void CleanupResourceGroups()
        {
            if (Mode != RecordedTestMode.Playback)
            {
                Parallel.ForEach(ResourceGroupCleanupPolicy.ResourceGroupsCreated, resourceGroup =>
                {
                    try
                    {
                        var sub = _cleanupClient.GetSubscriptions().GetIfExists(TestEnvironment.SubscriptionId);
                        sub.Value?.GetResourceGroups().Get(resourceGroup).Value.StartDelete();
                    }
                    catch (RequestFailedException e) when(e.Status == 404)
                    {
                        //we assume the test case cleaned it up if it no longer exists.
                    }
                });

                Parallel.ForEach(ManagementGroupCleanupPolicy.ManagementGroupsCreated, mgmtGroupId =>
                {
                    try
                    {
                        _cleanupClient.GetManagementGroupOperations(mgmtGroupId).StartDelete();
                    }
                    catch (RequestFailedException e) when(e.Status == 404 || e.Status == 403)
                    {
                        //we assume the test case cleaned it up if it no longer exists.
                    }
                });
            }
        }
コード例 #3
0
 protected async Task CleanupResourceGroupsAsync()
 {
     if (CleanupPolicy != null && Mode != RecordedTestMode.Playback)
     {
         _cleanupClient ??= new ArmClient(
             TestEnvironment.Credential,
             TestEnvironment.SubscriptionId,
             new ArmClientOptions());
         SubscriptionResource subscription = _cleanupClient.GetSubscriptions().Exists(TestEnvironment.SubscriptionId)
             ? _cleanupClient.GetSubscriptions().Get(TestEnvironment.SubscriptionId)
             : null;
         foreach (var resourceGroup in CleanupPolicy.ResourceGroupsCreated)
         {
             await subscription?.GetResourceGroups().Get(resourceGroup).Value.DeleteAsync(WaitUntil.Completed);
         }
     }
 }
コード例 #4
0
 public void GettingSpecificSubscription()
 {
     #region Snippet:Hello_World_SpecificSubscription
     string       subscriptionId = "your-subscription-id";
     ArmClient    armClient      = new ArmClient(new DefaultAzureCredential());
     Subscription subscription   = armClient.GetSubscriptions().Get(subscriptionId);
     Console.WriteLine($"Got subscription: {subscription.Data.DisplayName}");
     #endregion Snippet:Hello_World_SpecificSubscription
 }
コード例 #5
0
        public async Task GettingSpecificSubscriptionAsync()
        {
            #region Snippet:Hello_World_Async_SpecificSubscription
            string       subscriptionId = "your-subscription-id";
            var          armClient      = new ArmClient(new DefaultAzureCredential());
            Subscription subscription   = await armClient.GetSubscriptions().GetAsync(subscriptionId);

            Console.WriteLine(subscription.Id);
            #endregion Snippet:Hello_World_Async_SpecificSubscription
        }
コード例 #6
0
 public async Task ManageAvailabilitySetOld()
 {
     #region Snippet:Readme_ManageAvailabilitySetOld
     ResourceIdentifier id = new ResourceIdentifier("/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/workshop2021-rg/providers/Microsoft.Compute/availabilitySets/ws2021availSet");
     // We construct a new armClient to work with
     ArmClient armClient = new ArmClient(new DefaultAzureCredential());
     // Next we get the specific subscription this resource belongs to
     Subscription subscription = await armClient.GetSubscriptions().GetAsync(id.SubscriptionId);
     // Next we get the specific resource group this resource belongs to
     ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(id.ResourceGroupName);
     // Finally we get the resource itself
     // Note: for this last step in this example, Azure.ResourceManager.Compute is needed
     AvailabilitySet availabilitySet = await resourceGroup.GetAvailabilitySets().GetAsync(id.Name);
     #endregion Snippet:Readme_ManageAvailabilitySetOld
 }