]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/mgr_module: add tool_exec() command
authorSage Weil <sage@newdream.net>
Thu, 28 Oct 2021 22:11:38 +0000 (18:11 -0400)
committerMichael Fritch <mfritch@suse.com>
Fri, 29 Oct 2021 20:03:21 +0000 (14:03 -0600)
Run a (ceph) tool with the appropriate keyring and entity name.

Signed-off-by: Sage Weil <sage@newdream.net>
src/pybind/mgr/mgr_module.py

index fa71980ee99dcb28b303a273ad53d2aa4813c566..73839000cd56533dcedfc305eae4cb46b39a10ef 100644 (file)
@@ -1557,6 +1557,34 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin):
         """
         self._ceph_send_command(result, svc_type, svc_id, command, tag, inbuf)
 
+    def tool_exec(
+        self,
+        args: List[str],
+        timeout: int = 10,
+        stdin: Optional[bytes] = None
+    ) -> Tuple[int, str, str]:
+        try:
+            tool = args.pop(0)
+            cmd = [
+                tool,
+                '-k', str(self.get_ceph_option('keyring')),
+                '-n', f'mgr.{self.get_mgr_id()}',
+            ] + args
+            self.log.debug('exec: ' + ' '.join(cmd))
+            p = subprocess.run(
+                cmd,
+                input=stdin,
+                stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE,
+                timeout=timeout,
+            )
+        except subprocess.TimeoutExpired as ex:
+            self.log.error(ex)
+            return -errno.ETIMEDOUT, '', str(ex)
+        if p.returncode:
+            self.log.error(f'Non-zero return from {cmd}: {p.stderr.decode()}')
+        return p.returncode, p.stdout.decode(), p.stderr.decode()
+
     def set_health_checks(self, checks: HealthChecksT) -> None:
         """
         Set the module's current map of health checks.  Argument is a