Skip to content

Commit 928a90f

Browse files
committed
feat(Enterprise Billing Units): add service to project
1 parent df19ff2 commit 928a90f

File tree

6 files changed

+2181
-1
lines changed

6 files changed

+2181
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Service Name | Imported Class Name
5151
[Case Management](https://cloud.ibm.com/apidocs/case-management) | CaseManagementV1
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
54+
[Enterprise Billing Units](https://cloud.ibm.com/apidocs/enterprise-apis/billing-unit) | EnterpriseBillingUnitsV1
5455
[Enterprise Management](https://cloud.ibm.com/apidocs/enterprise-apis/enterprise) | EnterpriseManagementV1
5556
[Enterprise Usage Reports](https://cloud.ibm.com/apidocs/enterprise-apis/resource-usage-reports) | EnterpriseUsageReportsV1
5657
[Global Catalog](https://cloud.ibm.com/apidocs/resource-catalog/global-catalog) | GlobalCatalogV1
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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+
Examples for EnterpriseBillingUnitsV1
17+
"""
18+
19+
import os
20+
import pytest
21+
import json
22+
from ibm_cloud_sdk_core import ApiException, read_external_sources
23+
from ibm_platform_services.enterprise_billing_units_v1 import *
24+
25+
#
26+
# This file provides an example of how to use the Enterprise Billing Units service.
27+
#
28+
# The following configuration properties are assumed to be defined in the external configuration file:
29+
# ENTERPRISE_BILLING_UNITS_URL=<service url>
30+
# ENTERPRISE_BILLING_UNITS_AUTHTYPE=iam
31+
# ENTERPRISE_BILLING_UNITS_APIKEY=<your iam apikey>
32+
# ENTERPRISE_BILLING_UNITS_AUTH_URL=<IAM token service URL - omit this if using the production environment>
33+
# ENTERPRISE_BILLING_UNITS_ENTERPRISE_ID=<id of enterprise to use for examples>
34+
# ENTERPRISE_BILLING_UNITS_BILLING_UNIT_ID=<id of billing unit to use for examples>
35+
#
36+
# Config file name
37+
config_file = 'enterprise_billing_units.env'
38+
39+
enterprise_billing_units_service = None
40+
41+
config = None
42+
43+
enterprise_id = None
44+
billing_unit_id = None
45+
46+
47+
##############################################################################
48+
# Start of Examples for Service: EnterpriseBillingUnitsV1
49+
##############################################################################
50+
# region
51+
class TestEnterpriseBillingUnitsV1Examples():
52+
"""
53+
Example Test Class for EnterpriseBillingUnitsV1
54+
"""
55+
@classmethod
56+
def setup_class(cls):
57+
global enterprise_billing_units_service
58+
if os.path.exists(config_file):
59+
os.environ['IBM_CREDENTIALS_FILE'] = config_file
60+
61+
# begin-common
62+
63+
enterprise_billing_units_service = EnterpriseBillingUnitsV1.new_instance(
64+
)
65+
66+
# end-common
67+
assert enterprise_billing_units_service is not None
68+
69+
# Load the configuration
70+
71+
global config, enterprise_id, billing_unit_id
72+
config = read_external_sources(
73+
EnterpriseBillingUnitsV1.DEFAULT_SERVICE_NAME)
74+
75+
enterprise_id = config['ENTERPRISE_ID']
76+
billing_unit_id = config['BILLING_UNIT_ID']
77+
78+
print('Setup complete.')
79+
80+
needscredentials = pytest.mark.skipif(
81+
not os.path.exists(config_file),
82+
reason="External configuration not available, skipping...")
83+
84+
@needscredentials
85+
def test_get_billing_unit_example(self):
86+
"""
87+
get_billing_unit request example
88+
"""
89+
try:
90+
global billing_unit_id
91+
# begin-get_billing_unit
92+
93+
billing_unit = enterprise_billing_units_service.get_billing_unit(
94+
billing_unit_id=billing_unit_id).get_result()
95+
96+
print(json.dumps(billing_unit, indent=2))
97+
98+
# end-get_billing_unit
99+
100+
except ApiException as e:
101+
pytest.fail(str(e))
102+
103+
@needscredentials
104+
def test_list_billing_units_example(self):
105+
"""
106+
list_billing_units request example
107+
"""
108+
try:
109+
global enterprise_id
110+
# begin-list_billing_units
111+
112+
billing_units_list = enterprise_billing_units_service.list_billing_units(
113+
enterprise_id=enterprise_id).get_result()
114+
115+
print(json.dumps(billing_units_list, indent=2))
116+
117+
# end-list_billing_units
118+
119+
except ApiException as e:
120+
pytest.fail(str(e))
121+
122+
@needscredentials
123+
def test_list_billing_options_example(self):
124+
"""
125+
list_billing_options request example
126+
"""
127+
try:
128+
global billing_unit_id
129+
# begin-list_billing_options
130+
131+
billing_options_list = enterprise_billing_units_service.list_billing_options(
132+
billing_unit_id=billing_unit_id).get_result()
133+
134+
print(json.dumps(billing_options_list, indent=2))
135+
136+
# end-list_billing_options
137+
138+
except ApiException as e:
139+
pytest.fail(str(e))
140+
141+
@needscredentials
142+
def test_get_credit_pools_example(self):
143+
"""
144+
get_credit_pools request example
145+
"""
146+
try:
147+
global billing_unit_id
148+
# begin-get_credit_pools
149+
150+
credit_pools_list = enterprise_billing_units_service.get_credit_pools(
151+
billing_unit_id=billing_unit_id, type='PLATFORM').get_result()
152+
153+
print(json.dumps(credit_pools_list, indent=2))
154+
155+
# end-get_credit_pools
156+
157+
except ApiException as e:
158+
pytest.fail(str(e))
159+
160+
161+
# endregion
162+
##############################################################################
163+
# End of Examples for Service: EnterpriseBillingUnitsV1
164+
##############################################################################

ibm_platform_services/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
1615
"""
1716
This package provides a client library for accessing the IBM Cloud Platform Services.
1817
"""
@@ -25,6 +24,7 @@
2524
from .case_management_v1 import CaseManagementV1
2625
from .catalog_management_v1 import CatalogManagementV1
2726
from .configuration_governance_v1 import ConfigurationGovernanceV1
27+
from .enterprise_billing_units_v1 import EnterpriseBillingUnitsV1
2828
from .enterprise_management_v1 import EnterpriseManagementV1
2929
from .enterprise_usage_reports_v1 import EnterpriseUsageReportsV1
3030
from .global_catalog_v1 import GlobalCatalogV1

0 commit comments

Comments
 (0)