glusterfs

Форк
0
/
handlers.py 
40 строк · 1.2 Кб
1
# -*- coding: utf-8 -*-
2
#
3
#  Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
4
#  This file is part of GlusterFS.
5
#
6
#  This file is licensed to you under your choice of the GNU Lesser
7
#  General Public License, version 3 or any later version (LGPLv3 or
8
#  later), or the GNU General Public License, version 2 (GPLv2), in all
9
#  cases as published by the Free Software Foundation.
10
#
11

12
import utils
13

14

15
def generic_handler(ts, key, data):
16
    """
17
    Generic handler to broadcast message to all peers, custom handlers
18
    can be created by func name handler_<event_name>
19
    Ex: handle_event_volume_create(ts, key, data)
20
    """
21
    utils.publish(ts, key, data)
22

23

24
def handle_event_volume_set(ts, key, data):
25
    """
26
    Received data will have all the options as one string, split into
27
    list of options. "key1,value1,key2,value2" into
28
    [[key1, value1], [key2, value2]]
29
    """
30
    opts = data.get("options", "").strip(",").split(",")
31
    data["options"] = []
32
    for i, opt in enumerate(opts):
33
        if i % 2 == 0:
34
            # Add new array with key
35
            data["options"].append([opt])
36
        else:
37
            # Add to the last added array
38
            data["options"][-1].append(opt)
39

40
    utils.publish(ts, key, data)
41

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.