Remove meter service
As per the mailing list thread on ceilometerclient, the REST API for ceilometer has been long deprecated and is now completely unsupported. Remove the meter service and its sub-service alarm. On the one hand, it's a REST API so there is no need for us to not support it. As a general rule removing support for services that we have already is a bad thing. On the other hand, we haven't cut the 1.0 yet, and as ceilometer doesn't exist anymore we can't really do devstack testing of it. The previous patch adds support for out-of-tree services. So anyone who cares about the 'meter' service can grab this, port it to Proxy2 and then do an add_service. Change-Id: Ic226c5ac048ba09e316c89cae1e8f2828e753e80
This commit is contained in:
parent
dffe0f0463
commit
1f05e3ac4c
@ -43,8 +43,6 @@ def get_proxy_methods():
|
||||
"openstack.network.v2._proxy",
|
||||
"openstack.object_store.v1._proxy",
|
||||
"openstack.orchestration.v1._proxy",
|
||||
"openstack.meter.v2._proxy",
|
||||
"openstack.meter.alarm.v2._proxy",
|
||||
"openstack.workflow.v2._proxy"]
|
||||
|
||||
modules = (importlib.import_module(name) for name in names)
|
||||
|
@ -1,11 +0,0 @@
|
||||
Using OpenStack Meter
|
||||
=========================
|
||||
|
||||
.. caution::
|
||||
BETA: This API is a work in progress and is subject to change.
|
||||
|
||||
Before working with the Meter service, you'll need to create a connection
|
||||
to your OpenStack cloud by following the :doc:`connect` user guide. This will
|
||||
provide you with the ``conn`` variable used in the examples below.
|
||||
|
||||
.. TODO(thowe): Implement this guide
|
@ -40,7 +40,6 @@ approach, this is where you'll want to begin.
|
||||
Image <guides/image>
|
||||
Key Manager <guides/key_manager>
|
||||
Message <guides/message>
|
||||
Meter <guides/meter>
|
||||
Network <guides/network>
|
||||
Object Store <guides/object_store>
|
||||
Orchestration <guides/orchestration>
|
||||
@ -95,7 +94,6 @@ provided by the SDK.
|
||||
Message v1 <proxies/message_v1>
|
||||
Message v2 <proxies/message_v2>
|
||||
Network <proxies/network>
|
||||
Meter <proxies/meter>
|
||||
Metric <proxies/metric>
|
||||
Object Store <proxies/object_store>
|
||||
Orchestration <proxies/orchestration>
|
||||
@ -125,7 +123,6 @@ The following services have exposed *Resource* classes.
|
||||
Image <resources/image/index>
|
||||
Key Management <resources/key_manager/index>
|
||||
Load Balancer <resources/load_balancer/index>
|
||||
Meter <resources/meter/index>
|
||||
Metric <resources/metric/index>
|
||||
Network <resources/network/index>
|
||||
Orchestration <resources/orchestration/index>
|
||||
|
@ -1,85 +0,0 @@
|
||||
Meter API
|
||||
=============
|
||||
|
||||
.. caution::
|
||||
BETA: This API is a work in progress and is subject to change.
|
||||
|
||||
For details on how to use meter, see :doc:`/user/guides/meter`
|
||||
|
||||
.. automodule:: openstack.meter.v2._proxy
|
||||
|
||||
The Meter Class
|
||||
-------------------
|
||||
|
||||
The meter high-level interface is available through the ``meter``
|
||||
member of a :class:`~openstack.connection.Connection` object. The
|
||||
``meter`` member will only be added if the service is detected.
|
||||
|
||||
Sample Operations
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: openstack.meter.v2._proxy.Proxy
|
||||
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.find_sample
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.samples
|
||||
|
||||
Statistic Operations
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: openstack.meter.v2._proxy.Proxy
|
||||
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.find_statistics
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.statistics
|
||||
|
||||
Resource Operations
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: openstack.meter.v2._proxy.Proxy
|
||||
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.get_resource
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.find_resource
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.resources
|
||||
|
||||
Meter Operations
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: openstack.meter.v2._proxy.Proxy
|
||||
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.find_meter
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.meters
|
||||
|
||||
Capability Operations
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: openstack.meter.v2._proxy.Proxy
|
||||
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.find_capability
|
||||
.. automethod:: openstack.meter.v2._proxy.Proxy.capabilities
|
||||
|
||||
The Alarm Class
|
||||
---------------
|
||||
|
||||
The alarm high-level interface is available through the ``meter.alarm``
|
||||
member of a :class:`~openstack.connection.Connection` object. The
|
||||
``meter.alarm`` member will only be added if the service is detected.
|
||||
|
||||
Alarm Operations
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: openstack.meter.alarm.v2._proxy.Proxy
|
||||
|
||||
.. automethod:: openstack.meter.alarm.v2._proxy.Proxy.create_alarm
|
||||
.. automethod:: openstack.meter.alarm.v2._proxy.Proxy.update_alarm
|
||||
.. automethod:: openstack.meter.alarm.v2._proxy.Proxy.delete_alarm
|
||||
.. automethod:: openstack.meter.alarm.v2._proxy.Proxy.get_alarm
|
||||
.. automethod:: openstack.meter.alarm.v2._proxy.Proxy.find_alarm
|
||||
.. automethod:: openstack.meter.alarm.v2._proxy.Proxy.alarms
|
||||
|
||||
|
||||
Alarm Change Operations
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: openstack.meter.alarm.v2._proxy.Proxy
|
||||
|
||||
.. automethod:: openstack.meter.alarm.v2._proxy.Proxy.find_alarm_change
|
||||
.. automethod:: openstack.meter.alarm.v2._proxy.Proxy.alarm_changes
|
@ -1,11 +0,0 @@
|
||||
Meter Resources
|
||||
===================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
v2/capability
|
||||
v2/meter
|
||||
v2/resource
|
||||
v2/sample
|
||||
v2/statistics
|
@ -1,12 +0,0 @@
|
||||
openstack.meter.v2.capability
|
||||
=================================
|
||||
|
||||
.. automodule:: openstack.meter.v2.capability
|
||||
|
||||
The Capability Class
|
||||
--------------------
|
||||
|
||||
The ``Capability`` class inherits from :class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.meter.v2.capability.Capability
|
||||
:members:
|
@ -1,12 +0,0 @@
|
||||
openstack.meter.v2.meter
|
||||
============================
|
||||
|
||||
.. automodule:: openstack.meter.v2.meter
|
||||
|
||||
The Meter Class
|
||||
----------------
|
||||
|
||||
The ``Meter`` class inherits from :class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.meter.v2.meter.Meter
|
||||
:members:
|
@ -1,12 +0,0 @@
|
||||
openstack.meter.v2.resource
|
||||
===============================
|
||||
|
||||
.. automodule:: openstack.meter.v2.resource
|
||||
|
||||
The Resource Class
|
||||
------------------
|
||||
|
||||
The ``Resource`` class inherits from :class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.meter.v2.resource.Resource
|
||||
:members:
|
@ -1,12 +0,0 @@
|
||||
openstack.meter.v2.sample
|
||||
=============================
|
||||
|
||||
.. automodule:: openstack.meter.v2.sample
|
||||
|
||||
The Sample Class
|
||||
----------------
|
||||
|
||||
The ``Sample`` class inherits from :class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.meter.v2.sample.Sample
|
||||
:members:
|
@ -1,12 +0,0 @@
|
||||
openstack.meter.v2.statistics
|
||||
=================================
|
||||
|
||||
.. automodule:: openstack.meter.v2.statistics
|
||||
|
||||
The Statistics Class
|
||||
--------------------
|
||||
|
||||
The ``Statistics`` class inherits from :class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.meter.v2.statistics.Statistics
|
||||
:members:
|
@ -1,24 +0,0 @@
|
||||
# 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 service_filter
|
||||
|
||||
|
||||
class AlarmService(service_filter.ServiceFilter):
|
||||
"""The alarm service."""
|
||||
|
||||
valid_versions = [service_filter.ValidVersion('v2')]
|
||||
|
||||
def __init__(self, version=None):
|
||||
"""Create an alarm service."""
|
||||
super(AlarmService, self).__init__(service_type='alarming',
|
||||
version=version)
|
@ -1,129 +0,0 @@
|
||||
# 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.meter.alarm.v2 import alarm as _alarm
|
||||
from openstack.meter.alarm.v2 import alarm_change as _alarm_change
|
||||
|
||||
|
||||
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.meter.v2.alarm.Alarm`,
|
||||
comprised of the properties on the Alarm class.
|
||||
|
||||
:returns: The results of alarm creation
|
||||
:rtype: :class:`~openstack.meter.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.meter.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.meter.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.meter.v2.alarm.Alarm` instance.
|
||||
|
||||
:returns: One :class:`~openstack.meter.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.meter.v2.alarm.Alarm`
|
||||
"""
|
||||
# TODO(Qiming): Check the alarm service API docs/code to verify if
|
||||
# the parameters need a change.
|
||||
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.meter.v2.alarm.Alarm` instance.
|
||||
:attrs kwargs: The attributes to update on the alarm represented
|
||||
by ``value``.
|
||||
|
||||
:returns: The updated alarm
|
||||
:rtype: :class:`~openstack.meter.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.meter.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.meter.v2.alarm_change.AlarmChange`
|
||||
"""
|
||||
# TODO(Qiming): Check the alarm service API docs/code to verify if
|
||||
# the parameters need a change.
|
||||
alarm_id = _alarm.Alarm.from_id(alarm).id
|
||||
return self._list(_alarm_change.AlarmChange, paginated=False,
|
||||
path_args={'alarm_id': alarm_id}, **query)
|
@ -1,91 +0,0 @@
|
||||
# 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 resource
|
||||
from openstack.meter.alarm import alarm_service
|
||||
from openstack import utils
|
||||
|
||||
|
||||
class Alarm(resource.Resource):
|
||||
""".. caution:: This API is a work in progress and is subject to change."""
|
||||
id_attribute = 'alarm_id'
|
||||
base_path = '/alarms'
|
||||
service = alarm_service.AlarmService()
|
||||
|
||||
# Supported Operations
|
||||
allow_create = True
|
||||
allow_retrieve = True
|
||||
allow_update = True
|
||||
allow_delete = True
|
||||
allow_list = True
|
||||
|
||||
# Properties
|
||||
#: The actions to do when alarm state changes to alarm
|
||||
alarm_actions = resource.prop('alarm_actions')
|
||||
#: The ID of the alarm
|
||||
alarm_id = resource.prop('alarm_id')
|
||||
# TODO(briancurtin): undocumented
|
||||
combination_rule = resource.prop('combination_rule')
|
||||
#: The description of the alarm
|
||||
description = resource.prop('description')
|
||||
#: ``True`` if this alarm is enabled. *Type: bool*
|
||||
is_enabled = resource.prop('enabled', type=bool)
|
||||
#: The actions to do when alarm state changes to insufficient data
|
||||
insufficient_data_actions = resource.prop('insufficient_data_actions')
|
||||
#: The actions should be re-triggered on each evaluation cycle.
|
||||
#: *Type: bool*
|
||||
is_repeat_actions = resource.prop('repeat_actions', type=bool)
|
||||
#: The name for the alarm
|
||||
name = resource.prop('name')
|
||||
#: The actions to do when alarm state change to ok
|
||||
ok_actions = resource.prop('ok_actions')
|
||||
#: The ID of the project that owns the alarm
|
||||
project_id = resource.prop('project_id')
|
||||
#: The severity of the alarm
|
||||
severity = resource.prop('severity')
|
||||
#: The state off the alarm
|
||||
state = resource.prop('state')
|
||||
#: The timestamp of the last alarm state change.
|
||||
#: *Type: ISO 8601 formatted string*
|
||||
state_changed_at = resource.prop('state_timestamp')
|
||||
# TODO(briancurtin): undocumented
|
||||
threshold_rule = resource.prop('threshold_rule', type=dict)
|
||||
#: Describe time constraints for the alarm
|
||||
time_constraints = resource.prop('time_constraints')
|
||||
#: Explicit type specifier to select which rule to follow
|
||||
type = resource.prop('type')
|
||||
#: The timestamp of the last alarm definition update.
|
||||
#: *Type: ISO 8601 formatted string*
|
||||
updated_at = resource.prop('timestamp')
|
||||
#: The ID of the user who created the alarm
|
||||
user_id = resource.prop('user_id')
|
||||
|
||||
def change_state(self, session, next_state):
|
||||
"""Set the state of an alarm.
|
||||
|
||||
:param next_state: The valid values can be one of: ``ok``, ``alarm``,
|
||||
``insufficient data``.
|
||||
"""
|
||||
url = utils.urljoin(self.base_path, self.id, 'state')
|
||||
resp = session.put(url, json=next_state)
|
||||
return resp.json()
|
||||
|
||||
def check_state(self, session):
|
||||
"""Retrieve the current state of an alarm from the service.
|
||||
|
||||
The properties of the alarm are not modified.
|
||||
"""
|
||||
url = utils.urljoin(self.base_path, self.id, 'state')
|
||||
resp = session.get(url,)
|
||||
resp = resp.json()
|
||||
current_state = resp.replace('\"', '')
|
||||
return current_state
|
@ -1,52 +0,0 @@
|
||||
# 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 resource
|
||||
from openstack.meter.alarm import alarm_service
|
||||
|
||||
|
||||
class AlarmChange(resource.Resource):
|
||||
""".. caution:: This API is a work in progress and is subject to change."""
|
||||
id_attribute = 'event_id'
|
||||
resource_key = 'alarm_change'
|
||||
base_path = '/alarms/%(alarm_id)s/history'
|
||||
service = alarm_service.AlarmService()
|
||||
|
||||
# Supported Operations
|
||||
allow_list = True
|
||||
|
||||
# Properties
|
||||
#: The ID of the alarm
|
||||
alarm_id = resource.prop('alarm_id')
|
||||
#: Data describing the change
|
||||
detail = resource.prop('detail')
|
||||
#: The ID of the change event
|
||||
event_id = resource.prop('event_id')
|
||||
#: The project ID on behalf of which the change is being made
|
||||
on_behalf_of_id = resource.prop('on_behalf_of')
|
||||
#: The project ID of the initiating identity
|
||||
project_id = resource.prop('project_id')
|
||||
#: The time/date of the alarm change.
|
||||
#: *Type: ISO 8601 formatted string*
|
||||
triggered_at = resource.prop('timestamp')
|
||||
#: The type of change
|
||||
type = resource.prop('type')
|
||||
#: The user ID of the initiating identity
|
||||
user_id = resource.prop('user_id')
|
||||
|
||||
@classmethod
|
||||
def list(cls, session, limit=None, marker=None, path_args=None,
|
||||
paginated=False, **params):
|
||||
url = cls._get_url(path_args)
|
||||
resp = session.get(url, params=params)
|
||||
for item in resp.json():
|
||||
yield cls.existing(**item)
|
@ -1,24 +0,0 @@
|
||||
# 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 service_filter
|
||||
|
||||
|
||||
class MeterService(service_filter.ServiceFilter):
|
||||
"""The meter service."""
|
||||
|
||||
valid_versions = [service_filter.ValidVersion('v2')]
|
||||
|
||||
def __init__(self, version=None):
|
||||
"""Create a meter service."""
|
||||
super(MeterService, self).__init__(service_type='metering',
|
||||
version=version)
|
@ -1,167 +0,0 @@
|
||||
# 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 proxy2
|
||||
from openstack.meter.v2 import capability
|
||||
from openstack.meter.v2 import meter as _meter
|
||||
from openstack.meter.v2 import resource as _resource
|
||||
from openstack.meter.v2 import sample
|
||||
from openstack.meter.v2 import statistics
|
||||
|
||||
|
||||
class Proxy(proxy2.BaseProxy):
|
||||
""".. caution:: This API is a work in progress and is subject to change."""
|
||||
|
||||
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.meter.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.meter.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.meter.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.meter.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.meter.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.meter.v2.resource.Resource`
|
||||
instance.
|
||||
|
||||
:returns: One :class:`~openstack.meter.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.meter.v2.resource.Resource`
|
||||
"""
|
||||
return self._list(_resource.Resource, paginated=False, **query)
|
||||
|
||||
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.meter.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.meter.v2.sample.Sample`
|
||||
"""
|
||||
return self._list(sample.Sample, paginated=False,
|
||||
counter_name=meter, **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.meter.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.meter.v2.statistics.Statistics`
|
||||
"""
|
||||
return self._list(statistics.Statistics, paginated=False,
|
||||
meter_name=meter, **query)
|
@ -1,37 +0,0 @@
|
||||
# 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 resource2 as resource
|
||||
from openstack.meter import meter_service
|
||||
|
||||
|
||||
class Capability(resource.Resource):
|
||||
""".. caution:: This API is a work in progress and is subject to change."""
|
||||
resource_key = 'capability'
|
||||
resources_key = 'capabilities'
|
||||
base_path = '/capabilities'
|
||||
service = meter_service.MeterService()
|
||||
|
||||
# Supported Operations
|
||||
allow_list = True
|
||||
|
||||
# Properties
|
||||
is_enabled = resource.Body('enabled', type=bool)
|
||||
|
||||
@classmethod
|
||||
def list(cls, session, paginated=False, **params):
|
||||
resp = session.get(cls.base_path,
|
||||
params=params)
|
||||
resp = resp.json()
|
||||
for key, value in resp['api'].items():
|
||||
yield cls.existing(id=key, enabled=value)
|
@ -1,42 +0,0 @@
|
||||
# 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 resource2 as resource
|
||||
from openstack.meter import meter_service
|
||||
|
||||
|
||||
class Meter(resource.Resource):
|
||||
""".. caution:: This API is a work in progress and is subject to change."""
|
||||
resource_key = 'meter'
|
||||
base_path = '/meters'
|
||||
service = meter_service.MeterService()
|
||||
|
||||
# Supported Operations
|
||||
allow_list = True
|
||||
|
||||
# Properties
|
||||
#: The ID of the meter
|
||||
meter_id = resource.Body('meter_id', alternate_id=True)
|
||||
#: The unique name for the meter
|
||||
name = resource.Body('name')
|
||||
#: The ID of the project that owns the resource
|
||||
project_id = resource.Body('project_id')
|
||||
#: The ID of the resource for which the measurements are taken
|
||||
resource_id = resource.Body('resource_id')
|
||||
#: The name of the source where the meter comes from
|
||||
source = resource.Body('source')
|
||||
#: The meter type
|
||||
type = resource.Body('type')
|
||||
#: The unit of measure
|
||||
unit = resource.Body('unit')
|
||||
#: The ID of the user who last triggered an update to the resource
|
||||
user_id = resource.Body('user_id')
|
@ -1,44 +0,0 @@
|
||||
# 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 resource2 as resource
|
||||
from openstack.meter import meter_service
|
||||
|
||||
|
||||
class Resource(resource.Resource):
|
||||
""".. caution:: This API is a work in progress and is subject to change."""
|
||||
base_path = '/resources'
|
||||
service = meter_service.MeterService()
|
||||
|
||||
# Supported Operations
|
||||
allow_get = True
|
||||
allow_list = True
|
||||
|
||||
# Properties
|
||||
#: UTC date & time not later than the first sample known
|
||||
#: for this resource.
|
||||
first_sample_at = resource.Body('first_sample_timestamp')
|
||||
#: UTC date & time not earlier than the last sample known
|
||||
#: for this resource.
|
||||
last_sample_at = resource.Body('last_sample_timestamp')
|
||||
#: A list containing a self link and associated meter links
|
||||
links = resource.Body('links')
|
||||
#: Arbitrary metadata associated with the resource
|
||||
metadata = resource.Body('metadata')
|
||||
#: The ID of the owning project
|
||||
project_id = resource.Body('project_id')
|
||||
#: The ID for the resource
|
||||
resource_id = resource.Body('resource_id', alternate_id=True)
|
||||
#: The name of the source where the resource comes from
|
||||
source = resource.Body('source')
|
||||
#: The ID of the user who created the resource or updated it last
|
||||
user_id = resource.Body('user_id')
|
@ -1,52 +0,0 @@
|
||||
# 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 resource2 as resource
|
||||
from openstack.meter import meter_service
|
||||
|
||||
|
||||
class Sample(resource.Resource):
|
||||
""".. caution:: This API is a work in progress and is subject to change."""
|
||||
base_path = '/meters/%(counter_name)s'
|
||||
service = meter_service.MeterService()
|
||||
|
||||
# Supported Operations
|
||||
allow_get = True
|
||||
allow_list = True
|
||||
|
||||
# Properties
|
||||
#: When the sample has been generated.
|
||||
generated_at = resource.Body('timestamp')
|
||||
#: The message ID
|
||||
message_id = resource.Body('message_id', alternate_id=True)
|
||||
#: Arbitrary metadata associated with the sample
|
||||
metadata = resource.Body('metadata')
|
||||
#: The meter name this sample is for
|
||||
counter_name = resource.Body('counter_name')
|
||||
#: The meter name this sample is for
|
||||
counter_type = resource.Body('counter_type')
|
||||
#: The ID of the project this sample was taken for
|
||||
project_id = resource.Body('project_id')
|
||||
#: When the sample has been recorded.
|
||||
recorded_at = resource.Body('recorded_at')
|
||||
#: The ID of the resource this sample was taken for
|
||||
resource_id = resource.Body('resource_id')
|
||||
#: The name of the source that identifies where the sample comes from
|
||||
source = resource.Body('source')
|
||||
#: The meter type
|
||||
type = resource.Body('type')
|
||||
#: The unit of measure
|
||||
unit = resource.Body('unit')
|
||||
#: The ID of the user this sample was taken for
|
||||
user_id = resource.Body('user_id')
|
||||
#: The metered value
|
||||
volume = resource.Body('volume')
|
@ -1,62 +0,0 @@
|
||||
# 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 resource2 as resource
|
||||
from openstack.meter import meter_service
|
||||
|
||||
|
||||
class Statistics(resource.Resource):
|
||||
""".. caution:: This API is a work in progress and is subject to change."""
|
||||
resource_key = 'statistics'
|
||||
base_path = '/meters/%(meter_name)s/statistics'
|
||||
service = meter_service.MeterService()
|
||||
|
||||
# Supported Operations
|
||||
allow_list = True
|
||||
|
||||
# Properties
|
||||
#: The selectable aggregate value(s)
|
||||
aggregate = resource.Body('aggregate')
|
||||
#: The average of all of the volume values seen in the data
|
||||
avg = resource.Body('avg')
|
||||
#: The number of samples seen
|
||||
count = resource.Body('count')
|
||||
#: The difference, in seconds, between the oldest and newest timestamp
|
||||
duration = resource.Body('duration')
|
||||
#: UTC date and time of the oldest timestamp, or the query end time.
|
||||
duration_end_at = resource.Body('duration_end')
|
||||
#: UTC date and time of the earliest timestamp, or the query start time.
|
||||
duration_start_at = resource.Body('duration_start')
|
||||
#: Dictionary of field names for group, if groupby statistics are requested
|
||||
group_by = resource.Body('groupby')
|
||||
#: The maximum volume seen in the data
|
||||
max = resource.Body('max')
|
||||
#: The minimum volume seen in the data
|
||||
min = resource.Body('min')
|
||||
#: The difference, in seconds, between the period start and end
|
||||
period = resource.Body('period')
|
||||
#: UTC date and time of the period end.
|
||||
period_end_at = resource.Body('period_end')
|
||||
#: UTC date and time of the period start.
|
||||
period_start_at = resource.Body('period_start')
|
||||
#: The total of all of the volume values seen in the data
|
||||
sum = resource.Body('sum')
|
||||
#: The unit type of the data set
|
||||
#: TODO(Qiming): This is still incorrect
|
||||
unit = resource.Body('unit', alternate_id=True)
|
||||
|
||||
@classmethod
|
||||
def list(cls, session, paginated=False, **params):
|
||||
url = cls.base_path % {'meter_name': params.pop('meter_name')}
|
||||
resp = session.get(url, params=params)
|
||||
for stat in resp.json():
|
||||
yield cls.existing(**stat)
|
@ -65,8 +65,6 @@ from openstack.image import image_service
|
||||
from openstack.key_manager import key_manager_service
|
||||
from openstack.load_balancer import load_balancer_service as lb_service
|
||||
from openstack.message import message_service
|
||||
from openstack.meter.alarm import alarm_service
|
||||
from openstack.meter import meter_service
|
||||
from openstack.network import network_service
|
||||
from openstack.object_store import object_store_service
|
||||
from openstack.orchestration import orchestration_service
|
||||
@ -92,7 +90,6 @@ class Profile(object):
|
||||
"""
|
||||
self._services = {}
|
||||
|
||||
self._add_service(alarm_service.AlarmService(version="v2"))
|
||||
self._add_service(baremetal_service.BaremetalService(version="v1"))
|
||||
self._add_service(
|
||||
block_storage_service.BlockStorageService(version="v2"))
|
||||
@ -104,7 +101,6 @@ class Profile(object):
|
||||
self._add_service(key_manager_service.KeyManagerService(version="v1"))
|
||||
self._add_service(lb_service.LoadBalancerService(version="v2"))
|
||||
self._add_service(message_service.MessageService(version="v1"))
|
||||
self._add_service(meter_service.MeterService(version="v2"))
|
||||
self._add_service(network_service.NetworkService(version="v2"))
|
||||
self._add_service(
|
||||
object_store_service.ObjectStoreService(version="v1"))
|
||||
|
@ -1,55 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import unittest
|
||||
|
||||
from openstack.meter.alarm.v2 import alarm
|
||||
from openstack.tests.functional import base
|
||||
|
||||
|
||||
@unittest.skip("bug/1524468")
|
||||
class TestAlarm(base.BaseFunctionalTest):
|
||||
|
||||
ID = None
|
||||
|
||||
def setUp(self):
|
||||
super(TestAlarm, self).setUp()
|
||||
self.require_service('alarming')
|
||||
self.require_service('metering')
|
||||
|
||||
self.NAME = self.getUniqueString()
|
||||
meter = next(self.conn.meter.meters())
|
||||
sot = self.conn.alarm.create_alarm(
|
||||
name=self.NAME,
|
||||
type='threshold',
|
||||
threshold_rule={
|
||||
'meter_name': meter.name,
|
||||
'threshold': 1.1,
|
||||
},
|
||||
)
|
||||
assert isinstance(sot, alarm.Alarm)
|
||||
self.assertEqual(self.NAME, sot.name)
|
||||
self.ID = sot.id
|
||||
|
||||
def tearDown(self):
|
||||
sot = self.conn.alarm.delete_alarm(self.ID, ignore_missing=False)
|
||||
self.assertIsNone(sot)
|
||||
super(TestAlarm, self).tearDown()
|
||||
|
||||
def test_get(self):
|
||||
sot = self.conn.alarm.get_alarm(self.ID)
|
||||
self.assertEqual(self.NAME, sot.name)
|
||||
self.assertEqual(self.ID, sot.id)
|
||||
|
||||
def test_list(self):
|
||||
names = [o.name for o in self.conn.alarm.alarms()]
|
||||
self.assertIn(self.NAME, names)
|
@ -1,44 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import unittest
|
||||
|
||||
from openstack.tests.functional import base
|
||||
|
||||
|
||||
@unittest.skip("bug/1524468")
|
||||
class TestAlarmChange(base.BaseFunctionalTest):
|
||||
|
||||
alarm = None
|
||||
|
||||
def setUp(self):
|
||||
super(TestAlarmChange, self).setUp()
|
||||
self.require_service('alarming')
|
||||
self.require_service('metering')
|
||||
|
||||
self.NAME = self.getUniqueString()
|
||||
meter = next(self.conn.meter.meters())
|
||||
self.alarm = self.conn.alarm.create_alarm(
|
||||
name=self.NAME,
|
||||
type='threshold',
|
||||
threshold_rule={
|
||||
'meter_name': meter.name,
|
||||
'threshold': 1.1,
|
||||
},
|
||||
)
|
||||
self.addCleanup(
|
||||
self.conn.alarm.delete_alarm, self.alarm, ignore_missing=False)
|
||||
|
||||
def test_list(self):
|
||||
change = next(self.conn.alarm.alarm_changes(self.alarm))
|
||||
self.assertEqual(self.alarm.id, change.alarm_id)
|
||||
self.assertEqual('creation', change.type)
|
@ -1,27 +0,0 @@
|
||||
# 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.tests.functional import base
|
||||
|
||||
|
||||
class TestCapability(base.BaseFunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCapability, self).setUp()
|
||||
self.require_service('metering')
|
||||
|
||||
def test_list(self):
|
||||
ids = [o.id for o in self.conn.meter.capabilities()]
|
||||
self.assertIn('resources:query:simple', ids)
|
||||
self.assertIn('meters:query:simple', ids)
|
||||
self.assertIn('statistics:query:simple', ids)
|
||||
self.assertIn('samples:query:simple', ids)
|
@ -1,31 +0,0 @@
|
||||
# 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.tests.functional import base
|
||||
|
||||
|
||||
class TestMeter(base.BaseFunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestMeter, self).setUp()
|
||||
self.require_service('metering')
|
||||
|
||||
def test_list(self):
|
||||
# TODO(thowe): Remove this in favor of create_meter call.
|
||||
# Since we do not have a create meter method at the moment
|
||||
# make sure there is some data in there
|
||||
name = self.getUniqueString()
|
||||
tainer = self.conn.object_store.create_container(name=name)
|
||||
self.conn.object_store.delete_container(tainer)
|
||||
|
||||
names = set([o.name for o in self.conn.meter.meters()])
|
||||
self.assertIn('storage.objects.incoming.bytes', names)
|
@ -1,24 +0,0 @@
|
||||
# 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.tests.functional import base
|
||||
|
||||
|
||||
class TestResource(base.BaseFunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestResource, self).setUp()
|
||||
self.require_service('metering')
|
||||
|
||||
def test_list(self):
|
||||
ids = [o.resource_id for o in self.conn.meter.resources()]
|
||||
self.assertNotEqual(0, len(ids))
|
@ -1,26 +0,0 @@
|
||||
# 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.meter.v2 import sample
|
||||
from openstack.tests.functional import base
|
||||
|
||||
|
||||
class TestSample(base.BaseFunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSample, self).setUp()
|
||||
self.require_service('metering')
|
||||
|
||||
def test_list(self):
|
||||
for meter in self.conn.meter.meters():
|
||||
for sot in self.conn.meter.samples(meter):
|
||||
assert isinstance(sot, sample.Sample)
|
@ -1,26 +0,0 @@
|
||||
# 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.tests.functional import base
|
||||
|
||||
|
||||
class TestStatistics(base.BaseFunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestStatistics, self).setUp()
|
||||
self.require_service('metering')
|
||||
|
||||
def test_list(self):
|
||||
for met in self.conn.meter.meters():
|
||||
for stat in self.conn.meter.statistics(met):
|
||||
self.assertTrue(stat.period_end_at is not None)
|
||||
break
|
@ -1,28 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import testtools
|
||||
|
||||
from openstack.meter.alarm import alarm_service
|
||||
|
||||
|
||||
class TestAlarmService(testtools.TestCase):
|
||||
|
||||
def test_service(self):
|
||||
sot = alarm_service.AlarmService()
|
||||
self.assertEqual('alarming', sot.service_type)
|
||||
self.assertEqual('public', sot.interface)
|
||||
self.assertIsNone(sot.region)
|
||||
self.assertIsNone(sot.service_name)
|
||||
self.assertEqual(1, len(sot.valid_versions))
|
||||
self.assertEqual('v2', sot.valid_versions[0].module)
|
||||
self.assertEqual('v2', sot.valid_versions[0].path)
|
@ -1,107 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from openstack.meter.alarm.v2 import alarm
|
||||
|
||||
IDENTIFIER = 'IDENTIFIER'
|
||||
EXAMPLE = {
|
||||
'alarm_actions': ['1'],
|
||||
'alarm_id': IDENTIFIER,
|
||||
'combination_rule': {'alarm_ids': ['2', 'b'], 'operator': 'or', },
|
||||
'description': '3',
|
||||
'enabled': True,
|
||||
'insufficient_data_actions': ['4'],
|
||||
'name': '5',
|
||||
'ok_actions': ['6'],
|
||||
'project_id': '7',
|
||||
'repeat_actions': False,
|
||||
'severity': 'low',
|
||||
'state': 'insufficient data',
|
||||
'state_timestamp': '2015-03-09T12:15:57.233772',
|
||||
'timestamp': '2015-03-09T12:15:57.233772',
|
||||
'threshold_rule': {
|
||||
'meter_name': 'a',
|
||||
'evaluation_periods:': '1',
|
||||
'period': '60',
|
||||
'statistic': 'avg',
|
||||
'threshold': '92.6',
|
||||
'comparison_operator': 'gt',
|
||||
'exclude_outliers': True,
|
||||
},
|
||||
'time_constraints': [{'name': 'a', 'duration': 'b', 'start': 'c', }],
|
||||
'type': '10',
|
||||
'user_id': '11',
|
||||
}
|
||||
|
||||
|
||||
class TestAlarm(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAlarm, self).setUp()
|
||||
self.resp = mock.Mock()
|
||||
self.resp.body = ''
|
||||
self.resp.json = mock.Mock(return_value=self.resp.body)
|
||||
self.sess = mock.Mock()
|
||||
self.sess.put = mock.Mock(return_value=self.resp)
|
||||
|
||||
def test_basic(self):
|
||||
sot = alarm.Alarm()
|
||||
self.assertIsNone(sot.resource_key)
|
||||
self.assertIsNone(sot.resources_key)
|
||||
self.assertEqual('/alarms', sot.base_path)
|
||||
self.assertEqual('alarming', sot.service.service_type)
|
||||
self.assertTrue(sot.allow_create)
|
||||
self.assertTrue(sot.allow_retrieve)
|
||||
self.assertTrue(sot.allow_update)
|
||||
self.assertTrue(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
def test_make_it(self):
|
||||
sot = alarm.Alarm(EXAMPLE)
|
||||
self.assertEqual(IDENTIFIER, sot.id)
|
||||
self.assertEqual(EXAMPLE['alarm_actions'], sot.alarm_actions)
|
||||
self.assertEqual(IDENTIFIER, sot.alarm_id)
|
||||
self.assertEqual(EXAMPLE['combination_rule'], sot.combination_rule)
|
||||
self.assertEqual(EXAMPLE['description'], sot.description)
|
||||
self.assertTrue(sot.is_enabled)
|
||||
self.assertEqual(EXAMPLE['insufficient_data_actions'],
|
||||
sot.insufficient_data_actions)
|
||||
self.assertEqual(EXAMPLE['name'], sot.name)
|
||||
self.assertEqual(EXAMPLE['ok_actions'], sot.ok_actions)
|
||||
self.assertEqual(EXAMPLE['project_id'], sot.project_id)
|
||||
self.assertFalse(sot.is_repeat_actions)
|
||||
self.assertEqual(EXAMPLE['severity'], sot.severity)
|
||||
self.assertEqual(EXAMPLE['state'], sot.state)
|
||||
self.assertEqual(EXAMPLE['state_timestamp'], sot.state_changed_at)
|
||||
self.assertEqual(EXAMPLE['timestamp'], sot.updated_at)
|
||||
self.assertEqual(EXAMPLE['threshold_rule'], sot.threshold_rule)
|
||||
self.assertEqual(EXAMPLE['time_constraints'], sot.time_constraints)
|
||||
self.assertEqual(EXAMPLE['type'], sot.type)
|
||||
self.assertEqual(EXAMPLE['user_id'], sot.user_id)
|
||||
|
||||
def test_check_status(self):
|
||||
sot = alarm.Alarm(EXAMPLE)
|
||||
sot.check_state(self.sess)
|
||||
|
||||
url = 'alarms/IDENTIFIER/state'
|
||||
self.sess.get.assert_called_with(url,)
|
||||
|
||||
def test_change_status(self):
|
||||
sot = alarm.Alarm(EXAMPLE)
|
||||
self.assertEqual(self.resp.body, sot.change_state(self.sess, 'alarm'))
|
||||
|
||||
url = 'alarms/IDENTIFIER/state'
|
||||
self.sess.put.assert_called_with(url,
|
||||
json='alarm')
|
@ -1,74 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from openstack.meter.alarm.v2 import alarm_change
|
||||
|
||||
IDENTIFIER = 'IDENTIFIER'
|
||||
EXAMPLE = {
|
||||
'alarm_id': 0,
|
||||
'detail': '1',
|
||||
'event_id': IDENTIFIER,
|
||||
'on_behalf_of': '3',
|
||||
'project_id': '4',
|
||||
'timestamp': '2015-03-09T12:15:57.233772',
|
||||
'type': '6',
|
||||
'user_id': '7',
|
||||
}
|
||||
|
||||
|
||||
class TestAlarmChange(testtools.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = alarm_change.AlarmChange()
|
||||
self.assertEqual('alarm_change', sot.resource_key)
|
||||
self.assertIsNone(sot.resources_key)
|
||||
self.assertEqual('/alarms/%(alarm_id)s/history', sot.base_path)
|
||||
self.assertEqual('alarming', sot.service.service_type)
|
||||
self.assertFalse(sot.allow_create)
|
||||
self.assertFalse(sot.allow_retrieve)
|
||||
self.assertFalse(sot.allow_update)
|
||||
self.assertFalse(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
def test_make_it(self):
|
||||
sot = alarm_change.AlarmChange(EXAMPLE)
|
||||
self.assertEqual(IDENTIFIER, sot.id)
|
||||
self.assertEqual(EXAMPLE['alarm_id'], sot.alarm_id)
|
||||
self.assertEqual(EXAMPLE['detail'], sot.detail)
|
||||
self.assertEqual(IDENTIFIER, sot.event_id)
|
||||
self.assertEqual(EXAMPLE['on_behalf_of'], sot.on_behalf_of_id)
|
||||
self.assertEqual(EXAMPLE['project_id'], sot.project_id)
|
||||
self.assertEqual(EXAMPLE['timestamp'], sot.triggered_at)
|
||||
self.assertEqual(EXAMPLE['type'], sot.type)
|
||||
self.assertEqual(EXAMPLE['user_id'], sot.user_id)
|
||||
|
||||
def test_list(self):
|
||||
sess = mock.Mock()
|
||||
resp = mock.Mock()
|
||||
resp.json = mock.Mock(return_value=[EXAMPLE, EXAMPLE])
|
||||
sess.get = mock.Mock(return_value=resp)
|
||||
path_args = {'alarm_id': IDENTIFIER}
|
||||
|
||||
found = alarm_change.AlarmChange.list(sess, path_args=path_args)
|
||||
first = next(found)
|
||||
self.assertEqual(IDENTIFIER, first.id)
|
||||
self.assertEqual(EXAMPLE['alarm_id'], first.alarm_id)
|
||||
self.assertEqual(EXAMPLE['detail'], first.detail)
|
||||
self.assertEqual(IDENTIFIER, first.event_id)
|
||||
self.assertEqual(EXAMPLE['on_behalf_of'], first.on_behalf_of_id)
|
||||
self.assertEqual(EXAMPLE['project_id'], first.project_id)
|
||||
self.assertEqual(EXAMPLE['timestamp'], first.triggered_at)
|
||||
self.assertEqual(EXAMPLE['type'], first.type)
|
||||
self.assertEqual(EXAMPLE['user_id'], first.user_id)
|
@ -1,54 +0,0 @@
|
||||
# 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.meter.alarm.v2 import _proxy
|
||||
from openstack.meter.alarm.v2 import alarm
|
||||
from openstack.meter.alarm.v2 import alarm_change
|
||||
from openstack.tests.unit import test_proxy_base
|
||||
|
||||
|
||||
class TestAlarmProxy(test_proxy_base.TestProxyBase):
|
||||
def setUp(self):
|
||||
super(TestAlarmProxy, self).setUp()
|
||||
self.proxy = _proxy.Proxy(self.session)
|
||||
|
||||
def test_alarm_change_find(self):
|
||||
self.verify_find(self.proxy.find_alarm_change,
|
||||
alarm_change.AlarmChange)
|
||||
|
||||
def test_alarm_changes(self):
|
||||
larm = alarm.Alarm.existing(alarm_id='larm')
|
||||
expected_kwargs = {'path_args': {'alarm_id': 'larm'}}
|
||||
self.verify_list(self.proxy.alarm_changes, alarm_change.AlarmChange,
|
||||
method_args=[larm], paginated=False,
|
||||
expected_kwargs=expected_kwargs)
|
||||
|
||||
def test_alarm_create_attrs(self):
|
||||
self.verify_create(self.proxy.create_alarm, alarm.Alarm)
|
||||
|
||||
def test_alarm_delete(self):
|
||||
self.verify_delete(self.proxy.delete_alarm, alarm.Alarm, False)
|
||||
|
||||
def test_alarm_delete_ignore(self):
|
||||
self.verify_delete(self.proxy.delete_alarm, alarm.Alarm, True)
|
||||
|
||||
def test_alarm_find(self):
|
||||
self.verify_find(self.proxy.find_alarm, alarm.Alarm)
|
||||
|
||||
def test_alarm_get(self):
|
||||
self.verify_get(self.proxy.get_alarm, alarm.Alarm)
|
||||
|
||||
def test_alarms(self):
|
||||
self.verify_list(self.proxy.alarms, alarm.Alarm, paginated=False)
|
||||
|
||||
def test_alarm_update(self):
|
||||
self.verify_update(self.proxy.update_alarm, alarm.Alarm)
|
@ -1,28 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import testtools
|
||||
|
||||
from openstack.meter import meter_service
|
||||
|
||||
|
||||
class TestMeterService(testtools.TestCase):
|
||||
|
||||
def test_service(self):
|
||||
sot = meter_service.MeterService()
|
||||
self.assertEqual('metering', sot.service_type)
|
||||
self.assertEqual('public', sot.interface)
|
||||
self.assertIsNone(sot.region)
|
||||
self.assertIsNone(sot.service_name)
|
||||
self.assertEqual(1, len(sot.valid_versions))
|
||||
self.assertEqual('v2', sot.valid_versions[0].module)
|
||||
self.assertEqual('v2', sot.valid_versions[0].path)
|
@ -1,70 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from openstack.meter.v2 import capability
|
||||
|
||||
EXAMPLE = {
|
||||
"id": "123",
|
||||
"enabled": False,
|
||||
}
|
||||
BODY = {
|
||||
"api": {
|
||||
"statistics:query:complex": False,
|
||||
"alarms:history:query:simple": True,
|
||||
"events:query:simple": True,
|
||||
"alarms:query:simple": True,
|
||||
"resources:query:simple": True,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TestCapability(testtools.TestCase):
|
||||
def test_basic(self):
|
||||
sot = capability.Capability()
|
||||
self.assertEqual('capability', sot.resource_key)
|
||||
self.assertEqual('capabilities', sot.resources_key)
|
||||
self.assertEqual('/capabilities', sot.base_path)
|
||||
self.assertEqual('metering', sot.service.service_type)
|
||||
self.assertFalse(sot.allow_create)
|
||||
self.assertFalse(sot.allow_get)
|
||||
self.assertFalse(sot.allow_update)
|
||||
self.assertFalse(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
def test_make_it(self):
|
||||
sot = capability.Capability(**EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['id'], sot.id)
|
||||
self.assertEqual(EXAMPLE['enabled'], sot.is_enabled)
|
||||
|
||||
def test_list(self):
|
||||
sess = mock.Mock()
|
||||
resp = mock.Mock()
|
||||
resp.json = mock.Mock(return_value=BODY)
|
||||
sess.get = mock.Mock(return_value=resp)
|
||||
|
||||
caps = capability.Capability.list(sess)
|
||||
|
||||
caps = sorted(caps, key=lambda cap: cap.id)
|
||||
self.assertEqual(5, len(caps))
|
||||
self.assertEqual('alarms:history:query:simple', caps[0].id)
|
||||
self.assertTrue(caps[0].is_enabled)
|
||||
self.assertEqual('alarms:query:simple', caps[1].id)
|
||||
self.assertTrue(caps[1].is_enabled)
|
||||
self.assertEqual('events:query:simple', caps[2].id)
|
||||
self.assertTrue(caps[2].is_enabled)
|
||||
self.assertEqual('resources:query:simple', caps[3].id)
|
||||
self.assertTrue(caps[3].is_enabled)
|
||||
self.assertEqual('statistics:query:complex', caps[4].id)
|
||||
self.assertFalse(caps[4].is_enabled)
|
@ -1,54 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import testtools
|
||||
|
||||
from openstack.meter.v2 import meter
|
||||
|
||||
IDENTIFIER = 'IDENTIFIER'
|
||||
EXAMPLE = {
|
||||
'meter_id': IDENTIFIER,
|
||||
'name': 'instance',
|
||||
'project_id': '123',
|
||||
'resource_id': '456',
|
||||
'source': 'abc',
|
||||
'type': 'def',
|
||||
'unit': 'ghi',
|
||||
'user_id': '789'
|
||||
}
|
||||
|
||||
|
||||
class TestMeter(testtools.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = meter.Meter()
|
||||
self.assertEqual('meter', sot.resource_key)
|
||||
self.assertIsNone(sot.resources_key)
|
||||
self.assertEqual('/meters', sot.base_path)
|
||||
self.assertEqual('metering', sot.service.service_type)
|
||||
self.assertFalse(sot.allow_create)
|
||||
self.assertFalse(sot.allow_get)
|
||||
self.assertFalse(sot.allow_update)
|
||||
self.assertFalse(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
def test_make_it(self):
|
||||
sot = meter.Meter(**EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['meter_id'], sot.id)
|
||||
self.assertEqual(EXAMPLE['meter_id'], sot.meter_id)
|
||||
self.assertEqual(EXAMPLE['name'], sot.name)
|
||||
self.assertEqual(EXAMPLE['project_id'], sot.project_id)
|
||||
self.assertEqual(EXAMPLE['resource_id'], sot.resource_id)
|
||||
self.assertEqual(EXAMPLE['source'], sot.source)
|
||||
self.assertEqual(EXAMPLE['type'], sot.type)
|
||||
self.assertEqual(EXAMPLE['unit'], sot.unit)
|
||||
self.assertEqual(EXAMPLE['user_id'], sot.user_id)
|
@ -1,66 +0,0 @@
|
||||
# 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.meter.v2 import _proxy
|
||||
from openstack.meter.v2 import capability
|
||||
from openstack.meter.v2 import meter
|
||||
from openstack.meter.v2 import resource
|
||||
from openstack.meter.v2 import sample
|
||||
from openstack.meter.v2 import statistics
|
||||
from openstack.tests.unit import test_proxy_base2
|
||||
|
||||
|
||||
class TestMeterProxy(test_proxy_base2.TestProxyBase):
|
||||
def setUp(self):
|
||||
super(TestMeterProxy, self).setUp()
|
||||
self.proxy = _proxy.Proxy(self.session)
|
||||
|
||||
def test_capability_find(self):
|
||||
self.verify_find(self.proxy.find_capability, capability.Capability)
|
||||
|
||||
def test_capabilities(self):
|
||||
self.verify_list(self.proxy.capabilities, capability.Capability,
|
||||
paginated=False)
|
||||
|
||||
def test_meter_find(self):
|
||||
self.verify_find(self.proxy.find_meter, meter.Meter)
|
||||
|
||||
def test_meters(self):
|
||||
self.verify_list(self.proxy.meters, meter.Meter, paginated=False)
|
||||
|
||||
def test_resource_find(self):
|
||||
self.verify_find(self.proxy.find_resource, resource.Resource)
|
||||
|
||||
def test_resource_get(self):
|
||||
self.verify_get(self.proxy.get_resource, resource.Resource)
|
||||
|
||||
def test_resources(self):
|
||||
self.verify_list(self.proxy.resources, resource.Resource,
|
||||
paginated=False)
|
||||
|
||||
def test_sample_find(self):
|
||||
self.verify_find(self.proxy.find_sample, sample.Sample)
|
||||
|
||||
def test_samples(self):
|
||||
expected_kwargs = {'counter_name': 'meterone'}
|
||||
self.verify_list(self.proxy.samples, sample.Sample,
|
||||
method_args=['meterone'],
|
||||
paginated=False, expected_kwargs=expected_kwargs)
|
||||
|
||||
def test_statistics_find(self):
|
||||
self.verify_find(self.proxy.find_statistics, statistics.Statistics)
|
||||
|
||||
def test_statistics(self):
|
||||
expected_kwargs = {'meter_name': 'meterone'}
|
||||
self.verify_list(self.proxy.statistics, statistics.Statistics,
|
||||
method_args=['meterone'],
|
||||
paginated=False, expected_kwargs=expected_kwargs)
|
@ -1,59 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import testtools
|
||||
|
||||
from openstack.meter.v2 import resource
|
||||
|
||||
IDENTIFIER = 'IDENTIFIER'
|
||||
LINKS = [{'href': 'first_uri', 'rel': 'label 1', },
|
||||
{'href': 'other_uri', 'rel': 'label', }, ]
|
||||
EXAMPLE = {
|
||||
'resource_id': IDENTIFIER,
|
||||
'first_sample_timestamp': '2015-03-09T12:15:57.233772',
|
||||
'last_sample_timestamp': '2015-03-09T12:15:57.233772',
|
||||
'links': LINKS,
|
||||
'metadata': {'name_one': '1', 'name_two': '2', },
|
||||
'project_id': '123',
|
||||
'source': 'abc',
|
||||
'user_id': '789'
|
||||
}
|
||||
|
||||
|
||||
class TestResource(testtools.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = resource.Resource()
|
||||
self.assertIsNone(sot.resource_key)
|
||||
self.assertIsNone(sot.resources_key)
|
||||
self.assertEqual('/resources', sot.base_path)
|
||||
self.assertEqual('metering', sot.service.service_type)
|
||||
self.assertFalse(sot.allow_create)
|
||||
self.assertTrue(sot.allow_get)
|
||||
self.assertFalse(sot.allow_update)
|
||||
self.assertFalse(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
def test_make_it(self):
|
||||
sot = resource.Resource(**EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['resource_id'], sot.id)
|
||||
self.assertEqual(EXAMPLE['resource_id'], sot.resource_id)
|
||||
self.assertEqual(EXAMPLE['first_sample_timestamp'],
|
||||
sot.first_sample_at)
|
||||
self.assertEqual(EXAMPLE['last_sample_timestamp'],
|
||||
sot.last_sample_at)
|
||||
self.assertEqual(EXAMPLE['links'], sot.links)
|
||||
self.assertEqual(EXAMPLE['metadata'], sot.metadata)
|
||||
self.assertEqual(EXAMPLE['project_id'], sot.project_id)
|
||||
self.assertEqual(EXAMPLE['resource_id'], sot.resource_id)
|
||||
self.assertEqual(EXAMPLE['source'], sot.source)
|
||||
self.assertEqual(EXAMPLE['user_id'], sot.user_id)
|
@ -1,84 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from openstack.meter.v2 import sample
|
||||
|
||||
SAMPLE = {
|
||||
'sample_id': '0',
|
||||
'metadata': {'1': 'one'},
|
||||
'counter_name': '2',
|
||||
'message_id': '4',
|
||||
'project_id': '3',
|
||||
'recorded_at': '2015-03-09T12:15:57.233772',
|
||||
'resource_id': '5',
|
||||
'source': '6',
|
||||
'timestamp': '2015-03-09T12:15:57.233772',
|
||||
'type': '8',
|
||||
'unit': '9',
|
||||
'user_id': '10',
|
||||
'volume': '11.1',
|
||||
}
|
||||
|
||||
|
||||
class TestSample(testtools.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = sample.Sample()
|
||||
self.assertIsNone(sot.resource_key)
|
||||
self.assertIsNone(sot.resources_key)
|
||||
self.assertEqual('/meters/%(counter_name)s', sot.base_path)
|
||||
self.assertEqual('metering', sot.service.service_type)
|
||||
self.assertFalse(sot.allow_create)
|
||||
self.assertTrue(sot.allow_get)
|
||||
self.assertFalse(sot.allow_update)
|
||||
self.assertFalse(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
def test_make_new(self):
|
||||
sot = sample.Sample(**SAMPLE)
|
||||
self.assertEqual(SAMPLE['message_id'], sot.id)
|
||||
self.assertEqual(SAMPLE['metadata'], sot.metadata)
|
||||
self.assertEqual(SAMPLE['counter_name'], sot.counter_name)
|
||||
self.assertEqual(SAMPLE['project_id'], sot.project_id)
|
||||
self.assertEqual(SAMPLE['recorded_at'], sot.recorded_at)
|
||||
self.assertEqual(SAMPLE['resource_id'], sot.resource_id)
|
||||
self.assertEqual(SAMPLE['source'], sot.source)
|
||||
self.assertEqual(SAMPLE['timestamp'], sot.generated_at)
|
||||
self.assertEqual(SAMPLE['type'], sot.type)
|
||||
self.assertEqual(SAMPLE['unit'], sot.unit)
|
||||
self.assertEqual(SAMPLE['user_id'], sot.user_id)
|
||||
self.assertEqual(SAMPLE['volume'], sot.volume)
|
||||
|
||||
def test_list(self):
|
||||
sess = mock.Mock()
|
||||
resp = mock.Mock()
|
||||
resp.json = mock.Mock(return_value=[SAMPLE])
|
||||
resp.status_code = 200
|
||||
sess.get = mock.Mock(return_value=resp)
|
||||
|
||||
found = sample.Sample.list(sess, counter_name='name_of_meter')
|
||||
first = next(found)
|
||||
self.assertEqual(SAMPLE['message_id'], first.id)
|
||||
self.assertEqual(SAMPLE['metadata'], first.metadata)
|
||||
self.assertEqual(SAMPLE['counter_name'], first.counter_name)
|
||||
self.assertEqual(SAMPLE['project_id'], first.project_id)
|
||||
self.assertEqual(SAMPLE['recorded_at'], first.recorded_at)
|
||||
self.assertEqual(SAMPLE['resource_id'], first.resource_id)
|
||||
self.assertEqual(SAMPLE['source'], first.source)
|
||||
self.assertEqual(SAMPLE['timestamp'], first.generated_at)
|
||||
self.assertEqual(SAMPLE['type'], first.type)
|
||||
self.assertEqual(SAMPLE['unit'], first.unit)
|
||||
self.assertEqual(SAMPLE['user_id'], first.user_id)
|
||||
self.assertEqual(SAMPLE['volume'], first.volume)
|
@ -1,93 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from openstack.meter.v2 import statistics
|
||||
|
||||
EXAMPLE = {
|
||||
'aggregate': '1',
|
||||
'avg': '2',
|
||||
'count': '3',
|
||||
'duration': '4',
|
||||
'duration_end': '2015-03-09T12:45:00.000000',
|
||||
'duration_start': '2015-03-09T12:15:00.000000',
|
||||
'groupby': '7',
|
||||
'max': '8',
|
||||
'min': '9',
|
||||
'period': '10',
|
||||
'period_end': '2015-03-09T12:45:00.000000',
|
||||
'period_start': '2015-03-09T12:15:00.000000',
|
||||
'sum': '13',
|
||||
'unit': '14',
|
||||
}
|
||||
|
||||
|
||||
class TestStatistics(testtools.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = statistics.Statistics()
|
||||
self.assertEqual('statistics', sot.resource_key)
|
||||
self.assertIsNone(sot.resources_key)
|
||||
self.assertEqual('/meters/%(meter_name)s/statistics', sot.base_path)
|
||||
self.assertEqual('metering', sot.service.service_type)
|
||||
self.assertFalse(sot.allow_create)
|
||||
self.assertFalse(sot.allow_get)
|
||||
self.assertFalse(sot.allow_update)
|
||||
self.assertFalse(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
def test_make_it(self):
|
||||
sot = statistics.Statistics(**EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['unit'], sot.id)
|
||||
self.assertEqual(EXAMPLE['aggregate'], sot.aggregate)
|
||||
self.assertEqual(EXAMPLE['avg'], sot.avg)
|
||||
self.assertEqual(EXAMPLE['count'], sot.count)
|
||||
self.assertEqual(EXAMPLE['duration'], sot.duration)
|
||||
self.assertEqual(EXAMPLE['duration_end'], sot.duration_end_at)
|
||||
self.assertEqual(EXAMPLE['duration_start'], sot.duration_start_at)
|
||||
self.assertEqual(EXAMPLE['groupby'], sot.group_by)
|
||||
self.assertEqual(EXAMPLE['max'], sot.max)
|
||||
self.assertEqual(EXAMPLE['min'], sot.min)
|
||||
self.assertEqual(EXAMPLE['period'], sot.period)
|
||||
self.assertEqual(EXAMPLE['period_end'], sot.period_end_at)
|
||||
self.assertEqual(EXAMPLE['period_start'], sot.period_start_at)
|
||||
self.assertEqual(EXAMPLE['sum'], sot.sum)
|
||||
self.assertEqual(EXAMPLE['unit'], sot.unit)
|
||||
|
||||
def test_list(self):
|
||||
sess = mock.Mock()
|
||||
resp = mock.Mock()
|
||||
resp.json = mock.Mock(return_value=[EXAMPLE])
|
||||
sess.get = mock.Mock(return_value=resp)
|
||||
reply = statistics.Statistics.list(sess, meter_name='example')
|
||||
|
||||
url = '/meters/example/statistics'
|
||||
stat = next(reply)
|
||||
sess.get.assert_called_with(url,
|
||||
params={})
|
||||
self.assertEqual(EXAMPLE['aggregate'], stat.aggregate)
|
||||
self.assertEqual(EXAMPLE['avg'], stat.avg)
|
||||
self.assertEqual(EXAMPLE['count'], stat.count)
|
||||
self.assertEqual(EXAMPLE['duration'], stat.duration)
|
||||
self.assertEqual(EXAMPLE['duration_end'], stat.duration_end_at)
|
||||
self.assertEqual(EXAMPLE['duration_start'], stat.duration_start_at)
|
||||
self.assertEqual(EXAMPLE['groupby'], stat.group_by)
|
||||
self.assertEqual(EXAMPLE['max'], stat.max)
|
||||
self.assertEqual(EXAMPLE['min'], stat.min)
|
||||
self.assertEqual(EXAMPLE['period'], stat.period)
|
||||
self.assertEqual(EXAMPLE['period_end'], stat.period_end_at)
|
||||
self.assertEqual(EXAMPLE['period_start'], stat.period_start_at)
|
||||
self.assertEqual(EXAMPLE['sum'], stat.sum)
|
||||
self.assertEqual(EXAMPLE['unit'], stat.unit)
|
||||
self.assertRaises(StopIteration, next, reply)
|
@ -102,8 +102,6 @@ class TestConnection(base.RequestsMockTestCase):
|
||||
conn.load_balancer.__class__.__module__)
|
||||
self.assertEqual('openstack.orchestration.v1._proxy',
|
||||
conn.orchestration.__class__.__module__)
|
||||
self.assertEqual('openstack.meter.v2._proxy',
|
||||
conn.meter.__class__.__module__)
|
||||
self.assertEqual('openstack.workflow.v2._proxy',
|
||||
conn.workflow.__class__.__module__)
|
||||
|
||||
|
5
releasenotes/notes/removed-meter-6f6651b6e452e000.yaml
Normal file
5
releasenotes/notes/removed-meter-6f6651b6e452e000.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
upgrade:
|
||||
- |
|
||||
Meter and Alarm services have been removed. The Ceilometer REST API has
|
||||
been deprecated for quite some time and is no longer supported.
|
Loading…
Reference in New Issue
Block a user