Skip to content

Instantly share code, notes, and snippets.

@johnpauljanecek
Created July 23, 2015 22:55
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 johnpauljanecek/a91d45cf1ba6a03f5993 to your computer and use it in GitHub Desktop.
Save johnpauljanecek/a91d45cf1ba6a03f5993 to your computer and use it in GitHub Desktop.
common.py - file needed by digital_oceanconfig.py
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