blob: 6e2804197fab924a07b3691c9b7f60ef44439606 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/usr/bin/python
###############################################################
# Copyright (c) 2017 ZTE Corporation
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
from numpy import mean
from ansible.plugins.action import ActionBase
class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
if task_vars is None:
task_vars = dict()
result = super(ActionModule, self).run(tmp, task_vars)
if result.get('skipped', False):
return result
return aggregate(self._task.args.get('group'), task_vars)
# aggregate QPI results
def aggregate(group, task_vars):
qpi_results = [task_vars['hostvars'][host]['qpi_result'] for host in task_vars['groups'][group]]
return {
'score': int(mean([r['score'] for r in qpi_results]))
}
|