Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def sshConfig(self, name):
p = Popen(['vagrant', 'ssh-config', name],
stdout=PIPE,
stderr=None,
stdin=None,
cwd='tests/',
)
p.wait()
if p.returncode != 0:
raise RuntimeError('Could not get ssh-config for ' + repr(name))
ssh_config = paramiko.SSHConfig()
ssh_config.parse(p.stdout)
p.stdout.close()
return ssh_config.lookup(name)
def __init__(self, *args, **kwargs):
wat = "You're giving ssh_config explicitly, please use Config_!"
assert "ssh_config" not in kwargs, wat
# Give ssh_config explicitly -> shorter way of turning off loading
kwargs["ssh_config"] = SSHConfig()
super(Config, self).__init__(*args, **kwargs)
#but by 'name' only.
computer = Computer.get(machine)
print >> sys.stderr, "Using the existing computer {}...".format(computername)
except NotExistent:
print >> sys.stderr, "Creating a new computer..."
computer = Computer(hostname=computername,transport_type='ssh',
scheduler_type=schedulertype)
computer.set_workdir(workdir)
#computer.set_mpirun_command(mpirun_command)
computer.store()
auth_params = {'load_system_host_keys': True,
'compress': True}
config = paramiko.SSHConfig()
try:
config.parse(open(os.path.expanduser('~/.ssh/config')))
except IOError:
# No file found, so empty configuration
pass
# machine_config is a dict with only relevant properties set
machine_config = config.lookup(computername)
try:
auth_params['username'] = machine_config['user']
except KeyError:
# No user set up in the config file: I explicitly set the local username
auth_params['username'] = getpass.getuser()
try:
auth_params['key_filename'] = os.path.expanduser(
def connect_rhost(rhost):
rssh = paramiko.SSHClient()
rssh.load_system_host_keys()
rssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_config = paramiko.SSHConfig()
user_config_file = os.path.expanduser("~/.ssh/config")
if os.path.exists(user_config_file):
with open(user_config_file) as f:
ssh_config.parse(f)
#cfg = {'hostname': rhost, 'username': options["username"]}
cfg = {'hostname': rhost}
user_config = ssh_config.lookup(cfg['hostname'])
#for k in ('hostname', 'username', 'port'):
for k in ('hostname', 'port'):
if k in user_config:
cfg[k] = user_config[k]
cfg['username'] = USERNAME
if 'proxycommand' in user_config:
def _read_ssh_config_host(host):
ssh_config_file = os.path.expanduser("~/.ssh/config")
if os.path.exists(ssh_config_file):
conf = paramiko.SSHConfig()
with open(ssh_config_file) as f:
conf.parse(f)
return conf.lookup(host)['hostname'] if not None else host
return host
def connect(self, host):
# ssh config file
config = SSHConfig()
config.parse(open('%s/.ssh/config' % os.environ['HOME']))
o = config.lookup(host)
# ssh client
self.ssh_client = ssh = SSHClient()
ssh.load_system_host_keys()
ssh.connect(o['hostname'], username=o['user'], key_filename=o['identityfile'])
self.sftp_client = ssh.open_sftp()
def __init__(self, host, port=29418, user=None,
key=None, config="~/.ssh/config"):
self.key = key
self.host = host
self.port = port
self.user = user
config = os.path.expanduser(config)
if os.path.exists(config):
ssh = paramiko.SSHConfig()
ssh.parse(open(config))
conf = ssh.lookup(host)
self.host = conf['hostname']
self.port = int(conf.get('port', self.port))
self.user = conf.get('user', self.user)
self.key = conf.get('identityfile', self.key)
def _configure(self):
""" Configure the ssh parameters from the config file. """
configfile = expanduser("~/.ssh/config")
if not isfile(configfile):
raise GerritError("ssh config file '%s' does not exist" %
configfile)
config = SSHConfig()
config.parse(open(configfile))
data = config.lookup(self.hostname)
if not data:
raise GerritError("No ssh config for host %s" % self.hostname)
if 'hostname' not in data or 'port' not in data or 'user' not in data:
raise GerritError("Missing configuration data in %s" % configfile)
self.hostname = data['hostname']
self.username = data['user']
if 'identityfile' in data:
key_filename = abspath(expanduser(data['identityfile'][0]))
if not isfile(key_filename):
raise GerritError("Identity file '%s' does not exist" %
key_filename)
self.key_filename = key_filename
try:
self.port = int(data['port'])
def merge_ssh_config(args):
"""Merge the local SSH config into next-review's config."""
ssh_config = paramiko.SSHConfig()
try:
ssh_config.parse(open(os.path.expanduser('~/.ssh/config')))
except IOError:
# The user does not have an SSH config file (FileNotFoundError on py3),
# so just bail.
return
host_config = ssh_config.lookup(args.host)
if 'user' in host_config and not args.username:
args.username = host_config['user']
if 'identityfile' in host_config and not args.key:
args.key = host_config['identityfile']