Ejemplo n.º 1
0
def api_user():
    if request.method == "GET":
        users = model.get_user()
        return model.make_json_response(users)

    elif request.method == "POST":
        # バリデーション
        json = model.request_json_attribute(request)
        validation = model.attribute_dict_validation(json,[{"type":"is_empty","key":"password"}, {"type":"is_empty","key":"userId"}])

        if validation != True:
            return jsonify(validation), 400

        # ユーザ情報DB照会
        if virty.userIsExist(json['userId']):
            return abort(400)

        # ユーザ作成
        virty.UserAdd(json['userId'],virty.hash_password(json['password']))
        body = {'message': "succsess"}
        return jsonify(body), 200

    elif request.method == "DELETE":
        # バリデーション
        json = model.request_json_attribute(request)
        validation = model.attribute_dict_validation(json,[{"type":"in_value", "key":"userId", "value":"admin"}, {"type":"is_empty","key":"userId"}])

        if validation != True:
            return jsonify(validation), 400

        # ユーザー削除
        model.raw_commit("update domain_owner set user_id=? where user_id=?",[None,json['userId']])
        model.raw_commit("delete from users_groups where user_id=?",[json['userId']])
        model.raw_commit("delete from users where id=?",[json['userId']])
        body = {'message': "succsess"}
        return jsonify(body), 200
    
    elif request.method == "PUT":
        # バリデーション
        json = model.request_json_attribute(request)
        validation = model.attribute_dict_validation(json,[{"type":"is_empty","key":"password"}, {"type":"is_empty","key":"userId"}])

        if validation != True:
            return jsonify(validation), 400
        
        # パスワード更新
        virty.UserReset(json['userId'],virty.hash_password(json['password']))
        return jsonify({'message': "succsess"}), 200
Ejemplo n.º 2
0
def api_node():
    json = model.request_json_attribute(request)
    if json == None:
        data = model.get_node()
        return model.make_json_response(data)

    if json['node'] != None:
        sql = """
        select id, os, version, comment, url, icon, user, password from archive 
        left join archive_img on archive.id=archive_img.archive_id 
        where archive_img.node=?
        """
        archive = model.raw_fetchall(sql,[json['node']])

        sql = "select * from network where node=?"
        network = model.raw_fetchall(sql,[json['node']])

        sql = "select * from storage where node_name=?"
        storage = model.raw_fetchall(sql,[json['node']])

        data = {
            'archive': archive,
            'network': network,
            'storage': storage
        }
        return model.make_json_response(data)

    else:
        data = model.get_node()
        return model.make_json_response(data)
Ejemplo n.º 3
0
def api_vm_uuid(uuid):
    json = model.request_json_attribute(request)
    if request.method == "GET":
        domain = model.get_domain_by_uuid(uuid)
        if domain == None:
            return abort(404)
        return model.make_json_response(domain)
    elif request.method == "PUT":
        validation = model.attribute_dict_validation(json,[
            {"type":"is_empty","key":"userId"},
            {"type":"is_empty","key":"action"}
        ])
        if validation != True:
            return jsonify(validation), 400

        if json['action'] == "deleteUser":
            model.raw_commit("insert or ignore into domain_owner (dom_uuid,user_id,group_id) values (?,?,?)",[uuid,None,None])
            model.raw_commit("update domain_owner set user_id=? where dom_uuid=?",[None,uuid])
        elif json['action'] == "changeUser":
            print(json['userId'],uuid)
            model.raw_commit("insert or ignore into domain_owner (dom_uuid,user_id,group_id) values (?,?,?)",[uuid,None,None])
            model.raw_commit("update domain_owner set user_id=? where dom_uuid=?",[json['userId'],uuid])
        else:
            return abort(400)
        return jsonify({'message': "succsess"}), 200
Ejemplo n.º 4
0
def api_group():
    if request.method == "GET":
        return model.make_json_response(model.get_groups_users())

    elif request.method == "POST":
        # バリデーション
        json = model.request_json_attribute(request)
        validation = model.attribute_dict_validation(json,[{"type":"is_empty","key":"groupId"}])

        if validation != True:
            return jsonify(validation), 400

        # グループ情報DB照会
        if virty.groupIsExist(json['groupId']):
            return abort(400)

        # グループ作成
        model.raw_commit("insert into groups ('id') values (?)",[json['groupId']])
        return jsonify({'message': "succsess"}), 200

    elif request.method == "DELETE":
        # バリデーション
        json = model.request_json_attribute(request)
        validation = model.attribute_dict_validation(json,[{"type":"in_value", "key":"groupId", "value":"admin"}, {"type":"is_empty","key":"groupId"}])

        if validation != True:
            return jsonify(validation), 400

        # グループ削除
        model.raw_commit("update domain_owner set group_id=? where group_id=?",[None,json['groupId']])
        model.raw_commit("delete from users_groups where group_id=?",[json['groupId']])
        model.raw_commit("delete from groups where id=?",[json['groupId']])
        return jsonify({'message': "succsess"}), 200

    
    elif request.method == "PUT":
        # バリデーション
        json = model.request_json_attribute(request)
        validation = model.attribute_dict_validation(json,[{"type":"is_empty","key":"password"}, {"type":"is_empty","key":"userId"}])

        if validation != True:
            return jsonify(validation), 400
        
        # パスワード更新
        virty.UserReset(json['userId'],virty.hash_password(json['password']))
        return jsonify({'message': "succsess"}), 200
Ejemplo n.º 5
0
def api_archive():
    json = model.request_json_attribute(request)
    if request.method == "POST":
        validation = model.attribute_dict_validation(json,[
            {"type":"is_empty","key":"id"},
            {"type":"is_empty","key":"os"},
            {"type":"is_empty","key":"version"},
            {"type":"is_empty","key":"comment"},
            {"type":"is_empty","key":"url"},
            {"type":"is_empty","key":"icon"},
            {"type":"is_empty","key":"user"},
            {"type":"is_empty","key":"password"},
        ])

        if validation != True:
            return jsonify(validation), 400
        
        data = [json['id'],json['os'],json['version'],json['comment'],json['url'],json['icon'],json['user'],json['password']]
        virty.vsql.RawCommit("insert or ignore into archive (id,os,version,comment,url,icon,user,password) values (?,?,?,?,?,?,?,?)",data)
        return jsonify({'message': "succsess"}), 200

    elif request.method == "PUT":
        validation = model.attribute_dict_validation(json,[
            {"type":"is_empty","key":"archiveId"},
            {"type":"is_empty","key":"imageNode"},
            {"type":"is_empty","key":"imageStorage"},
            {"type":"is_empty","key":"imageName"}
        ])
        if validation != True:
            return jsonify(validation), 400
        
        data = [json['archiveId'],json['imageNode'],json['imageStorage'],json['imageName']]
        virty.vsql.RawCommit("insert or ignore into archive_img (archive_id,node,pool,name) values (?,?,?,?)",data)
        return jsonify({'message': "succsess"}), 200
    
    elif request.method == "DELETE":
        validation = model.attribute_dict_validation(json,[
            {"type":"is_empty","key":"archiveId"},
            {"type":"is_empty","key":"imageNode"},
            {"type":"is_empty","key":"imageStorage"},
            {"type":"is_empty","key":"imageName"}
        ])
        if validation != True:
            return jsonify(validation), 400
        
        data = [json['archiveId'],json['imageNode'],json['imageStorage'],json['imageName']]
        virty.vsql.RawCommit("delete from archive_img where archive_id=? and node=? and pool=? and name=?",data)
        return jsonify({'message': "succsess"}), 200


    else:
        data = model.get_archive()
        return model.make_json_response(data)
Ejemplo n.º 6
0
def api_queue():
    if request.args.get('status') == None:
        data = model.get_queue()
        return model.make_json_response(data)
    elif request.args.get('status') == "incomplete":
        json_attribute = model.request_json_attribute(request)
        json = []
        validation = model.attribute_dict_validation(json,[])
        if validation != True:
            return jsonify(validation), 400

        for att in json_attribute.obj:
            json.append(model.AttributeDict(att))
        
        data = []
        for i in range(50):
            data = model.get_queue_incomplete()

            if data != json:
                return model.make_json_response({'message': 'not match','post':json, 'db': data})
            time.sleep(0.1)
        return model.make_json_response({'message': 'match','post':json, 'db': data})
    else:
        return abort(400)