Skip to content

Commit

Permalink
fix(Resource Manager): update service after recent API changes and ge…
Browse files Browse the repository at this point in the history
…nerate examples (#90)


Co-authored-by: Phil Adams <padamstx@gmail.com>
  • Loading branch information
pyrooka and padamstx authored Mar 18, 2021
1 parent 2a3ecf5 commit 4fabb77
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 53 deletions.
251 changes: 251 additions & 0 deletions examples/test_resource_manager_v2_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
# -*- coding: utf-8 -*-
# (C) Copyright IBM Corp. 2021.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Examples for ResourceManagerV2
"""

import os
import pytest
from ibm_cloud_sdk_core import ApiException, read_external_sources
from ibm_platform_services.resource_manager_v2 import *

#
# This file provides an example of how to use the Resource Manager service.
#
# The following configuration properties are assumed to be defined:
# RESOURCE_MANAGER_URL=<service base url>
# RESOURCE_MANAGER_AUTH_TYPE=iam
# RESOURCE_MANAGER_APIKEY=<IAM apikey>
# RESOURCE_MANAGER_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
#
# These configuration properties can be exported as environment variables, or stored
# in a configuration file and then:
# export IBM_CREDENTIALS_FILE=<name of configuration file>
#
config_file = 'resource_manager.env'

resource_manager_service = None
delete_resource_manager_service = None

config = None

example_quota_id = None
example_user_account_id = None

resource_group_id = None

##############################################################################
# Start of Examples for Service: ResourceManagerV2
##############################################################################
# region
class TestResourceManagerV2Examples():
"""
Example Test Class for ResourceManagerV2
"""

@classmethod
def setup_class(cls):
global resource_manager_service
global delete_resource_manager_service

if os.path.exists(config_file):
os.environ['IBM_CREDENTIALS_FILE'] = config_file

# begin-common

resource_manager_service = ResourceManagerV2.new_instance(
service_name=ResourceManagerV2.DEFAULT_SERVICE_NAME,
)

delete_resource_manager_service = ResourceManagerV2.new_instance(
service_name='ALT_RESOURCE_MANAGER',
)

# end-common
assert resource_manager_service is not None
assert delete_resource_manager_service is not None

# Load the configuration
global config
config = read_external_sources(ResourceManagerV2.DEFAULT_SERVICE_NAME)

global example_quota_id
example_quota_id = config['QUOTA_ID']

global example_user_account_id
example_user_account_id = config['USER_ACCOUNT_ID']

print('Setup complete.')

needscredentials = pytest.mark.skipif(
not os.path.exists(config_file), reason="External configuration not available, skipping..."
)

@needscredentials
def test_create_resource_group_example(self):
"""
create_resource_group request example
"""
assert example_user_account_id is not None

try:
# begin-create_resource_group

res_create_resource_group = resource_manager_service.create_resource_group(
account_id=example_user_account_id,
name='ExampleGroup',
).get_result()

print(json.dumps(res_create_resource_group, indent=2))

# end-create_resource_group

global resource_group_id
resource_group_id = res_create_resource_group.get('id')

except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_get_resource_group_example(self):
"""
get_resource_group request example
"""
assert resource_group_id is not None

try:
# begin-get_resource_group

resource_group = resource_manager_service.get_resource_group(
id=resource_group_id,
).get_result()

print(json.dumps(resource_group, indent=2))

# end-get_resource_group

except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_update_resource_group_example(self):
"""
update_resource_group request example
"""
assert resource_group_id is not None

try:
# begin-update_resource_group

resource_group = resource_manager_service.update_resource_group(
id=resource_group_id,
name='RenamedExampleGroup',
state='ACTIVE',
).get_result()

print(json.dumps(resource_group, indent=2))

# end-update_resource_group

except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_list_resource_groups_example(self):
"""
list_resource_groups request example
"""
assert example_user_account_id is not None

try:
# begin-list_resource_groups

resource_group_list = resource_manager_service.list_resource_groups(
account_id=example_user_account_id,
include_deleted=True,
).get_result()

print(json.dumps(resource_group_list, indent=2))

# end-list_resource_groups

except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_delete_resource_group_example(self):
"""
delete_resource_group request example
"""
assert resource_group_id is not None

try:
# begin-delete_resource_group

response = delete_resource_manager_service.delete_resource_group(
id=resource_group_id,
).get_result()

print(json.dumps(response, indent=2))

# end-delete_resource_group

except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_get_quota_definition_example(self):
"""
get_quota_definition request example
"""
assert example_quota_id is not None

try:
# begin-get_quota_definition

quota_definition = resource_manager_service.get_quota_definition(
id=example_quota_id,
).get_result()

print(json.dumps(quota_definition, indent=2))

# end-get_quota_definition

except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_list_quota_definitions_example(self):
"""
list_quota_definitions request example
"""
try:
# begin-list_quota_definitions

quota_definition_list = resource_manager_service.list_quota_definitions().get_result()

print(json.dumps(quota_definition_list, indent=2))

# end-list_quota_definitions

except ApiException as e:
pytest.fail(str(e))


# endregion
##############################################################################
# End of Examples for Service: ResourceManagerV2
##############################################################################
34 changes: 23 additions & 11 deletions ibm_platform_services/resource_manager_v2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8

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

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

"""
Manage lifecycle of your Cloud resource groups using Resource Manager APIs.
Expand Down Expand Up @@ -80,6 +80,9 @@ def list_resource_groups(self,
*,
account_id: str = None,
date: str = None,
name: str = None,
default: bool = None,
include_deleted: bool = None,
**kwargs
) -> DetailedResponse:
"""
Expand All @@ -89,8 +92,14 @@ def list_resource_groups(self,
:param str account_id: (optional) The ID of the account that contains the
resource groups that you want to get.
:param str date: (optional) The date would be in a format of YYYY-MM which
returns resource groups exclude the deleted ones before this month.
:param str date: (optional) The date in the format of YYYY-MM which returns
resource groups. Deleted resource groups will be excluded before this
month.
:param str name: (optional) The name of the resource group.
:param bool default: (optional) Boolean value to specify whether or not to
list default resource groups.
:param bool include_deleted: (optional) Boolean value to specify whether or
not to list default resource groups.
:param dict headers: A `dict` containing the request headers
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
:rtype: DetailedResponse with `dict` result representing a `ResourceGroupList` object
Expand All @@ -104,7 +113,10 @@ def list_resource_groups(self,

params = {
'account_id': account_id,
'date': date
'date': date,
'name': name,
'default': default,
'include_deleted': include_deleted
}

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

def __init__(self,
Expand All @@ -615,7 +627,7 @@ def __init__(self,
group.
:param str crn: (optional) The full CRN (cloud resource name) associated
with the resource group. For more on this format, see [Cloud Resource
Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
Names](https://cloud.ibm.com/docs/account?topic=account-crn).
"""
self.id = id
self.crn = crn
Expand Down Expand Up @@ -669,7 +681,7 @@ class ResourceGroup():
:attr str id: (optional) An alpha-numeric value identifying the resource group.
:attr str crn: (optional) The full CRN (cloud resource name) associated with the
resource group. For more on this format, see [Cloud Resource
Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
Names](https://cloud.ibm.com/docs/account?topic=account-crn).
:attr str account_id: (optional) An alpha-numeric value identifying the account
ID.
:attr str name: (optional) The human-readable name of the resource group.
Expand Down Expand Up @@ -714,7 +726,7 @@ def __init__(self,
group.
:param str crn: (optional) The full CRN (cloud resource name) associated
with the resource group. For more on this format, see [Cloud Resource
Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
Names](https://cloud.ibm.com/docs/account?topic=account-crn).
:param str account_id: (optional) An alpha-numeric value identifying the
account ID.
:param str name: (optional) The human-readable name of the resource group.
Expand Down Expand Up @@ -900,7 +912,7 @@ class ResourceQuota():
:attr str resource_id: (optional) The human-readable name of the quota.
:attr str crn: (optional) The full CRN (cloud resource name) associated with the
quota. For more on this format, see
https://cloud.ibm.com/docs/resources?topic=resources-crn#crn.
https://cloud.ibm.com/docs/account?topic=account-crn.
:attr float limit: (optional) The limit number of this resource.
"""

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

0 comments on commit 4fabb77

Please sign in to comment.