ucloud-setup/app/scheduler.py
2019-08-30 06:23:45 +05:00

66 lines
1.6 KiB
Python

import click
import subprocess
import os
import shutil
from app.helper import (
clone,
clone_common,
clone_etcd_wrapper,
GitOperation,
PipenvOperation,
FileOperation,
)
@click.group()
def scheduler():
pass
@scheduler.command("setup")
@click.option("--path", required=True)
@click.option("--vm_prefix", required=True)
@click.option("--host_prefix", required=True)
@click.option("--request_prefix", required=True)
@click.option("--etcd_url", required=True)
@click.option("--etcd_password", required=True)
def setup(path, vm_prefix, host_prefix, request_prefix, etcd_url, etcd_password):
os.chdir(path)
repo_name = "ucloud-scheduler"
op_result = GitOperation.clone(
f"https://code.ungleich.ch/ungleich-public/{repo_name}.git"
)
content = (
f"VM_PREFIX={vm_prefix}\n"
f"HOST_PREFIX={host_prefix}\n"
f"REQUEST_PREFIX={request_prefix}\n"
f"ETCD_URL={etcd_url}\n"
f"ETCD_PASSWORD={etcd_password}\n"
)
op_result.add(
FileOperation.write, path=os.path.join(repo_name, ".env"), content=content
)
op_result.add(
GitOperation.clone,
path=repo_name,
url="https://code.ungleich.ch/ungleich-public/ucloud_common",
)
op_result.add(
GitOperation.clone,
path=repo_name,
url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper",
)
shutil.copytree(
src=os.path.join(repo_name, "etcd3_wrapper"),
dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"),
)
op_result.add(PipenvOperation.install, path=repo_name)