Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 def delete_disk(disk_id):
     """
     Delete a disk
     :param disk_id: Identifier of the disk
     :type disk_id: str
     """
     API._log('Deleting disk {0}'.format(disk_id))
     all_disks = DiskController.list_disks()
     if disk_id not in all_disks:
         raise BadRequest('Disk not available')
     if all_disks[disk_id]['available'] is True:
         raise BadRequest('Disk not yet configured')
     with file_mutex('disk_{0}'.format(disk_id)):
         mountpoints = FSTab.read()
         if disk_id in mountpoints:
             mountpoint = mountpoints[disk_id]
             asds = ASDController.list_asds(mountpoint)
             for asd_id in asds:
                 ASDController.remove_asd(asd_id, mountpoint)
             DiskController.clean_disk(disk_id, mountpoint)
Ejemplo n.º 3
0
    def clear_slot(slot_id):
        # type: (str) -> None
        """
        Clears a slot
        :param slot_id: Identifier of the slot
        :type slot_id: str
        :return: None
        :rtype: NoneType
        """
        try:
            disk = DiskList.get_by_alias(slot_id)
        except ObjectNotFoundException:
            API._logger.warning(
                'Disk with ID {0} is no longer present (or cannot be managed)'.
                format(slot_id))
            return None

        if disk.available is True:
            raise HttpNotAcceptableException(
                error='disk_not_configured',
                error_description='Disk not yet configured')

        with file_mutex('disk_{0}'.format(slot_id)):
            last_exception = None
            for asd in disk.asds:
                try:
                    ASDController.remove_asd(asd=asd)
                except Exception as ex:
                    last_exception = ex
            disk = Disk(disk.id)
            if len(disk.asds) == 0:
                DiskController.clean_disk(disk=disk)
            elif last_exception is not None:
                raise last_exception
            else:
                raise RuntimeError(
                    'Still some ASDs configured on Disk {0}'.format(slot_id))
Ejemplo n.º 4
0
def remove(silent=None):
    """
    Interactive removal part for the ASD manager
    :param silent: If silent == '--force-yes' no question will be asked to confirm the removal
    :type silent: str
    :return: None
    :rtype: NoneType
    """
    _print_and_log(message='\n' +
                   Interactive.boxed_message(['ASD Manager removal']))

    local_client = SSHClient(endpoint='127.0.0.1', username='******')
    if not local_client.file_exists(
            filename='{0}/main.db'.format(Setting.DATABASE_FOLDER)):
        _print_and_log(level='error',
                       message='\n' + Interactive.boxed_message(
                           ['The ASD Manager has already been removed']))
        sys.exit(1)

    _print_and_log(message=' - Validating configuration management')
    try:
        Configuration.list(key='ovs')
    except:
        _print_and_log(
            level='exception',
            message='\n' +
            Interactive.boxed_message(['Could not connect to Arakoon']))
        sys.exit(1)

    _print_and_log(message='  - Retrieving ASD information')
    all_asds = {}
    try:
        all_asds = ASDList.get_asds()
    except:
        _print_and_log(level='exception',
                       message='  - Failed to retrieve the ASD information')

    interactive = silent != '--force-yes'
    if interactive is True:
        message = 'Are you sure you want to continue?'
        if len(all_asds) > 0:
            _print_and_log(message='\n\n+++ ALERT +++\n', level='warning')
            message = 'DATA LOSS possible if proceeding! Continue?'

        proceed = Interactive.ask_yesno(message=message, default_value=False)
        if proceed is False:
            _print_and_log(level='error',
                           message='\n' +
                           Interactive.boxed_message(['Abort removal']))
            sys.exit(1)

    if len(all_asds) > 0:
        _print_and_log(message=' - Removing disks')
        for disk in DiskList.get_disks():
            if disk.available is True:
                continue
            try:
                _print_and_log(
                    message='    - Retrieving ASD information for disk {0}'.
                    format(disk.name))
                for asd in disk.asds:
                    _print_and_log(
                        message='      - Removing ASD {0}'.format(asd.name))
                    ASDController.remove_asd(asd)
                DiskController.clean_disk(disk)
            except Exception:
                _print_and_log(level='exception',
                               message='    - Deleting ASDs failed')

    _print_and_log(message=' - Removing services')
    service_manager = ServiceFactory.get_manager()
    for service in MaintenanceController.get_services():
        service_name = service
        _print_and_log(
            message='    - Removing service {0}'.format(service_name))
        guid = None
        for alba_backend_guid in Configuration.list(key='/ovs/alba/backends'):
            for maintenance_service_name in Configuration.list(
                    key='/ovs/alba/backends/{0}/maintenance/'.format(
                        alba_backend_guid)):
                if maintenance_service_name == service_name:
                    guid = alba_backend_guid
                    break
        MaintenanceController.remove_maintenance_service(
            name=service_name, alba_backend_guid=guid)

    for service_name in [WATCHER_SERVICE, MANAGER_SERVICE]:
        if service_manager.has_service(name=service_name, client=local_client):
            _print_and_log(
                message='   - Removing service {0}'.format(service_name))
            service_manager.stop_service(name=service_name,
                                         client=local_client)
            service_manager.remove_service(name=service_name,
                                           client=local_client)

    _print_and_log(message=' - Removing from configuration management')
    remaining_users = Configuration.uninitialize()
    if not remaining_users:
        local_client.file_delete(filenames=CACC_LOCATION)

    local_client.file_delete(
        filenames='{0}/main.db'.format(Setting.DATABASE_FOLDER))
    _print_and_log(
        message='\n' +
        Interactive.boxed_message(['ASD Manager removal completed']))