]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: deploy nfs-ganesha service
authorMichael Fritch <mfritch@suse.com>
Mon, 24 Feb 2020 18:47:34 +0000 (11:47 -0700)
committerSage Weil <sage@redhat.com>
Thu, 26 Mar 2020 01:55:56 +0000 (20:55 -0500)
orch daemon add nfs <svc_arg> <pool> [<namespace>] [<placement>]

Signed-off-by: Michael Fritch <mfritch@suse.com>
(cherry picked from commit 770816dc9f5b440fd1fc6cc507a06cd8573f6ea1)

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/nfs.py [new file with mode: 0644]

index 84d861530c992ce77bac67885ddda3a9c2858fd0..65607d06ecbba39eb33fd0d7d7b22cc8136e29f0 100644 (file)
@@ -40,6 +40,7 @@ from orchestrator import OrchestratorError, OrchestratorValidationError, HostSpe
     CLICommandMeta
 
 from . import remotes
+from .nfs import NFSGanesha
 from .osd import RemoveUtil, OSDRemoval
 
 
@@ -2207,24 +2208,34 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
                        keyring=None,
                        extra_args=None, extra_config=None,
                        reconfig=False,
-                       osd_uuid_map=None):
+                       osd_uuid_map=None,
+                       cephadm_config=None):
         if not extra_args:
             extra_args = []
         name = '%s.%s' % (daemon_type, daemon_id)
 
         start_time = datetime.datetime.utcnow()
         deps = []  # type: List[str]
-        cephadm_config = {}  # type: Dict[str, Any]
+        if not cephadm_config:
+            cephadm_config = {}
         if daemon_type == 'prometheus':
             cephadm_config, deps = self._generate_prometheus_config()
             extra_args.extend(['--config-json', '-'])
         elif daemon_type == 'grafana':
             cephadm_config, deps = self._generate_grafana_config()
             extra_args.extend(['--config-json', '-'])
+        elif daemon_type == 'nfs':
+            cephadm_config.update(
+                    self._get_config_and_keyring(
+                        daemon_type, daemon_id,
+                        keyring=keyring,
+                        extra_config=extra_config))
+            extra_args.extend(['--config-json', '-'])
         elif daemon_type == 'alertmanager':
             cephadm_config, deps = self._generate_alertmanager_config()
             extra_args.extend(['--config-json', '-'])
         else:
+            # Ceph.daemons (mon, mgr, mds, osd, etc)
             cephadm_config = self._get_config_and_keyring(
                     daemon_type, daemon_id,
                     keyring=keyring,
@@ -2529,6 +2540,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
                 daemon_type, daemon_id, host))
             if daemon_type == 'mon':
                 args.append((daemon_id, host, network))  # type: ignore
+            elif daemon_type == 'nfs':
+                args.append((daemon_id, host, spec)) # type: ignore
             else:
                 args.append((daemon_id, host))  # type: ignore
 
@@ -2743,6 +2756,17 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
     def apply_rbd_mirror(self, spec):
         return self._apply(spec)
 
+    def add_nfs(self, spec):
+        return self._add_daemon('nfs', spec, self._create_nfs)
+
+    def _create_nfs(self, daemon_id, host, spec):
+        nfs = NFSGanesha(self, daemon_id, spec.pool, namespace=spec.namespace)
+        keyring = nfs.create_keyring()
+        cephadm_config = nfs.get_cephadm_config()
+        return self._create_daemon('nfs', daemon_id, host,
+                                   keyring=keyring,
+                                   cephadm_config=cephadm_config)
+
     def _generate_prometheus_config(self):
         # type: () -> Tuple[Dict[str, Any], List[str]]
         deps = []  # type: List[str]
diff --git a/src/pybind/mgr/cephadm/nfs.py b/src/pybind/mgr/cephadm/nfs.py
new file mode 100644 (file)
index 0000000..691a785
--- /dev/null
@@ -0,0 +1,45 @@
+from typing import Dict, Optional
+
+import cephadm
+
+class NFSGanesha(object):
+    def __init__(self,
+                 mgr,
+                 daemon_id,
+                 pool,
+                 namespace=None):
+        # type: (cephadm.CephadmOrchestrator, str, str, Optional[str]) -> None
+        self.daemon_type = 'nfs'
+        self.daemon_id = daemon_id
+
+        self.mgr = mgr
+
+        # rados pool config
+        self.pool = pool
+        self.namespace = namespace
+
+    def get_daemon_name(self):
+        # type: () -> str
+        return '%s.%s' % (self.daemon_type, self.daemon_id)
+
+    def get_rados_user(self):
+        # type: () -> str
+        return 'admin' # TODO: 'nfs.' + self.daemon_id
+
+    def create_keyring(self):
+        # type: () -> str
+        ret, keyring, err = self.mgr.mon_command({
+            'prefix': 'auth get',
+            'entity': 'client.' + self.get_rados_user(),
+        })
+        return keyring
+
+    def get_cephadm_config(self):
+        # type: () -> Dict
+        config = {'pool' : self.pool} # type: Dict
+        if self.namespace:
+            config['namespace'] = self.namespace
+        config['files'] = {
+            'ganesha.conf' : '', # TODO: add ganesha.conf
+        }
+        return config