blob: 6fa34770df2bafb620761421f7b98aac143eb387 (
plain)
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
|
# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
# This software is distributed under the terms and conditions of the 'Apache-2.0'
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
from oslo_config import cfg
import oslo_messaging
import time
from oslo_log import log as logging
from moon_authz.api.generic import Status, Logs
from moon_authz.api.authorization import Authorization
from moon_utilities.api import APIList
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
class Server:
def __init__(self, component_id, keystone_project_id):
self.TOPIC = "authz-workers"
transport = oslo_messaging.get_notification_transport(cfg.CONF)
targets = [
oslo_messaging.Target(topic=self.TOPIC),
]
self.endpoints = [
APIList((Status, Logs)),
Status(),
Logs(),
Authorization(component_id)
]
pool = "authz-workers"
self.server = oslo_messaging.get_notification_listener(transport, targets,
self.endpoints, executor='threading',
pool=pool)
LOG.info("Starting MQ notification server with topic: {}".format(self.TOPIC))
def run(self):
try:
self.server.start()
while True:
time.sleep(0.1)
except KeyboardInterrupt:
print("Stopping server by crtl+c")
except SystemExit:
print("Stopping server")
self.server.stop()
|