Coverage for nova/baserpc.py: 100%
30 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-24 11:16 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-24 11:16 +0000
1#
2# Copyright 2013 Red Hat, Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15#
17"""
18Base RPC client and server common to all services.
19"""
21import oslo_messaging as messaging
22from oslo_serialization import jsonutils
24import nova.conf
25from nova import rpc
28CONF = nova.conf.CONF
30_NAMESPACE = 'baseapi'
33class BaseAPI(object):
34 """Client side of the base rpc API.
36 API version history:
38 1.0 - Initial version.
39 1.1 - Add get_backdoor_port
40 """
42 VERSION_ALIASES = {
43 # baseapi was added in havana
44 }
46 def __init__(self, topic):
47 super(BaseAPI, self).__init__()
48 target = messaging.Target(topic=topic,
49 namespace=_NAMESPACE,
50 version='1.0')
51 version_cap = self.VERSION_ALIASES.get(CONF.upgrade_levels.baseapi,
52 CONF.upgrade_levels.baseapi)
53 self.client = rpc.get_client(target, version_cap=version_cap)
55 def ping(self, context, arg, timeout=None):
56 arg_p = jsonutils.to_primitive(arg)
57 cctxt = self.client.prepare(timeout=timeout)
58 return cctxt.call(context, 'ping', arg=arg_p)
60 def get_backdoor_port(self, context, host):
61 cctxt = self.client.prepare(server=host, version='1.1')
62 return cctxt.call(context, 'get_backdoor_port')
65class BaseRPCAPI(object):
66 """Server side of the base RPC API."""
68 target = messaging.Target(namespace=_NAMESPACE, version='1.1')
70 def __init__(self, service_name, backdoor_port):
71 self.service_name = service_name
72 self.backdoor_port = backdoor_port
74 def ping(self, context, arg):
75 resp = {'service': self.service_name, 'arg': arg}
76 return jsonutils.to_primitive(resp)
78 def get_backdoor_port(self, context):
79 return self.backdoor_port