Skip to content

Commit 8a98786

Browse files
committed
Update gcp api client
1 parent 9122bd7 commit 8a98786

File tree

2 files changed

+116
-8
lines changed

2 files changed

+116
-8
lines changed

spotinst_sdk2/clients/ocean/__init__.py

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,73 @@ def launch_nodes_in_vng(self, ocean_launch_spec_id: str, amount: int):
24932493
response, self.camel_to_underscore)
24942494

24952495
return formatted_response["response"]["items"][0]
2496-
# endRegion
2496+
2497+
def detach_instances(self, ocean_id: str, detach_configuration: gcp_ocean.DetachInstancesConfig):
2498+
"""
2499+
Detach instances from your Ocean cluster.
2500+
2501+
# Arguments
2502+
ocean_id (String): ID of the Ocean Cluster
2503+
detach_configuration (DetachInstancesConfig): Detach instances request
2504+
2505+
# Returns
2506+
(Object): Detach Instance response
2507+
"""
2508+
request = gcp_ocean.DetachInstancesRequest(
2509+
detach_config=detach_configuration)
2510+
2511+
excluded_missing_dict = self.exclude_missing(
2512+
json.loads(request.toJSON()))
2513+
2514+
formatted_missing_dict = self.convert_json(
2515+
excluded_missing_dict, self.underscore_to_camel)
2516+
2517+
body_json = json.dumps(formatted_missing_dict)
2518+
2519+
response = self.send_put(
2520+
body=body_json,
2521+
url=self.__base_ocean_cluster_url + "/" + ocean_id + "/detachInstances",
2522+
entity_name='ocean gcp detach instances')
2523+
2524+
formatted_response = self.convert_json(
2525+
response, self.camel_to_underscore)
2526+
2527+
return formatted_response["response"]
2528+
2529+
def instance_types_filters_simulation(self, ocean_id: str, filters: gcp_ocean.InstanceTypesFilters):
2530+
"""
2531+
Returns all instances types that match the given filters.
2532+
These instance types will be used if the cluster is configured with these filters.
2533+
2534+
# Arguments
2535+
ocean_id (String): Id of the Ocean Cluster
2536+
filters (InstanceTypesFilters): List of filters
2537+
2538+
# Returns
2539+
(Object): Ocean Instance Type Simultion response
2540+
"""
2541+
request = gcp_ocean.InstanceTypesFilterRequest(filters)
2542+
2543+
excluded_missing_dict = self.exclude_missing(
2544+
json.loads(request.toJSON()))
2545+
2546+
formatted_missing_dict = self.convert_json(
2547+
excluded_missing_dict, self.underscore_to_camel)
2548+
2549+
body_json = json.dumps(formatted_missing_dict)
2550+
2551+
group_response = self.send_post(
2552+
body=body_json,
2553+
url=self.__base_ocean_cluster_url +
2554+
"/" + ocean_id + "/instanceTypeFiltersSimulation",
2555+
entity_name='ocean gcp')
2556+
2557+
formatted_response = self.convert_json(
2558+
group_response, self.camel_to_underscore)
2559+
2560+
return formatted_response["response"]["items"]
2561+
2562+
# endregion
24972563

24982564
# region RightSizing
24992565

@@ -2774,7 +2840,7 @@ def get_ocean_right_sizing_recommendations(self, ocean_id: str, cluster_resource
27742840

27752841
return formatted_response["response"]["items"]
27762842

2777-
# endRegion
2843+
# endregion
27782844

27792845
# region OceanEcs
27802846

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

3198-
return formatted_response["response"]["items"][0]
3264+
return formatted_response["response"]
31993265

32003266
def create_virtual_node_group(self, vng: ecs_ocean.VirtualNodeGroup):
32013267
"""

spotinst_sdk2/models/ocean/gcp/__init__.py

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def __init__(
178178
self.scheme = scheme
179179

180180

181-
class Filters:
181+
class InstanceTypesFilters:
182182
"""
183183
# Arguments
184184
exclude_families: List[str]
@@ -209,15 +209,15 @@ class InstanceTypes:
209209
# Arguments
210210
blacklist: List[str]
211211
whitelist: List[str]
212-
filters: Filters
212+
filters: InstanceTypesFilters
213213
preferred_types: List[str]
214214
"""
215215

216216
def __init__(
217217
self,
218218
blacklist: List[str] = none,
219219
whitelist: List[str] = none,
220-
filters: Filters = none,
220+
filters: InstanceTypesFilters = none,
221221
preferred_types: List[str] = none):
222222
self.blacklist = blacklist
223223
self.whitelist = whitelist
@@ -890,7 +890,7 @@ class VirtualNodeGroup:
890890
# Arguments
891891
auto_scale: AutoScale
892892
availability_zones: List[str]
893-
filters: Filters
893+
filters: InstanceTypesFilters
894894
instance_types: List[str]
895895
preferred_types: List[str]
896896
labels: List[Labels]
@@ -917,7 +917,7 @@ def __init__(
917917
auto_scale: AutoScale = none,
918918
availability_zones: List[str] = none,
919919
instance_types: List[str] = none,
920-
filters: Filters = none,
920+
filters: InstanceTypesFilters = none,
921921
preferred_types: List[str] = none,
922922
labels: List[Labels] = none,
923923
metadata: List[Metadata] = none,
@@ -1063,3 +1063,45 @@ def __init__(self, amount: int = none):
10631063
def toJSON(self):
10641064
return json.dumps(self, default=lambda o: o.__dict__,
10651065
sort_keys=True, indent=4)
1066+
1067+
1068+
class DetachInstancesConfig:
1069+
"""
1070+
# Arguments
1071+
instances_to_detach: List[str]
1072+
should_decrement_target_capacity: bool
1073+
should_terminate_instances: bool
1074+
draining_timeout: int
1075+
"""
1076+
1077+
def __init__(
1078+
self,
1079+
instances_to_detach: List[str] = none,
1080+
should_decrement_target_capacity: bool = none,
1081+
should_terminate_instances: bool = none,
1082+
draining_timeout: int = none):
1083+
self.instances_to_detach = instances_to_detach
1084+
self.should_decrement_target_capacity = should_decrement_target_capacity
1085+
self.should_terminate_instances = should_terminate_instances
1086+
self.draining_timeout = draining_timeout
1087+
1088+
1089+
class DetachInstancesRequest:
1090+
def __init__(self, detach_config: DetachInstancesConfig):
1091+
self.instances_to_detach = detach_config.instances_to_detach
1092+
self.should_decrement_target_capacity = detach_config.should_decrement_target_capacity
1093+
self.should_terminate_instances = detach_config.should_terminate_instances
1094+
self.draining_timeout = detach_config.draining_timeout
1095+
1096+
def toJSON(self):
1097+
return json.dumps(self, default=lambda o: o.__dict__,
1098+
sort_keys=True, indent=4)
1099+
1100+
1101+
class InstanceTypesFilterRequest:
1102+
def __init__(self, filters: InstanceTypesFilters):
1103+
self.filters = filters
1104+
1105+
def toJSON(self):
1106+
return json.dumps(self, default=lambda o: o.__dict__,
1107+
sort_keys=True, indent=4)

0 commit comments

Comments
 (0)