Skip to content

Commit

Permalink
mgr/smb: add squash method to ResultGroup
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
phlogistonjohn committed May 2, 2024
1 parent 7605397 commit e05121f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/pybind/mgr/smb/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ def append(self, result: Result) -> None:
def one(self) -> Result:
return one(self._contents)

def squash(self, target: SMBResource) -> Result:
match: Optional[Result] = None
others: List[Result] = []
for result in self._contents:
if result.src == target:
match = result
else:
others.append(result)
if match:
match.success = self.success
match.status = {} if match.status is None else match.status
match.status['additional_results'] = [
r.to_simplified() for r in others
]
return match
raise ValueError('no matching result for resource found')

def __iter__(self) -> Iterator[Result]:
return iter(self._contents)

Expand Down

0 comments on commit e05121f

Please sign in to comment.