diff options
author | melanie witt <melwitt@yahoo-inc.com> | 2016-02-02 00:40:31 +0000 |
---|---|---|
committer | melanie witt <melwittt@gmail.com> | 2016-05-16 15:34:35 +0000 |
commit | bdf984a7ce23e5d1775ae19cdf0c4adc16c0e677 (patch) | |
tree | 096bedc07d6942a6fc5ae7eaf44c99ac10dc73e9 /nova/rpc.py | |
parent | 0458f3e78ec3d6fce1f316302230fb5135dd5c49 (diff) | |
download | nova-bdf984a7ce23e5d1775ae19cdf0c4adc16c0e677.tar.gz |
Add message queue switching through RequestContext
This adds message queue connection information to the RequestContext
which can be used by nova-api to communicate with a targeted cell
message queue with each query.
A function 'get_cell_client' can be called in rpc functions to enable them
to use message queue transport information from a RequestContext. The
function creates a rpc client object dynamically if message queue
connection information is found in the RequestContext and falls back on
the default rpc client.
Example usage:
def get_cell_client(self, context):
return rpc.get_cell_client(context, self.client)
def build_and_run_instances(self, ctxt, instance, host, image, ...)
cctxt = self.get_cell_client(ctxt).prepare(...)
cctxt.cast(...)
Implements blueprint cells-mq-connection-switching
Change-Id: Idef670d5b73c9cef8501a0593eccd785b708bd2b
Diffstat (limited to 'nova/rpc.py')
-rw-r--r-- | nova/rpc.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/nova/rpc.py b/nova/rpc.py index 77207d1646..78c7189870 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -65,6 +65,20 @@ TRANSPORT_ALIASES = { } +def get_cell_client(context, default_client): + """Get a RPCClient object based on a RequestContext. + + :param context: The RequestContext that can contain a Transport + :param default_client: The default RPCClient + """ + if context.mq_connection: + return messaging.RPCClient( + context.mq_connection, default_client.target, + version_cap=default_client.version_cap, + serializer=default_client.serializer) + return default_client + + def init(conf): global TRANSPORT, NOTIFICATION_TRANSPORT, LEGACY_NOTIFIER, NOTIFIER exmods = get_allowed_exmods() @@ -185,6 +199,14 @@ def get_versioned_notifier(publisher_id): return NOTIFIER.prepare(publisher_id=publisher_id) +def create_transport(url): + exmods = get_allowed_exmods() + return messaging.get_transport(CONF, + url=url, + allowed_remote_exmods=exmods, + aliases=TRANSPORT_ALIASES) + + class LegacyValidatingNotifier(object): """Wraps an oslo.messaging Notifier and checks for allowed event_types.""" |