1
1
# -*- coding: utf-8 -*-
2
- # (C) Copyright IBM Corp. 2020 .
2
+ # (C) Copyright IBM Corp. 2024 .
3
3
#
4
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
5
# you may not use this file except in compliance with the License.
17
17
Examples for UsageReportsV4
18
18
"""
19
19
20
+ from ibm_cloud_sdk_core import ApiException , read_external_sources
20
21
import os
21
22
import pytest
22
- from ibm_cloud_sdk_core import ApiException , read_external_sources
23
23
from ibm_platform_services .usage_reports_v4 import *
24
24
25
25
#
54
54
snapshot_date_from = None
55
55
snapshot_date_to = None
56
56
57
+
57
58
##############################################################################
58
59
# Start of Examples for Service: UsageReportsV4
59
60
##############################################################################
60
61
# region
61
-
62
-
63
62
class TestUsageReportsV4Examples :
64
63
"""
65
64
Example Test Class for UsageReportsV4
@@ -129,11 +128,14 @@ def test_get_account_summary_example(self):
129
128
"""
130
129
try :
131
130
print ('\n get_account_summary() result:' )
131
+
132
132
# begin-get_account_summary
133
133
134
- account_summary = usage_reports_service .get_account_summary (
135
- account_id = account_id , billingmonth = billing_month
136
- ).get_result ()
134
+ response = usage_reports_service .get_account_summary (
135
+ account_id = account_id ,
136
+ billingmonth = billing_month ,
137
+ )
138
+ account_summary = response .get_result ()
137
139
138
140
print (json .dumps (account_summary , indent = 2 ))
139
141
@@ -149,11 +151,14 @@ def test_get_account_usage_example(self):
149
151
"""
150
152
try :
151
153
print ('\n get_account_usage() result:' )
154
+
152
155
# begin-get_account_usage
153
156
154
- account_usage = usage_reports_service .get_account_usage (
155
- account_id = account_id , billingmonth = billing_month
156
- ).get_result ()
157
+ response = usage_reports_service .get_account_usage (
158
+ account_id = account_id ,
159
+ billingmonth = billing_month ,
160
+ )
161
+ account_usage = response .get_result ()
157
162
158
163
print (json .dumps (account_usage , indent = 2 ))
159
164
@@ -169,11 +174,15 @@ def test_get_resource_group_usage_example(self):
169
174
"""
170
175
try :
171
176
print ('\n get_resource_group_usage() result:' )
177
+
172
178
# begin-get_resource_group_usage
173
179
174
- resource_group_usage = usage_reports_service .get_resource_group_usage (
175
- account_id = account_id , resource_group_id = resource_group_id , billingmonth = billing_month
176
- ).get_result ()
180
+ response = usage_reports_service .get_resource_group_usage (
181
+ account_id = account_id ,
182
+ resource_group_id = resource_group_id ,
183
+ billingmonth = billing_month ,
184
+ )
185
+ resource_group_usage = response .get_result ()
177
186
178
187
print (json .dumps (resource_group_usage , indent = 2 ))
179
188
@@ -182,43 +191,30 @@ def test_get_resource_group_usage_example(self):
182
191
except ApiException as e :
183
192
pytest .fail (str (e ))
184
193
185
- @needscredentials
186
- def test_get_org_usage_example (self ):
187
- """
188
- get_org_usage request example
189
- """
190
- try :
191
- print ('\n get_org_usage() result:' )
192
- # begin-get_org_usage
193
-
194
- org_usage = usage_reports_service .get_org_usage (
195
- account_id = account_id , organization_id = org_id , billingmonth = billing_month
196
- ).get_result ()
197
-
198
- print (json .dumps (org_usage , indent = 2 ))
199
-
200
- # end-get_org_usage
201
-
202
- except ApiException as e :
203
- pytest .fail (str (e ))
204
-
205
194
@needscredentials
206
195
def test_get_resource_usage_account_example (self ):
207
196
"""
208
197
get_resource_usage_account request example
209
198
"""
210
199
try :
211
200
print ('\n get_resource_usage_account() result:' )
201
+
212
202
# begin-get_resource_usage_account
213
203
214
- instances_usage = usage_reports_service .get_resource_usage_account (
215
- account_id = account_id , billingmonth = billing_month
216
- ).get_result ()
204
+ all_results = []
205
+ pager = GetResourceUsageAccountPager (
206
+ client = usage_reports_service ,
207
+ account_id = account_id ,
208
+ billingmonth = billing_month ,
209
+ )
210
+ while pager .has_next ():
211
+ next_page = pager .get_next ()
212
+ assert next_page is not None
213
+ all_results .extend (next_page )
217
214
218
- print (json .dumps (instances_usage , indent = 2 ))
215
+ print (json .dumps (all_results , indent = 2 ))
219
216
220
217
# end-get_resource_usage_account
221
-
222
218
except ApiException as e :
223
219
pytest .fail (str (e ))
224
220
@@ -229,16 +225,24 @@ def test_get_resource_usage_resource_group_example(self):
229
225
"""
230
226
try :
231
227
print ('\n get_resource_usage_resource_group() result:' )
228
+
232
229
# begin-get_resource_usage_resource_group
233
230
234
- instances_usage = usage_reports_service .get_resource_usage_resource_group (
235
- account_id = account_id , resource_group_id = resource_group_id , billingmonth = billing_month
236
- ).get_result ()
231
+ all_results = []
232
+ pager = GetResourceUsageResourceGroupPager (
233
+ client = usage_reports_service ,
234
+ account_id = account_id ,
235
+ resource_group_id = resource_group_id ,
236
+ billingmonth = billing_month ,
237
+ )
238
+ while pager .has_next ():
239
+ next_page = pager .get_next ()
240
+ assert next_page is not None
241
+ all_results .extend (next_page )
237
242
238
- print (json .dumps (instances_usage , indent = 2 ))
243
+ print (json .dumps (all_results , indent = 2 ))
239
244
240
245
# end-get_resource_usage_resource_group
241
-
242
246
except ApiException as e :
243
247
pytest .fail (str (e ))
244
248
@@ -249,15 +253,43 @@ def test_get_resource_usage_org_example(self):
249
253
"""
250
254
try :
251
255
print ('\n get_resource_usage_org() result:' )
256
+
252
257
# begin-get_resource_usage_org
253
258
254
- instances_usage = usage_reports_service .get_resource_usage_org (
259
+ all_results = []
260
+ pager = GetResourceUsageOrgPager (
261
+ client = usage_reports_service ,
262
+ account_id = account_id ,
263
+ organization_id = org_id ,
264
+ billingmonth = billing_month ,
265
+ )
266
+ while pager .has_next ():
267
+ next_page = pager .get_next ()
268
+ assert next_page is not None
269
+ all_results .extend (next_page )
270
+
271
+ print (json .dumps (all_results , indent = 2 ))
272
+
273
+ # end-get_resource_usage_org
274
+ except ApiException as e :
275
+ pytest .fail (str (e ))
276
+
277
+ @needscredentials
278
+ def test_get_org_usage_example (self ):
279
+ """
280
+ get_org_usage request example
281
+ """
282
+ try :
283
+ print ('\n get_org_usage() result:' )
284
+ # begin-get_org_usage
285
+
286
+ org_usage = usage_reports_service .get_org_usage (
255
287
account_id = account_id , organization_id = org_id , billingmonth = billing_month
256
288
).get_result ()
257
289
258
- print (json .dumps (instances_usage , indent = 2 ))
290
+ print (json .dumps (org_usage , indent = 2 ))
259
291
260
- # end-get_resource_usage_org
292
+ # end-get_org_usage
261
293
262
294
except ApiException as e :
263
295
pytest .fail (str (e ))
@@ -269,6 +301,7 @@ def test_create_reports_snapshot_config_example(self):
269
301
"""
270
302
try :
271
303
print ('\n create_reports_snapshot_config() result:' )
304
+
272
305
# begin-create_reports_snapshot_config
273
306
274
307
response = usage_reports_service .create_reports_snapshot_config (
@@ -293,6 +326,7 @@ def test_get_reports_snapshot_config_example(self):
293
326
"""
294
327
try :
295
328
print ('\n get_reports_snapshot_config() result:' )
329
+
296
330
# begin-get_reports_snapshot_config
297
331
298
332
response = usage_reports_service .get_reports_snapshot_config (
@@ -314,10 +348,12 @@ def test_update_reports_snapshot_config_example(self):
314
348
"""
315
349
try :
316
350
print ('\n update_reports_snapshot_config() result:' )
351
+
317
352
# begin-update_reports_snapshot_config
318
353
319
354
response = usage_reports_service .update_reports_snapshot_config (
320
- account_id = account_id , report_types = ["account_summary" , "enterprise_summary" ]
355
+ account_id = account_id ,
356
+ report_types = ["account_summary" , "enterprise_summary" ],
321
357
)
322
358
snapshot_config = response .get_result ()
323
359
@@ -335,6 +371,7 @@ def test_validate_reports_snapshot_config_example(self):
335
371
"""
336
372
try :
337
373
print ('\n validate_reports_snapshot_config() result:' )
374
+
338
375
# begin-validate_reports_snapshot_config
339
376
340
377
response = usage_reports_service .validate_reports_snapshot_config (
@@ -359,7 +396,9 @@ def test_get_reports_snapshot_example(self):
359
396
"""
360
397
try :
361
398
print ('\n get_reports_snapshot() result:' )
399
+
362
400
# begin-get_reports_snapshot
401
+
363
402
all_results = []
364
403
pager = GetReportsSnapshotPager (
365
404
client = usage_reports_service ,
@@ -377,7 +416,6 @@ def test_get_reports_snapshot_example(self):
377
416
print (json .dumps (all_results , indent = 2 ))
378
417
379
418
# end-get_reports_snapshot
380
-
381
419
except ApiException as e :
382
420
pytest .fail (str (e ))
383
421
0 commit comments