neutron_lib.rpc module¶
-
class
neutron_lib.rpc.BackingOffClient(transport, target, timeout=None, version_cap=None, serializer=None, retry=None, call_monitor_timeout=None, transport_options=None, _manual_load=True)¶ Bases:
oslo_messaging.rpc.client.RPCClientAn oslo messaging RPC Client that implements a timeout backoff.
This has all of the same interfaces as oslo_messaging.RPCClient but if the timeout parameter is not specified, the _BackingOffContextWrapper returned will track when call timeout exceptions occur and exponentially increase the timeout for the given call method.
-
prepare(*args, **kwargs)¶ Prepare a method invocation context.
Use this method to override client properties for an individual method invocation. For example:
def test(self, ctxt, arg): cctxt = self.prepare(version='2.5') return cctxt.call(ctxt, 'test', arg=arg)
- Parameters
exchange (str) – see Target.exchange
topic (str) – see Target.topic
namespace (str) – see Target.namespace
version (str) – requirement the server must support, see Target.version
server (str) – send to a specific server, see Target.server
fanout (bool) – send to all servers on topic, see Target.fanout
timeout (int or float) – an optional default timeout (in seconds) for call()s
version_cap (str) – raise a RPCVersionCapError version exceeds this cap
retry (int) – an optional connection retries configuration: None or -1 means to retry forever. 0 means no retry is attempted. N means attempt at most N retries.
transport_options (dictionary) – additional parameters to configure the driver for example to send parameters as “mandatory” flag in RabbitMQ
call_monitor_timeout (int) – an optional timeout (in seconds) for active call heartbeating. If specified, requires the server to heartbeat long-running calls at this interval (less than the overall timeout parameter).
-
static
set_max_timeout(max_timeout)¶ Set RPC timeout ceiling for all backing-off RPC clients.
-
-
class
neutron_lib.rpc.Connection¶ Bases:
objectA utility class that manages a collection of RPC servers.
-
close()¶
-
consume_in_threads()¶
-
create_consumer(topic, endpoints, fanout=False)¶
-
-
class
neutron_lib.rpc.RequestContextSerializer(base=None)¶ Bases:
oslo_messaging.serializer.SerializerConvert RPC common context into Neutron Context.
-
deserialize_context(ctxt)¶ Deserialize a dictionary into a request context.
- Parameters
ctxt – Request context dictionary
- Returns
Deserialized form of entity
-
deserialize_entity(ctxt, entity)¶ Deserialize something from primitive form.
- Parameters
ctxt – Request context, in deserialized form
entity – Primitive to be deserialized
- Returns
Deserialized form of entity
-
serialize_context(ctxt)¶ Serialize a request context into a dictionary.
- Parameters
ctxt – Request context
- Returns
Serialized form of context
-
serialize_entity(ctxt, entity)¶ Serialize something to primitive form.
- Parameters
ctxt – Request context, in deserialized form
entity – Entity to be serialized
- Returns
Serialized form of entity
-
-
class
neutron_lib.rpc.Service(host, topic, manager=None, serializer=None)¶ Bases:
oslo_service.backend.eventlet.service.ServiceService object for binaries running on hosts.
A service enables rpc by listening to queues based on topic and host.
-
reset()¶ Reset a service in case it received a SIGHUP.
-
start()¶ Start a service.
-
stop()¶ Stop a service.
- Parameters
graceful – indicates whether to wait for all threads to finish or terminate them instantly
-
wait()¶ Wait for a service to shut down.
-
-
neutron_lib.rpc.cleanup()¶ Deactivate and cleanup the global RPC objects.
- Returns
None.
-
neutron_lib.rpc.get_client(target, version_cap=None, serializer=None)¶ Get an RPC client for the said target.
The init() function must be called prior to calling this. :param target: The RPC target for the client. :param version_cap: The optional version cap for the RPC client. :param serializer: The optional serializer to use for the RPC client. :returns: A new RPC client.
-
neutron_lib.rpc.get_notifier(service=None, host=None, publisher_id=None)¶ Get a new notifier reference.
- Parameters
service – The optional service for the notifier. If not given, None is used as the service name (deprecated since 2025.1).
host – The optional host for the notifier. If not given, the host will be taken from the global CONF.
publisher_id – The optional publisher ID for the notifier. Overrides service and host arguments.
- Returns
A new RPC notifier reference.
-
neutron_lib.rpc.get_server(target, endpoints, serializer=None)¶ Get a new RPC server reference.
- Parameters
target – The target for the new RPC server.
endpoints – The endpoints for the RPC server.
serializer – The optional serialize to use for the RPC server.
- Returns
A new RPC server reference.
-
neutron_lib.rpc.init(conf, rpc_ext_mods=None)¶ Initialize the global RPC objects.
- Parameters
conf – The oslo conf to use for initialization.
rpc_ext_mods – Exception modules to expose via RPC.
- Returns
None.