Skip to content

Commit

Permalink
Create external connector and local connector
Browse files Browse the repository at this point in the history
Signed-off-by: Vinay Vinod <[email protected]>
  • Loading branch information
Vinay-Vinod committed Oct 26, 2023
1 parent 5ca5aa8 commit f5d7895
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions opensearch_py_ml/ml_commons/ml_commons_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,64 @@ def delete_task(self, task_id: str) -> object:
method="DELETE",
url=API_URL,
)

def create_connector(self, connector_payload: dict) -> dict:
"""
This method creates a connector in the OpenSearch cluster using the ml-common plugin's API.
:param connector_payload: Dictionary containing the details of the connector.
:type connector_payload: dict
:return: API response
:rtype: dict
"""
API_URL = f"{ML_BASE_URI}/connectors/_create"
return self._client.transport.perform_request(

Check warning on line 594 in opensearch_py_ml/ml_commons/ml_commons_client.py

View check run for this annotation

Codecov / codecov/patch

opensearch_py_ml/ml_commons/ml_commons_client.py#L593-L594

Added lines #L593 - L594 were not covered by tests
method="POST",
url=API_URL,
body=connector_payload,
)

def delete_connector(self, connector_id: str) -> dict:
"""
This method deletes a specific connector using its ID.
:param connector_id: ID of the connector to be deleted.
:type connector_id: str
:return: API response
:rtype: dict
"""
API_URL = f"{ML_BASE_URI}/connectors/{connector_id}"
return self._client.transport.perform_request(

Check warning on line 610 in opensearch_py_ml/ml_commons/ml_commons_client.py

View check run for this annotation

Codecov / codecov/patch

opensearch_py_ml/ml_commons/ml_commons_client.py#L609-L610

Added lines #L609 - L610 were not covered by tests
method="DELETE",
url=API_URL,
)

def list_connectors(self) -> dict:
"""
This method lists all connectors in the OpenSearch cluster.
:return: API response containing a list of connectors.
:rtype: dict
"""
API_URL = f"{ML_BASE_URI}/connectors"
return self._client.transport.perform_request(

Check warning on line 623 in opensearch_py_ml/ml_commons/ml_commons_client.py

View check run for this annotation

Codecov / codecov/patch

opensearch_py_ml/ml_commons/ml_commons_client.py#L622-L623

Added lines #L622 - L623 were not covered by tests
method="GET",
url=API_URL,
)


def search_connectors(self, search_payload: dict) -> dict:
"""
This method searches for connectors based on specific criteria.
:param search_payload: Dictionary containing search criteria.
:type search_payload: dict
:return: API response containing search results.
:rtype: dict
"""
API_URL = f"{ML_BASE_URI}/connectors/_search"
return self._client.transport.perform_request(

Check warning on line 639 in opensearch_py_ml/ml_commons/ml_commons_client.py

View check run for this annotation

Codecov / codecov/patch

opensearch_py_ml/ml_commons/ml_commons_client.py#L638-L639

Added lines #L638 - L639 were not covered by tests
method="POST",
url=API_URL,
body=search_payload,
)

0 comments on commit f5d7895

Please sign in to comment.