)
with _store_transaction(staging.destination_store):
results = staging.save()
- _prune_linked_entries(staging)
+ staging.prune_linked_entries()
with _store_transaction(staging.destination_store):
self._sync_modified(results)
return results
return sorted(resource_objs, key=_keyfunc)
-def _prune_linked_entries(staging: Staging) -> None:
- cids = set(ClusterEntry.ids(staging))
- for auth_id in JoinAuthEntry.ids(staging):
- join_auth = staging.get_join_auth(auth_id)
- if (
- join_auth.linked_to_cluster
- and join_auth.linked_to_cluster not in cids
- ):
- JoinAuthEntry.from_store(
- staging.destination_store, auth_id
- ).remove()
- for ug_id in UsersAndGroupsEntry.ids(staging):
- ug = staging.get_users_and_groups(ug_id)
- if ug.linked_to_cluster and ug.linked_to_cluster not in cids:
- UsersAndGroupsEntry.from_store(
- staging.destination_store, ug_id
- ).remove()
-
-
def _generate_share(
share: resources.Share, resolver: PathResolver, cephx_entity: str
) -> Dict[str, Dict[str, str]]:
List,
Optional,
Set,
+ Type,
)
import functools
from .internal import (
ClusterEntry,
JoinAuthEntry,
+ ResourceEntry,
ShareEntry,
UsersAndGroupsEntry,
resource_entry,
result = Result(resource, success=True, status={'state': state})
return result
+ def _prune(
+ self,
+ cids: Collection[str],
+ ecls: Type[ResourceEntry],
+ rcls: Type[SMBResource],
+ ) -> None:
+ for _id in ecls.ids(self):
+ assert isinstance(_id, str)
+ rentry = ecls.from_store_by_key(self.destination_store, _id)
+ resource = rentry.get_resource_type(rcls)
+ _linked_to_cluster = getattr(resource, 'linked_to_cluster', None)
+ if not _linked_to_cluster:
+ continue
+ if _linked_to_cluster not in cids:
+ rentry.remove()
+
+ def prune_linked_entries(self) -> None:
+ cids = set(ClusterEntry.ids(self))
+ self._prune(cids, JoinAuthEntry, resources.JoinAuth)
+ self._prune(cids, UsersAndGroupsEntry, resources.UsersAndGroups)
+
def auth_refs(cluster: resources.Cluster) -> Collection[str]:
"""Return all IDs for join_auth resources referenced by the supplied