Exemple #1
0
def warn_about_low_disk_space(request):
    """Warn about insufficient space on root partition."""
    if not is_user_admin(request, cached=True):
        return

    disks = storage.get_disks()
    list_root = [disk for disk in disks if disk['mountpoint'] == '/']
    if not list_root:
        logger.error('Error getting information about root partition.')
        return

    percent_used = list_root[0]['percent_used']
    size_bytes = list_root[0]['size']
    free_bytes = list_root[0]['free']
    free_gib = free_bytes / (1024 ** 3)

    message = format_lazy(
        # Translators: xgettext:no-python-format
        _('Warning: Low space on system partition ({percent_used}% used, '
          '{free_space} free).'),
        percent_used=percent_used,
        free_space=storage.format_bytes(free_bytes))

    if percent_used > 90 or free_gib < 1:
        messages.error(request, message)
    elif percent_used > 75 or free_gib < 2:
        messages.warning(request, message)
Exemple #2
0
def warn_about_low_disk_space(request):
    """Warn about insufficient space on root partition."""
    if not is_user_admin(request, cached=True):
        return

    disks = storage_module.get_disks()
    list_root = [disk for disk in disks if disk['mountpoint'] == '/']
    if not list_root:
        logger.error('Error getting information about root partition.')
        return

    perc_used = list_root[0]['percentage_used']
    size_bytes = _interpret_size_string(list_root[0]['size'])
    free_bytes = size_bytes * (100 - perc_used) / 100

    message = format_lazy(
        # Translators: xgettext:no-python-format
        _('Warning: Low space on system partition ({percent_used}% used, '
          '{free_space} free).'),
        percent_used=perc_used, free_space=_format_bytes(free_bytes))

    free_gib = free_bytes / (1024 ** 3)
    if perc_used > 90 or free_gib < 1:
        messages.error(request, message)
    elif perc_used > 75 or free_gib < 2:
        messages.warning(request, message)
    def get_context_data(self, *args, **kwargs):
        """Return template context data."""
        context = super().get_context_data(*args, **kwargs)
        disks = storage.get_disks()
        shares = samba.get_shares()

        for disk in disks:
            disk['name'] = samba.disk_name(disk['mount_point'])
        context['disks'] = disks

        shared_mounts = defaultdict(list)
        for share in shares:
            shared_mounts[share['mount_point']].append(share['share_type'])
        context['shared_mounts'] = shared_mounts

        context['share_types'] = [('open', _('Open Share')),
                                  ('group', _('Group Share')),
                                  ('home', _('Home Share'))]

        unavailable_shares = []
        for share in shares:
            for disk in disks:
                if share['mount_point'] == disk['mount_point']:
                    break
            else:
                unavailable_shares.append(share)
        context['unavailable_shares'] = unavailable_shares

        context['users'] = samba.get_users()

        return context
Exemple #4
0
    def get_context_data(self, *args, **kwargs):
        """Return template context data."""
        context = super().get_context_data(*args, **kwargs)

        disks = storage.get_disks()
        root_device = storage.get_root_device(disks)
        expandable_root_size = storage.is_expandable(root_device)
        expandable_root_size = storage.format_bytes(expandable_root_size)

        context['disks'] = disks
        context['expandable_root_size'] = expandable_root_size
        return context
Exemple #5
0
def index(request):
    """Show connection list."""
    disks = storage.get_disks()
    root_device = storage.get_root_device(disks)
    expandable_root_size = storage.is_expandable(root_device)
    expandable_root_size = storage.format_bytes(expandable_root_size)

    warn_about_low_disk_space(request)

    return TemplateResponse(request, 'storage.html',
                            {'title': _('Storage'),
                             'disks': disks,
                             'expandable_root_size': expandable_root_size})
Exemple #6
0
def index(request):
    """Show connection list."""
    disks = storage_module.get_disks()
    root_device = storage_module.get_root_device(disks)
    expandable_root_size = storage_module.is_expandable(root_device)
    expandable_root_size = _format_bytes(expandable_root_size)

    warn_about_low_disk_space(request)

    return TemplateResponse(request, 'storage.html',
                            {'title': _('Storage'),
                             'disks': disks,
                             'expandable_root_size': expandable_root_size})
Exemple #7
0
def expand(request):
    """Warn and expand the root partition."""
    disks = storage.get_disks()
    root_device = storage.get_root_device(disks)

    if request.method == 'POST':
        expand_partition(request, root_device)
        return redirect(reverse('storage:index'))

    expandable_root_size = storage.is_expandable(root_device)
    expandable_root_size = storage.format_bytes(expandable_root_size)
    return TemplateResponse(request, 'storage_expand.html',
                            {'title': _('Expand Root Partition'),
                             'expandable_root_size': expandable_root_size})
Exemple #8
0
def expand(request):
    """Warn and expand the root partition."""
    disks = storage_module.get_disks()
    root_device = storage_module.get_root_device(disks)

    if request.method == 'POST':
        expand_partition(request, root_device)
        return redirect(reverse('storage:index'))

    expandable_root_size = storage_module.is_expandable(root_device)
    expandable_root_size = _format_bytes(expandable_root_size)
    return TemplateResponse(request, 'storage_expand.html',
                            {'title': _('Expand Root Partition'),
                             'expandable_root_size': expandable_root_size})
def get_available_samba_shares():
    """Get available samba shares."""
    available_shares = []
    if is_module_enabled('samba'):
        samba_shares = json.loads(
            actions.superuser_run('samba', ['get-shares']))
        if samba_shares:
            disks = storage.get_disks()
            for share in samba_shares:
                for disk in disks:
                    if share['mount_point'] == disk['mount_point']:
                        available_shares.append(share)
                        break
    return available_shares
def get_disk_choices():
    """Returns a list of all available partitions except the root partition."""
    repositories = get_repositories()
    existing_paths = [
        repository.path for repository in repositories
        if repository.storage_type == 'disk'
    ]
    choices = []
    for device in get_disks():
        if device['mount_point'] == '/':
            continue

        path = os.path.join(device['mount_point'], 'FreedomBoxBackups')
        if path in existing_paths:
            continue

        name = device['label'] if device['label'] else device['mount_point']
        choices.append((device['mount_point'], name))

    return choices