Skip to content

Instantly share code, notes, and snippets.

@adam-stokes
Created October 10, 2014 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adam-stokes/633e75d020e93107c95b to your computer and use it in GitHub Desktop.
Save adam-stokes/633e75d020e93107c95b to your computer and use it in GitHub Desktop.
def container_run(name, cmd, nowait=False):
""" run command in container
:param str name: name of container
:param str cmd: command to run
"""
ip = container_ip(name)
cmd = "sudo -H -u {3} TERM=xterm256-color ssh -t -q " \
"-l ubuntu -o \"StrictHostKeyChecking=no\" " \
"-o \"UserKnownHostsFile=/dev/null\" " \
"-i {2} " \
"{0} {1} >>/dev/null".format(ip, cmd, ssh_privkey(), install_user())
if nowait:
log.debug("Running command without waiting for response.")
args = shlex.split(cmd)
Popen(args, stdout=DEVNULL, stderr=DEVNULL)
else:
os.system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment