def _setSSH(self):
        """
        Generate a key pair, save it in /root/.ssh/id_rsa.pub, and return the public key.
        The file /root/.sshSuccess is used to prevent this operation from running twice.
        :return Public key.
        """
        if not os.path.exists('/root/.sshSuccess'):
            subprocess.check_call(['ssh-keygen', '-f', '/root/.ssh/id_rsa', '-t', 'rsa', '-N', ''])
            with open('/root/.sshSuccess', 'w') as f:
                f.write('written here because of restrictive permissions on .ssh dir')
        os.chmod('/root/.ssh', 0o700)
        subprocess.check_call(['bash', '-c', 'eval $(ssh-agent) && ssh-add -k'])
        with open('/root/.ssh/id_rsa.pub') as f:
            masterPublicKey = f.read()
        masterPublicKey = masterPublicKey.split(' ')[1]  # take 'body' of key
        # confirm it really is an RSA public key
        assert masterPublicKey.startswith('AAAAB3NzaC1yc2E'), masterPublicKey
        return masterPublicKey
def _setSSH ( self ) : if not os . path . exists ( '/root/.sshSuccess' ) : subprocess . check_call ( [ 'ssh-keygen' , '-f' , '/root/.ssh/id_rsa' , '-t' , 'rsa' , '-N' , '' ] ) with open ( '/root/.sshSuccess' , 'w' ) as f : f . write ( 'written here because of restrictive permissions on .ssh dir' ) os . chmod ( '/root/.ssh' , 0o700 ) subprocess . check_call ( [ 'bash' , '-c' , 'eval $(ssh-agent) && ssh-add -k' ] ) with open ( '/root/.ssh/id_rsa.pub' ) as f : masterPublicKey = f . read ( ) masterPublicKey = masterPublicKey . split ( ' ' ) [ 1 ] assert masterPublicKey . startswith ( 'AAAAB3NzaC1yc2E' ) , masterPublicKey return masterPublicKey
Generate a key pair, save it in /root/.ssh/id_rsa.pub, and return the public key.
        The file /root/.sshSuccess is used to prevent this operation from running twice.
        :return Public key.