Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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