예제 #1
0
파일: views.py 프로젝트: hmpf/nav
def commit_configuration(request):
    """Commit pending config changes to startup config"""
    if not CONFIG.is_commit_enabled():
        _logger.debug('Not doing a configuration commit, it is configured off')
        return HttpResponse(
            "Configuration commit is configured to not be done")

    interface = get_object_or_404(Interface,
                                  pk=request.POST.get('interfaceid'))

    handler = get_management_handler(interface.netbox)
    if handler:
        try:
            handler.commit_configuration()
        except ManagementError as error:
            error_message = 'Error committing configuration on {}: {}'.format(
                handler.netbox, error)
            _logger.error(error_message)
            return HttpResponse(error_message, status=500)
        except (AttributeError, NotImplementedError):
            error_message = 'Error committing configuration on {}: {}'.format(
                handler.netbox, 'Configuration commit not supported')
            _logger.error(error_message)
            return HttpResponse(error_message, status=500)

        return HttpResponse()
    else:
        return HttpResponse(status=500)
예제 #2
0
파일: views.py 프로젝트: hmpf/nav
def handle_trunk_edit(request, agent, interface):
    """Edit a trunk"""

    native_vlan = int(request.POST.get('native_vlan', 1))
    trunked_vlans = [int(vlan) for vlan in request.POST.getlist('trunk_vlans')]

    if should_check_access_rights(get_account(request)):
        # A user can avoid the form restrictions by sending a forged post
        # request Make sure only the allowed vlans are set

        old_native, old_trunked = agent.get_native_and_trunked_vlans(interface)
        allowed_vlans = [
            v.vlan for v in find_allowed_vlans_for_user(get_account(request))
        ]

        trunked_vlans = filter_vlans(trunked_vlans, old_trunked, allowed_vlans)
        native_vlan = native_vlan if native_vlan in allowed_vlans else old_native

    _logger.info('Interface %s - native: %s, trunk: %s', interface,
                 native_vlan, trunked_vlans)
    LogEntry.add_log_entry(
        request.account,
        u'set-vlan',
        u'{actor}: {object} - native vlan: "%s", trunk vlans: "%s"' %
        (native_vlan, trunked_vlans),
        subsystem=u'portadmin',
        object=interface,
    )

    if trunked_vlans:
        agent.set_trunk(interface, native_vlan, trunked_vlans)
    else:
        agent.set_access(interface, native_vlan)
    if CONFIG.is_commit_enabled():
        agent.commit_configuration()