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
			
			
This commit is contained in:
		 melanie witt
					melanie witt
				
			
				
					committed by
					
						 melanie witt
						melanie witt
					
				
			
			
				
	
			
			
			 melanie witt
						melanie witt
					
				
			
						parent
						
							0458f3e78e
						
					
				
				
					commit
					bdf984a7ce
				
			
							
								
								
									
										22
									
								
								nova/rpc.py
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								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.""" | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user