44
55from dstack ._internal .core .models .configurations import AnyRunConfiguration
66from dstack ._internal .core .models .profiles import (
7- DEFAULT_INSTANCE_RETRY_DURATION ,
8- DEFAULT_POOL_TERMINATION_IDLE_TIME ,
97 CreationPolicy ,
108 Profile ,
119 ProfileRetryPolicy ,
1614)
1715
1816
19- def register_profile_args (parser : argparse .ArgumentParser , pool_add : bool = False ):
17+ def register_profile_args (parser : argparse .ArgumentParser ):
2018 """
21- Registers `parser` with `dstack run` and `dstack pool add`
19+ Registers `parser` with `dstack apply` run configuration
2220 CLI arguments that override `profiles.yml` settings.
2321 """
2422 profile_group = parser .add_argument_group ("Profile" )
@@ -36,14 +34,13 @@ def register_profile_args(parser: argparse.ArgumentParser, pool_add: bool = Fals
3634 help = "The maximum price per hour, in dollars" ,
3735 dest = "max_price" ,
3836 )
39- if not pool_add :
40- profile_group .add_argument (
41- "--max-duration" ,
42- type = max_duration ,
43- dest = "max_duration" ,
44- help = "The maximum duration of the run" ,
45- metavar = "DURATION" ,
46- )
37+ profile_group .add_argument (
38+ "--max-duration" ,
39+ type = max_duration ,
40+ dest = "max_duration" ,
41+ help = "The maximum duration of the run" ,
42+ metavar = "DURATION" ,
43+ )
4744 profile_group .add_argument (
4845 "-b" ,
4946 "--backend" ,
@@ -67,42 +64,28 @@ def register_profile_args(parser: argparse.ArgumentParser, pool_add: bool = Fals
6764 dest = "instance_types" ,
6865 help = "The cloud-specific instance types that will be tried for provisioning" ,
6966 )
70- if pool_add :
71- pools_group_exc = parser
72- else :
73- pools_group = parser .add_argument_group ("Pools" )
74- pools_group_exc = pools_group .add_mutually_exclusive_group ()
75- pools_group_exc .add_argument (
76- "--pool" ,
77- dest = "pool_name" ,
78- help = "The name of the pool. If not set, the default pool will be used" ,
79- )
80- pools_group_exc .add_argument (
67+
68+ fleets_group = parser .add_argument_group ("Fleets" )
69+ fleets_group_exc = fleets_group .add_mutually_exclusive_group ()
70+ fleets_group_exc .add_argument (
8171 "-R" ,
8272 "--reuse" ,
8373 dest = "creation_policy_reuse" ,
8474 action = "store_true" ,
85- help = "Reuse instance from pool " ,
75+ help = "Reuse an existing instance from fleet (do not provision a new one) " ,
8676 )
87- pools_group_exc .add_argument (
77+ fleets_group_exc .add_argument (
8878 "--dont-destroy" ,
8979 dest = "dont_destroy" ,
9080 action = "store_true" ,
91- help = "Do not destroy instance after the run is finished" ,
81+ help = "Do not destroy instance after the run is finished (if the run provisions a new instance) " ,
9282 )
93- pools_group_exc .add_argument (
83+ fleets_group_exc .add_argument (
9484 "--idle-duration" ,
9585 dest = "idle_duration" ,
9686 type = str ,
97- help = "Time to wait before destroying the idle instance" ,
87+ help = "Time to wait before destroying the idle instance (if the run provisions a new instance) " ,
9888 )
99- if not pool_add :
100- pools_group_exc .add_argument (
101- "--instance" ,
102- dest = "instance_name" ,
103- metavar = "NAME" ,
104- help = "Reuse instance from pool with name [code]NAME[/]" ,
105- )
10689
10790 spot_group = parser .add_argument_group ("Spot policy" )
10891 spot_group_exc = spot_group .add_mutually_exclusive_group ()
@@ -149,7 +132,6 @@ def register_profile_args(parser: argparse.ArgumentParser, pool_add: bool = Fals
149132def apply_profile_args (
150133 args : argparse .Namespace ,
151134 profile_settings : Union [Profile , AnyRunConfiguration ],
152- pool_add : bool = False ,
153135):
154136 """
155137 Overrides `profile_settings` settings with arguments registered by `register_profile_args()`.
@@ -165,53 +147,29 @@ def apply_profile_args(
165147 profile_settings .instance_types = args .instance_types
166148 if args .max_price is not None :
167149 profile_settings .max_price = args .max_price
168- if not pool_add :
169- if args .max_duration is not None :
170- profile_settings .max_duration = args .max_duration
171-
172- if args .pool_name :
173- profile_settings .pool_name = args .pool_name
150+ if args .max_duration is not None :
151+ profile_settings .max_duration = args .max_duration
174152
175153 if args .idle_duration is not None :
176154 profile_settings .termination_idle_time = args .idle_duration
177- if pool_add and args .idle_duration is None :
178- profile_settings .termination_idle_time = DEFAULT_POOL_TERMINATION_IDLE_TIME
179155
180156 if args .dont_destroy :
181157 profile_settings .termination_policy = TerminationPolicy .DONT_DESTROY
182- if not pool_add :
183- if args .instance_name :
184- profile_settings .instance_name = args .instance_name
185- if args .creation_policy_reuse :
186- profile_settings .creation_policy = CreationPolicy .REUSE
158+ if args .creation_policy_reuse :
159+ profile_settings .creation_policy = CreationPolicy .REUSE
187160
188161 if args .spot_policy is not None :
189162 profile_settings .spot_policy = args .spot_policy
190- if pool_add and args .spot_policy is None : # ONDEMAND by default for `dstack pool add`
191- profile_settings .spot_policy = SpotPolicy .ONDEMAND
192-
193- if not pool_add :
194- if args .retry_policy is not None :
195- if not profile_settings .retry_policy :
196- profile_settings .retry_policy = ProfileRetryPolicy ()
197- profile_settings .retry_policy .retry = args .retry_policy
198- elif args .retry_duration is not None :
199- if not profile_settings .retry_policy :
200- profile_settings .retry_policy = ProfileRetryPolicy ()
201- profile_settings .retry_policy .retry = True
202- profile_settings .retry_policy .duration = args .retry_duration
203- else :
204- if args .retry_policy is not None :
205- if not profile_settings .retry_policy :
206- profile_settings .retry_policy = ProfileRetryPolicy ()
207- profile_settings .retry_policy .retry = args .retry_policy
208- if profile_settings .retry_policy .retry :
209- profile_settings .retry_policy .duration = DEFAULT_INSTANCE_RETRY_DURATION
210- elif args .retry_duration is not None :
211- if not profile_settings .retry_policy :
212- profile_settings .retry_policy = ProfileRetryPolicy ()
213- profile_settings .retry_policy .retry = True
214- profile_settings .retry_policy .duration = args .retry_duration # --retry-duration
163+
164+ if args .retry_policy is not None :
165+ if not profile_settings .retry_policy :
166+ profile_settings .retry_policy = ProfileRetryPolicy ()
167+ profile_settings .retry_policy .retry = args .retry_policy
168+ elif args .retry_duration is not None :
169+ if not profile_settings .retry_policy :
170+ profile_settings .retry_policy = ProfileRetryPolicy ()
171+ profile_settings .retry_policy .retry = True
172+ profile_settings .retry_policy .duration = args .retry_duration
215173
216174
217175def max_duration (v : str ) -> int :
0 commit comments