1- from typing import List
1+ from typing import List , Optional
22
33from pydantic import parse_obj_as
44
@@ -29,11 +29,7 @@ def get_plan(
2929 spec : FleetSpec ,
3030 ) -> FleetPlan :
3131 body = GetFleetPlanRequest (spec = spec )
32- body_json = body .json ()
33- if spec .configuration_path is None :
34- # Handle old server versions that do not accept configuration_path
35- # TODO: Can be removed in 0.19
36- body_json = body .json (exclude = {"spec" : {"configuration_path" }})
32+ body_json = body .json (exclude = _get_fleet_spec_excludes (spec ))
3733 resp = self ._request (f"/api/project/{ project_name } /fleets/get_plan" , body = body_json )
3834 return parse_obj_as (FleetPlan .__response__ , resp .json ())
3935
@@ -43,11 +39,7 @@ def create(
4339 spec : FleetSpec ,
4440 ) -> Fleet :
4541 body = CreateFleetRequest (spec = spec )
46- body_json = body .json ()
47- if spec .configuration_path is None :
48- # Handle old server versions that do not accept configuration_path
49- # TODO: Can be removed in 0.19
50- body_json = body .json (exclude = {"spec" : {"configuration_path" }})
42+ body_json = body .json (exclude = _get_fleet_spec_excludes (spec ))
5143 resp = self ._request (f"/api/project/{ project_name } /fleets/create" , body = body_json )
5244 return parse_obj_as (Fleet .__response__ , resp .json ())
5345
@@ -58,3 +50,19 @@ def delete(self, project_name: str, names: List[str]) -> None:
5850 def delete_instances (self , project_name : str , name : str , instance_nums : List [int ]) -> None :
5951 body = DeleteFleetInstancesRequest (name = name , instance_nums = instance_nums )
6052 self ._request (f"/api/project/{ project_name } /fleets/delete_instances" , body = body .json ())
53+
54+
55+ def _get_fleet_spec_excludes (fleet_spec : FleetSpec ) -> Optional [dict ]:
56+ exclude = {}
57+ # TODO: Can be removed in 0.19
58+ if fleet_spec .configuration_path is None :
59+ exclude ["spec" ] = {"configuration_path" }
60+ if fleet_spec .configuration .ssh_config is not None :
61+ if all (
62+ isinstance (h , str ) or h .internal_ip is None
63+ for h in fleet_spec .configuration .ssh_config .hosts
64+ ):
65+ exclude ["spec" ] = {
66+ "configuration" : {"ssh_config" : {"hosts" : {"__all__" : {"internal_ip" }}}}
67+ }
68+ return exclude or None
0 commit comments