Skip to content

Commit 7846657

Browse files
committed
flux-jobs: add -i, --include=HOSTS|RANKS option
Problem: There is no easy way to restrict the output of flux-jobs(1) based on a set of hosts or ranks, but this is basic and useful functionality. Add a new `-i, --include=` optiont that takes a hostlist or idset of targets, and adds a constraint to the JobList query that restricts matching jobs to those that were allocated the provided targets. Fixes #6202
1 parent 4ac4ceb commit 7846657

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/cmd/flux-jobs.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import sys
1818

1919
import flux.constants
20+
from flux.hostlist import Hostlist
21+
from flux.idset import IDset
2022
from flux.job import JobID, JobInfo, JobInfoFormat, JobList, job_fields_to_attrs
2123
from flux.job.stats import JobStats
2224
from flux.util import (
@@ -156,6 +158,16 @@ def fetch_jobs_flux(args, fields, flux_handle=None):
156158
if not args.filter:
157159
args.filter = {"pending", "running"}
158160

161+
constraint = None
162+
if args.include:
163+
try:
164+
constraint = {"ranks": [IDset(args.include).encode()]}
165+
except ValueError:
166+
try:
167+
constraint = {"hostlist": [Hostlist(args.include).encode()]}
168+
except ValueError:
169+
raise ValueError(f"-i/--include: invalid targets: {args.include}")
170+
159171
jobs_rpc = JobList(
160172
flux_handle,
161173
ids=args.jobids,
@@ -166,6 +178,7 @@ def fetch_jobs_flux(args, fields, flux_handle=None):
166178
since=since,
167179
name=args.name,
168180
queue=args.queue,
181+
constraint=constraint,
169182
)
170183

171184
jobs = jobs_rpc.jobs()
@@ -270,6 +283,14 @@ def parse_args():
270283
metavar="QUEUE,...",
271284
help="Limit output to specific queue or queues",
272285
)
286+
parser.add_argument(
287+
"-i",
288+
"--include",
289+
type=str,
290+
metavar="HOSTS|RANKS",
291+
help="Limit output to jobs that were allocated to the specified "
292+
+ "HOSTS or RANKS provided as a hostlist or idset.",
293+
)
273294
parser.add_argument(
274295
"-o",
275296
"--format",

0 commit comments

Comments
 (0)