Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / helpdesk / templatetags / helpdesk_tags.py @ c3564ce9

History | View | Annotate | Download (998 Bytes)

1
from django import template
2

    
3
register = template.Library()
4

    
5
@register.filter(name="vm_public_ip")
6
def vm_public_ip(vm):
7
    """
8
    Identify if vm is connected to ``public`` network and return the ipv4
9
    address
10
    """
11
    try:
12
        return vm.nics.filter(network__name="public")[0].ipv4
13
    except IndexError:
14
        return "No public ip"
15

    
16

    
17
STATE_CSS_MAP = {
18
        'BUILD': 'warning',
19
        'ERROR': 'important',
20
        'STOPPED': 'notice',
21
        'STARTED': 'success',
22
        'DESTROYED': 'inverse'
23
}
24
@register.filter(name="vm_status_badge")
25
def vm_status_badge(vm):
26
    """
27
    Return a span badge styled based on the vm current status
28
    """
29
    state_cls = STATE_CSS_MAP[vm.operstate]
30
    badge_cls = "badge badge-%s" % state_cls
31

    
32
    deleted_badge = ""
33
    if vm.deleted:
34
        deleted_badge = '<span class="badge badge-important">Deleted</span>'
35
    return '<span class="%s">%s</span>%s' % (badge_cls,
36
            vm.operstate, deleted_badge)
37

    
38
vm_status_badge.is_safe = True