From 4d9a437d44da5ef9e2831189ed62c89f006b71ee Mon Sep 17 00:00:00 2001
From: pripatra <106669742+pripatra@users.noreply.github.com>
Date: Fri, 29 Mar 2024 18:31:56 +0530
Subject: [PATCH] SPOTAUT-17229 Ocean AKS Migration (#161)
---
CHANGELOG.md | 3 +
docs/clients/ocean/ocean_aws_client.md | 2 +-
docs/clients/ocean/ocean_azure_client.md | 80 ++++++++++++
docs/models/ocean/azure.md | 28 +++++
spotinst_sdk2/clients/ocean/__init__.py | 125 ++++++++++++++++++-
spotinst_sdk2/models/ocean/azure/__init__.py | 57 +++++++++
spotinst_sdk2/version.py | 2 +-
7 files changed, 291 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f3fe1a1..048418f0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
+## [2.8.0] - 2024-03-29
+### Added
+- Added support for Ocean AKS Migration APIs.
## [2.7.0] - 2024-03-14
### Added
diff --git a/docs/clients/ocean/ocean_aws_client.md b/docs/clients/ocean/ocean_aws_client.md
index c6cfb306..bfd36298 100644
--- a/docs/clients/ocean/ocean_aws_client.md
+++ b/docs/clients/ocean/ocean_aws_client.md
@@ -628,7 +628,7 @@ Stop an ongoing Workload Migration.
__Arguments__
- __ocean_id (String)__: ID of the Ocean Cluster
-- __migration_id (bool)__: The migration identifier of a specific migration
+- __migration_id (String)__: The migration identifier of a specific migration
- __migration (Migration)__: Migration Update Configuration
__Returns__
diff --git a/docs/clients/ocean/ocean_azure_client.md b/docs/clients/ocean/ocean_azure_client.md
index 0b258f3c..fd3db039 100644
--- a/docs/clients/ocean/ocean_azure_client.md
+++ b/docs/clients/ocean/ocean_azure_client.md
@@ -297,3 +297,83 @@ __Returns__
`(Object)`: Cluster Roll API response
+
create_migration
+
+```python
+OceanAzureClient.create_migration(ocean_id: str, migration: Migration)
+```
+
+Create a migration for a given existing instances.
+
+__Arguments__
+
+- __migration (Migration)__: Migration Object
+
+__Returns__
+
+`(Object)`: Migration create response
+
+get_migration_discovery
+
+```python
+OceanAzureClient.get_migration_discovery(ocean_id: str,
+ should_fetch_pods: bool)
+```
+
+Get information about nodes which can be migrated into Ocean.
+
+__Arguments__
+
+- __ocean_id (String)__: ID of the Ocean Cluster
+- __should_fetch_pods (bool)__: Should fetch data about running pods for each node.
+
+__Returns__
+
+`(Object)`: Ocean API response
+
+stop_migration
+
+```python
+OceanAzureClient.stop_migration(ocean_id: str, migration_id: str)
+```
+
+Stop an ongoing Workload Migration.
+
+__Arguments__
+
+- __ocean_id (String)__: ID of the Ocean Cluster
+- __migration_id (String)__: The migration identifier of a specific migration
+
+__Returns__
+
+`(Object)`: Ocean Migration response
+
+get_migration
+
+```python
+OceanAzureClient.get_migration(ocean_id: str, migration_id: str)
+```
+
+Get Migration full info and status for an Ocean cluster.
+
+__Arguments__
+
+- __ocean_id (String)__: ID of the Ocean Cluster
+- __migration_id (String)__: The migration identifier of a specific migration.
+
+__Returns__
+
+`(Object)`: Ocean API response
+
+list_migrations
+
+```python
+OceanAzureClient.list_migrations(ocean_id: str)
+```
+
+Get summary of migrations history for an Ocean cluster.
+
+__Returns__
+
+`(Object)`: Ocean Migrations response
+
diff --git a/docs/models/ocean/azure.md b/docs/models/ocean/azure.md
index de3fbf7d..60b06898 100644
--- a/docs/models/ocean/azure.md
+++ b/docs/models/ocean/azure.md
@@ -689,3 +689,31 @@ __Arguments__
- __node_names__: List[str]
+Migration
+
+```python
+Migration(
+ self,
+ node_names: typing.List[str] = 'd3043820717d74d9a17694c176d39733',
+ node_pool_names: typing.List[str] = 'd3043820717d74d9a17694c176d39733',
+ batch_size_percentage: int = 'd3043820717d74d9a17694c176d39733',
+ batch_min_healthy_percentage: int = 'd3043820717d74d9a17694c176d39733',
+ comment: str = 'd3043820717d74d9a17694c176d39733',
+ respect_pdb: bool = 'd3043820717d74d9a17694c176d39733',
+ respect_restrict_scale_down: bool = 'd3043820717d74d9a17694c176d39733',
+ should_evict_standalone_pods: bool = 'd3043820717d74d9a17694c176d39733',
+ should_terminate_nodes: bool = 'd3043820717d74d9a17694c176d39733')
+```
+
+__Arguments__
+
+- __node_names__: List[str]
+- __node_pool_names__: List[str]
+- __batch_size_percentage__: int
+- __batch_min_healthy_percentage__: int
+- __comment__: str
+- __respect_pdb__: bool
+- __respect_restrict_scale_down__: bool
+- __should_evict_standalone_pods__: bool
+- __should_terminate_nodes__: bool
+
diff --git a/spotinst_sdk2/clients/ocean/__init__.py b/spotinst_sdk2/clients/ocean/__init__.py
index f2a85f5d..975d2eee 100644
--- a/spotinst_sdk2/clients/ocean/__init__.py
+++ b/spotinst_sdk2/clients/ocean/__init__.py
@@ -237,13 +237,13 @@ def initiate_roll(self, ocean_id: str, cluster_roll: aws_ocean.Roll):
body_json = json.dumps(formatted_missing_dict)
- aggregated_costs_response = self.send_post(
+ rolls_response = self.send_post(
body=body_json,
url=self.__base_ocean_cluster_url + "/" + ocean_id + "/roll",
entity_name='ocean (Cluster Roll)')
formatted_response = self.convert_json(
- aggregated_costs_response, self.camel_to_underscore)
+ rolls_response, self.camel_to_underscore)
return formatted_response["response"]["items"][0]
@@ -951,7 +951,7 @@ def get_migration_discovery(self, ocean_id: str, should_fetch_pods: bool):
formatted_response = self.convert_json(
response, self.camel_to_underscore)
- return formatted_response["response"]["items"][0]
+ return formatted_response["response"]["items"]
def stop_migration(self, ocean_id: str, migration_id: str, migration: aws_ocean.Migration):
"""
@@ -959,7 +959,7 @@ def stop_migration(self, ocean_id: str, migration_id: str, migration: aws_ocean.
# Arguments
ocean_id (String): ID of the Ocean Cluster
- migration_id (bool): The migration identifier of a specific migration
+ migration_id (String): The migration identifier of a specific migration
migration (Migration): Migration Update Configuration
# Returns
@@ -1575,4 +1575,121 @@ def stop_roll(self, ocean_id: str, roll_id: str):
return formatted_response["response"]["items"][0]
+ def create_migration(self, ocean_id: str, migration: azure_ocean.Migration):
+ """
+ Create a migration for a given existing instances.
+
+ # Arguments
+ migration (Migration): Migration Object
+
+ # Returns
+ (Object): Migration create response
+ """
+ migration = azure_ocean.MigrationRequest(migration)
+
+ excluded_missing_dict = self.exclude_missing(
+ json.loads(migration.toJSON()))
+
+ formatted_missing_dict = self.convert_json(
+ excluded_missing_dict, self.underscore_to_camel)
+
+ body_json = json.dumps(formatted_missing_dict)
+
+ response = self.send_post(
+ body=body_json,
+ url=self.__base_ocean_cluster_url + "/" + ocean_id + "/migration",
+ entity_name='ocean_azure_migration')
+
+ formatted_response = self.convert_json(response,
+ self.camel_to_underscore)
+
+ return formatted_response["response"]
+
+ def get_migration_discovery(self, ocean_id: str, should_fetch_pods: bool):
+ """
+ Get information about nodes which can be migrated into Ocean.
+
+ # Arguments
+ ocean_id (String): ID of the Ocean Cluster
+ should_fetch_pods (bool): Should fetch data about running pods for each node.
+
+ # Returns
+ (Object): Ocean API response
+ """
+ query_params = dict(shouldFetchPods=should_fetch_pods)
+
+ response = self.send_get(
+ url=self.__base_ocean_cluster_url + "/" + ocean_id + "/migration/discovery",
+ entity_name="ocean_azure_migration",
+ query_params=query_params
+ )
+
+ formatted_response = self.convert_json(
+ response, self.camel_to_underscore)
+
+ return formatted_response["response"]
+
+ def stop_migration(self, ocean_id: str, migration_id: str):
+ """
+ Stop an ongoing Workload Migration.
+
+ # Arguments
+ ocean_id (String): ID of the Ocean Cluster
+ migration_id (String): The migration identifier of a specific migration
+
+ # Returns
+ (Object): Ocean Migration response
+ """
+
+ response = self.send_put(
+ url=self.__base_ocean_cluster_url + "/" +
+ ocean_id + "/migration/" + migration_id + "/stop",
+ entity_name="ocean_azure_migration",
+ )
+
+ formatted_response = self.convert_json(
+ response, self.camel_to_underscore)
+
+ return formatted_response["response"]
+
+ def get_migration(self, ocean_id: str, migration_id: str):
+ """
+ Get Migration full info and status for an Ocean cluster.
+
+ # Arguments
+ ocean_id (String): ID of the Ocean Cluster
+ migration_id (String): The migration identifier of a specific migration.
+
+ # Returns
+ (Object): Ocean API response
+ """
+
+ response = self.send_get(
+ url=self.__base_ocean_cluster_url + "/" +
+ ocean_id + "/migration/" + migration_id,
+ entity_name="ocean_azure_migration"
+ )
+
+ formatted_response = self.convert_json(
+ response, self.camel_to_underscore)
+
+ return formatted_response["response"]
+
+ def list_migrations(self, ocean_id: str):
+ """
+ Get summary of migrations history for an Ocean cluster.
+
+ # Returns
+ (Object): Ocean Migrations response
+ """
+
+ response = self.send_get(
+ url=self.__base_ocean_cluster_url + "/" + ocean_id + "/migration",
+ entity_name="ocean_azure_migration",
+ )
+
+ formatted_response = self.convert_json(
+ response, self.camel_to_underscore)
+
+ return formatted_response["response"]
# endregion
diff --git a/spotinst_sdk2/models/ocean/azure/__init__.py b/spotinst_sdk2/models/ocean/azure/__init__.py
index 0bd6953a..bbc81ad8 100644
--- a/spotinst_sdk2/models/ocean/azure/__init__.py
+++ b/spotinst_sdk2/models/ocean/azure/__init__.py
@@ -726,3 +726,60 @@ def __init__(self, roll: Roll = none):
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True, indent=4)
+
+# region Migration
+
+
+class Migration:
+ """
+ # Arguments
+ node_names: List[str]
+ node_pool_names: List[str]
+ batch_size_percentage: int
+ batch_min_healthy_percentage: int
+ comment: str
+ respect_pdb: bool
+ respect_restrict_scale_down: bool
+ should_evict_standalone_pods: bool
+ should_terminate_nodes: bool
+ """
+
+ def __init__(
+ self,
+ node_names: List[str] = none,
+ node_pool_names: List[str] = none,
+ batch_size_percentage: int = none,
+ batch_min_healthy_percentage: int = none,
+ comment: str = none,
+ respect_pdb: bool = none,
+ respect_restrict_scale_down: bool = none,
+ should_evict_standalone_pods: bool = none,
+ should_terminate_nodes: bool = none,
+ ):
+ self.node_names = node_names
+ self.node_pool_names = node_pool_names
+ self.batch_size_percentage = batch_size_percentage
+ self.batch_min_healthy_percentage = batch_min_healthy_percentage
+ self.comment = comment
+ self.respect_pdb = respect_pdb
+ self.respect_restrict_scale_down = respect_restrict_scale_down
+ self.should_evict_standalone_pods = should_evict_standalone_pods
+ self.should_terminate_nodes = should_terminate_nodes
+
+
+class MigrationRequest:
+ def __init__(self, migration: Migration):
+ self.node_names = migration.node_names
+ self.node_pool_names = migration.node_pool_names
+ self.batch_size_percentage = migration.batch_size_percentage
+ self.batch_min_healthy_percentage = migration.batch_min_healthy_percentage
+ self.comment = migration.comment
+ self.respect_pdb = migration.respect_pdb
+ self.respect_restrict_scale_down = migration.respect_restrict_scale_down
+ self.should_evict_standalone_pods = migration.should_evict_standalone_pods
+ self.should_terminate_nodes = migration.should_terminate_nodes
+
+ def toJSON(self):
+ return json.dumps(self, default=lambda o: o.__dict__,
+ sort_keys=True, indent=4)
+# endregion
diff --git a/spotinst_sdk2/version.py b/spotinst_sdk2/version.py
index 766ce2d0..f2df444a 100644
--- a/spotinst_sdk2/version.py
+++ b/spotinst_sdk2/version.py
@@ -1 +1 @@
-__version__ = '2.7.0'
+__version__ = '2.8.0'