Implemented GMR plugin to show CDM structures

In this changeset, I implemented a small GMR plugin that converts
the cluster data model structure into an XML structure.

Change-Id: I75548952635a0aa3c7dbd6d068831b5765a5db1a
Closes-Bug: #1620551
This commit is contained in:
Vincent Françoise
2016-09-06 12:15:51 +02:00
parent 8a38c4f479
commit 74989fe94e
6 changed files with 267 additions and 8 deletions

View File

@@ -0,0 +1,48 @@
# -*- encoding: utf-8 -*-
# Copyright (c) 2016 b<>com
#
# Authors: Vincent FRANCOISE <vincent.francoise@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.
from oslo_reports import guru_meditation_report as gmr
from watcher._i18n import _
from watcher.decision_engine.model.collector import manager
def register_gmr_plugins():
"""Register GMR plugins that are specific to watcher-decision-engine."""
gmr.TextGuruMeditation.register_section(_('CDMCs'), show_models)
def show_models():
"""Create a formatted output of all the CDMs
Mainly used as a Guru Meditation Report (GMR) plugin
"""
mgr = manager.CollectorManager()
output = []
for name, cdmc in mgr.get_collectors().items():
output.append("")
output.append("~" * len(name))
output.append(name)
output.append("~" * len(name))
output.append("")
cdmc_struct = cdmc.cluster_data_model.to_string()
output.append(cdmc_struct)
return "\n".join(output)

View File

@@ -14,6 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import collections
from lxml import etree
import six
from watcher._i18n import _
@@ -159,3 +162,61 @@ class ModelRoot(object):
def get_resource_from_id(self, resource_id):
return self.resource[str(resource_id)]
def get_node_instances(self, node):
return self.mapping.get_node_instances(node)
def _build_compute_node_element(self, compute_node):
attrib = collections.OrderedDict(
uuid=compute_node.uuid, human_id=compute_node.human_id,
hostname=compute_node.hostname, state=compute_node.state,
status=compute_node.status)
for resource_name, resource in self.resource.items():
res_value = resource.get_capacity(compute_node)
if res_value is not None:
attrib[resource_name] = six.text_type(res_value)
compute_node_el = etree.Element("ComputeNode", attrib=attrib)
return compute_node_el
def _build_instance_element(self, instance):
attrib = collections.OrderedDict(
uuid=instance.uuid, human_id=instance.human_id,
hostname=instance.hostname, state=instance.state)
for resource_name, resource in self.resource.items():
res_value = resource.get_capacity(instance)
if res_value is not None:
attrib[resource_name] = six.text_type(res_value)
instance_el = etree.Element("Instance", attrib=attrib)
return instance_el
def to_string(self):
root = etree.Element("ModelRoot")
# Build compute node tree
for cn in sorted(self.get_all_compute_nodes().values(),
key=lambda cn: cn.uuid):
compute_node_el = self._build_compute_node_element(cn)
# Build mapped instance tree
node_instance_uuids = self.get_node_instances(cn)
for instance_uuid in sorted(node_instance_uuids):
instance = self.get_instance_from_id(instance_uuid)
instance_el = self._build_instance_element(instance)
compute_node_el.append(instance_el)
root.append(compute_node_el)
# Build unmapped instance tree (i.e. not assigned to any compute node)
for instance in sorted(self.get_all_instances().values(),
key=lambda inst: inst.uuid):
try:
self.get_node_from_instance_id(instance.uuid)
except exception.InstanceNotFound:
root.append(self._build_instance_element(instance))
return etree.tostring(root, pretty_print=True).decode('utf-8')

View File

@@ -252,11 +252,11 @@ class BasicConsolidation(base.ServerConsolidationBaseStrategy):
:rtype: float
"""
resource_id = "%s_%s" % (node.uuid, node.hostname)
host_avg_cpu_util = self.ceilometer. \
statistic_aggregation(resource_id=resource_id,
meter_name=self.HOST_CPU_USAGE_METRIC_NAME,
period="7200",
aggregate='avg')
host_avg_cpu_util = self.ceilometer.statistic_aggregation(
resource_id=resource_id,
meter_name=self.HOST_CPU_USAGE_METRIC_NAME,
period="7200",
aggregate='avg')
if host_avg_cpu_util is None:
LOG.error(
@@ -269,7 +269,7 @@ class BasicConsolidation(base.ServerConsolidationBaseStrategy):
cpu_capacity = self.compute_model.get_resource_from_id(
element.ResourceType.cpu_cores).get_capacity(node)
total_cores_used = cpu_capacity * (host_avg_cpu_util / 100)
total_cores_used = cpu_capacity * (host_avg_cpu_util / 100.0)
return self.calculate_weight(node, total_cores_used, 0, 0)