예제 #1
0
    def get_letter_from_index(adapter_info, array_index):
        arrays = adapter_info['configuration']['arrays']

        try:
            our_array = arrays[array_index]
        except IndexError:
            raise RAIDAbstractionException(
                'array {} does not exist'.format(array_index))

        # noinspection PyTypeChecker
        return our_array['extra']['letter']
예제 #2
0
    def transform_configuration(self, original):
        configuration = {'arrays': [], 'spares': [], 'unassigned': []}

        for array in original['arrays']:
            configuration['arrays'].append({
                'free_space':
                array['free_space'],
                'extra': {
                    'letter': array['letter']
                },
                'logical_drives':
                self.transform_logical_drives(array['logical_drives']),
                'physical_drives':
                self.transform_physical_drives(array['physical_drives'])
            })

        #####################################################################################
        # hpssa spares look like this:
        #     [{'arrays': ['A'],
        #       'bay': '8',
        #       'box': '1',
        #       'port': '1I',
        #       'size': 300000000000,
        #       'status': 'OK',
        #       'type': 'SAS'}]
        # since this abstraction layer uses indexes for everything, we convert the letter
        # references to an index reference
        #####################################################################################

        for spare in original['spares']:
            array_indices = []
            for ref in spare['arrays']:
                idx = self.get_array_index_from_letter(configuration['arrays'],
                                                       ref)
                if idx == -1:
                    raise RAIDAbstractionException(
                        'A spare is defined with an invalid array reference')
                array_indices.append(idx)

            spare_physical_drive = self.convert_physical_drive(spare)
            spare_physical_drive['target'] = array_indices
            configuration['spares'].append(spare_physical_drive)

        for unassigned in original['unassigned']:
            configuration['unassigned'].append(
                self.convert_physical_drive(unassigned))

        return configuration
예제 #3
0
    def convert_physical_drive(self, physical_drive):
        status = self.physical_drive_status_map.get(physical_drive['status'])
        if not status:
            raise RAIDAbstractionException(
                'Drive {port}:{box}:{bay} is in an unknown state: {status}'.
                format(**physical_drive))

        new_physical_drive = {
            'size': physical_drive['size'],
            'status': status,
            'type': physical_drive['type'],
            'extra': {
                'port': physical_drive['port'],
                'box': physical_drive['box'],
                'bay': physical_drive['bay'],
            }
        }
        return new_physical_drive
예제 #4
0
    def transform_adapter_info(self, adapter_index):
        """
        Transforms Storcli.controllers[adapter_index] into standard form
        :param adapter_index:
        :return: Adapter details in standard from
        """
        try:
            adapter = self.storcli.controllers[adapter_index]
        except IndexError:
            raise RAIDAbstractionException('Controller does not exist')

        adapter_details = {
            'name': adapter['Basics']['Model'],
            'provider': 'megaraid',
            'vendor_info': self.get_vendor_info(adapter)
        }

        return adapter_details
예제 #5
0
    def delete_logical_drive(self, adapter, array, logical_drive):
        """
        Implementation for RAIDActions.delete_logical_drive

        :param adapter: adapter index
        :param array: array index
        :param logical_drive: logical drive index
        :return:
        """
        adapter_info = self.get_adapter_info(adapter)
        slot = self.get_slot(adapter_info)
        arrays = adapter_info['configuration']['arrays']
        try:
            target = arrays[array]['logical_drives'][logical_drive]
        except IndexError:
            raise RAIDAbstractionException(
                'Logical Drive does not exist at {}:{}:{}'.format(
                    adapter, array, logical_drive))

        return self.hpssa.delete_logical_drive(slot, target['extra']['id'])
예제 #6
0
    def transform_adapter_info(self, adapter_index):
        """
        Transforms python-hpssa adapter information into the standard format expected
        by RAIDActions
        :param adapter_index: list index of the adapter we are targeting
        :return: Adapter details in standard form
        """
        try:
            adapter = self.hpssa.adapters[adapter_index]
        except IndexError:
            raise RAIDAbstractionException('Adapter does not exist')

        adapter_details = {
            'name': adapter['name'],
            'provider': 'hspa',
            'vendor_info': self.get_vendor_info(adapter),
            'configuration':
            self.transform_configuration(adapter['configuration'])
        }

        return adapter_details
예제 #7
0
 def get_slot(adapter_info):
     try:
         return int(adapter_info['vendor_info']['slot'])
     except KeyError:
         raise RAIDAbstractionException(
             'Adapter is missing HP vendor/slot information')
예제 #8
0
 def transform_adapter_info(self, adapter_index):
     try:
         return self.dummy_data[adapter_index]
     except IndexError:
         raise RAIDAbstractionException('...')