parameters: (*devices, task=None)
return_statement: return index_device
docstring: Initialize a set of disks to serve as our index device.
       - There can only be one index device.
       - Two disks are expected and combined as a RAID 1, though a single disk can be used as well.
       - Additional disks are added as spares.
      :param devices: The disks to include in the RAID.
      :param task: celery.Task
      :return: None
      :raises: ValueError, RuntimeError
docstring_summary: Initialize a set of disks to serve as our index device.
       - There can only be one index device.
       - Two disks are expected and combined as a RAID 1, though a single disk can be used as well.
       - Additional disks are added as spares.
      :param devices: The disks to include in the RAID.
      :param task: celery.Task
      :return: None
      :raises: ValueError, RuntimeError
docstring_tokens: Initialize a set of disks to serve as our index device . - There can only be one index device . - Two disks are expected and combined as a RAID 1 though a single disk can be used as well . - Additional disks are added as spares . : param devices : The disks to include in the RAID . : param task : celery . Task : return : None : raises : ValueError RuntimeError
function: def init_index_device(*devices, task=None):
      """
      Initialize a set of disks to serve as our index device.
       - There can only be one index device.
       - Two disks are expected and combined as a RAID 1, though a single disk can be used as well.
       - Additional disks are added as spares.
      :param devices: The disks to include in the RAID.
      :param task: celery.Task
      :return: None
      :raises: ValueError, RuntimeError
      """
  
      bd = Device.get_devices()
      dev_obs = []
  
      # Make sure the disks are suitable for use.
      for dev in devices:
          if dev not in bd:
              raise RuntimeError("Can't find disk: {}.".format(dev))
          dev_ob = bd[dev]
          if dev_ob.state:
              raise RuntimeError("Disk {} already in use: {}".format(dev, dev_ob.state))
  
          dev_obs.append(dev_ob)
  
      # Make sure the disks are reasonably close in size.
      base = dev_obs[0].size
      for dev_ob in dev_obs[1:]:
          if abs(dev_ob.size - base) >= SIZE_VARIATION:
              raise RuntimeError("Disk sizes are too different. {d1.dev_path} - {d1.size_hr()}, "
                                 "{d2.dev_path} - {d2.size_hr()}".format(d1=base, d2=dev_ob))
  
      if not devices:
          raise ValueError("You must specify at least one devices.")
  
      md_num = _next_md(bd)
      # Create a RAID 1, but with only one workind disk.
      mdadm_cmd = [settings.SUDO_PATH, CREATE_INDEX_CMD, '/dev/md{0:d}'.format(md_num),
                   dev_obs[0].dev_path]
      log.info('create index raid command:{}'.format(mdadm_cmd))
  
      proc = subprocess.Popen(mdadm_cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE, stdin=subprocess.PIPE)
      outs, errs = proc.communicate(input=b'y', timeout=5)
      if proc.poll() != 0:
          raise RuntimeError("Raid creation failed: {}.".format(errs))
  
      if len(dev_obs) == 2:
          # Now add the second disk as a spare
          mdadm_add_cmd = [settings.SUDO_PATH, ADD_SPARE_CMD, '/dev/md{0:d}'.format(md_num),
                           dev_obs[1].dev_path]
          proc = subprocess.Popen(mdadm_add_cmd, stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE, stdin=subprocess.PIPE)
          outs, errs = proc.communicate(input=b'y', timeout=5)
          if proc.poll() != 0:
              raise RuntimeError("Fail/ed to add second device: {}.".format(errs))
  
      if task is not None:
          task.update_state(state='WORKING', meta={'msg': 'Formatting device. This may take a '
                                                          'while.',
                                                   'progress': 5})
  
      index_device = MDRaidDevice('md{0:d}'.format(md_num))
  
      index_device.format_xfs(label=settings.INDEX_DEV_LABEL)
  
      return index_device
function_tokens: def init_index_device ( * devices , task = None ) : bd = Device . get_devices ( ) dev_obs = [ ] # Make sure the disks are suitable for use. for dev in devices : if dev not in bd : raise RuntimeError ( "Can't find disk: {}." . format ( dev ) ) dev_ob = bd [ dev ] if dev_ob . state : raise RuntimeError ( "Disk {} already in use: {}" . format ( dev , dev_ob . state ) ) dev_obs . append ( dev_ob ) # Make sure the disks are reasonably close in size. base = dev_obs [ 0 ] . size for dev_ob in dev_obs [ 1 : ] : if abs ( dev_ob . size - base ) >= SIZE_VARIATION : raise RuntimeError ( "Disk sizes are too different. {d1.dev_path} - {d1.size_hr()}, " "{d2.dev_path} - {d2.size_hr()}" . format ( d1 = base , d2 = dev_ob ) ) if not devices : raise ValueError ( "You must specify at least one devices." ) md_num = _next_md ( bd ) # Create a RAID 1, but with only one workind disk. mdadm_cmd = [ settings . SUDO_PATH , CREATE_INDEX_CMD , '/dev/md{0:d}' . format ( md_num ) , dev_obs [ 0 ] . dev_path ] log . info ( 'create index raid command:{}' . format ( mdadm_cmd ) ) proc = subprocess . Popen ( mdadm_cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE , stdin = subprocess . PIPE ) outs , errs = proc . communicate ( input = b'y' , timeout = 5 ) if proc . poll ( ) != 0 : raise RuntimeError ( "Raid creation failed: {}." . format ( errs ) ) if len ( dev_obs ) == 2 : # Now add the second disk as a spare mdadm_add_cmd = [ settings . SUDO_PATH , ADD_SPARE_CMD , '/dev/md{0:d}' . format ( md_num ) , dev_obs [ 1 ] . dev_path ] proc = subprocess . Popen ( mdadm_add_cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE , stdin = subprocess . PIPE ) outs , errs = proc . communicate ( input = b'y' , timeout = 5 ) if proc . poll ( ) != 0 : raise RuntimeError ( "Fail/ed to add second device: {}." . format ( errs ) ) if task is not None : task . update_state ( state = 'WORKING' , meta = { 'msg' : 'Formatting device. This may take a ' 'while.' , 'progress' : 5 } ) index_device = MDRaidDevice ( 'md{0:d}' . format ( md_num ) ) index_device . format_xfs ( label = settings . INDEX_DEV_LABEL ) return index_device