Skip to content

Commit 8f20580

Browse files
committed
feat(Enterprise Usage Reports): add service to project
1 parent 6baf64f commit 8f20580

File tree

6 files changed

+1622
-0
lines changed

6 files changed

+1622
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Service Name | Imported Class Name
5252
[Catalog Management](https://cloud.ibm.com/apidocs/resource-catalog/private-catalog) | CatalogManagementV1
5353
[Configuration Governance](https://cloud.ibm.com/apidocs/security-compliance/config) | ConfigurationGovernanceV1
5454
[Enterprise Management](https://cloud.ibm.com/apidocs/enterprise-apis/enterprise) | EnterpriseManagementV1
55+
[Enterprise Usage Reports](https://cloud.ibm.com/apidocs/enterprise-apis/resource-usage-reports) | EnterpriseUsageReportsV1
5556
[Global Catalog](https://cloud.ibm.com/apidocs/resource-catalog/global-catalog) | GlobalCatalogV1
5657
[Global Search](https://cloud.ibm.com/apidocs/search) | GlobalSearchV2
5758
[Global Tagging](https://cloud.ibm.com/apidocs/tagging) | GlobalTaggingV1
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# -*- coding: utf-8 -*-
2+
# (C) Copyright IBM Corp. 2020.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
"""
17+
Examples for EnterpriseUsageReportsV1
18+
"""
19+
20+
import os
21+
import pytest
22+
from ibm_cloud_sdk_core import ApiException, read_external_sources
23+
from ibm_platform_services.enterprise_usage_reports_v1 import *
24+
25+
#
26+
# This file provides an example of how to use the Usage Reports service.
27+
#
28+
# The following configuration properties are assumed to be defined:
29+
# ENTERPRISE_USAGE_REPORTS_URL=<service url>
30+
# ENTERPRISE_USAGE_REPORTS_AUTHTYPE=iam
31+
# ENTERPRISE_USAGE_REPORTS_APIKEY=<IAM api key of user with authority to create rules>
32+
# ENTERPRISE_USAGE_REPORTS_AUTH_URL=<IAM token service URL - omit this if using the production environment>
33+
# ENTERPRISE_USAGE_REPORTS_ENTERPRISE_ID=<the id of the enterprise whose usage info will be retrieved>
34+
# ENTERPRISE_USAGE_REPORTS_ACCOUNT_ID=<the id of the account whose usage info will be retrieved>
35+
# ENTERPRISE_USAGE_REPORTS_ACCOUNT_GROUP_ID=<the id of the account group whose usage info will be retrieved>
36+
# ENTERPRISE_USAGE_REPORTS_BILLING_MONTH=<the billing month (yyyy-mm) for which usage info will be retrieved>
37+
#
38+
# These configuration properties can be exported as environment variables, or stored
39+
# in a "credentials" file and then:
40+
# export IBM_CREDENTIALS_FILE=<name of credentials file>
41+
#
42+
43+
# Config file name
44+
config_file = 'enterprise_usage_reports.env'
45+
46+
enterprise_usage_reports_service = None
47+
48+
config = None
49+
50+
enterprise_id = None
51+
billing_month = None
52+
53+
##############################################################################
54+
# Start of Examples for Service: EnterpriseUsageReportsV1
55+
##############################################################################
56+
# region
57+
58+
59+
class TestEnterpriseUsageReportsV1Examples():
60+
"""
61+
Example Test Class for EnterpriseUsageReportsV1
62+
"""
63+
64+
@classmethod
65+
def setup_class(cls):
66+
global enterprise_usage_reports_service
67+
if os.path.exists(config_file):
68+
os.environ['IBM_CREDENTIALS_FILE'] = config_file
69+
70+
# begin-common
71+
72+
enterprise_usage_reports_service = EnterpriseUsageReportsV1.new_instance()
73+
74+
# end-common
75+
assert enterprise_usage_reports_service is not None
76+
77+
# Load the configuration
78+
global config
79+
config = read_external_sources(
80+
EnterpriseUsageReportsV1.DEFAULT_SERVICE_NAME)
81+
82+
global enterprise_id
83+
enterprise_id = config.get("ENTERPRISE_ID")
84+
85+
global billing_month
86+
billing_month = config.get("BILLING_MONTH")
87+
88+
assert enterprise_id is not None
89+
assert billing_month is not None
90+
91+
print('Setup complete.')
92+
93+
needscredentials = pytest.mark.skipif(
94+
not os.path.exists(config_file), reason="External configuration not available, skipping..."
95+
)
96+
97+
@needscredentials
98+
def test_get_resource_usage_report_example(self):
99+
"""
100+
get_resource_usage_report request example
101+
"""
102+
try:
103+
global enterprise_id, billing_month
104+
# begin-get_resource_usage_report
105+
106+
reports = enterprise_usage_reports_service.get_resource_usage_report(
107+
enterprise_id=enterprise_id,
108+
month=billing_month,
109+
limit=10
110+
).get_result()
111+
112+
print(json.dumps(reports, indent=2))
113+
114+
# end-get_resource_usage_report
115+
116+
except ApiException as e:
117+
pytest.fail(str(e))
118+
119+
# endregion
120+
##############################################################################
121+
# End of Examples for Service: EnterpriseUsageReportsV1
122+
##############################################################################

ibm_platform_services/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .catalog_management_v1 import CatalogManagementV1
2727
from .configuration_governance_v1 import ConfigurationGovernanceV1
2828
from .enterprise_management_v1 import EnterpriseManagementV1
29+
from .enterprise_usage_reports_v1 import EnterpriseUsageReportsV1
2930
from .global_catalog_v1 import GlobalCatalogV1
3031
from .global_search_v2 import GlobalSearchV2
3132
from .global_tagging_v1 import GlobalTaggingV1

0 commit comments

Comments
 (0)