def get_drive_info_for_array(config, raid_dev):
    # capture the current status of the drives
    num_expected = config.get_as_int('MONITOR_EXPECTED_NUM_DRIVES')
    working_drives = raidutils.num_working_drives_in_array(raid_dev)
    drives_in_array = raidutils.drives_in_array(raid_dev)
    missing_drives = raidutils.get_missing_drives_for_array(config, raid_dev)

    # build a list of tuples for all drives with the following information:
    # ( drive_num, logical name, serial number, drive state[missing, active, fautly, spare] )
    # for missing drives the logical name will be empty
    all_drive_information = []

    for logical_name, drive_state in drives_in_array:
        serial_num = diskutils.id_for_device('/dev/%s' % logical_name)

        if serial_num == None:
            serial_num = None
            drive_num = -1
        else:
            drive_num = get_drive_number(config, serial_num, num_expected)
        all_drive_information.append(
            (drive_num, logical_name, serial_num, drive_state))

    for drive_num, serial_num in missing_drives:
        logical_name = 'None'
        drive_state = 'missing'
        all_drive_information.append(
            (drive_num, logical_name, serial_num, drive_state))

    all_drive_information.sort(lambda x, y: cmp(x[0], y[0]))

    return [raid_dev, all_drive_information]
def get_drive_info_for_array(config,raid_dev):
        # capture the current status of the drives
        num_expected = config.get_as_int('MONITOR_EXPECTED_NUM_DRIVES')
        working_drives = raidutils.num_working_drives_in_array(raid_dev)
        drives_in_array = raidutils.drives_in_array(raid_dev)
        missing_drives = raidutils.get_missing_drives_for_array(config,raid_dev)

        # build a list of tuples for all drives with the following information:
        # ( drive_num, logical name, serial number, drive state[missing, active, fautly, spare] )
        # for missing drives the logical name will be empty
        all_drive_information = [] 

        for logical_name,drive_state in drives_in_array:
                serial_num=diskutils.id_for_device('/dev/%s' % logical_name)
                
                if serial_num==None:
                        serial_num=None
                        drive_num=-1
                else:
                        drive_num=get_drive_number(config,serial_num,num_expected)
                all_drive_information.append( (drive_num, logical_name, serial_num, drive_state) )

        for drive_num,serial_num in missing_drives:
                logical_name='None'
                drive_state='missing'
                all_drive_information.append( (drive_num, logical_name, serial_num, drive_state) )

        all_drive_information.sort(lambda x,y: cmp(x[0],y[0]))

        return [raid_dev,all_drive_information];
Пример #3
0
    def main(self, md):
        """ 
        Identify the drives in the MD array be serial number 
        and record in raid_monitor.conf.
        Argument is of form 'md0'
        """
        
        syslog.openlog('inv-driveid', 0, syslog.LOG_LOCAL5)

        # drives come back sorted for me! Whee!
        good_drives=raidutils.drives_in_array(md, True)
        if good_drives == None:
            message="No drives found for device: %s\n" % md
            syslog.syslog(message)
            sys.stderr.write(message+"\n")
            return -1

        if len(good_drives) != 2:
            message="Only 1 drive found, not recording result"
            syslog.syslog(message)
            sys.stderr.write(message+"\n")
            return 0
            
        # load config
        config = fileutils.ConfigFileDict(constants.INV_RAID_MONITOR_CONFIG_FILE)

        for x in (0,1):
            id = diskutils.id_for_device('/dev/'+good_drives[x][0])
            disk='DISK'+str(x+1)
            config.set_as_str(disk,id)
            message="%s id: %s" % (disk, id)
            sys.stdout.write(message+"\n")
            syslog.syslog(message)

        config.save_config()
        
        return 0