Skip to content

Commit 894de4e

Browse files
committed
flux-resource: add R subcommand
Problem: There is no way for a user to easily get the R being used for job allocations in an instance. The resource.R KVS key is only available to the instance owner, and doesn't represent the scheduler view of resources. Add a `flux resource R` command that fetches the scheduler's operating resource set and emits an R on stdout. Similar options to `flux resource list` are supported so that a user can get an R in any of the supported states "up", "down", "allocated", "free", "all".
1 parent 73943c7 commit 894de4e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/cmd/flux-resource.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,19 @@ def info(args):
569569
list_handler(args)
570570

571571

572+
def emit_R(args):
573+
"""Emit R in JSON on stdout for requested set of resources"""
574+
resources, config = get_resource_list(args)
575+
576+
rset = ResourceSet()
577+
for state in args.states:
578+
try:
579+
rset.add(resources[state])
580+
except AttributeError:
581+
raise ValueError(f"unknown state {state}")
582+
print(rset.encode())
583+
584+
572585
LOGGER = logging.getLogger("flux-resource")
573586

574587

@@ -766,6 +779,24 @@ def main():
766779
help="allow resources to contain invalid ranks",
767780
)
768781

782+
R_parser = subparsers.add_parser("R", formatter_class=flux.util.help_formatter())
783+
R_parser.set_defaults(func=emit_R)
784+
R_parser.add_argument(
785+
"-s",
786+
"--states",
787+
metavar="STATE,...",
788+
default="all",
789+
help="Emit R for resources in given states",
790+
)
791+
R_parser.add_argument(
792+
"-i",
793+
"--include",
794+
metavar="TARGETS",
795+
help="Include only specified targets in output set. TARGETS may be "
796+
+ "provided as an idset or hostlist.",
797+
)
798+
R_parser.add_argument("--from-stdin", action="store_true", help=argparse.SUPPRESS)
799+
769800
args = parser.parse_args()
770801
args.func(args)
771802

0 commit comments

Comments
 (0)