1212 get_start_time ,
1313)
1414from dstack ._internal .core .errors import CLIError
15+ from dstack ._internal .core .models .common import EntityReference
1516from dstack ._internal .core .models .events import EventTargetType
1617from dstack ._internal .server .schemas .events import LIST_EVENTS_DEFAULT_LIMIT
1718from dstack .api import Client
@@ -55,6 +56,7 @@ def _register(self):
5556 action = "append" ,
5657 metavar = "NAME" ,
5758 dest = "target_fleets" ,
59+ type = EntityReference .parse ,
5860 help = "Only show events that target the specified fleets" ,
5961 )
6062 target_filters_group .add_argument (
@@ -91,6 +93,7 @@ def _register(self):
9193 action = "append" ,
9294 metavar = "NAME" ,
9395 dest = "within_fleets" ,
96+ type = EntityReference .parse ,
9497 help = "Only show events that target the specified fleets or instances within those fleets" ,
9598 )
9699 within_filters_group .add_argument (
@@ -137,9 +140,11 @@ def _list(self, args: argparse.Namespace):
137140def _build_filters (args : argparse .Namespace , api : Client ) -> EventListFilters :
138141 filters = EventListFilters ()
139142
143+ has_target_filters = True
140144 if args .target_fleets :
141145 filters .target_fleets = [
142- api .client .fleets .get (api .project , name ).id for name in args .target_fleets
146+ api .client .fleets .get (ref .project or api .project , ref .name ).id
147+ for ref in args .target_fleets
143148 ]
144149 elif args .target_runs :
145150 filters .target_runs = [
@@ -165,16 +170,21 @@ def _build_filters(args: argparse.Namespace, api: Client) -> EventListFilters:
165170 filters .target_secrets = [
166171 api .client .secrets .get (api .project , name = name ).id for name in args .target_secrets
167172 ]
173+ else :
174+ has_target_filters = False
168175
169176 if args .within_fleets :
170177 filters .within_fleets = [
171- api .client .fleets .get (api .project , name ).id for name in args .within_fleets
178+ api .client .fleets .get (ref .project or api .project , ref .name ).id
179+ for ref in args .within_fleets
172180 ]
173181 elif args .within_runs :
174182 filters .within_runs = [
175183 api .client .runs .get (api .project , name ).id for name in args .within_runs
176184 ]
177- else :
185+ elif not has_target_filters :
186+ # default - limit to current project,
187+ # unless there are more specific filters (e.g., for imported entities)
178188 filters .within_projects = [api .client .projects .get (api .project ).project_id ]
179189
180190 if args .include_target_types :
0 commit comments