コード例 #1
0
ファイル: test_cluster.py プロジェクト: deejay1/vaas
 def test_should_throw_vcl_load_exception_on_any_error_while_connecting_to_varnish_api(
         self):
     with patch.object(VarnishApi, '__init__', side_effect=Exception):
         with patch.object(VarnishApi, '__del__'):
             varnish_cluster = VarnishApiProvider()
             with self.assertRaises(VclLoadException):
                 varnish_cluster.get_api(servers[0])
コード例 #2
0
ファイル: admin.py プロジェクト: bieli/vaas
class VarnishServerAdmin(admin.ModelAdmin):
    search_fields = ['dc__symbol', 'ip', 'hostname', 'template__name']
    list_display = (
        'hostname',
        'ip',
        'port',
        'dc',
        'cluster',
        'cluster_weight',
        'template',
        'custom_enabled',
        'is_connected',
        'vcl'
    )
    actions = [enable_varnish_servers, disable_varnish_servers]
    varnish_api_provider = None

    def get_list_display(self, request):
        self.varnish_api_provider = VarnishApiProvider()
        return super(VarnishServerAdmin, self).get_list_display(request)

    def custom_enabled(self, obj):
        if obj.enabled:
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-mini btn-success' href='#'>" +
                "<i class='icon-ok-circle'></i></a>" +
                "</div>"
            )
        else:
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-mini' href='#'><i class='icon-ban-circle'></i></a>" +
                "</div>"
            )
    custom_enabled.short_description = 'Enabled'

    def is_connected(self, obj):
        try:
            self.varnish_api_provider.get_api(obj)
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-mini btn-success' href='#'><i class='icon-ok'></i></a>" +
                "</div>"
            )
        except:
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-mini btn-danger' href='#'><i class='icon-off'></i></a>" +
                "</div>"
            )

    def vcl(self, obj):
        return format_html(
            ("<div class='span13 text-center'>" +
             "<button class='btn btn-success' data-remote='/manager/varnish/vcl/%s/' " +
             "data-toggle='modal' data-target='#vclModal'>Show vcl</button>" +
             "</div>") % obj.id
        )
コード例 #3
0
ファイル: admin.py プロジェクト: andrzejwawrzyniak/vaas
class VarnishServerAdmin(admin.ModelAdmin):
    search_fields = ['dc__symbol', 'ip', 'hostname', 'template__name']
    list_filter = ['cluster__name']
    list_display = ('hostname', 'ip', 'port', 'dc', 'cluster',
                    'cluster_weight', 'template', 'template_version',
                    'custom_enabled', 'is_connected', 'vcl')
    actions = [enable_varnish_servers, disable_varnish_servers]
    varnish_api_provider = None

    def get_list_display(self, request):
        self.varnish_api_provider = VarnishApiProvider()
        return super(VarnishServerAdmin, self).get_list_display(request)

    def template_version(self, obj):
        return obj.template.get_template_version()

    def custom_enabled(self, obj):
        if obj.enabled:
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-mini btn-success' href='#'>" +
                "<i class='icon-ok-circle'></i></a>" + "</div>")
        else:
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-mini' href='#'><i class='icon-ban-circle'></i></a>"
                + "</div>")

    custom_enabled.short_description = 'Enabled'

    def is_connected(self, obj):
        try:
            self.varnish_api_provider.get_api(obj)
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-mini btn-success' href='#'><i class='icon-ok'></i></a>"
                + "</div>")
        except:
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-mini btn-danger' href='#'><i class='icon-off'></i></a>"
                + "</div>")

    def vcl(self, obj):
        return format_html((
            "<div class='span13 text-center'>" +
            "<button class='btn btn-success' data-remote='/manager/varnish/vcl/%s/' "
            + "data-toggle='modal' data-target='#vclModal'>Show vcl</button>" +
            "</div>") % obj.id)
コード例 #4
0
ファイル: admin.py プロジェクト: awesome-python/vaas
class VarnishServerAdmin(admin.ModelAdmin):
    search_fields = ['dc__symbol', 'ip', 'hostname', 'template__name']
    list_filter = ['cluster__name', OutdatedFilter]
    list_display = (
        'hostname',
        'ip',
        'port',
        'http_port',
        'dc',
        'cluster',
        'cluster_weight',
        'template',
        'template_version',
        'custom_enabled',
        'is_connected',
        'custom_is_canary',
        'vcl'
    )
    actions = [enable_varnish_servers, maintenance_varnish_servers, disable_varnish_servers]
    varnish_api_provider = None

    def get_list_display(self, request):
        self.varnish_api_provider = VarnishApiProvider()
        return super(VarnishServerAdmin, self).get_list_display(request)

    def template_version(self, obj):
        return obj.template.get_template_version()

    def custom_enabled(self, obj):
        if obj.status == 'active':
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-xs btn-success' href='#'>" +
                "<i class='glyphicon glyphicon-ok-sign'></i></a>" +
                "</div>"
            )
        elif obj.status == 'maintenance':
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-xs btn-warning' href='#'>" +
                "<i class='glyphicon glyphicon-wrench'></i></a>" +
                "</div>"
            )
        else:
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-xs' href='#'><i class='glyphicon glyphicon-ban-circle'></i></a>" +
                "</div>"
            )
    custom_enabled.short_description = 'Enabled'

    def is_connected(self, obj):
        if obj.status == 'active':
            try:
                self.varnish_api_provider.get_api(obj)
                return format_html(
                    "<div class='span13 text-center'>" +
                    "<a class='btn btn-xs btn-success' href='#'><i class='glyphicon glyphicon-ok'></i></a>" +
                    "</div>"
                )
            except:
                return format_html(
                    "<div class='span13 text-center'>" +
                    "<a class='btn btn-xs btn-danger' href='#'><i class='glyphicon glyphicon-off'></i></a>" +
                    "</div>"
                )
        elif obj.status == 'maintenance':
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-xs btn-warning' href='#'>" +
                "<i class='glyphicon glyphicon-wrench'></i></a>" +
                "</div>"
            )
        else:
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-xs' href='#'><i class='glyphicon glyphicon-ban-circle'></i></a>" +
                "</div>"
            )

    def custom_is_canary(self, obj):
        if obj.is_canary:
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-xs btn-success' href='#'>" +
                "<i class='glyphicon glyphicon-ok-sign'></i></a>" +
                "</div>"
            )
        else:
            return format_html(
                "<div class='span13 text-center'>" +
                "<a class='btn btn-xs' href='#'><i class='glyphicon glyphicon-ban-circle'></i></a>" +
                "</div>"
            )
    custom_is_canary.short_description = 'Canary'

    def vcl(self, obj):
        if obj.status in ('active', 'maintenance'):
            return format_html(
                ("<div class='span13 text-center'>" +
                 "<button type='button' class='btn btn-success' data-toggle='modal' " +
                 "data-vcl='/manager/varnish/vcl/%s/'" +
                 "data-target='#vclModal'>Show vcl</button>" +
                 "</div>") % obj.id
            )
        else:
            return format_html(
                ("<div class='span13 text-center'>" +
                 "<button class='btn btn-danger' disabled>Show vcl</button>" +
                 "</div>")
            )
コード例 #5
0
 def test_should_throw_vcl_load_exception_on_any_error_while_connecting_to_varnish_api(self):
     with patch.object(VarnishApi, '__init__', side_effect=Exception):
         with patch.object(VarnishApi, '__del__'):
             varnish_cluster = VarnishApiProvider()
             with self.assertRaises(VclLoadException):
                 varnish_cluster.get_api(servers[0])