def setup_ips(ips, label):
 existing = set(loopback_ips(label))
 toadd = (set([ip_address(ip) for net in ips for ip in net]) - existing)
 for ip in toadd:
  logger.debug(u'Setup loopback IP address %s', ip)
  with open(os.devnull, u'w') as fnull:
   cmd = [u'ip', u'address', u'add', str(ip), u'dev', u'lo']
   if label:
    cmd += [u'label', u'lo:{0}'.format(label)]
   subprocess.check_call(cmd, stdout=fnull, stderr=fnull)
 def sigterm_handler(signum, frame):
  remove_ips(ips, label)
 signal.signal(signal.SIGTERM, sigterm_handler)

def setup_ips ( ips , label ) : existing = set ( loopback_ips ( label ) ) toadd = ( set ( [ ip_address ( ip ) for net in ips for ip in net ] ) - existing ) for ip in toadd : logger . debug ( u'Setup loopback IP address %s' , ip ) with open ( os . devnull , u'w' ) as fnull : cmd = [ u'ip' , u'address' , u'add' , str ( ip ) , u'dev' , u'lo' ] if label : cmd += [ u'label' , u'lo:{0}' . format ( label ) ] subprocess . check_call ( cmd , stdout = fnull , stderr = fnull ) def sigterm_handler ( signum , frame ) : remove_ips ( ips , label ) signal . signal ( signal . SIGTERM , sigterm_handler )
setup missing ip on loopback interface .