From 1cbd19bafc561eab91410b2ecdeef08e42fc9fa5 Mon Sep 17 00:00:00 2001 From: rajat08 Date: Mon, 15 Aug 2022 10:35:19 -0400 Subject: [PATCH 1/5] Change how IndexDescription works --- pinecone/manage.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index b71b7ef96..ca77d7536 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -21,17 +21,13 @@ ] -class IndexDescription(NamedTuple): - name: str - metric: str - replicas: int - dimension: int - shards: int - pods: int - pod_type: str - status: None - metadata_config: None - source_collection: None +class IndexDescription(object): + def __init__(self, keys, values): + for k, v in zip(keys, values): + self.__dict__[k] = v + + def __str__(self): + return str(self.__dict__) class CollectionDescription(object): @@ -193,15 +189,10 @@ def describe_index(name: str): :return: Description of an index """ api_instance = _get_api_instance() - response = api_instance.describe_index(name) - db = response['database'] - ready = response['status']['ready'] - state = response['status']['state'] - return IndexDescription(name=db['name'], metric=db['metric'], - replicas=db['replicas'], dimension=db['dimension'], shards=db['shards'], - pods=db.get('pods', db['shards'] * db['replicas']), pod_type=db.get('pod_type', 'p1'), - status={'ready': ready, 'state': state}, metadata_config=db.get('metadata_config'), - source_collection=db.get('source_collection', '')) + response = api_instance.describe_index(name).to_dict() + response_object = IndexDescription(response.keys(), response.values()) + return response_object + # return IndexDescription(**returned_values) def scale_index(name: str, replicas: int): From ff67d707aa0e711dadae9c52a77ae7e29451f7b4 Mon Sep 17 00:00:00 2001 From: rajat08 Date: Mon, 15 Aug 2022 10:36:37 -0400 Subject: [PATCH 2/5] remove comment --- pinecone/manage.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index ca77d7536..e88c190e8 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -192,7 +192,6 @@ def describe_index(name: str): response = api_instance.describe_index(name).to_dict() response_object = IndexDescription(response.keys(), response.values()) return response_object - # return IndexDescription(**returned_values) def scale_index(name: str, replicas: int): From 3e6c3c9dd1c833041d10026aa512cf7501e2b4b2 Mon Sep 17 00:00:00 2001 From: rajat08 Date: Mon, 15 Aug 2022 10:58:29 -0400 Subject: [PATCH 3/5] Fixes --- pinecone/manage.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index e88c190e8..5322a80b1 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -189,7 +189,13 @@ def describe_index(name: str): :return: Description of an index """ api_instance = _get_api_instance() - response = api_instance.describe_index(name).to_dict() + response = api_instance.describe_index(name) + db_status = response.get('status', {}) + response = response['database'].to_dict() + state = db_status.get('state', '') + ready = db_status.get('ready', '') + status = {'state': state, 'ready': ready} + response['status'] = status response_object = IndexDescription(response.keys(), response.values()) return response_object @@ -258,3 +264,4 @@ def configure_index(name: str, replicas: Optional[int] = None, pod_type: Optiona config_args.update(replicas=replicas) patch_request = PatchRequest(**config_args) api_instance.configure_index(name, patch_request=patch_request) + From 7769b1d9f8d25e3f7345221fb2f50db082c32097 Mon Sep 17 00:00:00 2001 From: rajat08 Date: Mon, 15 Aug 2022 12:24:06 -0400 Subject: [PATCH 4/5] PR comments fixes --- pinecone/manage.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index 5322a80b1..27248c977 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -196,6 +196,10 @@ def describe_index(name: str): ready = db_status.get('ready', '') status = {'state': state, 'ready': ready} response['status'] = status + shards = response.get('shards', 1) + replicas = response.get('replicas', 1) + pods = shards * replicas + response['pods'] = pods response_object = IndexDescription(response.keys(), response.values()) return response_object @@ -264,4 +268,3 @@ def configure_index(name: str, replicas: Optional[int] = None, pod_type: Optiona config_args.update(replicas=replicas) patch_request = PatchRequest(**config_args) api_instance.configure_index(name, patch_request=patch_request) - From 2059332709b3ae54658ead9973a1dc47dd691cba Mon Sep 17 00:00:00 2001 From: rajat08 Date: Mon, 15 Aug 2022 13:07:30 -0400 Subject: [PATCH 5/5] Changes --- pinecone/manage.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index 27248c977..f5bf5f8c5 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -22,8 +22,8 @@ class IndexDescription(object): - def __init__(self, keys, values): - for k, v in zip(keys, values): + def __init__(self, response: dict): + for k, v in response.items(): self.__dict__[k] = v def __str__(self): @@ -192,15 +192,15 @@ def describe_index(name: str): response = api_instance.describe_index(name) db_status = response.get('status', {}) response = response['database'].to_dict() - state = db_status.get('state', '') - ready = db_status.get('ready', '') + state = db_status.get('state', None) + ready = db_status.get('ready', None) status = {'state': state, 'ready': ready} response['status'] = status shards = response.get('shards', 1) replicas = response.get('replicas', 1) pods = shards * replicas response['pods'] = pods - response_object = IndexDescription(response.keys(), response.values()) + response_object = IndexDescription(response) return response_object