Skip to content

Commit e05121f

Browse files
mgr/smb: add squash method to ResultGroup
The new squash method works similarly to `one` but permits multiple resources to be reported on by moving them into the report for the "parent" resource. This is meant for upcoming changes to `cluster create` when it starts using linked join auths and linked users-and-groups. Signed-off-by: John Mulligan <[email protected]>
1 parent 7605397 commit e05121f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/pybind/mgr/smb/results.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ def append(self, result: Result) -> None:
6868
def one(self) -> Result:
6969
return one(self._contents)
7070

71+
def squash(self, target: SMBResource) -> Result:
72+
match: Optional[Result] = None
73+
others: List[Result] = []
74+
for result in self._contents:
75+
if result.src == target:
76+
match = result
77+
else:
78+
others.append(result)
79+
if match:
80+
match.success = self.success
81+
match.status = {} if match.status is None else match.status
82+
match.status['additional_results'] = [
83+
r.to_simplified() for r in others
84+
]
85+
return match
86+
raise ValueError('no matching result for resource found')
87+
7188
def __iter__(self) -> Iterator[Result]:
7289
return iter(self._contents)
7390

0 commit comments

Comments
 (0)