# Path: aodh/api/controllers/v2/base.py
# class ClientSideError(wsme.exc.ClientSideError):
# class ProjectNotAuthorized(ClientSideError):
# class AdvEnum(wtypes.wsproperty):
# class Base(wtypes.DynamicBase):
# class Query(Base):
# class AlarmNotFound(ClientSideError):
# class AlarmRule(Base):
#     def __init__(self, error, status_code=400):
#     def __init__(self, id, aspect='project'):
#     def __init__(self, name, *args, **kwargs):
#     def _get(self, parent):
#     def _set(self, parent, value):
#     def from_db_model(cls, m):
#     def from_db_and_links(cls, m, links):
#     def as_dict(self, db_model):
#     def as_dict_from_keys(self, keys):
#     def to_dict(self):
#     def get_op(self):
#     def set_op(self, value):
#     def __repr__(self):
#     def sample(cls):
#     def as_dict(self):
#     def get_value(self, forced_type=None):
#     def __init__(self, alarm, auth_project):
#     def validate_alarm(alarm):
#     def create_hook(alarm):
#     def update_hook(alarm):
# 
# Path: aodh/api/controllers/v2/utils.py
# def get_auth_project(on_behalf_of=None):
# def sanitize_query(query, db_func, on_behalf_of=None):
# def _verify_query_segregation(query, auth_project=None):
# def validate_query(query, db_func, internal_keys=None,
#                    allow_timestamps=True):
#     def _is_field_metadata(field):
# def _validate_timestamp_fields(query, field_name, operator_list,
#                                allow_timestamps):
# def query_to_kwargs(query, db_func, internal_keys=None,
#                     allow_timestamps=True):
# def _get_query_timestamps(args=None):
#     def _parse_timestamp(timestamp):
# def set_resp_location_hdr(location):
# def get_pagination_options(sort, limit, marker, api_model):
# def get_query_value(queries, field, type=None):
# def is_field_exist(queries, field):
# 
# Path: aodh/keystone_client.py
# CFG_GROUP = "service_credentials"
# OPTS = [
#     cfg.StrOpt('region-name',
#                default=os.environ.get('OS_REGION_NAME'),
#                deprecated_name="os-region-name",
#                help='Region name to use for OpenStack service endpoints.'),
#     cfg.StrOpt('interface',
#                default=os.environ.get(
#                    'OS_INTERFACE', os.environ.get('OS_ENDPOINT_TYPE',
#                                                   'public')),
#                deprecated_name="os-endpoint-type",
#                choices=('public', 'internal', 'admin', 'auth', 'publicURL',
#                         'internalURL', 'adminURL'),
#                help='Type of endpoint in Identity service catalog to use for '
#                     'communication with OpenStack services.'),
# ]
# def get_session(conf):
# def get_client(conf):
# def get_trusted_client(conf, trust_id):
# def get_auth_token(client):
# def get_client_on_behalf_user(conf, auth_plugin):
# def create_trust_id(conf, trustor_user_id, trustor_project_id, roles,
#                     auth_plugin):
# def delete_trust_id(conf, trust_id, auth_plugin):
# def url_for(conf, **kwargs):
# def get_heat_client_from_trust(conf, trust_id):
# def register_keystoneauth_opts(conf):


import json
import threading
import cachetools
import pecan
import wsme
from gnocchiclient import client
from gnocchiclient import exceptions
from keystoneauth1 import exceptions as ka_exceptions
from oslo_config import cfg
from oslo_log import log
from wsme import types as wtypes
from aodh.api.controllers.v2 import base
from aodh.api.controllers.v2 import utils as v2_utils
from aodh import keystone_client

    threshold = wsme.wsattr(float, mandatory=True)
    "The threshold of the alarm"

    aggregation_method = wsme.wsattr(wtypes.text, mandatory=True)
    "The aggregation_method to compare to the threshold"

    evaluation_periods = wsme.wsattr(wtypes.IntegerType(minimum=1), default=1)
    "The number of historical periods to evaluate the threshold"

    granularity = wsme.wsattr(wtypes.IntegerType(minimum=1), default=60)
    "The time range in seconds over which query"

    cache = cachetools.TTLCache(maxsize=1, ttl=3600)
    lock = threading.RLock()

    @classmethod
    def validate_alarm(cls, alarm):
        alarm_rule = getattr(alarm, "%s_rule" % alarm.type)
        aggregation_method = alarm_rule.aggregation_method
        if aggregation_method not in cls._get_aggregation_methods():
            raise base.ClientSideError(
                'aggregation_method should be in %s not %s' % (
                    cls._get_aggregation_methods(), aggregation_method))

    @staticmethod
    @cachetools.cached(cache, lock=lock)
    def _get_aggregation_methods():
        conf = pecan.request.cfg
        gnocchi_client = client.Client(

# Path: aodh/api/controllers/v2/base.py
# class ClientSideError(wsme.exc.ClientSideError):
# class ProjectNotAuthorized(ClientSideError):
# class AdvEnum(wtypes.wsproperty):
# class Base(wtypes.DynamicBase):
# class Query(Base):
# class AlarmNotFound(ClientSideError):
# class AlarmRule(Base):
#     def __init__(self, error, status_code=400):
#     def __init__(self, id, aspect='project'):
#     def __init__(self, name, *args, **kwargs):
#     def _get(self, parent):
#     def _set(self, parent, value):
#     def from_db_model(cls, m):
#     def from_db_and_links(cls, m, links):
#     def as_dict(self, db_model):
#     def as_dict_from_keys(self, keys):
#     def to_dict(self):
#     def get_op(self):
#     def set_op(self, value):
#     def __repr__(self):
#     def sample(cls):
#     def as_dict(self):
#     def get_value(self, forced_type=None):
#     def __init__(self, alarm, auth_project):
#     def validate_alarm(alarm):
#     def create_hook(alarm):
#     def update_hook(alarm):
# 
# Path: aodh/api/controllers/v2/utils.py
# def get_auth_project(on_behalf_of=None):
# def sanitize_query(query, db_func, on_behalf_of=None):
# def _verify_query_segregation(query, auth_project=None):
# def validate_query(query, db_func, internal_keys=None,
#                    allow_timestamps=True):
#     def _is_field_metadata(field):
# def _validate_timestamp_fields(query, field_name, operator_list,
#                                allow_timestamps):
# def query_to_kwargs(query, db_func, internal_keys=None,
#                     allow_timestamps=True):
# def _get_query_timestamps(args=None):
#     def _parse_timestamp(timestamp):
# def set_resp_location_hdr(location):
# def get_pagination_options(sort, limit, marker, api_model):
# def get_query_value(queries, field, type=None):
# def is_field_exist(queries, field):
# 
# Path: aodh/keystone_client.py
# CFG_GROUP = "service_credentials"
# OPTS = [
#     cfg.StrOpt('region-name',
#                default=os.environ.get('OS_REGION_NAME'),
#                deprecated_name="os-region-name",
#                help='Region name to use for OpenStack service endpoints.'),
#     cfg.StrOpt('interface',
#                default=os.environ.get(
#                    'OS_INTERFACE', os.environ.get('OS_ENDPOINT_TYPE',
#                                                   'public')),
#                deprecated_name="os-endpoint-type",
#                choices=('public', 'internal', 'admin', 'auth', 'publicURL',
#                         'internalURL', 'adminURL'),
#                help='Type of endpoint in Identity service catalog to use for '
#                     'communication with OpenStack services.'),
# ]
# def get_session(conf):
# def get_client(conf):
# def get_trusted_client(conf, trust_id):
# def get_auth_token(client):
# def get_client_on_behalf_user(conf, auth_plugin):
# def create_trust_id(conf, trustor_user_id, trustor_project_id, roles,
#                     auth_plugin):
# def delete_trust_id(conf, trust_id, auth_plugin):
# def url_for(conf, **kwargs):
# def get_heat_client_from_trust(conf, trust_id):
# def register_keystoneauth_opts(conf):


# Path: aodh/api/controllers/v2/alarm_rules/gnocchi.py
import json
import threading
import cachetools
import pecan
import wsme
from gnocchiclient import client
from gnocchiclient import exceptions
from keystoneauth1 import exceptions as ka_exceptions
from oslo_config import cfg
from oslo_log import log
from wsme import types as wtypes
from aodh.api.controllers.v2 import base
from aodh.api.controllers.v2 import utils as v2_utils
from aodh import keystone_client


    threshold = wsme.wsattr(float, mandatory=True)
    "The threshold of the alarm"

    aggregation_method = wsme.wsattr(wtypes.text, mandatory=True)
    "The aggregation_method to compare to the threshold"

    evaluation_periods = wsme.wsattr(wtypes.IntegerType(minimum=1), default=1)
    "The number of historical periods to evaluate the threshold"

    granularity = wsme.wsattr(wtypes.IntegerType(minimum=1), default=60)
    "The time range in seconds over which query"

    cache = cachetools.TTLCache(maxsize=1, ttl=3600)
    lock = threading.RLock()

    @classmethod
    def validate_alarm(cls, alarm):
        alarm_rule = getattr(alarm, "%s_rule" % alarm.type)
        aggregation_method = alarm_rule.aggregation_method
        if aggregation_method not in cls._get_aggregation_methods():
            raise base.ClientSideError(
                'aggregation_method should be in %s not %s' % (
                    cls._get_aggregation_methods(), aggregation_method))

    @staticmethod
    @cachetools.cached(cache, lock=lock)
    def _get_aggregation_methods():
        conf = pecan.request.cfg
        gnocchi_client = client.Client(

            '1', keystone_client.get_session(conf),