Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/dstack/_internal/cli/commands/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_start_time,
)
from dstack._internal.core.errors import CLIError
from dstack._internal.core.models.common import EntityReference
from dstack._internal.core.models.events import EventTargetType
from dstack._internal.server.schemas.events import LIST_EVENTS_DEFAULT_LIMIT
from dstack.api import Client
Expand Down Expand Up @@ -55,6 +56,7 @@ def _register(self):
action="append",
metavar="NAME",
dest="target_fleets",
type=EntityReference.parse,
help="Only show events that target the specified fleets",
)
target_filters_group.add_argument(
Expand Down Expand Up @@ -91,6 +93,7 @@ def _register(self):
action="append",
metavar="NAME",
dest="within_fleets",
type=EntityReference.parse,
help="Only show events that target the specified fleets or instances within those fleets",
)
within_filters_group.add_argument(
Expand Down Expand Up @@ -137,9 +140,11 @@ def _list(self, args: argparse.Namespace):
def _build_filters(args: argparse.Namespace, api: Client) -> EventListFilters:
filters = EventListFilters()

has_target_filters = True
if args.target_fleets:
filters.target_fleets = [
api.client.fleets.get(api.project, name).id for name in args.target_fleets
api.client.fleets.get(ref.project or api.project, ref.name).id
for ref in args.target_fleets
]
elif args.target_runs:
filters.target_runs = [
Expand All @@ -165,16 +170,21 @@ def _build_filters(args: argparse.Namespace, api: Client) -> EventListFilters:
filters.target_secrets = [
api.client.secrets.get(api.project, name=name).id for name in args.target_secrets
]
else:
has_target_filters = False

if args.within_fleets:
filters.within_fleets = [
api.client.fleets.get(api.project, name).id for name in args.within_fleets
api.client.fleets.get(ref.project or api.project, ref.name).id
for ref in args.within_fleets
]
elif args.within_runs:
filters.within_runs = [
api.client.runs.get(api.project, name).id for name in args.within_runs
]
else:
elif not has_target_filters:
# default - limit to current project,
# unless there are more specific filters (e.g., for imported entities)
filters.within_projects = [api.client.projects.get(api.project).project_id]

if args.include_target_types:
Expand Down
Loading