"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cloudkitty/collector/monasca.py" between
cloudkitty-12.1.0.tar.gz and cloudkitty-13.0.0.tar.gz

About: OpenStack CloudKitty provides Rating-as-a-Service for OpenStack.
The "Victoria" series (latest release).

monasca.py  (cloudkitty-12.1.0):monasca.py  (cloudkitty-13.0.0)
skipping to change at line 17 skipping to change at line 17
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
from keystoneauth1 import loading as ks_loading from keystoneauth1 import loading as ks_loading
from keystoneclient.v3 import client as ks_client
from monascaclient import client as mclient
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from voluptuous import All from voluptuous import All
from voluptuous import In from voluptuous import In
from voluptuous import Length from voluptuous import Length
from voluptuous import Required from voluptuous import Required
from voluptuous import Schema from voluptuous import Schema
from cloudkitty import collector from cloudkitty import collector
from cloudkitty.common import monasca_client as mon_client_utils
from cloudkitty import dataframe from cloudkitty import dataframe
from cloudkitty import utils as ck_utils from cloudkitty import utils as ck_utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
MONASCA_API_VERSION = '2_0' MONASCA_API_VERSION = '2_0'
COLLECTOR_MONASCA_OPTS = 'collector_monasca' COLLECTOR_MONASCA_OPTS = 'collector_monasca'
collector_monasca_opts = [ collector_monasca_opts = [
cfg.StrOpt( cfg.StrOpt(
skipping to change at line 70 skipping to change at line 69
Required('resource_key', default='resource_id'): Required('resource_key', default='resource_id'):
All(str, Length(min=1)), All(str, Length(min=1)),
Required('aggregation_method', default='max'): Required('aggregation_method', default='max'):
In(['max', 'mean', 'min']), In(['max', 'mean', 'min']),
# In case the metrics in Monasca do not belong to the project # In case the metrics in Monasca do not belong to the project
# cloudkitty is identified in # cloudkitty is identified in
Required('forced_project_id', default=''): str, Required('forced_project_id', default=''): str,
}, },
} }
class EndpointNotFound(Exception):
"""Exception raised if the Monasca endpoint is not found"""
class MonascaCollector(collector.BaseCollector): class MonascaCollector(collector.BaseCollector):
collector_name = 'monasca' collector_name = 'monasca'
@staticmethod @staticmethod
def check_configuration(conf): def check_configuration(conf):
conf = collector.BaseCollector.check_configuration(conf) conf = collector.BaseCollector.check_configuration(conf)
metric_schema = Schema(collector.METRIC_BASE_SCHEMA).extend( metric_schema = Schema(collector.METRIC_BASE_SCHEMA).extend(
MONASCA_EXTRA_SCHEMA) MONASCA_EXTRA_SCHEMA)
output = {} output = {}
for metric_name, metric in conf.items(): for metric_name, metric in conf.items():
met = output[metric_name] = metric_schema(metric) met = output[metric_name] = metric_schema(metric)
if met['extra_args']['resource_key'] not in met['groupby']: if met['extra_args']['resource_key'] not in met['groupby']:
met['groupby'].append(met['extra_args']['resource_key']) met['groupby'].append(met['extra_args']['resource_key'])
return output return output
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(MonascaCollector, self).__init__(**kwargs) super(MonascaCollector, self).__init__(**kwargs)
self._conn = mon_client_utils.get_monasca_client(
self.auth = ks_loading.load_auth_from_conf_options( CONF, COLLECTOR_MONASCA_OPTS)
CONF,
COLLECTOR_MONASCA_OPTS)
self.session = ks_loading.load_session_from_conf_options(
CONF,
COLLECTOR_MONASCA_OPTS,
auth=self.auth)
self.ks_client = ks_client.Client(
session=self.session,
interface=CONF.collector_monasca.interface,
)
self.mon_endpoint = self._get_monasca_endpoint()
if not self.mon_endpoint:
raise EndpointNotFound()
self._conn = mclient.Client(
api_version=MONASCA_API_VERSION,
session=self.session,
endpoint=self.mon_endpoint)
# NOTE(lukapeschke) This function should be removed as soon as the endpoint
# it no longer required by monascaclient
def _get_monasca_endpoint(self):
service_name = cfg.CONF.collector_monasca.monasca_service_name
endpoint_interface_type = cfg.CONF.collector_monasca.interface
service_list = self.ks_client.services.list(name=service_name)
if not service_list:
return None
mon_service = service_list[0]
endpoints = self.ks_client.endpoints.list(mon_service.id)
for endpoint in endpoints:
if endpoint.interface == endpoint_interface_type:
return endpoint.url
return None
def _get_metadata(self, metric_name, conf): def _get_metadata(self, metric_name, conf):
info = {} info = {}
info['unit'] = conf['metrics'][metric_name]['unit'] info['unit'] = conf['metrics'][metric_name]['unit']
dimension_names = self._conn.metric.list_dimension_names( dimension_names = self._conn.metric.list_dimension_names(
metric_name=metric_name) metric_name=metric_name)
info['metadata'] = [d['dimension_name'] for d in dimension_names] info['metadata'] = [d['dimension_name'] for d in dimension_names]
return info return info
 End of changes. 4 change blocks. 
40 lines changed or deleted 3 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)