-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathConsumptionExtensions.cs
234 lines (218 loc) · 13.3 KB
/
ConsumptionExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated/>
#nullable disable
using System;
using System.Threading;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.ResourceManager;
using Azure.ResourceManager.Consumption.Models;
using Azure.ResourceManager.ManagementGroups;
using Azure.ResourceManager.Resources;
namespace Azure.ResourceManager.Consumption
{
/// <summary> A class to add extension methods to Azure.ResourceManager.Consumption. </summary>
public static partial class ConsumptionExtensions
{
private static TenantResourceExtensionClient GetExtensionClient(TenantResource tenantResource)
{
return tenantResource.GetCachedClient((client) =>
{
return new TenantResourceExtensionClient(client, tenantResource.Id);
}
);
}
private static SubscriptionResourceExtensionClient GetExtensionClient(SubscriptionResource subscriptionResource)
{
return subscriptionResource.GetCachedClient((client) =>
{
return new SubscriptionResourceExtensionClient(client, subscriptionResource.Id);
}
);
}
/// <summary>
/// Gets the price sheet for a subscription. Price sheet is available via this API only for May 1, 2014 or later.
/// <list type="bullet">
/// <item>
/// <term>Request Path</term>
/// <description>/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/pricesheets/default</description>
/// </item>
/// <item>
/// <term>Operation Id</term>
/// <description>PriceSheet_Get</description>
/// </item>
/// </list>
/// </summary>
/// <param name="subscriptionResource"> The <see cref="SubscriptionResource" /> instance the method will execute against. </param>
/// <param name="expand"> May be used to expand the properties/meterDetails within a price sheet. By default, these fields are not included when returning price sheet. </param>
/// <param name="skipToken"> Skiptoken is only used if a previous operation returned a partial result. If a previous response contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a starting point to use for subsequent calls. </param>
/// <param name="top"> May be used to limit the number of results to the top N results. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public static async Task<Response<PriceSheetResult>> GetPriceSheetAsync(this SubscriptionResource subscriptionResource, string expand = null, string skipToken = null, int? top = null, CancellationToken cancellationToken = default)
{
return await GetExtensionClient(subscriptionResource).GetPriceSheetAsync(expand, skipToken, top, cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Gets the price sheet for a subscription. Price sheet is available via this API only for May 1, 2014 or later.
/// <list type="bullet">
/// <item>
/// <term>Request Path</term>
/// <description>/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/pricesheets/default</description>
/// </item>
/// <item>
/// <term>Operation Id</term>
/// <description>PriceSheet_Get</description>
/// </item>
/// </list>
/// </summary>
/// <param name="subscriptionResource"> The <see cref="SubscriptionResource" /> instance the method will execute against. </param>
/// <param name="expand"> May be used to expand the properties/meterDetails within a price sheet. By default, these fields are not included when returning price sheet. </param>
/// <param name="skipToken"> Skiptoken is only used if a previous operation returned a partial result. If a previous response contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a starting point to use for subsequent calls. </param>
/// <param name="top"> May be used to limit the number of results to the top N results. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public static Response<PriceSheetResult> GetPriceSheet(this SubscriptionResource subscriptionResource, string expand = null, string skipToken = null, int? top = null, CancellationToken cancellationToken = default)
{
return GetExtensionClient(subscriptionResource).GetPriceSheet(expand, skipToken, top, cancellationToken);
}
private static ManagementGroupResourceExtensionClient GetExtensionClient(ManagementGroupResource managementGroupResource)
{
return managementGroupResource.GetCachedClient((client) =>
{
return new ManagementGroupResourceExtensionClient(client, managementGroupResource.Id);
}
);
}
/// <summary>
/// Provides the aggregate cost of a management group and all child management groups by current billing period.
/// <list type="bullet">
/// <item>
/// <term>Request Path</term>
/// <description>/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Consumption/aggregatedcost</description>
/// </item>
/// <item>
/// <term>Operation Id</term>
/// <description>AggregatedCost_GetByManagementGroup</description>
/// </item>
/// </list>
/// </summary>
/// <param name="managementGroupResource"> The <see cref="ManagementGroupResource" /> instance the method will execute against. </param>
/// <param name="filter"> May be used to filter aggregated cost by properties/usageStart (Utc time), properties/usageEnd (Utc time). The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. Tag filter is a key value pair string where key and value is separated by a colon (:). </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public static async Task<Response<ConsumptionAggregatedCostResult>> GetAggregatedCostAsync(this ManagementGroupResource managementGroupResource, string filter = null, CancellationToken cancellationToken = default)
{
return await GetExtensionClient(managementGroupResource).GetAggregatedCostAsync(filter, cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Provides the aggregate cost of a management group and all child management groups by current billing period.
/// <list type="bullet">
/// <item>
/// <term>Request Path</term>
/// <description>/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Consumption/aggregatedcost</description>
/// </item>
/// <item>
/// <term>Operation Id</term>
/// <description>AggregatedCost_GetByManagementGroup</description>
/// </item>
/// </list>
/// </summary>
/// <param name="managementGroupResource"> The <see cref="ManagementGroupResource" /> instance the method will execute against. </param>
/// <param name="filter"> May be used to filter aggregated cost by properties/usageStart (Utc time), properties/usageEnd (Utc time). The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. Tag filter is a key value pair string where key and value is separated by a colon (:). </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public static Response<ConsumptionAggregatedCostResult> GetAggregatedCost(this ManagementGroupResource managementGroupResource, string filter = null, CancellationToken cancellationToken = default)
{
return GetExtensionClient(managementGroupResource).GetAggregatedCost(filter, cancellationToken);
}
private static ArmResourceExtensionClient GetExtensionClient(ArmClient client, ResourceIdentifier scope)
{
return client.GetResourceClient(() =>
{
return new ArmResourceExtensionClient(client, scope);
}
);
}
private static ArmResourceExtensionClient GetExtensionClient(ArmResource armResource)
{
return armResource.GetCachedClient((client) =>
{
return new ArmResourceExtensionClient(client, armResource.Id);
}
);
}
/// <summary> Gets a collection of ConsumptionBudgetResources in the ArmResource. </summary>
/// <param name="client"> The <see cref="ArmClient" /> instance the method will execute against. </param>
/// <param name="scope"> The scope that the resource will apply against. </param>
/// <returns> An object representing collection of ConsumptionBudgetResources and their operations over a ConsumptionBudgetResource. </returns>
public static ConsumptionBudgetCollection GetConsumptionBudgets(this ArmClient client, ResourceIdentifier scope)
{
return GetExtensionClient(client, scope).GetConsumptionBudgets();
}
/// <summary>
/// Gets the budget for the scope by budget name.
/// <list type="bullet">
/// <item>
/// <term>Request Path</term>
/// <description>/{scope}/providers/Microsoft.Consumption/budgets/{budgetName}</description>
/// </item>
/// <item>
/// <term>Operation Id</term>
/// <description>Budgets_Get</description>
/// </item>
/// </list>
/// </summary>
/// <param name="client"> The <see cref="ArmClient" /> instance the method will execute against. </param>
/// <param name="scope"> The scope that the resource will apply against. </param>
/// <param name="budgetName"> Budget Name. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentException"> <paramref name="budgetName"/> is an empty string, and was expected to be non-empty. </exception>
/// <exception cref="ArgumentNullException"> <paramref name="budgetName"/> is null. </exception>
[ForwardsClientCalls]
public static async Task<Response<ConsumptionBudgetResource>> GetConsumptionBudgetAsync(this ArmClient client, ResourceIdentifier scope, string budgetName, CancellationToken cancellationToken = default)
{
return await client.GetConsumptionBudgets(scope).GetAsync(budgetName, cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Gets the budget for the scope by budget name.
/// <list type="bullet">
/// <item>
/// <term>Request Path</term>
/// <description>/{scope}/providers/Microsoft.Consumption/budgets/{budgetName}</description>
/// </item>
/// <item>
/// <term>Operation Id</term>
/// <description>Budgets_Get</description>
/// </item>
/// </list>
/// </summary>
/// <param name="client"> The <see cref="ArmClient" /> instance the method will execute against. </param>
/// <param name="scope"> The scope that the resource will apply against. </param>
/// <param name="budgetName"> Budget Name. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="ArgumentException"> <paramref name="budgetName"/> is an empty string, and was expected to be non-empty. </exception>
/// <exception cref="ArgumentNullException"> <paramref name="budgetName"/> is null. </exception>
[ForwardsClientCalls]
public static Response<ConsumptionBudgetResource> GetConsumptionBudget(this ArmClient client, ResourceIdentifier scope, string budgetName, CancellationToken cancellationToken = default)
{
return client.GetConsumptionBudgets(scope).Get(budgetName, cancellationToken);
}
#region ConsumptionBudgetResource
/// <summary>
/// Gets an object representing a <see cref="ConsumptionBudgetResource" /> along with the instance operations that can be performed on it but with no data.
/// You can use <see cref="ConsumptionBudgetResource.CreateResourceIdentifier" /> to create a <see cref="ConsumptionBudgetResource" /> <see cref="ResourceIdentifier" /> from its components.
/// </summary>
/// <param name="client"> The <see cref="ArmClient" /> instance the method will execute against. </param>
/// <param name="id"> The resource ID of the resource to get. </param>
/// <returns> Returns a <see cref="ConsumptionBudgetResource" /> object. </returns>
public static ConsumptionBudgetResource GetConsumptionBudgetResource(this ArmClient client, ResourceIdentifier id)
{
return client.GetResourceClient(() =>
{
ConsumptionBudgetResource.ValidateResourceId(id);
return new ConsumptionBudgetResource(client, id);
}
);
}
#endregion
}
}