Skip to content

Commit 4fabb77

Browse files
pyrookapadamstx
andauthored
fix(Resource Manager): update service after recent API changes and generate examples (#90)
Co-authored-by: Phil Adams <padamstx@gmail.com>
1 parent 2a3ecf5 commit 4fabb77

File tree

4 files changed

+321
-53
lines changed

4 files changed

+321
-53
lines changed
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
# -*- coding: utf-8 -*-
2+
# (C) Copyright IBM Corp. 2021.
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 ResourceManagerV2
18+
"""
19+
20+
import os
21+
import pytest
22+
from ibm_cloud_sdk_core import ApiException, read_external_sources
23+
from ibm_platform_services.resource_manager_v2 import *
24+
25+
#
26+
# This file provides an example of how to use the Resource Manager service.
27+
#
28+
# The following configuration properties are assumed to be defined:
29+
# RESOURCE_MANAGER_URL=<service base url>
30+
# RESOURCE_MANAGER_AUTH_TYPE=iam
31+
# RESOURCE_MANAGER_APIKEY=<IAM apikey>
32+
# RESOURCE_MANAGER_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
33+
#
34+
# These configuration properties can be exported as environment variables, or stored
35+
# in a configuration file and then:
36+
# export IBM_CREDENTIALS_FILE=<name of configuration file>
37+
#
38+
config_file = 'resource_manager.env'
39+
40+
resource_manager_service = None
41+
delete_resource_manager_service = None
42+
43+
config = None
44+
45+
example_quota_id = None
46+
example_user_account_id = None
47+
48+
resource_group_id = None
49+
50+
##############################################################################
51+
# Start of Examples for Service: ResourceManagerV2
52+
##############################################################################
53+
# region
54+
class TestResourceManagerV2Examples():
55+
"""
56+
Example Test Class for ResourceManagerV2
57+
"""
58+
59+
@classmethod
60+
def setup_class(cls):
61+
global resource_manager_service
62+
global delete_resource_manager_service
63+
64+
if os.path.exists(config_file):
65+
os.environ['IBM_CREDENTIALS_FILE'] = config_file
66+
67+
# begin-common
68+
69+
resource_manager_service = ResourceManagerV2.new_instance(
70+
service_name=ResourceManagerV2.DEFAULT_SERVICE_NAME,
71+
)
72+
73+
delete_resource_manager_service = ResourceManagerV2.new_instance(
74+
service_name='ALT_RESOURCE_MANAGER',
75+
)
76+
77+
# end-common
78+
assert resource_manager_service is not None
79+
assert delete_resource_manager_service is not None
80+
81+
# Load the configuration
82+
global config
83+
config = read_external_sources(ResourceManagerV2.DEFAULT_SERVICE_NAME)
84+
85+
global example_quota_id
86+
example_quota_id = config['QUOTA_ID']
87+
88+
global example_user_account_id
89+
example_user_account_id = config['USER_ACCOUNT_ID']
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_create_resource_group_example(self):
99+
"""
100+
create_resource_group request example
101+
"""
102+
assert example_user_account_id is not None
103+
104+
try:
105+
# begin-create_resource_group
106+
107+
res_create_resource_group = resource_manager_service.create_resource_group(
108+
account_id=example_user_account_id,
109+
name='ExampleGroup',
110+
).get_result()
111+
112+
print(json.dumps(res_create_resource_group, indent=2))
113+
114+
# end-create_resource_group
115+
116+
global resource_group_id
117+
resource_group_id = res_create_resource_group.get('id')
118+
119+
except ApiException as e:
120+
pytest.fail(str(e))
121+
122+
@needscredentials
123+
def test_get_resource_group_example(self):
124+
"""
125+
get_resource_group request example
126+
"""
127+
assert resource_group_id is not None
128+
129+
try:
130+
# begin-get_resource_group
131+
132+
resource_group = resource_manager_service.get_resource_group(
133+
id=resource_group_id,
134+
).get_result()
135+
136+
print(json.dumps(resource_group, indent=2))
137+
138+
# end-get_resource_group
139+
140+
except ApiException as e:
141+
pytest.fail(str(e))
142+
143+
@needscredentials
144+
def test_update_resource_group_example(self):
145+
"""
146+
update_resource_group request example
147+
"""
148+
assert resource_group_id is not None
149+
150+
try:
151+
# begin-update_resource_group
152+
153+
resource_group = resource_manager_service.update_resource_group(
154+
id=resource_group_id,
155+
name='RenamedExampleGroup',
156+
state='ACTIVE',
157+
).get_result()
158+
159+
print(json.dumps(resource_group, indent=2))
160+
161+
# end-update_resource_group
162+
163+
except ApiException as e:
164+
pytest.fail(str(e))
165+
166+
@needscredentials
167+
def test_list_resource_groups_example(self):
168+
"""
169+
list_resource_groups request example
170+
"""
171+
assert example_user_account_id is not None
172+
173+
try:
174+
# begin-list_resource_groups
175+
176+
resource_group_list = resource_manager_service.list_resource_groups(
177+
account_id=example_user_account_id,
178+
include_deleted=True,
179+
).get_result()
180+
181+
print(json.dumps(resource_group_list, indent=2))
182+
183+
# end-list_resource_groups
184+
185+
except ApiException as e:
186+
pytest.fail(str(e))
187+
188+
@needscredentials
189+
def test_delete_resource_group_example(self):
190+
"""
191+
delete_resource_group request example
192+
"""
193+
assert resource_group_id is not None
194+
195+
try:
196+
# begin-delete_resource_group
197+
198+
response = delete_resource_manager_service.delete_resource_group(
199+
id=resource_group_id,
200+
).get_result()
201+
202+
print(json.dumps(response, indent=2))
203+
204+
# end-delete_resource_group
205+
206+
except ApiException as e:
207+
pytest.fail(str(e))
208+
209+
@needscredentials
210+
def test_get_quota_definition_example(self):
211+
"""
212+
get_quota_definition request example
213+
"""
214+
assert example_quota_id is not None
215+
216+
try:
217+
# begin-get_quota_definition
218+
219+
quota_definition = resource_manager_service.get_quota_definition(
220+
id=example_quota_id,
221+
).get_result()
222+
223+
print(json.dumps(quota_definition, indent=2))
224+
225+
# end-get_quota_definition
226+
227+
except ApiException as e:
228+
pytest.fail(str(e))
229+
230+
@needscredentials
231+
def test_list_quota_definitions_example(self):
232+
"""
233+
list_quota_definitions request example
234+
"""
235+
try:
236+
# begin-list_quota_definitions
237+
238+
quota_definition_list = resource_manager_service.list_quota_definitions().get_result()
239+
240+
print(json.dumps(quota_definition_list, indent=2))
241+
242+
# end-list_quota_definitions
243+
244+
except ApiException as e:
245+
pytest.fail(str(e))
246+
247+
248+
# endregion
249+
##############################################################################
250+
# End of Examples for Service: ResourceManagerV2
251+
##############################################################################

ibm_platform_services/resource_manager_v2.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding: utf-8
22

3-
# (C) Copyright IBM Corp. 2020.
3+
# (C) Copyright IBM Corp. 2021.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-d753183b-20201209-163011
17+
# IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-4883cbcd-20210301-143711
1818

1919
"""
2020
Manage lifecycle of your Cloud resource groups using Resource Manager APIs.
@@ -80,6 +80,9 @@ def list_resource_groups(self,
8080
*,
8181
account_id: str = None,
8282
date: str = None,
83+
name: str = None,
84+
default: bool = None,
85+
include_deleted: bool = None,
8386
**kwargs
8487
) -> DetailedResponse:
8588
"""
@@ -89,8 +92,14 @@ def list_resource_groups(self,
8992
9093
:param str account_id: (optional) The ID of the account that contains the
9194
resource groups that you want to get.
92-
:param str date: (optional) The date would be in a format of YYYY-MM which
93-
returns resource groups exclude the deleted ones before this month.
95+
:param str date: (optional) The date in the format of YYYY-MM which returns
96+
resource groups. Deleted resource groups will be excluded before this
97+
month.
98+
:param str name: (optional) The name of the resource group.
99+
:param bool default: (optional) Boolean value to specify whether or not to
100+
list default resource groups.
101+
:param bool include_deleted: (optional) Boolean value to specify whether or
102+
not to list default resource groups.
94103
:param dict headers: A `dict` containing the request headers
95104
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
96105
:rtype: DetailedResponse with `dict` result representing a `ResourceGroupList` object
@@ -104,7 +113,10 @@ def list_resource_groups(self,
104113

105114
params = {
106115
'account_id': account_id,
107-
'date': date
116+
'date': date,
117+
'name': name,
118+
'default': default,
119+
'include_deleted': include_deleted
108120
}
109121

110122
if 'headers' in kwargs:
@@ -601,7 +613,7 @@ class ResCreateResourceGroup():
601613
:attr str id: (optional) An alpha-numeric value identifying the resource group.
602614
:attr str crn: (optional) The full CRN (cloud resource name) associated with the
603615
resource group. For more on this format, see [Cloud Resource
604-
Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
616+
Names](https://cloud.ibm.com/docs/account?topic=account-crn).
605617
"""
606618

607619
def __init__(self,
@@ -615,7 +627,7 @@ def __init__(self,
615627
group.
616628
:param str crn: (optional) The full CRN (cloud resource name) associated
617629
with the resource group. For more on this format, see [Cloud Resource
618-
Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
630+
Names](https://cloud.ibm.com/docs/account?topic=account-crn).
619631
"""
620632
self.id = id
621633
self.crn = crn
@@ -669,7 +681,7 @@ class ResourceGroup():
669681
:attr str id: (optional) An alpha-numeric value identifying the resource group.
670682
:attr str crn: (optional) The full CRN (cloud resource name) associated with the
671683
resource group. For more on this format, see [Cloud Resource
672-
Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
684+
Names](https://cloud.ibm.com/docs/account?topic=account-crn).
673685
:attr str account_id: (optional) An alpha-numeric value identifying the account
674686
ID.
675687
:attr str name: (optional) The human-readable name of the resource group.
@@ -714,7 +726,7 @@ def __init__(self,
714726
group.
715727
:param str crn: (optional) The full CRN (cloud resource name) associated
716728
with the resource group. For more on this format, see [Cloud Resource
717-
Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
729+
Names](https://cloud.ibm.com/docs/account?topic=account-crn).
718730
:param str account_id: (optional) An alpha-numeric value identifying the
719731
account ID.
720732
:param str name: (optional) The human-readable name of the resource group.
@@ -900,7 +912,7 @@ class ResourceQuota():
900912
:attr str resource_id: (optional) The human-readable name of the quota.
901913
:attr str crn: (optional) The full CRN (cloud resource name) associated with the
902914
quota. For more on this format, see
903-
https://cloud.ibm.com/docs/resources?topic=resources-crn#crn.
915+
https://cloud.ibm.com/docs/account?topic=account-crn.
904916
:attr float limit: (optional) The limit number of this resource.
905917
"""
906918

@@ -917,7 +929,7 @@ def __init__(self,
917929
:param str resource_id: (optional) The human-readable name of the quota.
918930
:param str crn: (optional) The full CRN (cloud resource name) associated
919931
with the quota. For more on this format, see
920-
https://cloud.ibm.com/docs/resources?topic=resources-crn#crn.
932+
https://cloud.ibm.com/docs/account?topic=account-crn.
921933
:param float limit: (optional) The limit number of this resource.
922934
"""
923935
self.id = id

0 commit comments

Comments
 (0)