Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support detach nodes in Python SDK (pre-requisite for Test automation) #176

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.8.0] - 2024-06-21
### Added
- Added detach nodes, get elastilog and cost APIs for Ocean AKS.

## [3.7.1] - 2024-06-17
### Fixed
- Fixed `AggressiveScaleDown` model in GCP Ocean.
Expand Down
77 changes: 77 additions & 0 deletions docs/clients/ocean/ocean_azure_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,80 @@ __Returns__

`(Object)`: Ocean Migrations response

<h2 id="spotinst_sdk2.clients.ocean.OceanAzureClient.detach_nodes">detach_nodes</h2>

```python
OceanAzureClient.detach_nodes(detach_nodes: DetachNodes)
```

Detach nodes from your Ocean cluster.

__Arguments__

- __detach_nodes (DetachNodes)__: Detach Nodes Object

__Returns__

`(Object)`: Detach Nodes response

<h2 id="spotinst_sdk2.clients.ocean.OceanAzureClient.get_elastilog">get_elastilog</h2>

```python
OceanAzureClient.get_elastilog(ocean_id: str,
from_date: str,
to_date: str,
severity: str = None,
resource_id: str = None,
limit: int = None)
```

Get the log of an Ocean Cluster.

__Arguments__

- __to_date (String)__: end date value
- __from_date (String)__: beginning date value
- __severity(String) (Optional)__: Log level severity
- __resource_id(String) (Optional)__: specific resource identifier
- __limit(int) (Optional)__: Maximum number of lines to extract in a response

__Returns__

`(Object)`: Ocean Get Log API response

<h2 id="spotinst_sdk2.clients.ocean.OceanAzureClient.get_aggregated_detailed_costs">get_aggregated_detailed_costs</h2>

```python
OceanAzureClient.get_aggregated_detailed_costs(
ocean_id: str, aggregated_cluster_costs: AggregatedClusterCosts)
```

Provides Kubernetes cluster resource usage and costs over a time interval which can be grouped and/or filtered by label/annotaion

__Arguments__

- __ocean_id (String)__: ID of the Ocean Cluster
- __aggregated_cluster_costs (AggregatedClusterCosts)__: Aggregated Cluster Costs request

__Returns__

`(Object)`: Aggregated Cluster Costs API response

<h2 id="spotinst_sdk2.clients.ocean.OceanAzureClient.get_aggregated_summary_costs">get_aggregated_summary_costs</h2>

```python
OceanAzureClient.get_aggregated_summary_costs(
ocean_id: str, aggregated_cluster_costs: AggregatedClusterCosts)
```

Provides Kubernetes cluster summary usage and costs over a time interval which can be grouped and/or filtered by label/annotaion

__Arguments__

- __ocean_id (String)__: ID of the Ocean Cluster
- __aggregated_cluster_costs (AggregatedClusterCosts)__: Aggregated Cluster Costs request

__Returns__

`(Object)`: Aggregated Cluster Costs API response

14 changes: 14 additions & 0 deletions docs/models/ocean/azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -844,3 +844,17 @@ __Arguments__
- __should_evict_standalone_pods__: bool
- __should_terminate_nodes__: bool

<h2 id="spotinst_sdk2.models.ocean.azure.DetachNodes">DetachNodes</h2>

```python
DetachNodes(self,
node_names_to_detach:
typing.List[str] = 'd3043820717d74d9a17694c176d39733',
ocean_id: str = 'd3043820717d74d9a17694c176d39733')
```

__Arguments__

- __node_names_to_detach__: List[str]
- __ocean_id__: str

123 changes: 123 additions & 0 deletions spotinst_sdk2/clients/ocean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,7 @@ def delete_extended_resource_definition(self, ocean_extended_resource_definition
class OceanAzureClient(Client):
__base_ocean_cluster_url = "/ocean/azure/np/cluster"
__base_ocean_vng_url = "/ocean/azure/np/virtualNodeGroup"
__base_ocean_k8s_url = "/ocean/azure/k8s/cluster/"

def create_ocean_cluster(self, ocean: azure_ocean.Ocean):
"""
Expand Down Expand Up @@ -1693,6 +1694,128 @@ def list_migrations(self, ocean_id: str):
response, self.camel_to_underscore)

return formatted_response["response"]

def detach_nodes(self, detach_nodes: azure_ocean.DetachNodes):
"""
Detach nodes from your Ocean cluster.
# Arguments
detach_nodes (DetachNodes): Detach Nodes Object
# Returns
(Object): Detach Nodes response
"""
request = azure_ocean.DetachNodesRequest(detach_nodes)

excluded_missing_dict = self.exclude_missing(
json.loads(request.toJSON()))

formatted_missing_dict = self.convert_json(
excluded_missing_dict, self.underscore_to_camel)

body_json = json.dumps(formatted_missing_dict)

response = self.send_put(
body=body_json,
url=self.__base_ocean_cluster_url + "/detachNodes",
entity_name='ocean detach nodes')

formatted_response = self.convert_json(
response, self.camel_to_underscore)

return formatted_response["response"]["items"][0]

def get_elastilog(self, ocean_id: str, from_date: str, to_date: str, severity: str = None, resource_id: str = None,
limit: int = None):
"""
Get the log of an Ocean Cluster.
# Arguments
to_date (String): end date value
from_date (String): beginning date value
severity(String) (Optional): Log level severity
resource_id(String) (Optional): specific resource identifier
limit(int) (Optional): Maximum number of lines to extract in a response
# Returns
(Object): Ocean Get Log API response
"""
geturl = self.__base_ocean_cluster_url + "/" + ocean_id + "/log"
query_params = dict(toDate=to_date, fromDate=from_date, severity=severity,
resourceId=resource_id, limit=limit)

result = self.send_get(
url=geturl, entity_name='ocean azure elastilog', query_params=query_params)

formatted_response = self.convert_json(
result, self.camel_to_underscore)

return formatted_response["response"]["items"]

def get_aggregated_detailed_costs(self, ocean_id: str, aggregated_cluster_costs: azure_ocean.AggregatedClusterCosts):
"""
Provides Kubernetes cluster resource usage and costs over a time interval which can be grouped and/or filtered by label/annotaion
# Arguments
ocean_id (String): ID of the Ocean Cluster
aggregated_cluster_costs (AggregatedClusterCosts): Aggregated Cluster Costs request
# Returns
(Object): Aggregated Cluster Costs API response
"""
aggregated_cluster_costs_request = azure_ocean.AggregatedClusterCostRequest(
aggregated_cluster_costs)

excluded_missing_dict = self.exclude_missing(
json.loads(aggregated_cluster_costs_request.toJSON()))

formatted_missing_dict = self.convert_json_with_list_of_lists(
excluded_missing_dict, self.underscore_to_camel)

body_json = json.dumps(formatted_missing_dict)

aggregated_costs_response = self.send_post(
body=body_json,
url=self.__base_ocean_k8s_url + ocean_id + "/aggregatedCosts",
entity_name='ocean (aggregated cluster costs)')

formatted_response = self.convert_json(
aggregated_costs_response, self.camel_to_underscore)

return formatted_response["response"]["items"][0]

def get_aggregated_summary_costs(self, ocean_id: str, aggregated_cluster_costs: azure_ocean.AggregatedClusterCosts):
"""
Provides Kubernetes cluster summary usage and costs over a time interval which can be grouped and/or filtered by label/annotaion
# Arguments
ocean_id (String): ID of the Ocean Cluster
aggregated_cluster_costs (AggregatedClusterCosts): Aggregated Cluster Costs request
# Returns
(Object): Aggregated Cluster Costs API response
"""
aggregated_cluster_costs_request = azure_ocean.AggregatedClusterCostRequest(
aggregated_cluster_costs)

excluded_missing_dict = self.exclude_missing(
json.loads(aggregated_cluster_costs_request.toJSON()))

formatted_missing_dict = self.convert_json_with_list_of_lists(
excluded_missing_dict, self.underscore_to_camel)

body_json = json.dumps(formatted_missing_dict)

aggregated_summary_costs_response = self.send_post(
body=body_json,
url=self.__base_ocean_k8s_url +
ocean_id + "/aggregatedCosts/summary",
entity_name='ocean (aggregated summary costs)')

formatted_response = self.convert_json(
aggregated_summary_costs_response, self.camel_to_underscore)

return formatted_response["response"]["items"][0]
# endregion


Expand Down
24 changes: 24 additions & 0 deletions spotinst_sdk2/models/ocean/azure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,3 +893,27 @@ def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True, indent=4)
# endregion


class DetachNodes:
"""
# Arguments
node_names_to_detach: List[str]
ocean_id: str
"""

def __init__(self,
node_names_to_detach: List[str] = none,
ocean_id: str = none):
self.node_names_to_detach = node_names_to_detach
self.ocean_id = ocean_id


class DetachNodesRequest:
def __init__(self, detach_nodes_obj: DetachNodes):
self.node_names_to_detach = detach_nodes_obj.node_names_to_detach
self.ocean_id = detach_nodes_obj.ocean_id

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True, indent=4)
2 changes: 1 addition & 1 deletion spotinst_sdk2/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.7.1'
__version__ = '3.8.0'