Exemplo n.º 1
0
def discount(host, user, score, score_update):
    """Update points for 'discount' loyality program"""
    if host.loyality_type != DISCOUNT_LOYALITY or not Host.check_loyality(
            host.loyality_type, host.loyality_param, host.loyality_time_param,
            host.loyality_burn_param):
        return jsonify({'message': "Wrong loyality type"}), HTTP_403_FORBIDDEN
    # increasing points
    if score_update <= 0:
        return jsonify({'message':
                        "Wrong value for update"}), HTTP_400_BAD_REQUEST
    discount = score.get_discount()
    counted_score = score_update - score_update * discount
    score.score += counted_score
    score.save()
    return jsonify({
        'code': 0,
        'score': score.score,
        'discount': discount,
        'message': "Updated"
    })
Exemplo n.º 2
0
    async def post(self):

        data = await self.request.post()

        group_id = get_data_or_400(data, 'group_id', raise_exception=False)
        hostname = get_data_or_400(data, 'hostname')
        ip_address = get_data_or_400(data, 'ip_address')
        username = get_data_or_400(data, 'username')
        password = get_data_or_400(data, 'password')
        ssh_key = get_data_or_400(data, 'ssh_key')
        post_login_cmd = get_data_or_400(data, 'post_login_cmd')

        if data and Host.filter(**data).exists():
            raise HTTPBadRequest()

        if group_id is not None and not Group.filter(Group.id == group_id).exists():
            raise HTTPBadRequest()

        host = dict_to_model(Host, data)
        host.save()

        return HTTPOk()
Exemplo n.º 3
0
def get_hosts():
    hosts = Host.list()
    hosts = [h.to_json() for h in hosts] if hosts else None
    return hosts
Exemplo n.º 4
0
    def getHost(self, id):

        params = {'output': 'extend', "hostids": id}
        res = self.execute("host.get", params)
        #print (res['result'])
        return Host(res['result'][0])
Exemplo n.º 5
0
def update_host():
    """All fields updated at a time"""
    host_uid = get_current_host_id()
    if not host_uid:
        return jsonify({'message': "Not logged in"}), HTTP_403_FORBIDDEN
    data = get_request_data(request)
    if not data.get(TITLE):
        return jsonify({'message': "Title required"}), HTTP_400_BAD_REQUEST
    host = Host(uid=host_uid)
    if current_user.uid != host.owner_uid:
        return jsonify({'message':
                        "You are not this host"}), HTTP_403_FORBIDDEN
    host.title = data[TITLE]
    host.description = data.get(DESCRIPTION)
    host.address = data.get(ADDRESS)
    host.latitude = data.get(LATITUDE)
    host.longitude = data.get(LONGITUDE)
    host.time_open = Host.parse_time(data.get(TIME_OPEN))
    host.time_close = Host.parse_time(data.get(TIME_CLOSE))
    result_uid = host.save()
    if result_uid is None:
        return jsonify({'message': "Update failed"}), HTTP_409_CONFLICT
    return jsonify({'code': 0, 'message': "OK"})
Exemplo n.º 6
0
 def Host(self):
     return Host(self)
Exemplo n.º 7
0
async def index(request):
    recently_up = [
        host
        async for host in Host.filter_by(db=request.app.redis_connection, up=1)
    ]
    return {"hosts": recently_up}
Exemplo n.º 8
0
 def get(self, hostname):
     host = Host.find_by_hostname(hostname)
     if host:
         return host.json()
     return {'message': 'Host not found'}, 404
Exemplo n.º 9
0
 def delete(self, hostname):
     host = Host.find_by_hostname(hostname)
     if host:
         Host.delete_from_db(host)
     return {'message': 'Hostname {} deleted'.format(host.hostname)}