summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorThomas Wiest <twiest@redhat.com>2015-05-01 16:58:41 -0400
committerThomas Wiest <twiest@redhat.com>2015-05-01 17:16:25 -0400
commitdad421c863006f9774f2fed9fc32f3de8f871af6 (patch)
treed70d3f3e6e54765082153bcf75c01750895115ef /bin
parent5da7d14ef47e7f5f8f5d93474ab77d2aec8cdca5 (diff)
downloadopenshift-dad421c863006f9774f2fed9fc32f3de8f871af6.tar.gz
openshift-dad421c863006f9774f2fed9fc32f3de8f871af6.tar.bz2
openshift-dad421c863006f9774f2fed9fc32f3de8f871af6.tar.xz
openshift-dad421c863006f9774f2fed9fc32f3de8f871af6.zip
Added utils.py that contains a normalize_dnsname function good for sorting dns names to a human readable list.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ohi5
-rw-r--r--bin/openshift_ansible/utils.py30
2 files changed, 34 insertions, 1 deletions
diff --git a/bin/ohi b/bin/ohi
index 408961ee4..af1fb8068 100755
--- a/bin/ohi
+++ b/bin/ohi
@@ -12,12 +12,15 @@ import subprocess
import ConfigParser
from openshift_ansible import awsutil
+from openshift_ansible import utils
from openshift_ansible.awsutil import ArgumentError
CONFIG_MAIN_SECTION = 'main'
CONFIG_HOST_TYPE_ALIAS_SECTION = 'host_type_aliases'
CONFIG_INVENTORY_OPTION = 'inventory'
+
+
class Ohi(object):
def __init__(self):
self.inventory = None
@@ -60,7 +63,7 @@ class Ohi(object):
# We weren't able to determine what they wanted to do
raise ArgumentError("Invalid combination of arguments")
- for host in hosts:
+ for host in sorted(hosts, key=utils.normalize_dnsname):
print host
return 0
diff --git a/bin/openshift_ansible/utils.py b/bin/openshift_ansible/utils.py
new file mode 100644
index 000000000..e6243aa5a
--- /dev/null
+++ b/bin/openshift_ansible/utils.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# vim: expandtab:tabstop=4:shiftwidth=4
+
+''' The purpose of this module is to contain small utility functions.
+'''
+
+import re
+
+def normalize_dnsname(name, padding=10):
+ ''' The purpose of this function is to return a dns name with zero padding,
+ so that it sorts properly (as a human would expect).
+
+ Example: name=ex-lrg-node10.prod.rhcloud.com
+ Returns: ex-lrg-node0000000010.prod.rhcloud.com
+
+ Example Usage:
+ sorted(['a3.example.com', 'a10.example.com', 'a1.example.com'],
+ key=normalize_dnsname)
+
+ Returns: ['a1.example.com', 'a3.example.com', 'a10.example.com']
+ '''
+ parts = re.split(r'(\d+)', name)
+ retval = []
+ for part in parts:
+ if re.match(r'^\d+$', part):
+ retval.append(part.zfill(padding))
+ else:
+ retval.append(part)
+
+ return ''.join(retval)