2 # -------------------------------------------------------------------------
3 # Copyright (c) 2015-2017 AT&T Intellectual Property
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # -------------------------------------------------------------------------
20 from oslo_config import cfg
22 from conductor.common import music
23 from conductor.common.music.messaging import component
25 DEFAULT_URL = "__default__"
30 # Pull in messaging server opts. We use them here.
31 MESSAGING_SERVER_OPTS = component.MESSAGING_SERVER_OPTS
32 CONF.register_opts(MESSAGING_SERVER_OPTS, group='messaging_server')
36 """Messaging setup, if any"""
37 # oslo_messaging.set_transport_defaults('conductor')
41 # TODO(jdandrea): Remove Music-specific aspects (keyspace -> namespace?)
42 # TODO(jdandrea): Make Music an oslo rpc backend (difficulty level: high?)
43 def get_transport(conf, url=None, optional=False, cache=True):
44 """Initialise the Music messaging layer."""
46 cache_key = url or DEFAULT_URL
47 transport = TRANSPORTS.get(cache_key)
49 if not transport or not cache:
51 # "Somebody set up us the API." ;)
52 # Yes, we know an API is not a transport. Cognitive dissonance FTW!
53 # TODO(jdandrea): try/except to catch problems
54 keyspace = conf.messaging_server.keyspace
55 transport = music.api.API()
56 transport.keyspace_create(keyspace=keyspace)
58 if not optional or url:
59 # NOTE(sileht): oslo_messaging is configured but unloadable
60 # so reraise the exception
65 TRANSPORTS[cache_key] = transport
70 """Cleanup the Music messaging layer."""
72 for url in TRANSPORTS: