diff options
| author | Wesley Hearn <wesley.s.hearn@gmail.com> | 2015-05-06 10:27:42 -0400 | 
|---|---|---|
| committer | Wesley Hearn <wesley.s.hearn@gmail.com> | 2015-05-06 10:27:42 -0400 | 
| commit | 1d8e743921a48a5abd2ca75323321f6db261101b (patch) | |
| tree | 8f3370fd2d9537a568d97e48ece9e18f3d0032bb /bin/openshift_ansible | |
| parent | 196d37e2ffa0d7f4221a857b143fd09f84a9d00b (diff) | |
| parent | e0b2d98a6cac21cfa555afe4d660cb62c1180856 (diff) | |
| download | openshift-1d8e743921a48a5abd2ca75323321f6db261101b.tar.gz openshift-1d8e743921a48a5abd2ca75323321f6db261101b.tar.bz2 openshift-1d8e743921a48a5abd2ca75323321f6db261101b.tar.xz openshift-1d8e743921a48a5abd2ca75323321f6db261101b.zip  | |
Merge pull request #208 from openshift/master
Merge Master Into INT
Diffstat (limited to 'bin/openshift_ansible')
| -rw-r--r-- | bin/openshift_ansible/utils.py | 30 | 
1 files changed, 30 insertions, 0 deletions
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)  | 
