ucloud-setup/app/ceph.py

27 lines
897 B
Python
Raw Normal View History

2019-08-29 12:23:54 +00:00
import click
import os
import subprocess
@click.group()
def ceph():
pass
@ceph.command("setup")
@click.option("--ceph_url", required=True)
@click.option("--ssh_username", required=True)
def setup(ceph_url, ssh_username):
2019-08-29 13:31:38 +00:00
try:
os.makedirs("/etc/ceph", exist_ok=True)
command = f"sftp -b ./ceph_batch_cmd {ssh_username}@{ceph_url}:/etc/ceph"
subprocess.check_output(command.split())
except Exception:
p = subprocess.check_output(f"ssh-keyscan {ceph_url}".split())
2019-08-29 13:34:17 +00:00
keys = p.decode("utf-8").strip().split("\n")
2019-08-29 13:37:44 +00:00
keys = "\n".join(keys)
2019-08-29 13:32:21 +00:00
with open(os.path.expanduser("~/.ssh/known_hosts"), "a") as known_hosts:
2019-08-29 13:41:21 +00:00
known_hosts.write(keys)
2019-08-29 13:39:34 +00:00
os.makedirs("/etc/ceph", exist_ok=True)
command = f"sftp -b ./ceph_batch_cmd {ssh_username}@{ceph_url}:/etc/ceph"
subprocess.check_output(command.split())