a
This commit is contained in:
commit
d51f7fcbfd
7 changed files with 153 additions and 0 deletions
0
app/__init__
Normal file
0
app/__init__
Normal file
41
app/api.py
Normal file
41
app/api.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import click
|
||||
import subprocess
|
||||
|
||||
|
||||
from app.helper import clone, clone_common,\
|
||||
clone_etcd_wrapper, pipenv_install
|
||||
|
||||
@click.group()
|
||||
def api():
|
||||
pass
|
||||
|
||||
@api.command("setup")
|
||||
@click.option("--auth_name", required=True)
|
||||
@click.option("--auth_seed", required=True)
|
||||
@click.option("--auth_realm", required=True)
|
||||
@click.option("--realm_allowed", multiple=True, required=True)
|
||||
@click.option("--otp_server", default="https://otp.ungleich.ch/ungleichotp/",
|
||||
help="URL of ungleich OTP server")
|
||||
|
||||
def setup(auth_name, auth_seed, auth_realm, realm_allowed, otp_server):
|
||||
if clone("https://code.ungleich.ch/ungleich-public/ucloud-api.git"):
|
||||
with open(".env", "w") as env_file:
|
||||
lines = [f"AUTH_NAME={auth_name}",
|
||||
f"AUTH_SEED={auth_seed}",
|
||||
f"AUTH_REALM={auth_seed}",
|
||||
f"REALM_ALLOWED={realm_allowed}",
|
||||
f"OTP_SERVER={otp_server}"]
|
||||
|
||||
env_file.writelines(lines)
|
||||
|
||||
result = []
|
||||
result.append(clone_common())
|
||||
result.append(clone_etcd_wrapper())
|
||||
|
||||
if all(result):
|
||||
result.append(pipenv_install("ucloud-api"))
|
||||
|
||||
if all(result):
|
||||
print("Successfull installation :)")
|
||||
else:
|
||||
print("Unsuccessful installation ;(")
|
||||
36
app/helper.py
Normal file
36
app/helper.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import subprocess
|
||||
|
||||
|
||||
def clone(repo):
|
||||
command = f"git clone {repo}"
|
||||
try:
|
||||
subprocess.check_output(command.split())
|
||||
except subprocess.CalledProcessError as e:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def clone_common():
|
||||
return clone("https://code.ungleich.ch/ungleich-public/ucloud_common")
|
||||
|
||||
def clone_etcd_wrapper():
|
||||
return clone("https://code.ungleich.ch/ahmedbilal/etcd3_wrapper")
|
||||
|
||||
|
||||
class Operation(object):
|
||||
def __init__(self):
|
||||
self.result = []
|
||||
|
||||
def execute(self, rc):
|
||||
self.result.append(rc)
|
||||
|
||||
|
||||
def pipenv_install(_dir):
|
||||
command = f"pipenv install"
|
||||
try:
|
||||
subprocess.check_output(command.split(), cwd=_dir)
|
||||
except subprocess.CalledProcessError as e:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
16
app/scheduler.py
Normal file
16
app/scheduler.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import click
|
||||
import subprocess
|
||||
|
||||
|
||||
@click.group()
|
||||
def scheduler():
|
||||
pass
|
||||
|
||||
|
||||
@scheduler.command("setup")
|
||||
def setup():
|
||||
command = "git clone https://code.ungleich.ch/ungleich-public/ucloud-scheduler.git"
|
||||
try:
|
||||
subprocess.check_output(command.split())
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Some Error Occurrred", e)
|
||||
Loading…
Add table
Add a link
Reference in a new issue