Change in vdsm[master]: wait for network
phoracek at redhat.com
phoracek at redhat.com
Tue Sep 15 08:36:57 UTC 2015
Petr Horáček has uploaded a new change for review.
Change subject: wait for network
......................................................................
wait for network
Change-Id: Iaa9d53f8f436b5c5f11643ae03bdd768d555b83d
Signed-off-by: Petr Horáček <phoracek at redhat.com>
---
A init/wait_for_network.py
1 file changed, 56 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/48/46148/1
diff --git a/init/wait_for_network.py b/init/wait_for_network.py
new file mode 100644
index 0000000..8c89b0a
--- /dev/null
+++ b/init/wait_for_network.py
@@ -0,0 +1,56 @@
+#!/bin/python
+
+from os import listdir
+from os.path import isfile, join
+
+from vdsm.netlink import monitor
+from vdsm.netinfo import getIpInfo
+
+
+NETWORK_SCRIPTS = '/etc/sysconfig/network-scripts/'
+
+
+def _get_vdsm_ip_onboot_devs():
+ """ Returns set of VDSM devices with assigned IPv4 and ONBOOT=yes """
+ vdsm_ip_onboot_devs = set()
+ ifcfgs = [f for f in listdir(NETWORK_SCRIPTS)
+ if (isfile(join(NETWORK_SCRIPTS, f)) and f.startswith('ifcfg-'))]
+ for ifcfg in ifcfgs:
+ with open(join(NETWORK_SCRIPTS, ifcfg)) as f:
+ # match regexes -> add to vdsm_ip_onboot_devs
+ vdsm_ip_onboot_devs.add(ifcfg[6:])
+ return vdsm_ip_onboot_devs
+
+
+def _get_ipless_devs(devs):
+ """ Return set of IPless devices filtered out of devs """
+ ipless_devs = set()
+ for dev in devs:
+ # XXX: does it report running ip?
+ if getIpInfo(dev)[0] is None:
+ ipless_devs.add(dev)
+ return ipless_devs
+
+
+def _wait_for_ipv4():
+ devs = _get_vdsm_ip_onboot_devs()
+ try:
+ with monitor.Monitor(groups=('ipv4-ifaddr',), timeout=10) as mon:
+ ipless_devs = _get_ipless_devs(devs)
+ for event in mon:
+ label = event.get('label')
+ if (label in ipless_devs and
+ event.get('event') == 'new_addr' and
+ event.get('scope') == 'global'):
+ ipless_devs.remove(label)
+ if not ipless_devs:
+ mon.stop()
+ except monitor.MonitorError as e:
+ if e[0] == monitor.E_TIMEOUT:
+ pass
+ else:
+ raise
+
+
+if __name__ == '__main__':
+ _wait_for_ipv4()
--
To view, visit https://gerrit.ovirt.org/46148
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa9d53f8f436b5c5f11643ae03bdd768d555b83d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Petr Horáček <phoracek at redhat.com>
More information about the vdsm-patches
mailing list