Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

support create ssh connection by using sshkey #1950

Closed
tyusr opened this issue Jan 13, 2020 · 0 comments
Closed

support create ssh connection by using sshkey #1950

tyusr opened this issue Jan 13, 2020 · 0 comments

Comments

@tyusr
Copy link
Contributor

tyusr commented Jan 13, 2020

What would you like to be added:
nnictl create ssh connection using ssh-key

Why is this needed:
ssh-key connection support in nnictl create by sshKeyPath param in config.yml, but nnictl experiment delete only use password to create ssh connection:

def remote_clean(machine_list, experiment_id=None):
'''clean up remote data'''
for machine in machine_list:
passwd = machine.get('passwd')
userName = machine.get('username')
host = machine.get('ip')
port = machine.get('port')
if experiment_id:
remote_dir = '/' + '/'.join(['tmp', 'nni', 'experiments', experiment_id])
else:
remote_dir = '/' + '/'.join(['tmp', 'nni', 'experiments'])
sftp = create_ssh_sftp_client(host, port, userName, passwd)
print_normal('removing folder {0}'.format(host + ':' + str(port) + remote_dir))
remove_remote_directory(sftp, remote_dir)

Without this feature, how does current nni work
Can not use nnictl experiment delete in remote mode

Components that may involve changes:
Any code calls function create_ssh_sftp_client in nni/tools/nni_cmd/ssh_utils.py

Brief description of your proposal if any:
Maybe add an input param for create_ssh_sftp_client? Like this:

def create_ssh_sftp_client(host_ip, port, username, password, ssh_key_path=None, passphrase=None):
    '''create ssh client'''
    try:
        paramiko = check_environment()
        conn = paramiko.Transport(host_ip, port)
        ssh_key = paramiko.from_private_key_file(ssh_key_path, password=passphrase) if ssh_key_path else None 
        conn.connect(username=username, password=password, pkey=ssh_key)
        sftp = paramiko.SFTPClient.from_transport(conn)
        return sftp
    except Exception as exception:
        print_error('Create ssh client error %s\n' % exception)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants