2727 resource_status ,
2828)
2929from flux .rpc import RPC
30- from flux .util import Deduplicator , UtilConfig
30+ from flux .util import Deduplicator , FilterActionSetUpdate , UtilConfig
3131
3232
3333class FluxResourceConfig (UtilConfig ):
@@ -198,7 +198,7 @@ def ranks_by_queue(resource_set, config, queues):
198198 """
199199 queue_resources = QueueResources (resource_set , config )
200200 ranks = IDset ()
201- for queue in queues . split ( "," ) :
201+ for queue in queues :
202202 ranks .add (queue_resources .queue (queue ).ranks )
203203 return ranks
204204
@@ -492,8 +492,9 @@ def drain_list(args):
492492
493493
494494class ResourceSetExtra (ResourceSet ):
495- def __init__ (self , arg = None , version = 1 , flux_config = None ):
495+ def __init__ (self , arg = None , version = 1 , flux_config = None , queue = None ):
496496 self .flux_config = flux_config
497+ self ._queue = queue
497498 if isinstance (arg , ResourceSet ):
498499 self ._rset = arg
499500 if arg .state :
@@ -517,6 +518,13 @@ def propertiesx(self):
517518
518519 @property
519520 def queue (self ):
521+ # Note: queue may be set manually in self._queue for an empty
522+ # ResourceSet, which cannot otherwise have an associated queue.
523+ if self ._queue is not None :
524+ return self ._queue
525+
526+ # If self._queue is not set, then build list of queues from
527+ # set properties and queue configuration:
520528 queues = ""
521529 if self .flux_config and "queues" in self .flux_config :
522530 if not self .ranks :
@@ -558,7 +566,7 @@ def constraint_combinations(rset):
558566 return [rset .copy_constraint (x ) for x in constraint_combinations (rset )]
559567
560568
561- def resources_uniq_lines (resources , states , formatter , config ):
569+ def resources_uniq_lines (resources , states , formatter , config , queues = None ):
562570 """
563571 Generate a set of resource sets that would produce unique lines given
564572 the ResourceSet formatter argument. Include only the provided states
@@ -583,6 +591,15 @@ def resources_uniq_lines(resources, states, formatter, config):
583591
584592 fmt = flux .util .OutputFormat (uniq_fmt , headings = formatter .headings )
585593
594+ # Get a list of configured queues if a specific list of queues
595+ # was not supplied by the caller. If no queues are configured then
596+ # one "anonymous" queue is simulated with [None]
597+ if not queues :
598+ if config and "queues" in config :
599+ queues = config ["queues" ].keys ()
600+ else :
601+ queues = [None ]
602+
586603 # Create a mapping of resources sets that generate uniq "lines":
587604 lines = {}
588605 for state in states :
@@ -592,13 +609,14 @@ def resources_uniq_lines(resources, states, formatter, config):
592609 # resource set for output purposes. O/w the output for this
593610 # state would be suppressed.
594611 #
595- rset = ResourceSetExtra (flux_config = config )
596- rset .state = state
597- key = fmt .format (rset )
598- if key not in lines :
599- lines [key ] = rset
600- else :
601- lines [key ].add (rset )
612+ for queue in queues :
613+ rset = ResourceSetExtra (flux_config = config , queue = queue )
614+ rset .state = state
615+ key = fmt .format (rset )
616+ if key not in lines :
617+ lines [key ] = rset
618+ else :
619+ lines [key ].add (rset )
602620 continue
603621
604622 for rset in split_by_property_combinations (resources [state ]):
@@ -684,7 +702,9 @@ def list_handler(args):
684702 fmt = FluxResourceConfig ("list" ).load ().get_format_string (args .format )
685703 formatter = flux .util .OutputFormat (fmt , headings = headings )
686704
687- lines = resources_uniq_lines (resources , args .states , formatter , config )
705+ lines = resources_uniq_lines (
706+ resources , args .states , formatter , config , queues = args .queue
707+ )
688708 items = sort_output (args , lines .values ())
689709 formatter .print_items (items , no_header = args .no_header )
690710
@@ -759,6 +779,8 @@ def main():
759779 drain_parser .add_argument (
760780 "-q" ,
761781 "--queue" ,
782+ action = FilterActionSetUpdate ,
783+ default = set (),
762784 metavar = "QUEUE,..." ,
763785 help = "Include only specified queues in output" ,
764786 )
@@ -824,6 +846,8 @@ def main():
824846 status_parser .add_argument (
825847 "-q" ,
826848 "--queue" ,
849+ action = FilterActionSetUpdate ,
850+ default = set (),
827851 metavar = "QUEUE,..." ,
828852 help = "Include only specified queues in output" ,
829853 )
@@ -879,6 +903,8 @@ def main():
879903 list_parser .add_argument (
880904 "-q" ,
881905 "--queue" ,
906+ action = FilterActionSetUpdate ,
907+ default = set (),
882908 metavar = "QUEUE,..." ,
883909 help = "Include only specified queues in output" ,
884910 )
@@ -911,6 +937,8 @@ def main():
911937 info_parser .add_argument (
912938 "-q" ,
913939 "--queue" ,
940+ action = FilterActionSetUpdate ,
941+ default = set (),
914942 metavar = "QUEUE,..." ,
915943 help = "Include only specified queues in output" ,
916944 )
@@ -959,6 +987,8 @@ def main():
959987 R_parser .add_argument (
960988 "-q" ,
961989 "--queue" ,
990+ action = FilterActionSetUpdate ,
991+ default = set (),
962992 metavar = "QUEUE,..." ,
963993 help = "Include only specified queues in output" ,
964994 )
0 commit comments