def remove_ips(ips, label):
 existing = set(loopback_ips(label))
 toremove = (set([ip_address(ip) for net in ips for ip in net]) | existing)
 for ip in toremove:
  logger.debug(u'Remove loopback IP address %s', ip)
  with open(os.devnull, u'w') as fnull:
   cmd = [u'ip', u'address', u'delete', str(ip), u'dev', u'lo']
   if label:
    cmd += [u'label', u'lo:{0}'.format(label)]
   try:
    subprocess.check_call(cmd, stdout=fnull, stderr=fnull)
   except subprocess.CalledProcessError:
    logger.warn(u'Unable to remove loopback IP address %s - is                     healthcheck running as root?', str(ip))
 sys.exit(0)

def remove_ips ( ips , label ) : existing = set ( loopback_ips ( label ) ) toremove = ( set ( [ ip_address ( ip ) for net in ips for ip in net ] ) | existing ) for ip in toremove : logger . debug ( u'Remove loopback IP address %s' , ip ) with open ( os . devnull , u'w' ) as fnull : cmd = [ u'ip' , u'address' , u'delete' , str ( ip ) , u'dev' , u'lo' ] if label : cmd += [ u'label' , u'lo:{0}' . format ( label ) ] try : subprocess . check_call ( cmd , stdout = fnull , stderr = fnull ) except subprocess . CalledProcessError : logger . warn ( u'Unable to remove loopback IP address %s - is                     healthcheck running as root?' , str ( ip ) ) sys . exit ( 0 )
remove added ip on loopback interface .