Ejemplo n.º 1
0
def get():
    msg = {'err': None, 'res': None}

    try:
        name = request.args.get('name')
        namespace = request.args.get('namespace')

        k = f"{namespace}/{name}"
        v = mydb.get(db_path, k)
        if v is not None:
            msg['res'] = json.loads(v.decode())

        # # deployment
        # cmd = f'kubectl get deployment {name} -n {namespace} -o json'
        # st, res = subprocess.getstatusoutput(cmd)
        # if st != 0:
        #     logger.error(res)
        #     if msg['err'] is None:
        #         msg['err'] = {'k8s': {}}
        #     msg['err']['k8s']['deployment'] = res
        # else:
        #     msg['res']['k8s']['deployment'] = json.loads(res)
        #
        # service
        cmd = f'kubectl get services -l app={name} -n {namespace} -o json'
        st, res = subprocess.getstatusoutput(cmd)
        if st != 0:
            logger.error(res)
            msg['err'] = res
        else:
            obj = json.loads(res)
            if msg['res'] is None:
                msg['res'] = {}
            for item in obj['items']:
                msg['res']['ports'] = item['spec']['ports']
                msg['res']['clusterIP'] = item['spec']['clusterIP']

        # # serviceMonitor
        # cmd = f'kubectl get servicemonitor {name} -n {namespace} -o json'
        # st, res = subprocess.getstatusoutput(cmd)
        # if st != 0:
        #     logger.error(res)
        #     if msg['err'] is None:
        #         msg['err'] = {'k8s': {}}
        #     msg['err']['k8s']['serviceMonitor'] = res
        # else:
        #     obj = json.loads(res)
        #     for item in obj['items']:
        #         msg['res']['k8s']['serviceMonitor'] = item

    except Exception as e:
        logger.error(str(e))
        msg['err'] = str(e)

    return jsonify(msg)
Ejemplo n.º 2
0
def index():
    tbdata = get()
    df = pandas.DataFrame.from_dict(tbdata, orient='columns')
    df = df.reindex(columns=['Company_ID', 'Company_Name', 'Account_ID', 'Account_Name', 'Project_ID', 'Project_Name',
                             'Project_Status'])
    html = df.to_html(classes='Attendance', index=False, header=True, justify='center').replace('<tr>',
                                                                                                '<tr style="text-align: '
                                                                                                'center;">')
    index_file = open("index.html", "w")
    index_file.write(html)
    index_file.close()
Ejemplo n.º 3
0
def delete():
    msg = {'err': None, 'res': None}

    try:
        # schema validation
        yamale.validate(schema_delete,
                        yamale.make_data(content=request.data.decode('utf-8')))

        body = yaml.load(request.data, Loader=yaml.Loader)

        temp = f"""
apiVersion: apps/v1
kind: Deployment
metadata:
 name: {body['name']}
 namespace: {body['namespace']}
---
apiVersion: v1
kind: Service
metadata:
 name: {body['name']}
 namespace: {body['namespace']}
"""

        k = f"{body['namespace']}/{body['name']}"
        v = mydb.get(db_path, k)
        if v is not None:
            obj = json.loads(v.decode())
            if "monitorPorts" in obj:
                temp += f"""---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
 name: {body['name']}
 namespace: {body['namespace']}
"""

        # delete deployment & service
        cmd = f'cat << EOF | kubectl delete -f -\n{temp}\nEOF\n'
        st, res = subprocess.getstatusoutput(cmd)
        if st != 0:
            logger.error(res)
            msg['err'] = res

        # delete scheduleHint in db (integrity risk!!!) but, it's a etri's requirement.
        k = f"{body['namespace']}/{body['name']}"
        mydb.delete(db_path, k)

    except Exception as e:
        logger.error(str(e))
        msg['err'] = str(e)

    return jsonify(msg)
Ejemplo n.º 4
0
def get():
    msg = {'err': None, 'res': None}

    try:
        name = request.args.get('name')
        namespace = request.args.get('namespace')
        k = f"{namespace}/{name}"
        v = mydb.get(db_path, k)
        if v is not None:
            msg['res'] = json.loads(v.decode())
    except Exception as e:
        logger.error(str(e))
        msg['err'] = str(e)

    return jsonify(msg)
def saveCollectionFromJson(username, index, model):
    import library, mydb
    sql = "select ckey from collections where geek = %s and collectionindex = %s"
    ckeyData = mydb.query(sql,  [username, index])
    ckey = None
    if len(ckeyData) > 0:
        ckey = ckeyData[0][0]
    collRow = library.Row()
    collRow.collectionname = esc(model["name"])
    collRow.description = esc(model["description"])
    collRow.collectionindex = index
    collRow.geek = username
    if ckey is not None:
        collRow.ckey = ckey
        mydb.saveRow(collRow, "collections", "ckey = %d" % ckey)
    else:
        mydb.saveRow(collRow, "collections", None)
        ckeyData = mydb.query(sql,  [username, index]) 
        ckey = ckeyData[0][0]
    mydb.update("delete from collectiongroups where ckey = %d" % ckey)
    for g in model["groups"]:
        groupRow = library.Row()
        groupRow.ckey = ckey
        groupRow.groupname = esc(g["name"])
        groupRow.groupindex = g["index"]
        groupRow.groupname = g["name"]
        groupRow.groupdesc = esc(g["description"])
        groupRow.display = g["display"]                             
        mydb.saveRow(groupRow, "collectiongroups", None)
    mydb.update("delete from collectiongames where ckey = %d" % ckey)  
    db = mydb.get()
    for g in model["groups"]:
        order = 0    
        for game in g["games"]:
            gameRow = library.Row()
            gameRow.groupindex = g["index"]
            gameRow.bggid = game["id"]
            gameRow.orderindex = order
            order = order + 1
            gameRow.ckey = ckey
            mydb.saveRowDb(db, gameRow, "collectiongames", None)
    db.commit()
    db.close()