Skip to content

Commit

Permalink
Only 'vagrant up' if machine is not up
Browse files Browse the repository at this point in the history
First try 'ssh-config'; if that fails, call 'up' and try again.

This also means that 'upload' and 'download' commands now also start the
VM if needed, like 'run' does.
  • Loading branch information
remram44 committed Nov 18, 2014
1 parent 0dcd38c commit 24a087e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions reprounzip-vagrant/reprounzip/unpackers/vagrant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,18 @@ def read_dict(filename):
def get_ssh_parameters(target):
"""Reads the SSH parameters from ``vagrant ssh`` command output.
"""
stdout = subprocess.check_output(['vagrant', 'ssh-config'],
cwd=target.path)
try:
stdout = subprocess.check_output(['vagrant', 'ssh-config'],
cwd=target.path,
stderr=subprocess.PIPE)
except subprocess.CalledProcessError:
# Makes sure the VM is running
subprocess.check_call(['vagrant', 'up'],
cwd=target.path)
# Try again
stdout = subprocess.check_output(['vagrant', 'ssh-config'],
cwd=target.path)

info = {}
for line in stdout.split(b'\n'):
line = line.strip().split(b' ', 1)
Expand Down Expand Up @@ -353,10 +363,6 @@ def vagrant_run(args):
cmds.append(cmd)
cmds = ' && '.join(cmds)

# Makes sure the VM is running
subprocess.check_call(['vagrant', 'up'],
cwd=target.path)

# Gets vagrant SSH parameters
info = get_ssh_parameters(target)

Expand Down

0 comments on commit 24a087e

Please sign in to comment.