def attach_(dev=None):
 cache = uuid()
 if (not cache):
  log.error('No cache to attach {0} to'.format(dev))
  return False
 if (dev is None):
  res = {}
  for (dev, data) in status(alldevs=True).items():
   if ('cache' in data):
    res[dev] = attach_(dev)
  if len(res):
   return res
  else:
   return None
 bcache = uuid(dev)
 if bcache:
  if (bcache == cache):
   log.info('{0} is already attached to bcache {1}, doing nothing'.format(dev, cache))
   return None
  elif (not detach(dev)):
   return False
 log.debug('Attaching {0} to bcache {1}'.format(dev, cache))
 if (not _bcsys(dev, 'attach', cache, 'error', 'Error attaching {0} to bcache {1}'.format(dev, cache))):
  return False
 return _wait((lambda : (uuid(dev) == cache)), 'error', '{0} received attach to bcache {1}, but did not comply'.format(dev, cache))

def attach_ ( dev = None ) : cache = uuid ( ) if ( not cache ) : log . error ( 'No cache to attach {0} to' . format ( dev ) ) return False if ( dev is None ) : res = { } for ( dev , data ) in status ( alldevs = True ) . items ( ) : if ( 'cache' in data ) : res [ dev ] = attach_ ( dev ) if len ( res ) : return res else : return None bcache = uuid ( dev ) if bcache : if ( bcache == cache ) : log . info ( '{0} is already attached to bcache {1}, doing nothing' . format ( dev , cache ) ) return None elif ( not detach ( dev ) ) : return False log . debug ( 'Attaching {0} to bcache {1}' . format ( dev , cache ) ) if ( not _bcsys ( dev , 'attach' , cache , 'error' , 'Error attaching {0} to bcache {1}' . format ( dev , cache ) ) ) : return False return _wait ( ( lambda : ( uuid ( dev ) == cache ) ) , 'error' , '{0} received attach to bcache {1}, but did not comply' . format ( dev , cache ) )
attach a backing devices to a cache set if no dev is given .