40
40
server side of the API at the same time. However, as the code stands today,
41
41
there can be both versioned and unversioned APIs implemented in the same code
47
Nova was the first project to use versioned rpc APIs. Consider the compute rpc
48
API as an example. The client side is in nova/compute/rpcapi.py and the server
49
side is in nova/compute/manager.py.
52
Example 1) Adding a new method.
54
Adding a new method is a backwards compatible change. It should be added to
55
nova/compute/manager.py, and RPC_API_VERSION should be bumped from X.Y to
56
X.Y+1. On the client side, the new method in nova/compute/rpcapi.py should
57
have a specific version specified to indicate the minimum API version that must
58
be implemented for the method to be supported. For example:
60
def get_host_uptime(self, ctxt, host):
61
topic = _compute_topic(self.topic, ctxt, host, None)
62
return self.call(ctxt, self.make_msg('get_host_uptime'), topic,
65
In this case, version '1.1' is the first version that supported the
66
get_host_uptime() method.
69
Example 2) Adding a new parameter.
71
Adding a new parameter to an rpc method can be made backwards compatible. The
72
RPC_API_VERSION on the server side (nova/compute/manager.py) should be bumped.
73
The implementation of the method must not expect the parameter to be present.
75
def some_remote_method(self, arg1, arg2, newarg=None):
76
# The code needs to deal with newarg=None for cases
77
# where an older client sends a message without it.
80
On the client side, the same changes should be made as in example 1. The
81
minimum version that supports the new parameter should be specified.
45
84
from nova.openstack.common.rpc import common as rpc_common