spotinst / spotinst-sdk-python

Spotinst SDK for the Python programming language.
Apache License 2.0
17 stars 17 forks source link

the get_all_ocean_sizing function only filters by namespace, it does not return all the results #124

Closed fedeostrit closed 1 year ago

fedeostrit commented 1 year ago

Hi, I'm using v2 of spotinst_sdk2 and I need to make a request to the Spotinst API to get all the rigthsize recommendations of a cluster in AWS Ocean, the problem is that the get_all_ocean_sizing function filters by namespace and there is no way to show them all the cluster recommendations passing only "ocean_id", I leave you an example of the script for now:

`import spotinst_sdk2 import sys from argparse import ArgumentParser

parser = ArgumentParser( description='Generate kubectl output based on Spotinst Ocean sizing suggestions') parser.add_argument('-d', '--deployment', help='Name of the deployment to grab suggestions for.') parser.add_argument('-r', '--ratio', default=2, help='The number between resource requests divided by the suggestions.') parser.add_argument('-t', '--auth_token', help='Spotinst API Token.') parser.add_argument('-a', '--account_id', help='ID of the Spotinst account.') parser.add_argument('-o', '--ocean_id', help='ID of the Ocean cluster.') parser.add_argument('-n', '--namespace', help='Namespace of the deployment in the cluster.') args = parser.parse_args()

try: session = spotinst_sdk2.SpotinstSession(auth_token=args.auth_token,account_id=args.account_id) client = session.client("ocean_aws") except Exception as e: print('Failed client init.\n{}'.format(e)) sys.exit(1) try: sizing_suggestions = client.get_all_ocean_sizing(args.ocean_id,args.namespace) except Exception as e: print('Failed getting suggestions.\n{}'.format(e)) sys.exit(1)

print(sizing_suggestions) sys.exit(1)`

If I run the .py passing the namespace it gives me the correct result but if I don't pass namespace it gives me the empty response, I would need it to show me all the recommendations without having to pass the namespace to filter:

empty answer {'suggestions': []}

fedeostrit commented 1 year ago

@wilfamir , @kmcgrath, @guyalt3, @caduri, @anuragsharma-123, @SHxKM, hello, could you help me with this problem, I don't know if it is possible to obtain all the recommendations of the cluster without filtering by namespace, I would thank you a lot

anuragsharma-123 commented 1 year ago

Hello, @fedeostrit -

Checking.

anuragsharma-123 commented 1 year ago

Hello @fedeostrit - Seems like the current method implemented in the python-SDK is deprecated. I am confirming it and we will make a new SDK release as soon as possible if needed.

fedeostrit commented 1 year ago

thanks Anurag, I would need the module working with the option to filter by namespace as it already does and with the option to list all the recommendations available for the cluster

anuragsharma-123 commented 1 year ago

Hello @fedeostrit - we have released a new API - fetch_rightsizing_recommendations() where you can get all recommendations for a given cluster and also filter based on the namespace and other attributes. Please try it out in release version 2.1.31