Beispiel #1
0
def download_files_to_minion(host, usr, pwd):
    ssh = paramiko.SSHClient()
    try:
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(host, username=usr, password=pwd)
        scp = SCPClient(ssh.get_transport(), progress=progress)

        scp.put(os.path.join(_OP_FOLDER_PATH, 'MACsec_minion_dependencies'),
                recursive=True,
                remote_path="/var/db/scripts/commit")
        scp.put(os.path.join(_OP_FOLDER_PATH, 'local_minion.py'),
                remote_path="/var/db/scripts/commit")
        scp.put(os.path.join(_OP_FOLDER_PATH, 'minion_environment.yaml'),
                remote_path="/var/db/scripts/commit")
        scp.put(os.path.join(_OP_FOLDER_PATH, 'delete_MACsec_interface.py'),
                remote_path="/var/db/scripts/op")

        ssh.close()
    except Exception as err:
        print(err)
        return
    else:
        ssh.close()
Beispiel #2
0
    )
    print("[[hash algorism number]] 1: MD5, 2: SHA-1, 3: SHA-256, 4: SHA-512")
    sys.exit(1)

ssh = SSHClient()
ssh.load_system_host_keys()
# ssh.connect('192.168.7.71',username='******',password='******')
# print(sys.argv[1], type(sys.argv[1]))
ssh.connect(sys.argv[1], username=sys.argv[2], password=sys.argv[3])

# SCPCLient takes a paramiko transport as an argument
scp = SCPClient(ssh.get_transport())

# Uploading the 'test' directory with its content in the
# '/home/user/dump' remote directory
scp.put(sys.argv[4], recursive=True, remote_path='/home/lsiem/')

# send hash value file
BLOCKSIZE = 65536

if sys.argv[5] == '1':
    hasher = hashlib.md5()
elif sys.argv[5] == '2':
    hasher = hashlib.sha1()
elif sys.argv[5] == '3':
    hasher = hashlib.sha256()
elif sys.argv[5] == '4':
    hasher = hashlib.sha512()
else:
    print("not defined hash algorism number error")
Beispiel #3
0
def upload(ssh, script, targetdir):
    """upload a file to remote"""
    scp = SCPClient(ssh.get_transport())
    scp.put(script, targetdir)
Beispiel #4
0
def download_files_to_master(host, usr, pwd):
    if host == 'localhost':
        print(
            'copying MACsec_master_dependencies to /var/db/scripts/jet/MACsec_master_dependencies...'
        )
        cpdir(os.path.join(_OP_FOLDER_PATH, 'MACsec_master_dependencies'),
              '/var/db/scripts/jet/MACsec_master_dependencies')
        print('copying remote_master.py to /var/db/scripts/jet/...')
        copyfile(os.path.join(_OP_FOLDER_PATH, 'remote_master.py'),
                 '/var/db/scripts/jet/remote_master.py')
        print('copying master_environment.yaml to /var/db/scripts/jet/...')
        copyfile(os.path.join(_OP_FOLDER_PATH, 'master_environment.yaml'),
                 '/var/db/scripts/jet/master_environment.yaml')

        print(
            'copying MACsec_minion_dependencies to /var/db/scripts/commit/...')
        cpdir(os.path.join(_OP_FOLDER_PATH, 'MACsec_minion_dependencies'),
              '/var/db/scripts/commit/MACsec_minion_dependencies')
        print('copying local_minion.py to /var/db/scripts/commit/...')
        copyfile(os.path.join(_OP_FOLDER_PATH, 'local_minion.py'),
                 '/var/db/scripts/commit/local_minion.py')
        print('minion_environment.yaml to /var/db/scripts/commit/...')
        copyfile(os.path.join(_OP_FOLDER_PATH, 'minion_environment.yaml'),
                 '/var/db/scripts/commit/minion_environment.yaml')
    else:
        ssh = paramiko.SSHClient()
        try:
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            ssh.connect(host, username=usr, password=pwd)
            scp = SCPClient(ssh.get_transport(), progress=progress)

            scp.put(os.path.join(_OP_FOLDER_PATH,
                                 'MACsec_master_dependencies'),
                    recursive=True,
                    remote_path="/var/db/scripts/op")
            scp.put(os.path.join(_OP_FOLDER_PATH,
                                 'MACsec_master_dependencies'),
                    recursive=True,
                    remote_path="/var/db/scripts/jet")

            scp.put(os.path.join(_OP_FOLDER_PATH, 'remote_master.py'),
                    remote_path="/var/db/scripts/op")
            scp.put(os.path.join(_OP_FOLDER_PATH, 'remote_master.py'),
                    remote_path="/var/db/scripts/jet")
            scp.put(os.path.join(_OP_FOLDER_PATH, 'master_environment.yaml'),
                    remote_path="/var/db/scripts/op")
            scp.put(os.path.join(_OP_FOLDER_PATH, 'master_environment.yaml'),
                    remote_path="/var/db/scripts/jet")

            scp.put(os.path.join(_OP_FOLDER_PATH,
                                 'MACsec_minion_dependencies'),
                    recursive=True,
                    remote_path="/var/db/scripts/commit")

            scp.put(os.path.join(_OP_FOLDER_PATH, 'local_minion.py'),
                    remote_path="/var/db/scripts/commit")
            scp.put(os.path.join(_OP_FOLDER_PATH, 'minion_environment.yaml'),
                    remote_path="/var/db/scripts/commit")
            scp.put(os.path.join(_OP_FOLDER_PATH,
                                 'delete_MACsec_interface.py'),
                    remote_path="/var/db/scripts/op")

            ssh.close()
        except Exception as err:
            print(err)
            return
        else:
            ssh.close()