a
This commit is contained in:
commit
d51f7fcbfd
7 changed files with 153 additions and 0 deletions
12
Pipfile
Normal file
12
Pipfile
Normal file
|
@ -0,0 +1,12 @@
|
|||
[[source]]
|
||||
name = "pypi"
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[packages]
|
||||
click = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.7"
|
29
Pipfile.lock
generated
Normal file
29
Pipfile.lock
generated
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "e6728243c3982bd95c23ad63dc24514046979d9cf07efbb6dc60150bdf182788"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.7"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13",
|
||||
"sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==7.0"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
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)
|
19
ucloud-setup.py
Normal file
19
ucloud-setup.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import click
|
||||
from app.api import api
|
||||
from app.scheduler import scheduler
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@click.group()
|
||||
def entry_point():
|
||||
pass
|
||||
|
||||
|
||||
entry_point.add_command(api)
|
||||
entry_point.add_command(scheduler)
|
||||
|
||||
if __name__ == "__main__":
|
||||
entry_point()
|
Loading…
Reference in a new issue