Skip to content

Commit

Permalink
Update gcp api client
Browse files Browse the repository at this point in the history
  • Loading branch information
ramrutha497 committed Oct 16, 2024
1 parent 9122bd7 commit 8a98786
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 8 deletions.
72 changes: 69 additions & 3 deletions spotinst_sdk2/clients/ocean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2493,7 +2493,73 @@ def launch_nodes_in_vng(self, ocean_launch_spec_id: str, amount: int):
response, self.camel_to_underscore)

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

def detach_instances(self, ocean_id: str, detach_configuration: gcp_ocean.DetachInstancesConfig):
"""
Detach instances from your Ocean cluster.
# Arguments
ocean_id (String): ID of the Ocean Cluster
detach_configuration (DetachInstancesConfig): Detach instances request
# Returns
(Object): Detach Instance response
"""
request = gcp_ocean.DetachInstancesRequest(
detach_config=detach_configuration)

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 + "/" + ocean_id + "/detachInstances",
entity_name='ocean gcp detach instances')

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

return formatted_response["response"]

def instance_types_filters_simulation(self, ocean_id: str, filters: gcp_ocean.InstanceTypesFilters):
"""
Returns all instances types that match the given filters.
These instance types will be used if the cluster is configured with these filters.
# Arguments
ocean_id (String): Id of the Ocean Cluster
filters (InstanceTypesFilters): List of filters
# Returns
(Object): Ocean Instance Type Simultion response
"""
request = gcp_ocean.InstanceTypesFilterRequest(filters)

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)

group_response = self.send_post(
body=body_json,
url=self.__base_ocean_cluster_url +
"/" + ocean_id + "/instanceTypeFiltersSimulation",
entity_name='ocean gcp')

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

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

# endregion

# region RightSizing

Expand Down Expand Up @@ -2774,7 +2840,7 @@ def get_ocean_right_sizing_recommendations(self, ocean_id: str, cluster_resource

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

# endRegion
# endregion

# region OceanEcs

Expand Down Expand Up @@ -3195,7 +3261,7 @@ def detach_instances(self, ocean_id: str, detach_configuration: ecs_ocean.Detach
formatted_response = self.convert_json(
response, self.camel_to_underscore)

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

def create_virtual_node_group(self, vng: ecs_ocean.VirtualNodeGroup):
"""
Expand Down
52 changes: 47 additions & 5 deletions spotinst_sdk2/models/ocean/gcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def __init__(
self.scheme = scheme


class Filters:
class InstanceTypesFilters:
"""
# Arguments
exclude_families: List[str]
Expand Down Expand Up @@ -209,15 +209,15 @@ class InstanceTypes:
# Arguments
blacklist: List[str]
whitelist: List[str]
filters: Filters
filters: InstanceTypesFilters
preferred_types: List[str]
"""

def __init__(
self,
blacklist: List[str] = none,
whitelist: List[str] = none,
filters: Filters = none,
filters: InstanceTypesFilters = none,
preferred_types: List[str] = none):
self.blacklist = blacklist
self.whitelist = whitelist
Expand Down Expand Up @@ -890,7 +890,7 @@ class VirtualNodeGroup:
# Arguments
auto_scale: AutoScale
availability_zones: List[str]
filters: Filters
filters: InstanceTypesFilters
instance_types: List[str]
preferred_types: List[str]
labels: List[Labels]
Expand All @@ -917,7 +917,7 @@ def __init__(
auto_scale: AutoScale = none,
availability_zones: List[str] = none,
instance_types: List[str] = none,
filters: Filters = none,
filters: InstanceTypesFilters = none,
preferred_types: List[str] = none,
labels: List[Labels] = none,
metadata: List[Metadata] = none,
Expand Down Expand Up @@ -1063,3 +1063,45 @@ def __init__(self, amount: int = none):
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True, indent=4)


class DetachInstancesConfig:
"""
# Arguments
instances_to_detach: List[str]
should_decrement_target_capacity: bool
should_terminate_instances: bool
draining_timeout: int
"""

def __init__(
self,
instances_to_detach: List[str] = none,
should_decrement_target_capacity: bool = none,
should_terminate_instances: bool = none,
draining_timeout: int = none):
self.instances_to_detach = instances_to_detach
self.should_decrement_target_capacity = should_decrement_target_capacity
self.should_terminate_instances = should_terminate_instances
self.draining_timeout = draining_timeout


class DetachInstancesRequest:
def __init__(self, detach_config: DetachInstancesConfig):
self.instances_to_detach = detach_config.instances_to_detach
self.should_decrement_target_capacity = detach_config.should_decrement_target_capacity
self.should_terminate_instances = detach_config.should_terminate_instances
self.draining_timeout = detach_config.draining_timeout

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True, indent=4)


class InstanceTypesFilterRequest:
def __init__(self, filters: InstanceTypesFilters):
self.filters = filters

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True, indent=4)

0 comments on commit 8a98786

Please sign in to comment.