-
Notifications
You must be signed in to change notification settings - Fork 5
/
notifier.py
56 lines (43 loc) · 1.5 KB
/
notifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
# Copyright 2016-2019 The Wazo Authors (see the AUTHORS file)
# SPDX-License-Identifier: GPL-3.0-or-later
from xivo_bus.resources.context.event import (
CreateContextEvent,
DeleteContextEvent,
EditContextEvent,
)
from xivo_confd import bus, sysconfd
from .schema import ContextSchema
CONTEXT_FIELDS = [
'id',
'name',
'type',
'tenant_uuid',
]
class ContextNotifier(object):
def __init__(self, bus, sysconfd):
self.bus = bus
self.sysconfd = sysconfd
def send_sysconfd_handlers(self):
handlers = {
'ipbx': ['dialplan reload'],
'agentbus': [],
}
self.sysconfd.exec_request_handlers(handlers)
def created(self, context):
self.send_sysconfd_handlers()
context_serialized = ContextSchema(only=CONTEXT_FIELDS).dump(context).data
event = CreateContextEvent(**context_serialized)
self.bus.send_bus_event(event)
def edited(self, context):
self.send_sysconfd_handlers()
context_serialized = ContextSchema(only=CONTEXT_FIELDS).dump(context).data
event = EditContextEvent(**context_serialized)
self.bus.send_bus_event(event)
def deleted(self, context):
self.send_sysconfd_handlers()
context_serialized = ContextSchema(only=CONTEXT_FIELDS).dump(context).data
event = DeleteContextEvent(**context_serialized)
self.bus.send_bus_event(event)
def build_notifier():
return ContextNotifier(bus, sysconfd)