Ejemplo n.º 1
0
def servers_post():
    """
    CREATE new server from POST data.

    args:
        - none
    expected request json:
        - {'name': str, 'notes': str, 'cluster_id': int, 'is_active': bool}
    returns:
        - response with json payload and http status code
    """

    try:
        data = request.json
        keys = ['name', 'notes', 'is_active', 'cluster_id']
        server = Server()
        for key in keys:
            if key not in data:
                continue
            setattr(server, key, data[key])

        server.insert()
        return jsonify({'success': True, 'servers': [server.as_dict()]}), 200
    except Exception as err:
        abort(422, str(err))