Skip to content

Instantly share code, notes, and snippets.

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 eyasuyuki/cdb031b64ca20148f5a449f088286296 to your computer and use it in GitHub Desktop.
Save eyasuyuki/cdb031b64ca20148f5a449f088286296 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import sys
import commands
hosts = """\
[docker]
{0}
"""
ssh_config = """\
Host {0}
HostName {1}
User docker
UserKnownHostsFile /dev/null
IdentityFile ~/.docker/machine/machines/{0}/id_rsa
StrictHostKeyChecking no
"""
def usage(param):
print "python " + param[0] + " <vm name>"
exit(-1)
if __name__ == "__main__":
param = sys.argv
if len(param) <= 1:
usage(param)
ip = commands.getoutput("docker-machine ip "+param[1])
# hosts
f = open('hosts', 'w')
f.write(hosts.format(param[1]))
f.close()
# ssh_config
f = open('ssh_config', 'w')
f.write(ssh_config.format(param[1], ip))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment