@@ -742,6 +742,52 @@ def FromOutput(cls, stdout: str) -> ServicesEntry:
742742 return cls .FromDict (result )
743743
744744
745+ class SubIDEntry (object ):
746+ """
747+ Result of 'getsubids'.
748+ """
749+
750+ def __init__ (self , name : str , range_start : int , range_size : int ) -> None :
751+
752+ self .name : str = name
753+ """ User name"""
754+
755+ self .range_start : int = range_start
756+ """ SubID range start """
757+
758+ self .range_size : int = range_size
759+ """ SubID range size """
760+
761+ def __str__ (self ) -> str :
762+ return f"owner:{ self .name } , start:{ self .range_start } , size:{ self .range_size } )"
763+
764+ def __repr__ (self ) -> str :
765+ return str (self )
766+
767+ @classmethod
768+ def FromDict (cls , d : dict [str , Any ]) -> SubIDEntry :
769+ return cls (
770+ name = d .get ("name" , "" ),
771+ range_start = d .get ("range_start" , 0 ),
772+ range_size = d .get ("range_size" , 0 ),
773+ )
774+
775+ @classmethod
776+ def FromOutput (cls , stdout : str ) -> SubIDEntry :
777+ line = stdout .strip ()
778+ if ":" in line :
779+ parts = line .split (":" , 1 )
780+ if len (parts ) == 2 :
781+ rest = parts [1 ].strip ().split ()
782+ if len (rest ) == 3 :
783+ return cls (
784+ name = rest [0 ],
785+ range_start = int (rest [1 ]),
786+ range_size = int (rest [2 ]),
787+ )
788+ return cls (name = "" , range_start = 0 , range_size = 0 )
789+
790+
745791class LinuxToolsUtils (MultihostUtility [MultihostHost ]):
746792 """
747793 Run various standard commands on remote host.
@@ -762,6 +808,27 @@ def __init__(self, host: MultihostHost, fs: LinuxFileSystem) -> None:
762808 self .__fs : LinuxFileSystem = fs
763809 self .__rollback : list [str ] = []
764810
811+ def getsubid (self , name : str , group : bool = False ) -> SubIDEntry | None :
812+ """
813+ Call ``getsubids $name``
814+
815+ :param name: User name.
816+ :type name: str
817+ :param group: Get group range switch, optional
818+ :type group: bool, defaults to False
819+ :return: SubIDEntry data, None if not found
820+ :type: SubIDEntry | None
821+ """
822+ args = ""
823+ if group :
824+ args = "-g"
825+
826+ command = self .host .conn .run (f"getsubids { args } { name } " , raise_on_error = False )
827+ if command .rc != 0 :
828+ return None
829+
830+ return SubIDEntry .FromOutput (command .stdout )
831+
765832 def id (self , name : str | int ) -> IdEntry | None :
766833 """
767834 Run ``id`` command.
0 commit comments