Skip to content

Commit

Permalink
aks migration
Browse files Browse the repository at this point in the history
  • Loading branch information
pripatra committed Mar 28, 2024
1 parent a769bdf commit e99b631
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 3 deletions.
122 changes: 119 additions & 3 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,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):
"""
Expand Down Expand Up @@ -1575,4 +1575,120 @@ 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 (bool): 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 = None):
"""
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
52 changes: 52 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,55 @@ 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.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

0 comments on commit e99b631

Please sign in to comment.