def search_lxc_bridges():
 bridges = __context__.get('lxc.bridges', None)
 if (not bridges):
  bridges = set()
  running_bridges = set()
  bridges.add(DEFAULT_BR)
  try:
   output = __salt__['cmd.run_all']('brctl show')
   for line in output['stdout'].splitlines()[1:]:
    if (not line.startswith(' ')):
     running_bridges.add(line.split()[0].strip())
  except (SaltInvocationError, CommandExecutionError):
   pass
  for (ifc, ip) in six.iteritems(__grains__.get('ip_interfaces', {})):
   if (ifc in running_bridges):
    bridges.add(ifc)
   elif os.path.exists('/sys/devices/virtual/net/{0}/bridge'.format(ifc)):
    bridges.add(ifc)
  bridges = list(bridges)
  def sort_bridges(a):
   pref = 'z'
   if ('lxc' in a):
    pref = 'a'
   elif ('br0' == a):
    pref = 'c'
   return '{0}_{1}'.format(pref, a)
  bridges.sort(key=sort_bridges)
  __context__['lxc.bridges'] = bridges
 return bridges

def search_lxc_bridges ( ) : bridges = __context__ . get ( 'lxc.bridges' , None ) if ( not bridges ) : bridges = set ( ) running_bridges = set ( ) bridges . add ( DEFAULT_BR ) try : output = __salt__ [ 'cmd.run_all' ] ( 'brctl show' ) for line in output [ 'stdout' ] . splitlines ( ) [ 1 : ] : if ( not line . startswith ( ' ' ) ) : running_bridges . add ( line . split ( ) [ 0 ] . strip ( ) ) except ( SaltInvocationError , CommandExecutionError ) : pass for ( ifc , ip ) in six . iteritems ( __grains__ . get ( 'ip_interfaces' , { } ) ) : if ( ifc in running_bridges ) : bridges . add ( ifc ) elif os . path . exists ( '/sys/devices/virtual/net/{0}/bridge' . format ( ifc ) ) : bridges . add ( ifc ) bridges = list ( bridges ) def sort_bridges ( a ) : pref = 'z' if ( 'lxc' in a ) : pref = 'a' elif ( 'br0' == a ) : pref = 'c' return '{0}_{1}' . format ( pref , a ) bridges . sort ( key = sort_bridges ) __context__ [ 'lxc.bridges' ] = bridges return bridges
search which bridges are potentially available as lxc bridges cli example: .