Skip to content

Commit

Permalink
SPOTAUT-17229 Ocean AKS Migration (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
pripatra authored Mar 29, 2024
1 parent d0ba133 commit 4d9a437
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/clients/ocean/ocean_aws_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
80 changes: 80 additions & 0 deletions docs/clients/ocean/ocean_azure_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,83 @@ __Returns__

`(Object)`: Cluster Roll API response

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

```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

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

```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

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

```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

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

```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

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

```python
OceanAzureClient.list_migrations(ocean_id: str)
```

Get summary of migrations history for an Ocean cluster.

__Returns__

`(Object)`: Ocean Migrations response

28 changes: 28 additions & 0 deletions docs/models/ocean/azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,3 +689,31 @@ __Arguments__
- __node_names__: List[str]


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

```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

125 changes: 121 additions & 4 deletions spotinst_sdk2/clients/ocean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -951,15 +951,15 @@ 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):
"""
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
Expand Down Expand Up @@ -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
57 changes: 57 additions & 0 deletions spotinst_sdk2/models/ocean/azure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spotinst_sdk2/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.7.0'
__version__ = '2.8.0'

0 comments on commit 4d9a437

Please sign in to comment.