File: _proxy.py

package info (click to toggle)
python-openstacksdk 0.9.5-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,264 kB
  • ctags: 5,542
  • sloc: python: 20,419; makefile: 133; sh: 46
file content (275 lines) | stat: -rw-r--r-- 12,527 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from openstack.message.v2 import claim as _claim
from openstack.message.v2 import message as _message
from openstack.message.v2 import queue as _queue
from openstack.message.v2 import subscription as _subscription
from openstack import proxy2


class Proxy(proxy2.BaseProxy):

    def create_queue(self, **attrs):
        """Create a new queue from attributes

        :param dict attrs: Keyword arguments which will be used to create
                           a :class:`~openstack.message.v2.queue.Queue`,
                           comprised of the properties on the Queue class.

        :returns: The results of queue creation
        :rtype: :class:`~openstack.message.v2.queue.Queue`
        """
        return self._create(_queue.Queue, **attrs)

    def get_queue(self, queue):
        """Get a queue

        :param queue: The value can be the name of a queue or a
            :class:`~openstack.message.v2.queue.Queue` instance.

        :returns: One :class:`~openstack.message.v2.queue.Queue`
        :raises: :class:`~openstack.exceptions.ResourceNotFound` when no
            queue matching the name could be found.
        """
        return self._get(_queue.Queue, queue)

    def queues(self, **query):
        """Retrieve a generator of queues

        :param kwargs \*\*query: Optional query parameters to be sent to
            restrict the queues to be returned. Available parameters include:

            * limit: Requests at most the specified number of items be
                returned from the query.
            * marker: Specifies the ID of the last-seen queue. Use the limit
                parameter to make an initial limited request and use the ID of
                the last-seen queue from the response as the marker parameter
                value in a subsequent limited request.

        :returns: A generator of queue instances.
        """
        return self._list(_queue.Queue, paginated=True, **query)

    def delete_queue(self, value, ignore_missing=True):
        """Delete a queue

        :param value: The value can be either the name of a queue or a
                      :class:`~openstack.message.v2.queue.Queue` instance.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the queue does not exist.
                    When set to ``True``, no exception will be set when
                    attempting to delete a nonexistent queue.

        :returns: ``None``
        """
        return self._delete(_queue.Queue, value, ignore_missing=ignore_missing)

    def post_message(self, queue_name, messages):
        """Post messages to given queue

        :param queue_name: The name of target queue to post message to.
        :param list messages: List of messages body and TTL to post.

        :returns: A string includes location of messages successfully posted.
        """
        message = self._get_resource(_message.Message, None,
                                     queue_name=queue_name)
        return message.post(self.session, messages)

    def messages(self, queue_name, **query):
        """Retrieve a generator of messages

        :param queue_name: The name of target queue to query messages from.
        :param kwargs \*\*query: Optional query parameters to be sent to
            restrict the messages to be returned. Available parameters include:

            * limit: Requests at most the specified number of items be
                returned from the query.
            * marker: Specifies the ID of the last-seen subscription. Use the
                limit parameter to make an initial limited request and use the
                ID of the last-seen subscription from the response as the
                marker parameter value in a subsequent limited request.
            * echo: Indicate if the messages can be echoed back to the client
                that posted them.
            * include_claimed: Indicate if the messages list should include
                the claimed messages.

        :returns: A generator of message instances.
        """
        query["queue_name"] = queue_name
        return self._list(_message.Message, paginated=True, **query)

    def get_message(self, queue_name, message):
        """Get a message

        :param queue_name: The name of target queue to get message from.
        :param message: The value can be the name of a message or a
            :class:`~openstack.message.v2.message.Message` instance.

        :returns: One :class:`~openstack.message.v2.message.Message`
        :raises: :class:`~openstack.exceptions.ResourceNotFound` when no
            message matching the criteria could be found.
        """
        message = self._get_resource(_message.Message, message,
                                     queue_name=queue_name)
        return self._get(_message.Message, message)

    def delete_message(self, queue_name, value, ignore_missing=True):
        """Delete a message

        :param queue_name: The name of target queue to delete message from.
        :param value: The value can be either the name of a message or a
                      :class:`~openstack.message.v2.message.Message` instance.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the message does not exist.
                    When set to ``True``, no exception will be set when
                    attempting to delete a nonexistent message.

        :returns: ``None``
        """
        message = self._get_resource(_message.Message, value,
                                     queue_name=queue_name)
        return self._delete(_message.Message, message,
                            ignore_missing=ignore_missing)

    def create_subscription(self, queue_name, **attrs):
        """Create a new subscription from attributes

        :param queue_name: The name of target queue to subscribe on.
        :param dict attrs: Keyword arguments which will be used to create a
            :class:`~openstack.message.v2.subscription.Subscription`,
            comprised of the properties on the Subscription class.

        :returns: The results of subscription creation
        :rtype: :class:`~openstack.message.v2.subscription.Subscription`
        """
        return self._create(_subscription.Subscription, queue_name=queue_name,
                            **attrs)

    def subscriptions(self, queue_name, **query):
        """Retrieve a generator of subscriptions

        :param queue_name: The name of target queue to subscribe on.
        :param kwargs \*\*query: Optional query parameters to be sent to
            restrict the subscriptions to be returned. Available parameters
            include:

            * limit: Requests at most the specified number of items be
                returned from the query.
            * marker: Specifies the ID of the last-seen subscription. Use the
                limit parameter to make an initial limited request and use the
                ID of the last-seen subscription from the response as the
                marker parameter value in a subsequent limited request.

        :returns: A generator of subscription instances.
        """
        query["queue_name"] = queue_name
        return self._list(_subscription.Subscription, paginated=True, **query)

    def get_subscription(self, queue_name, subscription):
        """Get a subscription

        :param queue_name: The name of target queue of subscription.
        :param message: The value can be the ID of a subscription or a
            :class:`~openstack.message.v2.subscription.Subscription` instance.

        :returns: One :class:`~openstack.message.v2.subscription.Subscription`
        :raises: :class:`~openstack.exceptions.ResourceNotFound` when no
            subscription matching the criteria could be found.
        """
        subscription = self._get_resource(_subscription.Subscription,
                                          subscription,
                                          queue_name=queue_name)
        return self._get(_subscription.Subscription, subscription)

    def delete_subscription(self, queue_name, value, ignore_missing=True):
        """Delete a subscription

        :param queue_name: The name of target queue to delete subscription
                           from.
        :param value: The value can be either the name of a subscription or a
                      :class:`~openstack.message.v2.subscription.Subscription`
                      instance.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the subscription does not exist.
                    When set to ``True``, no exception will be thrown when
                    attempting to delete a nonexistent subscription.

        :returns: ``None``
        """
        subscription = self._get_resource(_subscription.Subscription, value,
                                          queue_name=queue_name)
        return self._delete(_subscription.Subscription, subscription,
                            ignore_missing=ignore_missing)

    def create_claim(self, queue_name, **attrs):
        """Create a new claim from attributes

        :param queue_name: The name of target queue to claim message from.
        :param dict attrs: Keyword arguments which will be used to create a
            :class:`~openstack.message.v2.claim.Claim`,
            comprised of the properties on the Claim class.

        :returns: The results of claim creation
        :rtype: :class:`~openstack.message.v2.claim.Claim`
        """
        return self._create(_claim.Claim, queue_name=queue_name, **attrs)

    def get_claim(self, queue_name, claim):
        """Get a claim

        :param queue_name: The name of target queue to claim message from.
        :param claim: The value can be either the ID of a claim or a
            :class:`~openstack.message.v2.claim.Claim` instance.

        :returns: One :class:`~openstack.message.v2.claim.Claim`
        :raises: :class:`~openstack.exceptions.ResourceNotFound` when no
            claim matching the criteria could be found.
        """
        return self._get(_claim.Claim, claim, queue_name=queue_name)

    def update_claim(self, queue_name, claim, **attrs):
        """Update an existing claim from attributes

        :param queue_name: The name of target queue to claim message from.
        :param claim: The value can be either the ID of a claim or a
            :class:`~openstack.message.v2.claim.Claim` instance.
        :param dict attrs: Keyword arguments which will be used to update a
            :class:`~openstack.message.v2.claim.Claim`,
            comprised of the properties on the Claim class.

        :returns: The results of claim update
        :rtype: :class:`~openstack.message.v2.claim.Claim`
        """
        return self._update(_claim.Claim, claim, queue_name=queue_name,
                            **attrs)

    def delete_claim(self, queue_name, claim, ignore_missing=True):
        """Delete a claim

        :param queue_name: The name of target queue to claim messages from.
        :param claim: The value can be either the ID of a claim or a
                      :class:`~openstack.message.v2.claim.Claim` instance.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the claim does not exist.
                    When set to ``True``, no exception will be thrown when
                    attempting to delete a nonexistent claim.

        :returns: ``None``
        """
        return self._delete(_claim.Claim, claim, queue_name=queue_name,
                            ignore_missing=ignore_missing)