]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: update staging funcs to include ext ceph cluster resource
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 23 Jan 2026 19:15:41 +0000 (14:15 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 17 Feb 2026 15:59:12 +0000 (10:59 -0500)
Update the functions in the staging.py support file to include support
for the newly added external ceph cluster type.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/staging.py

index 4c857434454ed2bc0b8fbdacb32504d671e44d1b..8cca672052550373993ed556e59fb7f6360406c6 100644 (file)
@@ -22,6 +22,7 @@ from .enums import (
     Intent,
     JoinSourceType,
     SMBClustering,
+    SourceReferenceType,
     State,
     UserGroupSourceType,
 )
@@ -580,6 +581,31 @@ def _check_tls_credential_present(
             )
 
 
+@cross_check_resource.register
+def _check_external_ceph_cluster_resource(
+    ext_cluster: resources.ExternalCephCluster, staging: Staging, **_: Any
+) -> None:
+    """Check that the external ceph cluster resource is valid."""
+    if ext_cluster.intent == Intent.PRESENT:
+        return
+    cids = set(ClusterEntry.ids(staging))
+    refs_in_use: Dict[str, List[str]] = {}
+    for cluster_id in cids:
+        cluster = staging.get_cluster(cluster_id)
+        for ref in ext_cluster_refs(cluster):
+            refs_in_use.setdefault(ref, []).append(cluster_id)
+    log.debug('ext cluster refs in use: %r', refs_in_use)
+    my_id = ext_cluster.external_ceph_cluster_id
+    if my_id in refs_in_use:
+        raise ErrorResult(
+            ext_cluster,
+            msg='external ceph cluster resource in use by clusters',
+            status={
+                'clusters': refs_in_use[my_id],
+            },
+        )
+
+
 def _tls_ref(src: Optional[resources.TLSSource]) -> str:
     if src and src.source_type == UserGroupSourceType.RESOURCE and src.ref:
         return src.ref
@@ -600,6 +626,17 @@ def tls_refs(cluster: resources.Cluster) -> Collection[str]:
     return {ref for ref in refs if ref}
 
 
+def ext_cluster_refs(cluster: resources.Cluster) -> Collection[str]:
+    if (
+        cluster.external_ceph_cluster
+        and cluster.external_ceph_cluster.source_type
+        == SourceReferenceType.RESOURCE
+        and cluster.external_ceph_cluster.ref
+    ):
+        return [cluster.external_ceph_cluster.ref]
+    return []
+
+
 def _parse_earmark(earmark: str) -> dict:
     parts = earmark.split('.')