summaryrefslogtreecommitdiffstats
path: root/filter_plugins
diff options
context:
space:
mode:
Diffstat (limited to 'filter_plugins')
-rw-r--r--filter_plugins/oo_filters.py60
-rw-r--r--filter_plugins/oo_zabbix_filters.py51
2 files changed, 110 insertions, 1 deletions
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py
index 9a17913c4..2386b5878 100644
--- a/filter_plugins/oo_filters.py
+++ b/filter_plugins/oo_filters.py
@@ -401,6 +401,63 @@ class FilterModule(object):
"certificate names in host inventory"))
return certificates
+ @staticmethod
+ def oo_pretty_print_cluster(data):
+ ''' Read a subset of hostvars and build a summary of the cluster
+ in the following layout:
+
+"c_id": {
+ "master": [
+ { "name": "c_id-master-12345", "public IP": "172.16.0.1", "private IP": "192.168.0.1", "subtype": "default" }]
+ "node": [
+ { "name": "c_id-node-infra-23456", "public IP": "172.16.0.2", "private IP": "192.168.0.2", "subtype": "infra" },
+ { "name": "c_id-node-compute-23456", "public IP": "172.16.0.3", "private IP": "192.168.0.3", "subtype": "compute" },
+ ...
+ ]}
+ '''
+
+ def _get_tag_value(tags, key):
+ ''' Extract values of a map implemented as a set.
+ Ex: tags = { 'tag_foo_value1', 'tag_bar_value2', 'tag_baz_value3' }
+ key = 'bar'
+ returns 'value2'
+ '''
+ for tag in tags:
+ # Skip tag_env-host-type to avoid ambiguity with tag_env
+ if tag[:17] == 'tag_env-host-type':
+ continue
+ if tag[:len(key)+4] == 'tag_' + key:
+ return tag[len(key)+5:]
+ raise KeyError(key)
+
+ def _add_host(clusters,
+ env,
+ host_type,
+ sub_host_type,
+ host):
+ ''' Add a new host in the clusters data structure '''
+ if env not in clusters:
+ clusters[env] = {}
+ if host_type not in clusters[env]:
+ clusters[env][host_type] = {}
+ if sub_host_type not in clusters[env][host_type]:
+ clusters[env][host_type][sub_host_type] = []
+ clusters[env][host_type][sub_host_type].append(host)
+
+ clusters = {}
+ for host in data:
+ try:
+ _add_host(clusters=clusters,
+ env=_get_tag_value(host['group_names'], 'env'),
+ host_type=_get_tag_value(host['group_names'], 'host-type'),
+ sub_host_type=_get_tag_value(host['group_names'], 'sub-host-type'),
+ host={'name': host['inventory_hostname'],
+ 'public IP': host['ansible_ssh_host'],
+ 'private IP': host['ansible_default_ipv4']['address']})
+ except KeyError:
+ pass
+ return clusters
+
def filters(self):
''' returns a mapping of filters to methods '''
return {
@@ -418,5 +475,6 @@ class FilterModule(object):
"oo_filter_list": self.oo_filter_list,
"oo_parse_heat_stack_outputs": self.oo_parse_heat_stack_outputs,
"oo_parse_certificate_names": self.oo_parse_certificate_names,
- "oo_haproxy_backend_masters": self.oo_haproxy_backend_masters
+ "oo_haproxy_backend_masters": self.oo_haproxy_backend_masters,
+ "oo_pretty_print_cluster": self.oo_pretty_print_cluster
}
diff --git a/filter_plugins/oo_zabbix_filters.py b/filter_plugins/oo_zabbix_filters.py
index c44b874e8..fcfe43777 100644
--- a/filter_plugins/oo_zabbix_filters.py
+++ b/filter_plugins/oo_zabbix_filters.py
@@ -95,6 +95,54 @@ class FilterModule(object):
return data
+ @staticmethod
+ def itservice_results_builder(data, clusters, keys):
+ '''Take a list of dict results,
+ loop through each results and create a hash
+ of:
+ [{clusterid: cluster1, key: 111 }]
+ '''
+ r_list = []
+ for cluster in clusters:
+ for results in data:
+ if cluster == results['item'][0]:
+ results = results['results']
+ if results and len(results) > 0 and all([results[0].has_key(_key) for _key in keys]):
+ tmp = {}
+ tmp['clusterid'] = cluster
+ for key in keys:
+ tmp[key] = results[0][key]
+ r_list.append(tmp)
+
+ return r_list
+
+ @staticmethod
+ def itservice_dependency_builder(data, cluster):
+ '''Take a list of dict results,
+ loop through each results and create a hash
+ of:
+ [{clusterid: cluster1, key: 111 }]
+ '''
+ r_list = []
+ for dep in data:
+ if cluster == dep['clusterid']:
+ r_list.append({'name': '%s - %s' % (dep['clusterid'], dep['description']), 'dep_type': 'hard'})
+
+ return r_list
+
+ @staticmethod
+ def itservice_dep_builder_list(data):
+ '''Take a list of dict results,
+ loop through each results and create a hash
+ of:
+ [{clusterid: cluster1, key: 111 }]
+ '''
+ r_list = []
+ for dep in data:
+ r_list.append({'name': '%s' % dep, 'dep_type': 'hard'})
+
+ return r_list
+
def filters(self):
''' returns a mapping of filters to methods '''
return {
@@ -105,4 +153,7 @@ class FilterModule(object):
"create_data": self.create_data,
"oo_build_zabbix_collect": self.oo_build_zabbix_collect,
"oo_remove_attr_from_list_dict": self.oo_remove_attr_from_list_dict,
+ "itservice_results_builder": self.itservice_results_builder,
+ "itservice_dependency_builder": self.itservice_dependency_builder,
+ "itservice_dep_builder_list": self.itservice_dep_builder_list,
}