Skip to content

Commit ec17f48

Browse files
authored
feat(Partner Usage Reports): add new service to project (#242)
Signed-off-by: manu.k.m <[email protected]>
1 parent 983fe46 commit ec17f48

File tree

6 files changed

+2278
-0
lines changed

6 files changed

+2278
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Service Name | Module Name | Service Class Name
6161
[IBM Cloud Shell](https://cloud.ibm.com/apidocs/cloudshell?code=python) | ibm_cloud_shell_v1 | IbmCloudShellV1
6262
[Open Service Broker](https://cloud.ibm.com/apidocs/resource-controller/ibm-cloud-osb-api?code=python) | open_service_broker_v1 | OpenServiceBrokerV1
6363
[Partner Billing Units](https://cloud.ibm.com/apidocs/partner-apis/billing-unit?code=python) | partner_billing_units_v1 | PartnerBillingUnitsV1
64+
[Partner Usage Reports](https://cloud.ibm.com/apidocs/partner-apis/resource-usage-reports?code=python) | partner_usage_reports_v1 | PartnerUsageReportsV1
6465
[Resource Controller](https://cloud.ibm.com/apidocs/resource-controller/resource-controller?code=python) | resource_controller_v2 | ResourceControllerV2
6566
[Resource Manager](https://cloud.ibm.com/apidocs/resource-controller/resource-manager?code=python) | resource_manager_v2 | ResourceManagerV2
6667
[Usage Metering](https://cloud.ibm.com/apidocs/usage-metering?code=python) | usage_metering_v4 | UsageMeteringV4
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# -*- coding: utf-8 -*-
2+
# (C) Copyright IBM Corp. 2024.
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 PartnerUsageReportsV1
18+
"""
19+
20+
from ibm_cloud_sdk_core import ApiException, read_external_sources
21+
import os
22+
import pytest
23+
from ibm_platform_services.partner_usage_reports_v1 import *
24+
25+
#
26+
# This file provides an example of how to use the Partner Usage Reports service.
27+
#
28+
# The following configuration properties are assumed to be defined:
29+
# PARTNER_USAGE_REPORTS_URL=<service base url>
30+
# PARTNER_USAGE_REPORTS_AUTH_TYPE=iam
31+
# PARTNER_USAGE_REPORTS_APIKEY=<IAM apikey>
32+
# PARTNER_USAGE_REPORTS_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
33+
# PARTNER_USAGE_REPORTS_PARTNER_ID=<Enterprise ID of the distributor or reseller for which the report is requested>
34+
# PARTNER_USAGE_REPORTS_CUSTOMER_ID=<Enterprise ID of the child customer for which the report is requested>
35+
# PARTNER_USAGE_REPORTS_RESELLER_ID=<Enterprise ID of the reseller for which the report is requested>
36+
# PARTNER_USAGE_REPORTS_BILLING_MONTH=<The billing month for which the usage report is requested. Format is `yyyy-mm`>
37+
# PARTNER_USAGE_REPORTS_VIEWPOINT=<Enables partner to view the cost of provisioned services as applicable at each level of the hierarchy>
38+
#
39+
# These configuration properties can be exported as environment variables, or stored
40+
# in a configuration file and then:
41+
# export IBM_CREDENTIALS_FILE=<name of configuration file>
42+
#
43+
config_file = 'partner_usage_reports_v1.env'
44+
45+
partner_usage_reports_service = None
46+
47+
config = None
48+
partner_id = None
49+
billing_month = None
50+
51+
52+
##############################################################################
53+
# Start of Examples for Service: PartnerUsageReportsV1
54+
##############################################################################
55+
# region
56+
class TestPartnerUsageReportsV1Examples:
57+
"""
58+
Example Test Class for PartnerUsageReportsV1
59+
"""
60+
61+
@classmethod
62+
def setup_class(cls):
63+
global partner_usage_reports_service
64+
if os.path.exists(config_file):
65+
os.environ['IBM_CREDENTIALS_FILE'] = config_file
66+
67+
# begin-common
68+
69+
partner_usage_reports_service = PartnerUsageReportsV1.new_instance()
70+
71+
# end-common
72+
assert partner_usage_reports_service is not None
73+
74+
# Load the configuration
75+
global config
76+
config = read_external_sources(PartnerUsageReportsV1.DEFAULT_SERVICE_NAME)
77+
78+
global partner_id
79+
partner_id = config.get("PARTNER_ID")
80+
81+
global billing_month
82+
billing_month = config.get("BILLING_MONTH")
83+
84+
assert partner_id is not None
85+
assert billing_month is not None
86+
87+
print('Setup complete.')
88+
89+
needscredentials = pytest.mark.skipif(
90+
not os.path.exists(config_file), reason="External configuration not available, skipping..."
91+
)
92+
93+
@needscredentials
94+
def test_get_resource_usage_report_example(self):
95+
"""
96+
get_resource_usage_report request example
97+
"""
98+
try:
99+
print('\nget_resource_usage_report() result:')
100+
# begin-get_resource_usage_report
101+
102+
all_results = []
103+
pager = GetResourceUsageReportPager(
104+
client=partner_usage_reports_service,
105+
partner_id=partner_id,
106+
month=billing_month,
107+
limit=10,
108+
)
109+
while pager.has_next():
110+
next_page = pager.get_next()
111+
assert next_page is not None
112+
all_results.extend(next_page)
113+
114+
print(json.dumps(all_results, indent=2))
115+
116+
# end-get_resource_usage_report
117+
except ApiException as e:
118+
pytest.fail(str(e))
119+
120+
121+
# endregion
122+
##############################################################################
123+
# End of Examples for Service: PartnerUsageReportsV1
124+
##############################################################################

ibm_platform_services/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from .ibm_cloud_shell_v1 import IbmCloudShellV1
3636
from .open_service_broker_v1 import OpenServiceBrokerV1
3737
from .partner_billing_units_v1 import PartnerBillingUnitsV1
38+
from .partner_usage_reports_v1 import PartnerUsageReportsV1
3839
from .resource_controller_v2 import ResourceControllerV2
3940
from .resource_manager_v2 import ResourceManagerV2
4041
from .usage_metering_v4 import UsageMeteringV4

0 commit comments

Comments
 (0)