Skip to content

Commit

Permalink
Adding support for HPA in Python SDK (Internal Release) (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsharma-123 authored Aug 21, 2024
1 parent 61066b8 commit b819892
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 31 deletions.
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.12.0] - 2024-08-21
### Fixed
- Updated new fields for ocean Automatic Rightsizing APIs (beta release. For internal use only).

## [3.11.0] - 2024-08-21
### Fixed
- Updated new fields for ocean Automatic Rightsizing APIs (beta release. For internal use only).
Expand Down
50 changes: 29 additions & 21 deletions spotinst_sdk2/clients/ocean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2490,33 +2490,40 @@ def launch_nodes_in_vng(self, ocean_launch_spec_id: str, amount: int):

class OceanRightSizingClient(Client):

def create_right_sizing_rule(self, ocean_id: str, rule_name: str, restart_pods: bool,
def create_right_sizing_rule(self, ocean_id: str, rule_name: str,
restart_replicas: right_sizing_ocean.RestartReplicas,
exclude_preliminary_recommendations: bool,
application_intervals: List[right_sizing_ocean.RecommendationApplicationInterval],
application_min_threshold: right_sizing_ocean.RecommendationApplicationMinThreshold = None,
application_boundaries: right_sizing_ocean.RecommendationApplicationBoundaries = None,
application_overhead_values: right_sizing_ocean.RecommendationApplicationOverheadValues = None):
application_overhead_values: right_sizing_ocean.RecommendationApplicationOverheadValues = None,
application_hpa: right_sizing_ocean.RecommendationApplicationHPA = None):
"""
Create a right sizing rule for an Ocean cluster.
# Arguments
ocean_id (String): ID of the Ocean Cluster
rule_name (String): Name of the Right Sizing Rule
restart_pods (boolean): Enable to sequentially restart pod batches according to recommendations
restart_replicas (RestartReplicas): Restart Replicas
exclude_preliminary_recommendations (boolean): Exclude preliminary recommendations
application_intervals (List[RecommendationApplicationIntervals]): Recommendation Application Intervals
application_min_threshold (RecommendationApplicationMinThreshold): Recommendation Application Min Threshold
application_boundaries (RecommendationApplicationBoundaries): Recommendation Application Boundaries
application_overhead_values (RecommendationApplicationOverheadValues): Recommendation Application Overhead Values
application_hpa (RecommendationApplicationHPA): Recommendation Application HPA
# Returns
(Object): Ocean Right Sizing Rule API response
"""
right_sizing_rule_request = right_sizing_ocean.CreateRightSizingRuleRequest(rule_name=rule_name, restart_pods=restart_pods, restart_replicas=restart_replicas, exclude_preliminary_recommendations=exclude_preliminary_recommendations, recommendation_application_intervals=application_intervals,
recommendation_application_min_threshold=application_min_threshold, recommendation_application_boundaries=application_boundaries, recommendation_application_overhead_values=application_overhead_values)
right_sizing_rule_request = right_sizing_ocean.CreateRightSizingRuleRequest(rule_name=rule_name,
restart_replicas=restart_replicas,
exclude_preliminary_recommendations=exclude_preliminary_recommendations,
recommendation_application_intervals=application_intervals,
recommendation_application_min_threshold=application_min_threshold,
recommendation_application_boundaries=application_boundaries,
recommendation_application_overhead_values=application_overhead_values,
recommendation_application_hpa=application_hpa)

excluded_missing_dict = self.exclude_missing(
json.loads(right_sizing_rule_request.toJSON()))
Expand Down Expand Up @@ -2566,36 +2573,37 @@ def delete_right_sizing_rule(self, ocean_id: str, rule_names: List[str]):

def update_right_sizing_rule(self, ocean_id: str,
rule_name: str,
restart_pods: bool,
restart_replicas: right_sizing_ocean.RestartReplicas,
exclude_preliminary_recommendations: bool,
application_intervals: right_sizing_ocean.RecommendationApplicationInterval,
application_intervals: List[right_sizing_ocean.RecommendationApplicationInterval],
application_min_threshold: right_sizing_ocean.RecommendationApplicationMinThreshold,
application_boundaries: right_sizing_ocean.RecommendationApplicationBoundaries,
application_overhead_values: right_sizing_ocean.RecommendationApplicationOverheadValues):
application_overhead_values: right_sizing_ocean.RecommendationApplicationOverheadValues,
application_hpa: right_sizing_ocean.RecommendationApplicationHPA = None):
"""
Update a right sizing rule for an Ocean cluster.
# Arguments
ocean_id (String): ID of the Ocean Cluster
rule_name (String): Rightsizing Rule name
restart_pods (Bool): Whether existing pods should be restarted or not.
recommendation_application_intervals (RecommendationApplicationIntervals): Recommendation Application Intervals
recommendation_application_min_threshold (RecommendationApplicationMinThreshold): Recommendation Application Min Threshold
recommendation_application_boundaries (RecommendationApplicationBoundaries): Recommendation Application Boundaries
recommendation_application_overhead_values (RecommendationApplicationOverheadValues): Recommendation Application Overhead Values
restart_replicas (RestartReplicas): Restart Replicas
exclude_preliminary_recommendations (boolean): Exclude preliminary recommendations
application_intervals (RecommendationApplicationIntervals): Recommendation Application Intervals
application_min_threshold (RecommendationApplicationMinThreshold): Recommendation Application Min Threshold
application_boundaries (RecommendationApplicationBoundaries): Recommendation Application Boundaries
application_overhead_values (RecommendationApplicationOverheadValues): Recommendation Application Overhead Values
application_hpa (RecommendationApplicationHPA): Recommendation Application HPA
# Returns
(Object): Ocean Right Sizing Rule API response
"""
right_sizing_rule_request = right_sizing_ocean.UpdateRightSizingRuleRequest(
restart_pods,
restart_replicas,
exclude_preliminary_recommendations,
application_intervals,
application_min_threshold,
application_boundaries,
application_overhead_values)
right_sizing_rule_request = right_sizing_ocean.UpdateRightSizingRuleRequest(restart_replicas=restart_replicas,
exclude_preliminary_recommendations=exclude_preliminary_recommendations,
recommendation_application_intervals=application_intervals,
recommendation_application_min_threshold=application_min_threshold,
recommendation_application_boundaries=application_boundaries,
recommendation_application_overhead_values=application_overhead_values,
recommendation_application_hpa=application_hpa)

excluded_missing_dict = self.exclude_missing(
json.loads(right_sizing_rule_request.toJSON()))
Expand Down
35 changes: 26 additions & 9 deletions spotinst_sdk2/models/ocean/rightsizing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,24 @@ def __init__(
self.memory_percentage = memory_percentage
# endregion

# region Label

# region RecommendationApplicationHPA
class RecommendationApplicationHPA:
"""
# Arguments
allow_h_p_a_recommendations: bool
"""

def __init__(
self,
allow_h_p_a_recommendations: bool = none,
):
self.allow_h_p_a_recommendations = allow_h_p_a_recommendations

# endregion


# region Label

class Label:
"""
Expand Down Expand Up @@ -236,6 +252,7 @@ def __init__(

# endregion


# region Namespace


Expand Down Expand Up @@ -298,21 +315,21 @@ class RestartReplicas(Enum):
class CreateRightSizingRuleRequest:
def __init__(self,
rule_name: str,
restart_pods: bool,
restart_replicas: RestartReplicas,
exclude_preliminary_recommendations: bool,
recommendation_application_intervals: List[RecommendationApplicationInterval],
recommendation_application_min_threshold: RecommendationApplicationMinThreshold,
recommendation_application_boundaries: RecommendationApplicationBoundaries,
recommendation_application_overhead_values: RecommendationApplicationOverheadValues):
recommendation_application_overhead_values: RecommendationApplicationOverheadValues,
recommendation_application_hpa: RecommendationApplicationHPA):
self.rule_name = rule_name
self.restart_pods = restart_pods
self.restart_replicas = restart_replicas
self.exclude_preliminary_recommendations = exclude_preliminary_recommendations
self.recommendation_application_intervals = recommendation_application_intervals
self.recommendation_application_min_threshold = recommendation_application_min_threshold
self.recommendation_application_boundaries = recommendation_application_boundaries
self.recommendation_application_overhead_values = recommendation_application_overhead_values
self.recommendation_application_h_p_a = recommendation_application_hpa

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
Expand All @@ -330,20 +347,20 @@ def toJSON(self):

class UpdateRightSizingRuleRequest:
def __init__(self,
restart_pods: bool,
restart_replicas: RestartReplicas,
exclude_preliminary_recommendations: bool,
recommendation_application_intervals: List[RecommendationApplicationInterval],
recommendation_application_threshold: RecommendationApplicationMinThreshold,
recommendation_application_min_threshold: RecommendationApplicationMinThreshold,
recommendation_application_boundaries: RecommendationApplicationBoundaries,
recommendation_application_overhead_values: RecommendationApplicationOverheadValues):
self.restart_pods = restart_pods
recommendation_application_overhead_values: RecommendationApplicationOverheadValues,
recommendation_application_hpa: RecommendationApplicationHPA):
self.restart_replicas = restart_replicas
self.exclude_preliminary_recommendations = exclude_preliminary_recommendations
self.recommendation_application_intervals = recommendation_application_intervals
self.recommendation_application_threshold = recommendation_application_threshold
self.recommendation_application_min_threshold = recommendation_application_min_threshold
self.recommendation_application_boundaries = recommendation_application_boundaries
self.recommendation_application_overhead_values = recommendation_application_overhead_values
self.recommendation_application_h_p_a = recommendation_application_hpa

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
Expand Down
2 changes: 1 addition & 1 deletion spotinst_sdk2/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.11.0'
__version__ = '3.12.0'

0 comments on commit b819892

Please sign in to comment.