Changes to the baseclass for datasources so strategies can be made compatible with every datasource. Baseclass methods clearly describe expected values and types for both parameters and for method returns. query_retry has been added as base method since every current datasource implements it. Ceilometer is updated to work with the new baseclass. Several methods which are not part of the baseclass and are not used by any strategies are removed. The signature of these methods would have to be changed to fit with the new base class while it would limit strategies to only work with Ceilometer. Gnocchi is updated to work with the new baseclass. Gnocchi and Ceilometer will perform a transformation for the host_airflow metric as it retrieves 1/10 th of the actual CFM Monasca is updated to work with the new baseclass. FakeMetrics for Gnocchi, Monasca and Ceilometer are updated to work with the new method signatures of the baseclass. FakeClusterAndMetrics for Ceilometer and Gnocchi are updated to work with the new method signatures of the baseclass. The strategies workload_balance, vm_workload_consolidation, workload_stabilization, basic_consolidation, noisy_neighbour, outlet_temp_control and uniform_airflow are updated to work with the new datasource baseclass. This patch will break compatibility with plugin strategies and datasources due to the changes in signatures. Depends-on: I7aa52a9b82f4aa849f2378d4d1c03453e45c0c78 Change-Id: Ie30ca3dbf01062cbb20d3be5d514ec6b5155cd7c Implements: blueprint formal-datasource-interface
129 lines
4.0 KiB
Python
129 lines
4.0 KiB
Python
# -*- encoding: utf-8 -*-
|
|
# Copyright (c) 2015 b<>com
|
|
#
|
|
# Authors: Jean-Emile DARTOIS <jean-emile.dartois@b-com.com>
|
|
#
|
|
# 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.
|
|
|
|
|
|
class FakeMonascaMetrics(object):
|
|
def __init__(self):
|
|
self.emptytype = ""
|
|
|
|
def empty_one_metric(self, emptytype):
|
|
self.emptytype = emptytype
|
|
|
|
def mock_get_statistics(self, resource=None, resource_type=None,
|
|
meter_name=None, period=None, aggregate='mean',
|
|
granularity=None):
|
|
result = 0.0
|
|
if meter_name == 'host_cpu_usage':
|
|
result = self.get_usage_compute_node_cpu(resource)
|
|
elif meter_name == 'instance_cpu_usage':
|
|
result = self.get_average_usage_instance_cpu(resource)
|
|
return result
|
|
|
|
def mock_get_statistics_wb(self, resource=None, resource_type=None,
|
|
meter_name=None, period=None, aggregate='mean',
|
|
granularity=None):
|
|
"""Statistics for workload balance strategy"""
|
|
|
|
result = 0.0
|
|
if meter_name == 'instance_cpu_usage':
|
|
result = self.get_average_usage_instance_cpu_wb(resource)
|
|
return result
|
|
|
|
@staticmethod
|
|
def get_usage_compute_node_cpu(*args, **kwargs):
|
|
"""The last VM CPU usage values to average
|
|
|
|
:param uuid:00
|
|
:return:
|
|
"""
|
|
|
|
resource = args[0]
|
|
uuid = resource.uuid
|
|
|
|
measurements = {}
|
|
# node 0
|
|
measurements['Node_0'] = 7
|
|
measurements['Node_1'] = 7
|
|
# node 1
|
|
measurements['Node_2'] = 80
|
|
# node 2
|
|
measurements['Node_3'] = 5
|
|
measurements['Node_4'] = 5
|
|
measurements['Node_5'] = 10
|
|
# node 3
|
|
measurements['Node_6'] = 8
|
|
measurements['Node_19'] = 10
|
|
# node 4
|
|
measurements['INSTANCE_7'] = 4
|
|
|
|
if uuid not in measurements.keys():
|
|
# measurements[uuid] = random.randint(1, 4)
|
|
measurements[uuid] = 8
|
|
|
|
statistics = [
|
|
{'columns': ['avg'],
|
|
'statistics': [[float(measurements[str(uuid)])]]}]
|
|
cpu_usage = None
|
|
for stat in statistics:
|
|
avg_col_idx = stat['columns'].index('avg')
|
|
values = [r[avg_col_idx] for r in stat['statistics']]
|
|
value = float(sum(values)) / len(values)
|
|
cpu_usage = value
|
|
return cpu_usage
|
|
|
|
@staticmethod
|
|
def get_average_usage_instance_cpu(*args, **kwargs):
|
|
"""The last VM CPU usage values to average
|
|
|
|
:param uuid:00
|
|
:return:
|
|
"""
|
|
|
|
resource = args[0]
|
|
uuid = resource.uuid
|
|
|
|
measurements = {}
|
|
# node 0
|
|
measurements['INSTANCE_0'] = 7
|
|
measurements['INSTANCE_1'] = 7
|
|
# node 1
|
|
measurements['INSTANCE_2'] = 10
|
|
# node 2
|
|
measurements['INSTANCE_3'] = 5
|
|
measurements['INSTANCE_4'] = 5
|
|
measurements['INSTANCE_5'] = 10
|
|
# node 3
|
|
measurements['INSTANCE_6'] = 8
|
|
# node 4
|
|
measurements['INSTANCE_7'] = 4
|
|
|
|
if uuid not in measurements.keys():
|
|
# measurements[uuid] = random.randint(1, 4)
|
|
measurements[uuid] = 8
|
|
|
|
statistics = [
|
|
{'columns': ['avg'],
|
|
'statistics': [[float(measurements[str(uuid)])]]}]
|
|
cpu_usage = None
|
|
for stat in statistics:
|
|
avg_col_idx = stat['columns'].index('avg')
|
|
values = [r[avg_col_idx] for r in stat['statistics']]
|
|
value = float(sum(values)) / len(values)
|
|
cpu_usage = value
|
|
return cpu_usage
|