Skip to content

Instantly share code, notes, and snippets.

Last active August 27, 2018 08:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Replacement wait-online script
from subprocess import check_output
from time import sleep
import click, sys
def is_interface_up(iface):
return b'state DOWN' not in check_output(["/usr/bin/ip", "link", "show", "dev", iface]) and \
b'inet' in check_output(["/usr/bin/ip", "addr", "show", "dev", iface])
except Exception as ex:
return False
def wait_online(ifaces, waitsec, maxwait):
elapsed = 0
for iface in ifaces:
while not is_interface_up(iface):
print('[%] Interface {} is down, sleeping.'.format(iface))
elapsed += waitsec
if elapsed > maxwait:
print('[!] Unable to bring interfaces up'.format(iface))
print('[+] Interface {} is online!'.format(iface))
@click.option("--waitsec", default=5)
@click.option("--maxwait", default=60)
@click.argument("interfaces", nargs=-1)
def cli(interfaces, waitsec, maxwait):
if interfaces:
print('[+] Waiting for interfaces {} to come up'.format(interfaces))
wait_online(interfaces, waitsec, maxwait)
print('[+] No interfaces are specified, exiting'.format(interfaces))
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment