]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: extend cluster resource type to define public ip addrs
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 22 Aug 2024 18:08:06 +0000 (14:08 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 27 Aug 2024 21:12:56 +0000 (17:12 -0400)
When a cluster defines public IPs it will pass this information along to
the smb service spec.

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

index 3f74ed04f2768565b111572353ec97e76dacb0bd..d91485f9992bb4a9e2e419db77e3996c404433b7 100644 (file)
@@ -5,7 +5,11 @@ import json
 
 import yaml
 
-from ceph.deployment.service_spec import PlacementSpec
+from ceph.deployment.service_spec import (
+    PlacementSpec,
+    SMBClusterPublicIPSpec,
+    SpecValidationError,
+)
 from object_format import ErrorResponseBase
 
 from . import resourcelib, validation
@@ -346,6 +350,25 @@ class WrappedPlacementSpec(PlacementSpec):
         return self.to_json()
 
 
+# This class is a near 1:1 mirror of the service spec helper class.
+@resourcelib.component()
+class ClusterPublicIPAssignment(_RBase):
+    address: str
+    destination: Union[List[str], str, None] = None
+
+    def to_spec(self) -> SMBClusterPublicIPSpec:
+        return SMBClusterPublicIPSpec(
+            address=self.address,
+            destination=self.destination,
+        )
+
+    def validate(self) -> None:
+        try:
+            self.to_spec().validate()
+        except SpecValidationError as err:
+            raise ValueError(str(err)) from err
+
+
 @resourcelib.resource('ceph.smb.cluster')
 class Cluster(_RBase):
     """Represents a cluster (instance) that is / should be present."""
@@ -361,6 +384,7 @@ class Cluster(_RBase):
     placement: Optional[WrappedPlacementSpec] = None
     # control if the cluster is really a cluster
     clustering: Optional[SMBClustering] = None
+    public_addrs: Optional[List[ClusterPublicIPAssignment]] = None
 
     def validate(self) -> None:
         if not self.cluster_id:
@@ -415,6 +439,13 @@ class Cluster(_RBase):
         # clustering enabled unless we're deploying a single instance "cluster"
         return count != 1
 
+    def service_spec_public_addrs(
+        self,
+    ) -> Optional[List[SMBClusterPublicIPSpec]]:
+        if self.public_addrs is None:
+            return None
+        return [a.to_spec() for a in self.public_addrs]
+
 
 @resourcelib.resource('ceph.smb.join.auth')
 class JoinAuth(_RBase):