Fixed missing attribute in the data model
Querying compute.node.* with Ceilometer requires some additional information in the cluster data model in order to build the resource_id. This patchset add the attribute hostname and change the query. Change-Id: Ifcefcd70a6d0f5967ab4f638ce077e38ef214f64 Closes-Bug: #1521559
This commit is contained in:
parent
ee82531314
commit
da4c9125f7
|
@ -15,11 +15,12 @@
|
|||
# limitations under the License.
|
||||
|
||||
|
||||
class NamedElement(object):
|
||||
class ComputeResource(object):
|
||||
|
||||
def __init__(self):
|
||||
self._uuid = ""
|
||||
self._human_id = ""
|
||||
self._hostname = ""
|
||||
|
||||
@property
|
||||
def uuid(self):
|
||||
|
@ -29,6 +30,14 @@ class NamedElement(object):
|
|||
def uuid(self, u):
|
||||
self._uuid = u
|
||||
|
||||
@property
|
||||
def hostname(self):
|
||||
return self._hostname
|
||||
|
||||
@hostname.setter
|
||||
def hostname(self, h):
|
||||
self._hostname = h
|
||||
|
||||
@property
|
||||
def human_id(self):
|
||||
return self._human_id
|
|
@ -13,13 +13,15 @@
|
|||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from watcher.decision_engine.model.compute_resource import ComputeResource
|
||||
from watcher.decision_engine.model.hypervisor_state import HypervisorState
|
||||
from watcher.decision_engine.model.named_element import NamedElement
|
||||
from watcher.decision_engine.model.power_state import PowerState
|
||||
|
||||
|
||||
class Hypervisor(NamedElement):
|
||||
class Hypervisor(ComputeResource):
|
||||
def __init__(self):
|
||||
super(Hypervisor, self).__init__()
|
||||
self._state = HypervisorState.ONLINE
|
||||
self._status = HypervisorState.ENABLED
|
||||
self._power_state = PowerState.g0
|
||||
|
|
|
@ -13,12 +13,13 @@
|
|||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from watcher.decision_engine.model.named_element import NamedElement
|
||||
from watcher.decision_engine.model.compute_resource import ComputeResource
|
||||
from watcher.decision_engine.model.vm_state import VMState
|
||||
|
||||
|
||||
class VM(NamedElement):
|
||||
class VM(ComputeResource):
|
||||
def __init__(self):
|
||||
super(VM, self).__init__()
|
||||
self._state = VMState.ACTIVE.value
|
||||
|
||||
@property
|
||||
|
|
|
@ -257,8 +257,10 @@ class BasicConsolidation(BaseStrategy):
|
|||
:param model:
|
||||
:return:
|
||||
"""
|
||||
resource_id = "{0}_{1}".format(hypervisor.uuid,
|
||||
hypervisor.hostname)
|
||||
cpu_avg_vm = self.ceilometer. \
|
||||
statistic_aggregation(resource_id=hypervisor.uuid,
|
||||
statistic_aggregation(resource_id=resource_id,
|
||||
meter_name='compute.node.cpu.percent',
|
||||
period="7200",
|
||||
aggregate='avg'
|
||||
|
@ -266,7 +268,7 @@ class BasicConsolidation(BaseStrategy):
|
|||
if cpu_avg_vm is None:
|
||||
LOG.error(
|
||||
"No values returned for {0} compute.node.cpu.percent".format(
|
||||
hypervisor.uuid))
|
||||
resource_id))
|
||||
cpu_avg_vm = 100
|
||||
|
||||
cpu_capacity = model.get_resource_from_id(
|
||||
|
|
|
@ -54,6 +54,7 @@ class NovaClusterModelCollector(BaseClusterModelCollector):
|
|||
# create hypervisor in cluster_model_collector
|
||||
hypervisor = Hypervisor()
|
||||
hypervisor.uuid = service.host
|
||||
hypervisor.hostname = h.hypervisor_hostname
|
||||
# set capacity
|
||||
mem.set_capacity(hypervisor, h.memory_mb)
|
||||
disk.set_capacity(hypervisor, h.free_disk_gb)
|
||||
|
|
|
@ -58,8 +58,11 @@ class FakerModelCollector(BaseClusterModelCollector):
|
|||
|
||||
for i in range(0, count_node):
|
||||
node_uuid = "Node_{0}".format(i)
|
||||
|
||||
hypervisor = Hypervisor()
|
||||
hypervisor.uuid = node_uuid
|
||||
hypervisor.hostname = "host_{0}".format(i)
|
||||
|
||||
mem.set_capacity(hypervisor, 132)
|
||||
disk.set_capacity(hypervisor, 250)
|
||||
num_cores.set_capacity(hypervisor, 40)
|
||||
|
@ -111,6 +114,7 @@ class FakerModelCollector(BaseClusterModelCollector):
|
|||
node_uuid = "Node_{0}".format(i)
|
||||
node = Hypervisor()
|
||||
node.uuid = node_uuid
|
||||
node.hostname = "hostname_{0}".format(i)
|
||||
|
||||
mem.set_capacity(node, 132)
|
||||
disk.set_capacity(node, 250)
|
||||
|
@ -182,6 +186,7 @@ class FakerModelCollector(BaseClusterModelCollector):
|
|||
node_uuid = "Node_{0}".format(i)
|
||||
node = Hypervisor()
|
||||
node.uuid = node_uuid
|
||||
node.hostname = "hostname_{0}".format(i)
|
||||
mem.set_capacity(node, 132)
|
||||
disk.set_capacity(node, 250)
|
||||
num_cores.set_capacity(node, 40)
|
||||
|
@ -219,6 +224,8 @@ class FakerModelCollector(BaseClusterModelCollector):
|
|||
node_uuid = "Node_{0}".format(i)
|
||||
node = Hypervisor()
|
||||
node.uuid = node_uuid
|
||||
node.hostname = "hostname_{0}".format(i)
|
||||
|
||||
mem.set_capacity(node, 132)
|
||||
disk.set_capacity(node, 250)
|
||||
num_cores.set_capacity(node, 40)
|
||||
|
@ -281,6 +288,7 @@ class FakerModelCollector(BaseClusterModelCollector):
|
|||
node_uuid = "Node_{0}".format(i)
|
||||
node = Hypervisor()
|
||||
node.uuid = node_uuid
|
||||
node.hostname = "hostname_{0}".format(i)
|
||||
|
||||
mem.set_capacity(node, 132)
|
||||
disk.set_capacity(node, 250)
|
||||
|
@ -328,6 +336,7 @@ class FakerModelCollector(BaseClusterModelCollector):
|
|||
node_uuid = "Node_{0}".format(i)
|
||||
node = Hypervisor()
|
||||
node.uuid = node_uuid
|
||||
node.hostname = "hostname_{0}".format(i)
|
||||
|
||||
mem.set_capacity(node, 1)
|
||||
disk.set_capacity(node, 1)
|
||||
|
@ -359,6 +368,7 @@ class FakerModelCollector(BaseClusterModelCollector):
|
|||
node_uuid = "Node_" + str(i)
|
||||
node = Hypervisor()
|
||||
node.uuid = node_uuid
|
||||
node.hostname = "hostname_{0}".format(i)
|
||||
|
||||
mem.set_capacity(node, 4)
|
||||
disk.set_capacity(node, 4)
|
||||
|
|
|
@ -49,20 +49,20 @@ class FakerMetricsCollector(object):
|
|||
# Normalize
|
||||
mock = {}
|
||||
# node 0
|
||||
mock['Node_0'] = 7
|
||||
mock['Node_1'] = 7
|
||||
mock['Node_0_hostname_0'] = 7
|
||||
mock['Node_1_hostname_1'] = 7
|
||||
# node 1
|
||||
mock['Node_2'] = 80
|
||||
mock['Node_2_hostname_2'] = 80
|
||||
# node 2
|
||||
mock['Node_3'] = 5
|
||||
mock['Node_4'] = 5
|
||||
mock['Node_5'] = 10
|
||||
mock['Node_3_hostname_3'] = 5
|
||||
mock['Node_4_hostname_4'] = 5
|
||||
mock['Node_5_hostname_5'] = 10
|
||||
|
||||
# node 3
|
||||
mock['Node_6'] = 8
|
||||
mock['Node_19'] = 10
|
||||
mock['Node_6_hostname_6'] = 8
|
||||
mock['Node_19_hostname_19'] = 10
|
||||
# node 4
|
||||
mock['VM_7'] = 4
|
||||
mock['VM_7_hostname_7'] = 4
|
||||
|
||||
if uuid not in mock.keys():
|
||||
# mock[uuid] = random.randint(1, 4)
|
||||
|
|
|
@ -16,17 +16,17 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
from watcher.decision_engine.model.named_element import NamedElement
|
||||
from watcher.decision_engine.model.compute_resource import ComputeResource
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestNamedElement(base.BaseTestCase):
|
||||
def test_namedelement(self):
|
||||
id = NamedElement()
|
||||
id = ComputeResource()
|
||||
id.uuid = "BLABLABLA"
|
||||
self.assertEqual(id.uuid, "BLABLABLA")
|
||||
|
||||
def test_set_get_human_id(self):
|
||||
id = NamedElement()
|
||||
id = ComputeResource()
|
||||
id.human_id = "BLABLABLA"
|
||||
self.assertEqual(id.human_id, "BLABLABLA")
|
||||
|
|
Loading…
Reference in New Issue