예제 #1
0
def detect():
    """Detect HP RAID controller configuration."""
    hwlist = []
    disk_count = 0
    try:
        cli = Cli(debug=False)
        if not cli.launch():
            return False
        controllers = cli.ctrl_all_show()
        if not controllers:
            sys.stderr.write('Info: No hpa controller found\n')
            return False

    except Error as expt:
        sys.stderr.write('Info: detect_hpa : %s\n' % expt.value)
        return False

    hwlist.append(('hpa', 'slots', 'count', str(len(controllers))))
    global_pdisk_size = 0
    for controller in controllers:
        try:
            slot = 'slot=%d' % controller[0]
            controllers_infos = cli.ctrl_show(slot)
            for controller_info in controllers_infos.keys():
                hwlist.append(('hpa', slot.replace('=', '_'),
                               controller_info,
                               controllers_infos[controller_info]))
            for _, disks in cli.ctrl_pd_all_show(slot):
                for disk in disks:
                    disk_count += 1
                    hwlist.append(('disk', disk[0], 'type', disk[1]))
                    hwlist.append(('disk', disk[0], 'slot',
                                   str(controller[0])))
                    disk_infos = cli.ctrl_pd_disk_show(slot, disk[0])
                    for disk_info in disk_infos.keys():
                        value = disk_infos[disk_info]
                        if disk_info == 'size':
                            value = detect_utils.size_in_gb(
                                disk_infos[disk_info])
                            global_pdisk_size = (
                                global_pdisk_size + float(value))
                        hwlist.append(('disk', disk[0], disk_info,
                                       value))
        except Error as expt:
            sys.stderr.write('Info: detect_hpa : controller %d : %s\n'
                             % (controller[0], expt.value))

    if global_pdisk_size > 0:
        hwlist.append(('disk', 'hpa', 'size', '%.2f' % global_pdisk_size))

    hwlist.append(('disk', 'hpa', 'count', str(disk_count)))
    return hwlist
예제 #2
0
 def test_size_in_nothing(self):
     self.assertEqual(detect_utils.size_in_gb('100'), '100')
예제 #3
0
 def test_size_in_dottb(self):
     self.assertEqual(detect_utils.size_in_gb('3.4601 TB'), '3460')
예제 #4
0
 def test_size_in_tb(self):
     self.assertEqual(detect_utils.size_in_gb('100TB'), '100000')
예제 #5
0
def detect():
    """Detect LSI MegaRAID controller configuration."""
    hw_lst = []
    ctrl_num = adp_count()
    if ctrl_num == 0:
        return hw_lst

    disk_count = 0
    global_pdisk_size = 0

    for ctrl in range(ctrl_num):
        ctrl_info = adp_all_info(ctrl)
        for entry in ctrl_info.keys():
            hw_lst.append(('megaraid', 'Controller_%d' % ctrl, '%s' % entry,
                           '%s' % ctrl_info[entry]))

        for enc in enc_info(ctrl):
            if "Enclosure" in enc.keys():
                for key in enc.keys():
                    ignore_list = ["ExitCode", "Enclosure"]
                    if key in ignore_list:
                        continue
                    hw_lst.append(('megaraid', 'Controller_%d/Enclosure_%s' %
                                   (ctrl, enc["Enclosure"]), '%s' % key,
                                   '%s' % enc[key]))

            for slot_num in range(enc['NumberOfSlots']):
                disk = 'disk%d' % slot_num
                info = pdinfo(ctrl, enc['DeviceId'], slot_num)

                # If no PdType, it means that's not a disk
                if 'PdType' not in info.keys():
                    continue

                disk_count += 1
                hw_lst.append(('pdisk', disk, 'ctrl', str(ctrl_num)))
                hw_lst.append(('pdisk', disk, 'type', info['PdType']))
                hw_lst.append(
                    ('pdisk', disk, 'id',
                     '%s:%d' % (info['EnclosureDeviceId'], slot_num)))
                disk_size = detect_utils.size_in_gb(
                    "%s %s" % (info['CoercedSize'].split()[0],
                               info['CoercedSize'].split()[1]))
                global_pdisk_size = global_pdisk_size + float(disk_size)
                hw_lst.append(('pdisk', disk, 'size', disk_size))

                for key in info.keys():
                    ignore_list = [
                        'PdType', 'EnclosureDeviceId', 'CoercedSize',
                        'ExitCode'
                    ]
                    if key not in ignore_list:
                        if "DriveTemperature" in key:
                            if "C" in str(info[key].split()[0]):
                                pdisk = info[key].split()[0].split("C")[0]
                                hw_lst.append(
                                    ('pdisk', disk, key, str(pdisk).strip()))
                                hw_lst.append(('pdisk', disk, "%s_units" % key,
                                               "Celsius"))
                            else:
                                hw_lst.append(('pdisk', disk, key,
                                               str(info[key]).strip()))
                        elif "InquiryData" in key:
                            count = 0
                            for mystring in info[key].split():
                                hw_lst.append(
                                    ('pdisk', disk, "%s[%d]" % (key, count),
                                     str(mystring.strip())))
                                count = count + 1
                        else:
                            hw_lst.append(
                                ('pdisk', disk, key, str(info[key]).strip()))
            if global_pdisk_size > 0:
                hw_lst.append(
                    ('pdisk', 'all', 'size', "%.2f" % global_pdisk_size))
            for ld_num in range(ld_get_num(ctrl)):
                disk = 'disk%d' % ld_num
                info = ld_get_info(ctrl, ld_num)
                ignore_list = ['Size']

                for item in info.keys():
                    if item not in ignore_list:
                        hw_lst.append(('ldisk', disk, item, str(info[item])))
                if 'Size' in info:
                    hw_lst.append(('ldisk', disk, 'Size',
                                   detect_utils.size_in_gb(info['Size'])))
    hw_lst.append(('disk', 'megaraid', 'count', str(disk_count)))
    return hw_lst