~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/rpc/proxy.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 Red Hat, Inc.
 
4
#
 
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
#    not use this file except in compliance with the License. You may obtain
 
7
#    a copy of the License at
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
#    Unless required by applicable law or agreed to in writing, software
 
12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
#    License for the specific language governing permissions and limitations
 
15
#    under the License.
 
16
 
 
17
"""
 
18
A helper class for proxy objects to remote APIs.
 
19
 
 
20
For more information about rpc API version numbers, see:
 
21
    rpc/dispatcher.py
 
22
"""
 
23
 
 
24
 
 
25
from nova import rpc
 
26
 
 
27
 
 
28
class RpcProxy(object):
 
29
    """A helper class for rpc clients.
 
30
 
 
31
    This class is a wrapper around the RPC client API.  It allows you to
 
32
    specify the topic and API version in a single place.  This is intended to
 
33
    be used as a base class for a class that implements the client side of an
 
34
    rpc API.
 
35
    """
 
36
 
 
37
    def __init__(self, topic, default_version):
 
38
        """Initialize an RpcProxy.
 
39
 
 
40
        :param topic: The topic to use for all messages.
 
41
        :param default_version: The default API version to request in all
 
42
               outgoing messages.  This can be overridden on a per-message
 
43
               basis.
 
44
        """
 
45
        self.topic = topic
 
46
        self.default_version = default_version
 
47
        super(RpcProxy, self).__init__()
 
48
 
 
49
    def _set_version(self, msg, vers):
 
50
        """Helper method to set the version in a message.
 
51
 
 
52
        :param msg: The message having a version added to it.
 
53
        :param vers: The version number to add to the message.
 
54
        """
 
55
        msg['version'] = vers if vers else self.default_version
 
56
 
 
57
    def _get_topic(self, topic):
 
58
        """Return the topic to use for a message."""
 
59
        return topic if topic else self.topic
 
60
 
 
61
    @staticmethod
 
62
    def make_msg(method, **kwargs):
 
63
        return {'method': method, 'args': kwargs}
 
64
 
 
65
    def call(self, context, msg, topic=None, version=None, timeout=None):
 
66
        """rpc.call() a remote method.
 
67
 
 
68
        :param context: The request context
 
69
        :param msg: The message to send, including the method and args.
 
70
        :param topic: Override the topic for this message.
 
71
        :param timeout: (Optional) A timeout to use when waiting for the
 
72
               response.  If no timeout is specified, a default timeout will be
 
73
               used that is usually sufficient.
 
74
        :param version: (Optional) Override the requested API version in this
 
75
               message.
 
76
 
 
77
        :returns: The return value from the remote method.
 
78
        """
 
79
        self._set_version(msg, version)
 
80
        return rpc.call(context, self._get_topic(topic), msg, timeout)
 
81
 
 
82
    def multicall(self, context, msg, topic=None, version=None, timeout=None):
 
83
        """rpc.multicall() a remote method.
 
84
 
 
85
        :param context: The request context
 
86
        :param msg: The message to send, including the method and args.
 
87
        :param topic: Override the topic for this message.
 
88
        :param timeout: (Optional) A timeout to use when waiting for the
 
89
               response.  If no timeout is specified, a default timeout will be
 
90
               used that is usually sufficient.
 
91
        :param version: (Optional) Override the requested API version in this
 
92
               message.
 
93
 
 
94
        :returns: An iterator that lets you process each of the returned values
 
95
                  from the remote method as they arrive.
 
96
        """
 
97
        self._set_version(msg, version)
 
98
        return rpc.multicall(context, self._get_topic(topic), msg, timeout)
 
99
 
 
100
    def cast(self, context, msg, topic=None, version=None):
 
101
        """rpc.cast() a remote method.
 
102
 
 
103
        :param context: The request context
 
104
        :param msg: The message to send, including the method and args.
 
105
        :param topic: Override the topic for this message.
 
106
        :param version: (Optional) Override the requested API version in this
 
107
               message.
 
108
 
 
109
        :returns: None.  rpc.cast() does not wait on any return value from the
 
110
                  remote method.
 
111
        """
 
112
        self._set_version(msg, version)
 
113
        rpc.cast(context, self._get_topic(topic), msg)
 
114
 
 
115
    def fanout_cast(self, context, msg, version=None):
 
116
        """rpc.fanout_cast() a remote method.
 
117
 
 
118
        :param context: The request context
 
119
        :param msg: The message to send, including the method and args.
 
120
        :param version: (Optional) Override the requested API version in this
 
121
               message.
 
122
 
 
123
        :returns: None.  rpc.fanout_cast() does not wait on any return value
 
124
                  from the remote method.
 
125
        """
 
126
        self._set_version(msg, version)
 
127
        rpc.fanout_cast(context, self.topic, msg)
 
128
 
 
129
    def cast_to_server(self, context, server_params, msg, topic=None,
 
130
            version=None):
 
131
        """rpc.cast_to_server() a remote method.
 
132
 
 
133
        :param context: The request context
 
134
        :param server_params: Server parameters.  See rpc.cast_to_server() for
 
135
               details.
 
136
        :param msg: The message to send, including the method and args.
 
137
        :param topic: Override the topic for this message.
 
138
        :param version: (Optional) Override the requested API version in this
 
139
               message.
 
140
 
 
141
        :returns: None.  rpc.cast_to_server() does not wait on any
 
142
                  return values.
 
143
        """
 
144
        self._set_version(msg, version)
 
145
        rpc.cast_to_server(context, server_params, self._get_topic(topic), msg)
 
146
 
 
147
    def fanout_cast_to_server(self, context, server_params, msg, version=None):
 
148
        """rpc.fanout_cast_to_server() a remote method.
 
149
 
 
150
        :param context: The request context
 
151
        :param server_params: Server parameters.  See rpc.cast_to_server() for
 
152
               details.
 
153
        :param msg: The message to send, including the method and args.
 
154
        :param version: (Optional) Override the requested API version in this
 
155
               message.
 
156
 
 
157
        :returns: None.  rpc.fanout_cast_to_server() does not wait on any
 
158
                  return values.
 
159
        """
 
160
        self._set_version(msg, version)
 
161
        rpc.fanout_cast_to_server(context, server_params, self.topic, msg)