44from rich .markup import escape
55from rich .table import Table
66
7+ from dstack ._internal .cli .models .offers import OfferCommandOutput , OfferRequirements
78from dstack ._internal .cli .utils .common import NO_OFFERS_WARNING , add_row_from_dict , console
89from dstack ._internal .core .models .backends .base import BackendType
910from dstack ._internal .core .models .configurations import DevEnvironmentConfiguration
1415)
1516from dstack ._internal .core .models .profiles import (
1617 DEFAULT_RUN_TERMINATION_IDLE_TIME ,
18+ SpotPolicy ,
1719 TerminationPolicy ,
1820)
1921from dstack ._internal .core .models .runs import (
2426 ProbeSpec ,
2527 RunPlan ,
2628 RunStatus ,
29+ get_policy_map ,
2730)
2831from dstack ._internal .core .models .runs import (
2932 Run as CoreRun ,
@@ -43,33 +46,22 @@ def print_offers_json(run_plan: RunPlan, run_spec):
4346 """Print offers information in JSON format."""
4447 job_plan = run_plan .job_plans [0 ]
4548
46- output = {
47- "project" : run_plan .project_name ,
48- "user" : run_plan .user ,
49- "resources" : job_plan .job_spec .requirements .resources .dict (),
50- "max_price" : (job_plan .job_spec .requirements .max_price ),
51- "spot" : run_spec .configuration .spot_policy ,
52- "reservation" : run_plan .run_spec .configuration .reservation ,
53- "offers" : [],
54- "total_offers" : job_plan .total_offers ,
55- }
56-
57- for offer in job_plan .offers :
58- output ["offers" ].append (
59- {
60- "backend" : ("ssh" if offer .backend .value == "remote" else offer .backend .value ),
61- "region" : offer .region ,
62- "instance_type" : offer .instance .name ,
63- "resources" : offer .instance .resources .dict (),
64- "spot" : offer .instance .resources .spot ,
65- "price" : float (offer .price ),
66- "availability" : offer .availability .value ,
67- }
68- )
49+ requirements = OfferRequirements (
50+ resources = job_plan .job_spec .requirements .resources ,
51+ max_price = job_plan .job_spec .requirements .max_price ,
52+ spot = get_policy_map (run_spec .configuration .spot_policy , default = SpotPolicy .AUTO ),
53+ reservation = run_plan .run_spec .configuration .reservation ,
54+ )
6955
70- import json
56+ output = OfferCommandOutput (
57+ project = run_plan .project_name ,
58+ user = run_plan .user ,
59+ requirements = requirements ,
60+ offers = job_plan .offers ,
61+ total_offers = job_plan .total_offers ,
62+ )
7163
72- print (json . dumps ( output , indent = 2 ))
64+ print (output . json ( ))
7365
7466
7567def print_run_plan (
0 commit comments