Created
July 23, 2015 22:55
-
-
Save johnpauljanecek/a91d45cf1ba6a03f5993 to your computer and use it in GitHub Desktop.
common.py - file needed by digital_oceanconfig.py
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
import os,subprocess,plumbum | |
import servers.secret as secret | |
sshDir = "%s/.ssh" % os.environ['HOME'] | |
def create_ssh_dir(): | |
if not os.path.exists(sshDir): | |
os.mkdir(sshDir) | |
def install_pip2(ssh): | |
""" | |
ssh : a plumdum machine <SshMachine ssh://root@128.199.177.1> | |
""" | |
try: | |
return ssh["pip2"]("--version") | |
except plumbum.CommandNotFound: | |
ssh["apt-get"]["install"]["python-pip"]("-y") | |
return ssh["pip2"]("--version") | |
def add_to_known_host(hostName): | |
ipScanStr = "ssh-keyscan -H {hostName} >> {sshDir}/known_hosts" | |
nameScanStr = "ssh-keyscan {hostName} >> {sshDir}/known_hosts" | |
subprocess.call(ipScanStr.format(hostName = hostName,sshDir = sshDir),shell=True) | |
subprocess.call(nameScanStr.format(hostName = hostName,sshDir = sshDir),shell=True) | |
def write_base_ssh_config(): | |
create_ssh_dir() | |
with open(os.path.join(sshDir,"id_rsa"),"wt") as f: | |
f.write(secret.idRsa) | |
subprocess.call("sudo chmod 600 %s" % os.path.join(sshDir,"id_rsa"),shell=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment