Jan Ulrich Hasecke
2019-11-21 47bc28d554b0c474b06cdd291d6e7b8c942af359
commit | author | age
d80dd3 1 import random
JUH 2 import string
3 import sys
4 from hs.admin.api import API
47bc28 5 from subprocess import check_output
JUH 6
7 paketadmin = sys.argv[1]
8 domainname = sys.argv[2]
9 projektid = sys.argv[3]
10
11 pw = check_output(["pass", "hostsharing/"+paketadmin]).decode("utf-8").strip("\n")
d80dd3 12
JUH 13 api = API(cas=dict(
14     uri='https://login.hostsharing.net/cas/v1/tickets',
15     service='https://config.hostsharing.net:443/hsar/backend'),
47bc28 16     credentials=dict(username=paketadmin, password=pw),
d80dd3 17     backends=[
JUH 18         'https://config.hostsharing.net:443/hsar/xmlrpc/hsadmin',
19         'https://config2.hostsharing.net:443/hsar/xmlrpc/hsadmin'])
20
21 def pwGen(stringLength=12):
22     """Function to generate a random password """
23
24     password_characters = string.ascii_letters + string.digits
25     return ''.join(random.choice(password_characters) for i in range(stringLength))
26
27 pw_dadmin = pwGen()
28 pw_dbuser = pwGen()
47bc28 29 dadmin = paketadmin+'-'+domainname.replace("-", "_")
JUH 30 dbuser = paketadmin+'_'+projektid
31 dbname = paketadmin+'_'+projektid
d80dd3 32
47bc28 33 api.user.add(set={'name': dadmin, 'password': pw_dadmin, 'shell': '/bin/bash'})
JUH 34 api.domain.add(set={'name': domainname, 'user': dadmin})
35 api.mysqluser.add(set={'name': dbuser, 'password': pw_dbuser})
36 api.mysqldb.add(set={'name': dbname, 'owner': dbuser})
d80dd3 37
JUH 38 print("Domainname:" +domainname)
47bc28 39 print("Domain-Admin: " + dadmin + " mit dem Passwort:" +pw_dadmin)
JUH 40 print("Datenbank-Nutzer: " +dbuser + " Passwort:" +pw_dbuser)
41 print("Datenbankname: " +dbname)