summaryrefslogtreecommitdiffstats
path: root/roles/openshift_facts/library
diff options
context:
space:
mode:
authorTobias Florek <tob@butter.sh>2015-11-11 09:20:56 +0100
committerTobias Florek <tob@butter.sh>2015-11-11 09:28:14 +0100
commit251dca6634e00fa58457611073ab6293468e3997 (patch)
tree39543ff33f88027f70ff481800a3e7710920e01a /roles/openshift_facts/library
parent586972b427061433ba6a1cde94228c257d84164e (diff)
downloadopenshift-251dca6634e00fa58457611073ab6293468e3997.tar.gz
openshift-251dca6634e00fa58457611073ab6293468e3997.tar.bz2
openshift-251dca6634e00fa58457611073ab6293468e3997.tar.xz
openshift-251dca6634e00fa58457611073ab6293468e3997.zip
remove netaddr dependency
Diffstat (limited to 'roles/openshift_facts/library')
-rwxr-xr-xroles/openshift_facts/library/openshift_facts.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py
index c108cd422..9a5d36643 100755
--- a/roles/openshift_facts/library/openshift_facts.py
+++ b/roles/openshift_facts/library/openshift_facts.py
@@ -24,8 +24,25 @@ import StringIO
import yaml
from distutils.util import strtobool
from distutils.version import LooseVersion
-from netaddr import IPNetwork
+import struct
+import socket
+def first_ip(network):
+ """ Return the first IPv4 address in network
+
+ Args:
+ network (str): network in CIDR format
+ Returns:
+ str: first IPv4 address
+ """
+ def atoi(addr):
+ return struct.unpack("!I", socket.inet_aton(addr))[0]
+ def itoa(addr):
+ return socket.inet_ntoa(struct.pack("!I", addr))
+
+ (address, netmask) = network.split('/')
+ netmask_i = (0xffffffff << (32 - atoi(netmask))) & 0xffffffff
+ return itoa((atoi(address) & netmask_i) + 1)
def hostname_valid(hostname):
""" Test if specified hostname should be considered valid
@@ -525,7 +542,7 @@ def set_aggregate_facts(facts):
'kubernetes.default.svc', 'kubernetes.default.svc.' + cluster_domain]
all_hostnames.update(svc_names)
internal_hostnames.update(svc_names)
- first_svc_ip = str(IPNetwork(facts['master']['portal_net'])[1])
+ first_svc_ip = first_ip(facts['master']['portal_net'])
all_hostnames.add(first_svc_ip)
internal_hostnames.add(first_svc_ip)
_add_etcd_data_dir_fact(facts)