Copy certificate from master to slaves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

47 lines
1.5 KiB

#!/usr/bin/python
import paramiko
import argparse
import os
from subprocess import list2cmdline
def connection_from_config(name):
"""Create a connection from a Host entry in the .ssh/config file"""
config = paramiko.config.SSHConfig()
cp = os.path.expanduser('~/.ssh/config')
with open(cp) as file:
config.parse(file)
info = config.lookup(name)
info['username'] = info.pop('user')
info['key_filename'] = info.pop('identityfile')
info['port'] = int(info['port'])
client = paramiko.client.SSHClient()
client.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
client.connect(**info)
return client
def scp(connection: paramiko.sftp_client.SFTPClient, src, dst):
"""Function to copy files from src to dst using connection"""
connection.put(src, dst)
def exec_remote(connection: paramiko.SSHClient, command):
"""Function to execute specified command on conection"""
if not isinstance(command, str):
command = list2cmdline(command)
stdin, stdout, stderr = connection.exec_command(command)
return stdout, stderr
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
'cert_path', help="location of the certificate to install")
parser.add_argument(
'key_path', help="localtion of the private key to install")
parser.add_argument(
'store_path',
help="directory to store the private key and certificate")
parser.add_argument('-d', '--dry', action='store_true')
args = parser.parse_args()