]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/ssh: add 'ssh get-pub-key' and 'ssh get-user' commands
authorSage Weil <sage@redhat.com>
Mon, 18 Nov 2019 01:25:56 +0000 (19:25 -0600)
committerSage Weil <sage@redhat.com>
Thu, 21 Nov 2019 18:40:53 +0000 (12:40 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/ssh/module.py

index 97bfffa850d8c3b3ec8770875dd09c48a0c1be69..09a966900a4b3c8103d17c4e76dbaace68a009d7 100644 (file)
@@ -245,8 +245,8 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
         # identity
         ssh_key = self.get_store("ssh_identity_key")
         ssh_pub = self.get_store("ssh_identity_pub")
-        tpub = None
-        tkey = None
+        self.ssh_pub = ssh_pub
+        self.ssh_key = ssh_key
         if ssh_key and ssh_pub:
             tkey = tempfile.NamedTemporaryFile(prefix='ceph-mgr-ssh-identity-')
             tkey.write(ssh_key.encode('utf-8'))
@@ -266,6 +266,9 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
             self._ssh_options = None
         self.log.info('ssh_options %s' % ssh_options)
 
+        # for now, always root
+        self.ssh_user = 'root'
+
     @staticmethod
     def can_run():
         if remoto is not None:
@@ -336,6 +339,21 @@ class SSHOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
         self.ssh_config_tmp = None
         return 0, "", ""
 
+    @orchestrator._cli_read_command(
+        'ssh get-pub-key',
+        desc='Show SSH public key for connecting to cluster hosts')
+    def _get_pub_key(self):
+        if self.ssh_pub:
+            return 0, self.ssh_pub, ''
+        else:
+            return -errno.ENOENT, '', 'No cluster SSH key defined'
+
+    @orchestrator._cli_read_command(
+        'ssh get-user',
+        desc='Show user for SSHing to cluster hosts')
+    def _get_user(self):
+        return 0, self.ssh_user, ''
+
     def _get_connection(self, host):
         """
         Setup a connection for running commands on remote host.