-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from MaxBab/add_catalog_object_storage_functio…
…nality [catalog] Add catalog object storage functionality
- Loading branch information
Showing
6 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
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,10 @@ | ||
from ibmcloud_python_sdk.catalog import catalog_service as cs | ||
|
||
# Intentiate the class | ||
catalog = cs.CatalogService() | ||
|
||
# Retrieve catalog cloud object storage plans list | ||
catalog.get_cloud_object_storage() | ||
|
||
# Retrieve specific catalog cloud object storage plan | ||
catalog.get_requested_object_storage_plan("standard") |
Empty file.
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,90 @@ | ||
from ibmcloud_python_sdk.config import params | ||
from ibmcloud_python_sdk.auth import get_headers as headers | ||
from ibmcloud_python_sdk.utils.common import query_wrapper as qw | ||
from ibmcloud_python_sdk.utils.common import resource_not_found | ||
|
||
|
||
class CatalogService(): | ||
|
||
def __init__(self): | ||
self.cfg = params() | ||
|
||
def get_cloud_object_storage(self): | ||
"""Retrieve cloud object storage list | ||
:return: List of cloud object storage | ||
"rtype: list | ||
""" | ||
try: | ||
# Connect to api endpoint for cloud-object-storage | ||
path = "/api/v1?q=cloud-object-storage" | ||
|
||
# Return data | ||
return qw("gc", "GET", path, headers())["data"] | ||
|
||
except Exception as error: | ||
print("Error fetching cloud object storage. {}".format(error)) | ||
raise | ||
|
||
def get_cloud_object_storage_id(self): | ||
"""Retrieve cloud object storage id | ||
:return: String of cloud object storage id | ||
:rtype: str | ||
""" | ||
try: | ||
cloud_obj_storage = self.get_cloud_object_storage() | ||
if "errors" in cloud_obj_storage: | ||
return cloud_obj_storage | ||
|
||
for cloud_object in cloud_obj_storage["resources"]: | ||
if cloud_object['children'][0]['id']: | ||
return cloud_object['children'][0]['id'] | ||
|
||
return resource_not_found() | ||
|
||
except Exception as error: | ||
print("Error fetching object storage id. {}". format( | ||
error)) | ||
raise | ||
|
||
def get_object_storage_plans(self): | ||
"""Retrieve object storage plans | ||
:return: List of cloud storage plans | ||
:rtype: list | ||
""" | ||
storage_id = self.get_cloud_object_storage_id() | ||
|
||
try: | ||
# Connect to api endpoint of defined storage plan | ||
path = "/api/v1/{}/plan".format(storage_id) | ||
|
||
# Return data | ||
return qw("gc", "GET", path, headers())["data"] | ||
|
||
except Exception as error: | ||
print("Error fetching storage plan. {}".format(error)) | ||
raise | ||
|
||
def get_requested_object_storage_plan(self, plan_name): | ||
"""Retrieve defined object storage plan | ||
:return: Dictionary of selected storage plan | ||
:rtype: dict | ||
""" | ||
try: | ||
storage_plans = self.get_object_storage_plans() | ||
if "errors" in storage_plans: | ||
return storage_plans | ||
|
||
for storage_plan in storage_plans["resources"]: | ||
if storage_plan["name"] == plan_name: | ||
return storage_plan | ||
|
||
return resource_not_found() | ||
|
||
except Exception as error: | ||
print("Error fetching requested storage plan {}. {}".format( | ||
plan_name, error)) | ||
raise |
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
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