Check ssh-agent
This commit is contained in:
parent
b58b9c3296
commit
7ee473c9b6
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from os import mkdir
|
from os import mkdir
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
|
from subprocess import STDOUT
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from emoji import emojize
|
from emoji import emojize
|
||||||
@ -11,8 +12,8 @@ from PyInquirer import prompt
|
|||||||
from autonomic.config import CONFIG_DIR, CONFIG_YAML, INFRA_DIR, INFRA_REPO
|
from autonomic.config import CONFIG_DIR, CONFIG_YAML, INFRA_DIR, INFRA_REPO
|
||||||
from autonomic.infra import members
|
from autonomic.infra import members
|
||||||
from autonomic.logger import log
|
from autonomic.logger import log
|
||||||
from autonomic.settings import add, get
|
from autonomic.settings import add
|
||||||
from autonomic.utils import qlist, run
|
from autonomic.utils import is_proc, qlist, run
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@ -24,6 +25,7 @@ def init(ctx):
|
|||||||
clone_infrastructure_repo()
|
clone_infrastructure_repo()
|
||||||
store_username()
|
store_username()
|
||||||
install_dependencies()
|
install_dependencies()
|
||||||
|
ssh_sanity_check()
|
||||||
|
|
||||||
|
|
||||||
def create_configuration_directory():
|
def create_configuration_directory():
|
||||||
@ -36,29 +38,21 @@ def clone_infrastructure_repo():
|
|||||||
"""Clone or update the infrastructure repository."""
|
"""Clone or update the infrastructure repository."""
|
||||||
if not exists(INFRA_DIR):
|
if not exists(INFRA_DIR):
|
||||||
cmd = ["git", "clone", INFRA_REPO, INFRA_DIR]
|
cmd = ["git", "clone", INFRA_REPO, INFRA_DIR]
|
||||||
run(cmd)
|
run(cmd, stderr=STDOUT)
|
||||||
else:
|
else:
|
||||||
cmd = ["git", "pull", "origin", "master"]
|
cmd = ["git", "pull", "origin", "master"]
|
||||||
run(cmd, cwd=INFRA_DIR)
|
run(cmd, cwd=INFRA_DIR, stderr=STDOUT)
|
||||||
|
|
||||||
|
|
||||||
def store_username():
|
def store_username():
|
||||||
"""Store Autonomic username in the settings."""
|
"""Store Autonomic username in the settings."""
|
||||||
if exists(CONFIG_YAML):
|
|
||||||
username = get("username")
|
|
||||||
if username is not None:
|
|
||||||
msg = "Username already configured as {}".format(username)
|
|
||||||
log.info(msg)
|
|
||||||
return
|
|
||||||
|
|
||||||
usernames = members(flatten="username")
|
usernames = members(flatten="username")
|
||||||
question = qlist("username", "What is you Autonomic username?", usernames)
|
question = qlist("username", "What is you Autonomic username?", usernames)
|
||||||
answer = prompt(question)
|
answer = prompt(question)
|
||||||
add(answer)
|
add(answer)
|
||||||
|
|
||||||
msg = "Welcome comrade {} :kissing:".format(answer["username"])
|
msg = "Welcome comrade {} :kissing:".format(answer["username"])
|
||||||
emojized = emojize(msg, use_aliases=True)
|
log.success(emojize(msg, use_aliases=True))
|
||||||
log.info(emojized)
|
|
||||||
|
|
||||||
|
|
||||||
def create_settings_file():
|
def create_settings_file():
|
||||||
@ -71,10 +65,10 @@ def create_settings_file():
|
|||||||
def install_dependencies():
|
def install_dependencies():
|
||||||
"""Install infrastructure dependencies."""
|
"""Install infrastructure dependencies."""
|
||||||
cmd = ["/usr/bin/python3", "-m", "venv", ".venv"]
|
cmd = ["/usr/bin/python3", "-m", "venv", ".venv"]
|
||||||
run(cmd, cwd=INFRA_DIR)
|
run(cmd, cwd=INFRA_DIR, stderr=STDOUT)
|
||||||
|
|
||||||
cmd = [".venv/bin/pip", "install", "-r", "requirements.txt"]
|
cmd = [".venv/bin/pip", "install", "-r", "requirements.txt"]
|
||||||
run(cmd, cwd=INFRA_DIR)
|
run(cmd, stderr=STDOUT)
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
".venv/bin/ansible-galaxy",
|
".venv/bin/ansible-galaxy",
|
||||||
@ -83,4 +77,14 @@ def install_dependencies():
|
|||||||
"requirements.yml",
|
"requirements.yml",
|
||||||
"--force",
|
"--force",
|
||||||
]
|
]
|
||||||
run(cmd, cwd=INFRA_DIR)
|
run(cmd, stderr=STDOUT)
|
||||||
|
|
||||||
|
|
||||||
|
def ssh_sanity_check():
|
||||||
|
"""Try to recommend some SSH tips."""
|
||||||
|
if not is_proc("ssh-agent"):
|
||||||
|
msg = "ssh-agent is not running :confounded:"
|
||||||
|
log.warning(emojize(msg, use_aliases=True))
|
||||||
|
else:
|
||||||
|
msg = "ssh-agent is running :rocket:"
|
||||||
|
log.success(emojize(msg, use_aliases=True))
|
||||||
|
@ -10,6 +10,8 @@ things here.
|
|||||||
from os import chdir
|
from os import chdir
|
||||||
from subprocess import CalledProcessError, check_output
|
from subprocess import CalledProcessError, check_output
|
||||||
|
|
||||||
|
from psutil import process_iter
|
||||||
|
|
||||||
from autonomic.logger import log
|
from autonomic.logger import log
|
||||||
from autonomic.yaml import yaml
|
from autonomic.yaml import yaml
|
||||||
|
|
||||||
@ -71,3 +73,14 @@ def yaml_dump(fpath, data):
|
|||||||
yaml.dump(data, handle)
|
yaml.dump(data, handle)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
log.error(str(exception))
|
log.error(str(exception))
|
||||||
|
|
||||||
|
|
||||||
|
def is_proc(name):
|
||||||
|
"""Determine if a process is running or not."""
|
||||||
|
for process in process_iter():
|
||||||
|
try:
|
||||||
|
if name.lower() in process.name().lower():
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
@ -45,6 +45,7 @@ install_requires =
|
|||||||
click >= 7.1.1, <= 8.0
|
click >= 7.1.1, <= 8.0
|
||||||
colorama >= 0.4.3, <= 0.5
|
colorama >= 0.4.3, <= 0.5
|
||||||
emoji >= 0.5.4, <= 0.6
|
emoji >= 0.5.4, <= 0.6
|
||||||
|
psutil >= 5.7.0, <= 6.0
|
||||||
pyinquirer >= 1.0.3, <= 1.1
|
pyinquirer >= 1.0.3, <= 1.1
|
||||||
ruamel.yaml >= 0.16.10, <= 0.17
|
ruamel.yaml >= 0.16.10, <= 0.17
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user