Example #1
0
    def create(self, adapter_info, level, drives=None, size=None, array=None):
        """

        :param adapter_info:
        :param level:
        :param drives:
        :param size:
        :param array:
        :return:
        """
        size_mb = size and round(size.megabytes) or None

        level = 'r{}'.format(level)

        target_drives = []
        for drive in drives:
            if drive['extra']['vendor_state'] != 'UGood':
                raise RAIDAbstractionException(
                    'Drive index: {}, address:{} is in a failed state, cannot '
                    'create array'.format(
                        drive['index'], drive['extra']['address']))

            target_drives.append(drive['extra']['address'])

        return self.storcli.add(
            controller=self.get_controller_id(adapter_info),
            array_type=level,
            drives=','.join(target_drives),
            size=size_mb
        )
Example #2
0
    def add_spares(self, adapter, drives, arrays=None):
        """

        :param adapter:
        :param drives:
        :param arrays:
        :return:
        """
        adapter_info = self.get_adapter_info(adapter)
        controller_id = self.get_controller_id(adapter_info)

        target_drives = self.get_drives_from_selection(adapter, drives)

        results = []
        dgs = []

        if arrays:
            for ary_index in arrays:
                try:
                    array = adapter_info['configuration']['arrays'][ary_index]
                except IndexError:
                    raise RAIDAbstractionException(
                        'Array {} does not exist'.format(ary_index))
                dgs.append(array['extra']['disk_group'])

        for drive in target_drives:
            enclosure, slot = (int(_)
                               for _ in drive['extra']['address'].split(':'))
            results.append(
                self.storcli.add_hotspare(controller=controller_id,
                                          enclosure=enclosure,
                                          slot=slot,
                                          disk_groups=dgs))

        return results
Example #3
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']
Example #4
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
Example #5
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
Example #6
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),
            'configuration': self.transform_configuration(adapter_index)
        }

        return adapter_details
Example #7
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'])
Example #8
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': 'hpsa',
            'vendor_info': self.get_vendor_info(adapter),
            'configuration':
            self.transform_configuration(adapter['configuration'])
        }

        return adapter_details
Example #9
0
    def delete_logical_drive(self, adapter, array, logical_drive):
        """

        :param adapter:
        :param array:
        :param logical_drive:
        :return:
        """
        adapter_info = self.get_adapter_info(adapter)
        controller_id = self.get_controller_id(adapter_info)

        arrays = adapter_info['configuration']['arrays']

        try:
            # ensure that the index exists
            assert len(arrays[array]['logical_drives']) >= logical_drive + 1
        except (IndexError, AssertionError):
            raise RAIDAbstractionException(
                'Logical Drive does not exist at {}:{}:{}'.format(
                    adapter, array, logical_drive))
        return self.storcli.delete(controller=controller_id,
                                   virtual_drive=logical_drive)
Example #10
0
 def transform_adapter_info(self, adapter_index):
     try:
         return self.dummy_data[adapter_index]
     except IndexError:
         raise RAIDAbstractionException('...')
Example #11
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')