Esempio n. 1
0
 def add_disk(disk_id):
     """
     Add a disk
     :param disk_id: Identifier of the disk  (eg: '/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0' or 'pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0')
     :type disk_id: str
     :return: Disk information about the newly added disk
     :rtype: dict
     """
     disk_data = DiskController.get_disk_data_by_alias(device_alias=disk_id)
     if disk_data['available'] is False:
         raise BadRequest('Disk already configured')
     alias = disk_data['aliases'][0]
     API._logger.info('Add disk {0}'.format(alias))
     with file_mutex('add_disk'), file_mutex('disk_{0}'.format(disk_id)):
         DiskController.prepare_disk(device_alias=alias)
     return DiskController.get_disk_data_by_alias(device_alias=alias)
Esempio n. 2
0
 def index_disk(disk_id):
     """
     Retrieve information about a single disk
     :param disk_id: Identifier of the disk  (eg: '/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0' or 'pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0')
     :type disk_id: str
     :return: Disk information
     :rtype: dict
     """
     API._logger.info('Listing disk {0}'.format(disk_id))
     return DiskController.get_disk_data_by_alias(device_alias=disk_id)
Esempio n. 3
0
 def list_asds_disk(disk_id):
     """
     Lists all ASDs on a given disk
     :param disk_id: Identifier of the disk  (eg: '/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0' or 'pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0')
     :type disk_id: str
     :return: ASD information for the specified disk
     :rtype: dict
     """
     disk_data = DiskController.get_disk_data_by_alias(device_alias=disk_id)
     for partition_alias, mountpoint in FSTab.read().iteritems():
         if partition_alias in disk_data['partition_aliases']:
             return ASDController.list_asds(mountpoint=mountpoint)
     raise BadRequest('Disk {0} is not yet initialized'.format(disk_data['aliases'][0]))
Esempio n. 4
0
 def add_asd_disk(disk_id):
     """
     Adds an ASD to a disk
     :param disk_id: Identifier of the disk  (eg: '/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0' or 'pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0')
     :type disk_id: str
     :return: None
     """
     disk_data = DiskController.get_disk_data_by_alias(device_alias=disk_id)
     for partition_alias, mountpoint in FSTab.read().iteritems():
         if partition_alias in disk_data['partition_aliases']:
             with file_mutex('add_asd'):
                 ASDController.create_asd(partition_alias=partition_alias)
                 return
     raise BadRequest('Disk {0} is not yet initialized'.format(disk_data['aliases'][0]))
Esempio n. 5
0
 def get_asd(disk_id, asd_id):
     """
     Gets an ASD
     :param disk_id: Identifier of the disk  (eg: '/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0' or 'pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0')
     :type disk_id: str
     :param asd_id: Identifier of the ASD  (eg: bnAWEXuPHN5YJceCeZo7KxaQW86ixXd4, found under /mnt/alba-asd/WDCztMxmRqi6Hx21/)
     :type asd_id: str
     :return: ASD information
     :rtype: dict
     """
     disk_data = DiskController.get_disk_data_by_alias(device_alias=disk_id)
     alias = disk_data['aliases'][0]
     for partition_alias, mountpoint in FSTab.read().iteritems():
         if partition_alias in disk_data['partition_aliases']:
             asds = ASDController.list_asds(mountpoint=mountpoint)
             if asd_id not in asds:
                 raise BadRequest('ASD {0} could not be found on disk'.format(alias))
             return asds[asd_id]
     raise BadRequest('Disk {0} is not yet initialized'.format(alias))
Esempio n. 6
0
    def delete_disk(disk_id):
        """
        Delete a disk
        :param disk_id: Identifier of the disk  (eg: '/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0' or 'pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0')
        :type disk_id: str
        :return: None
        """
        try:
            disk_data = DiskController.get_disk_data_by_alias(device_alias=disk_id)
        except DiskNotFoundError:
            API._logger.warning('Disk with ID {0} is no longer detected on the filesystem'.format(disk_id))
            disk_data = {}

        if disk_data.get('available') is True:
            raise BadRequest('Disk not yet configured')

        if disk_data:
            alias = disk_data['aliases'][0]
            mountpoint = disk_data['mountpoint'] or None
            partition_aliases = disk_data['partition_aliases']
            API._logger.info('Deleting disk {0}'.format(alias))
        else:  # Disk is most likely missing from filesystem
            alias = None
            mountpoint = None
            partition_aliases = json.loads(request.form['partition_aliases'])
            API._logger.info('Deleting unknown disk with partition aliases "{0}"'.format('", "'.join(partition_aliases)))

        if mountpoint is None:  # 'lsblk' did not return mountpoint for the device, but perhaps it's still mounted according to FSTab
            for partition_alias, mtpt in FSTab.read().iteritems():
                if partition_alias in partition_aliases:
                    API._logger.warning('Disk with ID {0} is still mounted on {1} according to FSTab'.format(disk_id, mountpoint))
                    mountpoint = mtpt
                    break

        with file_mutex('disk_{0}'.format(disk_id)):
            if mountpoint is not None:
                for asd_id in ASDController.list_asds(mountpoint=mountpoint):
                    ASDController.remove_asd(asd_id=asd_id,
                                             mountpoint=mountpoint)
            DiskController.clean_disk(device_alias=alias,
                                      mountpoint=mountpoint,
                                      partition_aliases=partition_aliases)
Esempio n. 7
0
 def asd_delete(disk_id, asd_id):
     """
     Deletes an ASD on a given disk
     :param disk_id: Identifier of the Disk  (eg: '/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0' or 'pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0')
     :type disk_id: str
     :param asd_id: Identifier of the ASD  (eg: bnAWEXuPHN5YJceCeZo7KxaQW86ixXd4, found under /mnt/alba-asd/WDCztMxmRqi6Hx21/)
     :type asd_id: str
     :return: None
     """
     disk_data = DiskController.get_disk_data_by_alias(device_alias=disk_id)
     alias = disk_data['aliases'][0]
     API._logger.info('Removing services for disk {0}'.format(alias))
     for partition_alias, mountpoint in FSTab.read().iteritems():
         if partition_alias in disk_data['partition_aliases']:
             if asd_id not in ASDController.list_asds(mountpoint=mountpoint):
                 raise BadRequest('Could not find ASD {0} on disk {1}'.format(asd_id, alias))
             ASDController.remove_asd(asd_id=asd_id,
                                      mountpoint=mountpoint)
             return
     raise BadRequest('Disk {0} is not yet initialized'.format(alias))
Esempio n. 8
0
 def restart_disk(disk_id):
     """
     Restart a disk
     :param disk_id: Identifier of the disk  (eg: '/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0' or 'pci-0000:03:00.0-sas-0x5000c29f4cf04566-lun-0')
     :type disk_id: str
     :return: None
     """
     API._logger.info('Restarting disk {0}'.format(disk_id))
     disk_data = DiskController.get_disk_data_by_alias(device_alias=disk_id)
     alias = disk_data['aliases'][0]
     with file_mutex('disk_{0}'.format(disk_id)):
         API._logger.info('Got lock for restarting disk {0}'.format(alias))
         for partition_alias, mountpoint in FSTab.read().iteritems():
             if partition_alias in disk_data['partition_aliases']:
                 asds = ASDController.list_asds(mountpoint=mountpoint)
                 for asd_id in asds:
                     ASDController.stop_asd(asd_id=asd_id)
                 DiskController.remount_disk(device_alias=alias,
                                             mountpoint=mountpoint)
                 asds = ASDController.list_asds(mountpoint=mountpoint)
                 for asd_id in asds:
                     ASDController.start_asd(asd_id=asd_id)
                 break