Created
July 1, 2016 05:10
-
-
Save eyasuyuki/cdb031b64ca20148f5a449f088286296 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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