-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
125 deletions.
There are no files selected for viewing
Empty file.
33 changes: 33 additions & 0 deletions
33
cloud_governance/common/clouds/ibm/platform_services/platform_service_operations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import json | ||
from urllib.parse import urlparse, parse_qs | ||
|
||
from ibm_platform_services import ResourceControllerV2 | ||
|
||
from cloud_governance.common.clouds.ibm.account.ibm_authenticator import IBMAuthenticator | ||
|
||
|
||
class PlatformServiceOperations(IBMAuthenticator): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.__client = ResourceControllerV2(authenticator=self.iam_authenticator) | ||
|
||
def get_resource_instances(self): | ||
""" | ||
This method returns all the service instances | ||
:return: | ||
""" | ||
responses = self.__client.list_resource_instances().get_result() | ||
resources = responses['resources'] | ||
while responses.get('next_url'): | ||
parsed_url = urlparse(responses['next_url']) | ||
params = parse_qs(parsed_url.query) | ||
if params and 'start' in params: | ||
start = params['start'][0] | ||
responses = self.__client.list_resource_instances(start=start).get_result() | ||
resources.extend(responses['resources']) | ||
resource_instances = [] | ||
for resource in resources: | ||
if resource['type'] == 'resource_instance': | ||
resource_instances.append(resource) | ||
return {'global': resource_instances} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters