File: _proxy.py

package info (click to toggle)
python-openstacksdk 0.8.1-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 2,748 kB
  • sloc: python: 15,505; makefile: 156; sh: 46
file content (289 lines) | stat: -rw-r--r-- 12,512 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# 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 import proxy
from openstack.telemetry.v2 import alarm as _alarm
from openstack.telemetry.v2 import alarm_change as _alarm_change
from openstack.telemetry.v2 import capability
from openstack.telemetry.v2 import meter as _meter
from openstack.telemetry.v2 import resource as _resource
from openstack.telemetry.v2 import sample
from openstack.telemetry.v2 import statistics


class Proxy(proxy.BaseProxy):
    """.. caution:: This API is a work in progress and is subject to change."""

    def create_alarm(self, **attrs):
        """Create a new alarm from attributes

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

        :returns: The results of alarm creation
        :rtype: :class:`~openstack.telemetry.v2.alarm.Alarm`
        """
        return self._create(_alarm.Alarm, **attrs)

    def delete_alarm(self, alarm, ignore_missing=True):
        """Delete an alarm

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

        :returns: ``None``
        """
        self._delete(_alarm.Alarm, alarm, ignore_missing=ignore_missing)

    def find_alarm(self, name_or_id, ignore_missing=True):
        """Find a single alarm

        :param name_or_id: The name or ID of a alarm.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the resource does not exist.
                    When set to ``True``, None will be returned when
                    attempting to find a nonexistent resource.
        :returns: One :class:`~openstack.telemetry.v2.alarm.Alarm` or None
        """
        return self._find(_alarm.Alarm, name_or_id,
                          ignore_missing=ignore_missing)

    def get_alarm(self, alarm):
        """Get a single alarm

        :param alarm: The value can be the ID of an alarm or a
                      :class:`~openstack.telemetry.v2.alarm.Alarm` instance.

        :returns: One :class:`~openstack.telemetry.v2.alarm.Alarm`
        :raises: :class:`~openstack.exceptions.ResourceNotFound`
                 when no resource can be found.
        """
        return self._get(_alarm.Alarm, alarm)

    def alarms(self, **query):
        """Return a generator of alarms

        :param kwargs \*\*query: Optional query parameters to be sent to limit
                                 the resources being returned.

        :returns: A generator of alarm objects
        :rtype: :class:`~openstack.telemetry.v2.alarm.Alarm`
        """
        return self._list(_alarm.Alarm, paginated=False, **query)

    def update_alarm(self, alarm, **attrs):
        """Update a alarm

        :param alarm: Either the id of a alarm or a
                      :class:`~openstack.telemetry.v2.alarm.Alarm` instance.
        :attrs kwargs: The attributes to update on the alarm represented
                       by ``value``.

        :returns: The updated alarm
        :rtype: :class:`~openstack.telemetry.v2.alarm.Alarm`
        """
        return self._update(_alarm.Alarm, alarm, **attrs)

    def find_alarm_change(self, name_or_id, ignore_missing=True):
        """Find a single alarm change

        :param name_or_id: The name or ID of a alarm change.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the resource does not exist.
                    When set to ``True``, None will be returned when
                    attempting to find a nonexistent resource.
        :returns: One :class:`~openstack.telemetry.v2.alarm_change.AlarmChange`
                  or None
        """
        return self._find(_alarm_change.AlarmChange, name_or_id,
                          ignore_missing=ignore_missing)

    def alarm_changes(self, alarm, **query):
        """Return a generator of alarm changes

        :param alarm: Alarm resource or id for alarm.
        :param kwargs \*\*query: Optional query parameters to be sent to limit
                                 the resources being returned.

        :returns: A generator of alarm change objects
        :rtype: :class:`~openstack.telemetry.v2.alarm_change.AlarmChange`
        """
        alarm_id = _alarm.Alarm.from_id(alarm).id
        return self._list(_alarm_change.AlarmChange, paginated=False,
                          path_args={'alarm_id': alarm_id}, **query)

    def find_capability(self, name_or_id, ignore_missing=True):
        """Find a single capability

        :param name_or_id: The name or ID of a capability.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the resource does not exist.
                    When set to ``True``, None will be returned when
                    attempting to find a nonexistent resource.
        :returns: One :class:`~openstack.telemetry.v2.capability.Capability`
                  or None
        """
        return self._find(capability.Capability, name_or_id,
                          ignore_missing=ignore_missing)

    def capabilities(self, **query):
        """Return a generator of capabilities

        :param kwargs \*\*query: Optional query parameters to be sent to limit
                                 the resources being returned.

        :returns: A generator of capability objects
        :rtype: :class:`~openstack.telemetry.v2.capability.Capability`
        """
        return self._list(capability.Capability, paginated=False, **query)

    def find_meter(self, name_or_id, ignore_missing=True):
        """Find a single meter

        :param name_or_id: The name or ID of a meter.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the resource does not exist.
                    When set to ``True``, None will be returned when
                    attempting to find a nonexistent resource.
        :returns: One :class:`~openstack.telemetry.v2.meter.Meter` or None
        """
        return self._find(_meter.Meter, name_or_id,
                          ignore_missing=ignore_missing)

    def meters(self, **query):
        """Return a generator of meters

        :param kwargs \*\*query: Optional query parameters to be sent to limit
                                 the resources being returned.

        :returns: A generator of meter objects
        :rtype: :class:`~openstack.telemetry.v2.meter.Meter`
        """
        return self._list(_meter.Meter, paginated=False, **query)

    def find_resource(self, name_or_id, ignore_missing=True):
        """Find a single resource

        :param name_or_id: The name or ID of a resource.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the resource does not exist.
                    When set to ``True``, None will be returned when
                    attempting to find a nonexistent resource.
        :returns: One :class:`~openstack.telemetry.v2.resource.Resource` or
                  None
        """
        return self._find(_resource.Resource, name_or_id,
                          ignore_missing=ignore_missing)

    def get_resource(self, resource):
        """Get a single resource

        :param resource: The value can be the ID of a resource or a
                         :class:`~openstack.telemetry.v2.resource.Resource`
                         instance.

        :returns: One :class:`~openstack.telemetry.v2.resource.Resource`
        :raises: :class:`~openstack.exceptions.ResourceNotFound`
                 when no resource can be found.
        """
        return self._get(_resource.Resource, resource)

    def resources(self, **query):
        """Return a generator of resources

        :param kwargs \*\*query: Optional query parameters to be sent to limit
                                 the resources being returned.

        :returns: A generator of resource objects
        :rtype: :class:`~openstack.telemetry.v2.resource.Resource`
        """
        return self._list(_resource.Resource, paginated=False, **query)

    def create_sample(self, **attrs):
        """Create a new sample from attributes

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

        :returns: The results of sample creation
        :rtype: :class:`~openstack.telemetry.v2.sample.Sample`
        """
        return self._create(sample.Sample, **attrs)

    def find_sample(self, name_or_id, ignore_missing=True):
        """Find a single sample

        :param name_or_id: The name or ID of a sample.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the resource does not exist.
                    When set to ``True``, None will be returned when
                    attempting to find a nonexistent resource.
        :returns: One :class:`~openstack.telemetry.v2.sample.Sample` or None
        """
        return self._find(sample.Sample, name_or_id,
                          ignore_missing=ignore_missing)

    def samples(self, meter, **query):
        """Return a generator of samples

        :param value: Meter resource or name for a meter.
        :param kwargs \*\*query: Optional query parameters to be sent to limit
                                 the resources being returned.

        :returns: A generator of sample objects
        :rtype: :class:`~openstack.telemetry.v2.sample.Sample`
        """
        meter_name = _meter.Meter.from_name(meter).name
        return self._list(sample.Sample, paginated=False,
                          path_args={'counter_name': meter_name}, **query)

    def find_statistics(self, name_or_id, ignore_missing=True):
        """Find a single statistics

        :param name_or_id: The name or ID of a statistics.
        :param bool ignore_missing: When set to ``False``
                    :class:`~openstack.exceptions.ResourceNotFound` will be
                    raised when the resource does not exist.
                    When set to ``True``, None will be returned when
                    attempting to find a nonexistent resource.
        :returns: One :class:`~openstack.telemetry.v2.statistics.Statistics`
                  or None
        """
        return self._find(statistics.Statistics, name_or_id,
                          ignore_missing=ignore_missing)

    def statistics(self, meter, **query):
        """Return a generator of statistics

        :param meter: Meter resource or name for a meter.
        :param kwargs \*\*query: Optional query parameters to be sent to limit
                                 the resources being returned.

        :returns: A generator of statistics objects
        :rtype: :class:`~openstack.telemetry.v2.statistics.Statistics`
        """
        meter_name = _meter.Meter.from_name(meter).name
        return self._list(statistics.Statistics, paginated=False,
                          path_args={'meter_name': meter_name}, **query)