Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for host, (guest, proto) in iteritems(all_ports))
write_vagrantfile(target, unpacked_info)
logger.info("Some requested ports are not yet forwarded, running "
"'vagrant reload'")
retcode = subprocess.call(['vagrant', 'reload', '--no-provision'],
cwd=target.path)
if retcode != 0:
logger.critical("vagrant reload failed with code %d, aborting",
retcode)
sys.exit(1)
write_dict(target, unpacked_info)
# X11 handler
if unpacked_info['gui']:
x11 = LocalX11Handler()
else:
x11 = X11Handler(args.x11, ('local', hostname), args.x11_display)
cmds = []
for run_number in selected_runs:
run = runs[run_number]
cmd = 'cd %s && ' % shell_escape(run['workingdir'])
if use_chroot:
cmd += '/busybox env -i '
else:
cmd += '/usr/bin/env -i '
environ = x11.fix_env(run['environ'])
environ = fixup_environment(environ, args)
cmd += ' '.join('%s=%s' % (shell_escape(k), shell_escape(v))
for k, v in iteritems(environ))
cmd += ' '
def _new_connection(self, channel, src_addr, dest_addr):
# Wraps the channel as a socket-like object that _forward() can use
socklike = self._ChannelWrapper(channel)
t = threading.Thread(target=self._forward,
args=(socklike, src_addr))
t.setDaemon(True)
t.start()
def vagrant_download(args):
"""Gets an output file out of the VM.
"""
target = Path(args.target[0])
files = args.file
use_chroot = read_dict(target)['use_chroot']
SSHDownloader(target, files, use_chroot, all_=args.all)
def vagrant_upload(args):
"""Replaces an input file in the VM.
"""
target = Path(args.target[0])
files = args.file
unpacked_info = read_dict(target)
input_files = unpacked_info.setdefault('input_files', {})
use_chroot = unpacked_info['use_chroot']
try:
SSHUploader(target, input_files, files, use_chroot)
finally:
write_dict(target, unpacked_info)
'-i', ssh_info['key_filename'],
'-p', '%d' % ssh_info['port']]
for remote_port, connector in forwarded_ports:
# Remote port will connect to a local port
fwd = LocalForwarder(connector)
args.append('-R%d:127.0.0.1:%d' % (remote_port, fwd.local_port))
args.append('%s@%s' % (ssh_info['username'],
ssh_info['hostname']))
args.append(cmd)
return interruptible_call(args)
else:
record_usage(vagrant_ssh='interactive' if interactive else 'simple')
# Connects to the machine
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(IgnoreMissingKey())
ssh.connect(**ssh_info)
# Starts forwarding
forwarders = []
for remote_port, connector in forwarded_ports:
forwarders.append(
SSHForwarder(ssh.get_transport(), remote_port, connector))
chan = ssh.get_transport().open_session()
if request_pty:
chan.get_pty()
# Execute command
logger.info("Connected via SSH, running command...")
chan.exec_command(cmd)
ssh_info['hostname']))
args.append(cmd)
return interruptible_call(args)
else:
record_usage(vagrant_ssh='interactive' if interactive else 'simple')
# Connects to the machine
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(IgnoreMissingKey())
ssh.connect(**ssh_info)
# Starts forwarding
forwarders = []
for remote_port, connector in forwarded_ports:
forwarders.append(
SSHForwarder(ssh.get_transport(), remote_port, connector))
chan = ssh.get_transport().open_session()
if request_pty:
chan.get_pty()
# Execute command
logger.info("Connected via SSH, running command...")
chan.exec_command(cmd)
# Get output
if interactive:
interactive_shell(chan)
else:
chan.shutdown_write()
while True:
data = chan.recv(1024)