예제 #1
0
    def test_should_extract_servers_by_touched_clusters(self):
        touched_clusters = [cluster1, cluster2]
        expected_extracted_servers = [servers[0], servers[1]]

        assert_equals(
            ServerExtractor().extract_servers_by_clusters(touched_clusters),
            expected_extracted_servers)
예제 #2
0
파일: api.py 프로젝트: jzmudzinski/vaas
    def obj_create(self, bundle, **kwargs):
        url, clusters = bundle.data['url'], bundle.data['clusters']
        purger = VarnishPurger()

        if not isinstance(clusters, list):
            clusters = [clusters]

        servers = ServerExtractor().extract_servers_by_clusters(
            LogicalCluster.objects.filter(name__in=clusters))
        raise ImmediateHttpResponse(
            self.create_json_response(purger.purge_url(url, servers),
                                      HttpResponse))
예제 #3
0
파일: api.py 프로젝트: yenaing/vaas
    def obj_create(self, bundle, **kwargs):
        try:
            if not bundle.request.user.is_staff:
                raise Unauthorized()
        except Unauthorized as e:
            self.unauthorized_result(e)

        url, clusters = bundle.data['url'], bundle.data['clusters']
        purger = VarnishPurger()

        if not isinstance(clusters, list):
            clusters = [clusters]

        servers = ServerExtractor().extract_servers_by_clusters(
            LogicalCluster.objects.filter(name__in=clusters))
        raise ImmediateHttpResponse(
            self.create_json_response(purger.purge_url(url, servers),
                                      HttpResponse))
예제 #4
0
def purge_view(request):
    if request.method == 'POST':
        form = PurgeForm(request.POST)
        if form.is_valid():
            cluster = LogicalCluster.objects.get(pk=form.cleaned_data['cluster'].pk)
            servers = ServerExtractor().extract_servers_by_clusters([cluster])
            result = VarnishPurger().purge_url(form.cleaned_data['url'], servers)
            messages.warning(
                request,
                'Url {} purged from cluster {} - cleaned {} server(s), errors occurred for {} server(s)'.format(
                    form.cleaned_data['url'], cluster.name, len(result['success']), len(result['error'])
                )
            )
            return HttpResponseRedirect('/')
    else:
        form = PurgeForm()

    return render(request, 'purge_form.html', {'form': form, 'has_permission': True})
예제 #5
0
    def obj_create(self, bundle, **kwargs):
        try:
            if not bundle.request.user.is_staff:
                raise Unauthorized()
        except Unauthorized as e:
            self.unauthorized_result(e)
        self.is_valid(bundle)
        if bundle.errors:
            raise ImmediateHttpResponse(response=self.error_response(bundle.request, bundle.errors))
        url, clusters, headers = bundle.data['url'], bundle.data['clusters'], bundle.data.get('headers')
        purger = VarnishPurger()

        if not isinstance(clusters, list):
            clusters = [clusters]

        servers = ServerExtractor().extract_servers_by_clusters(LogicalCluster.objects.filter(name__in=clusters))
        purger_result = purger.purge_url(url, servers, headers)
        if len(purger_result.get("error")) > 0:
            raise ImmediateHttpResponse(self.create_json_response(purger_result, HttpApplicationError))
        raise ImmediateHttpResponse(self.create_json_response(purger_result, HttpResponse))
예제 #6
0
def provide_backend_status_manager():
    return BackendStatusManager(VarnishApiProvider(),
                                ServerExtractor().servers,
                                settings.VAAS_GATHER_STATUSES_CONNECT_TIMEOUT,
                                settings.VAAS_GATHER_STATUSES_MAX_WORKERS)