summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason DeTiberus <jdetiber@redhat.com>2016-06-10 12:34:45 -0400
committerScott Dodson <sdodson@redhat.com>2016-08-24 16:02:48 -0400
commitc538cd6907c92ee2911e265f8a6308934984ed37 (patch)
tree0d32a237b49a9529773380c14e6ff844caff8a5d
parented5ec6907fa805c4dfde714c8cdd7748d15f56ca (diff)
downloadopenshift-c538cd6907c92ee2911e265f8a6308934984ed37.tar.gz
openshift-c538cd6907c92ee2911e265f8a6308934984ed37.tar.bz2
openshift-c538cd6907c92ee2911e265f8a6308934984ed37.tar.xz
openshift-c538cd6907c92ee2911e265f8a6308934984ed37.zip
[metrics] add filter to clean up hostname for use in metrics deployment
-rw-r--r--filter_plugins/oo_filters.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py
index b57bc0afa..0e4f23922 100644
--- a/filter_plugins/oo_filters.py
+++ b/filter_plugins/oo_filters.py
@@ -17,6 +17,7 @@ import re
import json
import yaml
from ansible.utils.unicode import to_unicode
+from urlparse import urlparse
# Disabling too-many-public-methods, since filter methods are necessarily
# public
@@ -709,7 +710,7 @@ class FilterModule(object):
fsType=filesystem,
volumeID=volume_id)))
persistent_volumes.append(persistent_volume)
- elif kind != 'object':
+ elif not (kind == 'object' or kind == 'dynamic'):
msg = "|failed invalid storage kind '{0}' for component '{1}'".format(
kind,
component)
@@ -829,6 +830,22 @@ class FilterModule(object):
return version
+ @staticmethod
+ def oo_hostname_from_url(url):
+ """ Returns the hostname contained in a URL
+
+ Ex: https://ose3-master.example.com/v1/api -> ose3-master.example.com
+ """
+ if not isinstance(url, basestring):
+ raise errors.AnsibleFilterError("|failed expects a string or unicode")
+ parse_result = urlparse(url)
+ if parse_result.netloc != '':
+ return parse_result.netloc
+ else:
+ # netloc wasn't parsed, assume url was missing scheme and path
+ return parse_result.path
+
+
def filters(self):
""" returns a mapping of filters to methods """
return {
@@ -859,5 +876,6 @@ class FilterModule(object):
"oo_get_hosts_from_hostvars": self.oo_get_hosts_from_hostvars,
"oo_image_tag_to_rpm_version": self.oo_image_tag_to_rpm_version,
"oo_merge_dicts": self.oo_merge_dicts,
+ "oo_hostname_from_url": self.oo_hostname_from_url,
"oo_merge_hostvars": self.oo_merge_hostvars,
}