def get_disk_info(disk_name): #Given a disk name like sda, get the disk info return_list = [] try: ids, err = get_disk_ids(disk_name) if err: raise Exception(err) disk_id = None if ids: for id in ids: if id.startswith('scsi'): disk_id = id break if not disk_id: for id in ids: if id.startswith('ata'): disk_id = id break if not disk_id: for id in ids: if id.startswith('wwn'): disk_id = id break capacity, err = get_capacity(disk_name) if err: raise Exception(err) rotational, err = is_rotational(disk_name) if err: raise Exception(err) partitions, err = get_partitions(disk_name) if err: raise Exception(err) scsi_info, err = get_disk_scsi_info(disk_name) if err: raise Exception(err) raid = False hw_platform, err = common.get_hardware_platform() if hw_platform and hw_platform == 'dell': from platforms import dell disk_hw_info_all, err = dell.get_all_disks(0) raid_to_unix_mapping, err = dell.get_hardware_raid_to_unix_mapping( ) if raid_to_unix_mapping and '/dev/%s' % disk_name in raid_to_unix_mapping.keys( ): #Its a hardware RAID so pull the underlying info raid = True controller_id = raid_to_unix_mapping[ '/dev/%s' % disk_name]['controller_number'] device_id = raid_to_unix_mapping['/dev/%s' % disk_name]['device_id'] disk_list, err = dell.get_hardware_raid_hard_drives( controller_id, device_id) if disk_list: for disk in disk_list: disk_dict = {} disk_dict['serial_number'] = disk['serial_number'] disk_dict['name'] = disk_name disk_dict['path'] = '/dev/%s' % disk_name disk_dict['id'] = disk_id disk_dict['capacity'] = capacity disk_dict['rotational'] = rotational disk_dict['partitions'] = partitions disk_dict['status'] = disk['status'] disk_dict['scsi_info'] = scsi_info disk_dict['hw_raid'] = True if disk_hw_info_all and disk[ 'serial_number'] in disk_hw_info_all.keys(): disk_dict['target_id'] = disk_hw_info_all[ disk['serial_number']]['target_id'] disk_dict['enclosure_id'] = disk_hw_info_all[ disk['serial_number']]['enclosure_id'] disk_dict['channel'] = disk_hw_info_all[ disk['serial_number']]['channel'] return_list.append(disk_dict) if not raid: disk_dict = {} disk_dict['name'] = disk_name disk_dict['hw_raid'] = False disk_dict['path'] = '/dev/%s' % disk_name disk_dict['id'] = disk_id disk_dict['capacity'] = capacity serial_number, err = get_serial_number(disk_name) if err: raise Exception(err) disk_dict['serial_number'] = serial_number disk_dict['rotational'] = rotational disk_dict['partitions'] = partitions status, err = get_smart_status(disk_name) if err: raise Exception(err) disk_dict['status'] = status disk_dict['scsi_info'] = scsi_info if hw_platform and hw_platform == 'dell': if disk_hw_info_all and serial_number in disk_hw_info_all.keys( ): disk_dict['target_id'] = disk_hw_info_all[serial_number][ 'target_id'] disk_dict['enclosure_id'] = disk_hw_info_all[ serial_number]['enclosure_id'] disk_dict['channel'] = disk_hw_info_all[serial_number][ 'channel'] return_list.append(disk_dict) except Exception, e: return None, "Error getting disk information : %s" % str(e)
def get_disk_status(disk_name): """Get the smart status of dell hw raid status if applicable of a disk given its name """ return_list = [] try: hw_platform, err = config.get_hardware_platform() hw_raid = False disk_hw_info_all = {} if hw_platform and hw_platform == 'dell': from platforms import dell disk_hw_info_tmp, err = dell.get_all_disks(0) iter = 1 while disk_hw_info_tmp: disk_hw_info_all.update(disk_hw_info_tmp) disk_hw_info_tmp, err = dell.get_all_disks(iter) iter += 1 raid_to_unix_mapping, err = dell.get_hardware_raid_to_unix_mapping() if raid_to_unix_mapping and '/dev/%s' % disk_name in raid_to_unix_mapping.keys(): # Its a hardware RAID so pull the underlying info hw_raid = True controller_id = raid_to_unix_mapping['/dev/%s' % disk_name]['controller_number'] device_id = raid_to_unix_mapping['/dev/%s' % disk_name]['device_id'] disk_list, err = dell.get_hardware_raid_hard_drives( controller_id, device_id) if disk_list: for disk in disk_list: disk_dict = {} disk_dict['serial_number'] = disk['serial_number'] disk_dict['hw_raid'] = True disk_dict['status'] = disk['status'] return_list.append(disk_dict) if not hw_raid: disk_dict = {} serial_number, err = get_serial_number(disk_name) if err: raise Exception(err) disk_dict['serial_number'] = serial_number status, err = get_smart_status(disk_name) if err: raise Exception(err) disk_dict['status'] = status return_list.append(disk_dict) partitions, err = get_partitions(disk_name) if err: raise Exception(err) scsi_info, err = get_disk_scsi_info(disk_name) if err: raise Exception(err) os_devices, err = get_os_devices() if err: raise Exception(err) for disk_dict in return_list: disk_dict['os_device'] = False if partitions: disk_dict['partitions'] = partitions for partition in partitions: if partition['name'] in os_devices: disk_dict['os_device'] = True if scsi_info: disk_dict['scsi_info'] = scsi_info disk_dict['name'] = disk_name disk_dict['path'] = '/dev/%s' % disk_name if hw_platform and hw_platform == 'dell': if disk_hw_info_all and disk_dict['serial_number'] in disk_hw_info_all.keys(): disk_dict['target_id'] = disk_hw_info_all[serial_number]['target_id'] disk_dict['controller_number'] = disk_hw_info_all[serial_number]['controller_number'] disk_dict['enclosure_id'] = disk_hw_info_all[serial_number]['enclosure_id'] disk_dict['channel'] = disk_hw_info_all[serial_number]['channel'] except Exception, e: return None, "Error getting disk status : %s" % str(e)
def get_disk_status(disk_name): """Get the smart status of dell hw raid status if applicable of a disk given its name """ return_list = [] try: hw_platform, err = config.get_hardware_platform() hw_raid = False disk_hw_info_all = {} if hw_platform and hw_platform == 'dell': from platforms import dell disk_hw_info_tmp, err = dell.get_all_disks(0) iter = 1 while disk_hw_info_tmp: disk_hw_info_all.update(disk_hw_info_tmp) disk_hw_info_tmp, err = dell.get_all_disks(iter) iter += 1 raid_to_unix_mapping, err = dell.get_hardware_raid_to_unix_mapping() if raid_to_unix_mapping and '/dev/%s' % disk_name in raid_to_unix_mapping.keys(): # Its a hardware RAID so pull the underlying info hw_raid = True controller_id = raid_to_unix_mapping['/dev/%s' % disk_name]['controller_number'] device_id = raid_to_unix_mapping['/dev/%s' % disk_name]['device_id'] disk_list, err = dell.get_hardware_raid_hard_drives( controller_id, device_id) if disk_list: for disk in disk_list: disk_dict = {} disk_dict['serial_number'] = disk['serial_number'] disk_dict['hw_raid'] = True disk_dict['status'] = disk['status'] return_list.append(disk_dict) if not hw_raid: disk_dict = {} serial_number, err = get_serial_number(disk_name) if err: raise Exception(err) disk_dict['serial_number'] = serial_number status, err = get_smart_status(disk_name) if err: raise Exception(err) disk_dict['status'] = status return_list.append(disk_dict) partitions, err = get_partitions(disk_name) if err: raise Exception(err) scsi_info, err = get_disk_scsi_info(disk_name) if err: raise Exception(err) for disk_dict in return_list: if partitions: disk_dict['partitions'] = partitions if scsi_info: disk_dict['scsi_info'] = scsi_info disk_dict['name'] = disk_name disk_dict['path'] = '/dev/%s' % disk_name if hw_platform and hw_platform == 'dell': if disk_hw_info_all and disk_dict['serial_number'] in disk_hw_info_all.keys(): serial_number = disk_dict['serial_number'] disk_dict['target_id'] = disk_hw_info_all[serial_number]['target_id'] disk_dict['controller_number'] = disk_hw_info_all[serial_number]['controller_number'] disk_dict['enclosure_id'] = disk_hw_info_all[serial_number]['enclosure_id'] disk_dict['channel'] = disk_hw_info_all[serial_number]['channel'] except Exception, e: return None, "Error getting disk status : %s" % str(e)