Revision 6a946adf flowspec/tasks.py

b/flowspec/tasks.py
42 42

  
43 43

  
44 44
@task
45
def delete(route, callback=None):
45
def delete(route, **kwargs):
46 46
    applier = PR.Applier(route_object=route)
47 47
    commit, response = applier.apply(operation="delete")
48
    reason_text = ''
48 49
    if commit:
49 50
        status = "INACTIVE"
51
        if "reason" in kwargs and kwargs['reason']=='EXPIRED':
52
            status = 'EXPIRED'
53
            reason_text = " Reason: %s " %status
50 54
    else:
51 55
        status = "ERROR"
52 56
    route.status = status
53 57
    route.response = response
54 58
    route.save()
55
    subtask(announce).delay("[%s] Route delete: %s - Result %s" %(route.applier, route.name, response), route.applier)
56

  
59
    subtask(announce).delay("[%s] Route removal: %s%s- Result %s" %(route.applier, route.name, reason_text, response), route.applier)
57 60

  
61
# May not work in the first place... proxy is not aware of Route models
62
@task
63
def batch_delete(routes, **kwargs):
64
    if routes:
65
        applier = PR.Applier(route_objects=routes)
66
        conf = applier.delete_routes()
67
        commit, response = applier.apply(configuration = conf)
68
        reason_text = ''
69
        if commit:
70
            status = "INACTIVE"
71
            if "reason" in kwargs and kwargs['reason']=='EXPIRED':
72
                status = 'EXPIRED'
73
                reason_text = " Reason: %s " %status
74
        else:
75
            status = "ERROR"
76
        for route in routes:
77
            route.status = status
78
            route.response = response
79
            route.save()
80
            subtask(announce).delay("[%s] Route removal: %s%s- Result %s" %(route.applier, route.name, reason_text, response), route.applier)
81
    else:
82
        return False
58 83

  
59 84
@task
60 85
def announce(messg, user):
......
69 94

  
70 95
@task
71 96
def check_sync(route_name=None, selected_routes = []):
97
    from flowspy.flowspec.models import Route, MatchPort, MatchDscp, ThenAction
72 98
    if not selected_routes:
73 99
        routes = Route.objects.all()
74 100
    else:
75 101
        routes = selected_routes
76 102
    if route_name:
77 103
        routes = routes.filter(name=route_name)
78
    for route in roures:
79
        if route.is_synced():
80
            logger.info("Route %s is synced" %route.name)
81
        else:
82
            logger.warn("Route %s is out of sync" %route.name)
104
    for route in routes:
105
        if route.has_expired() and route.status != 'EXPIRED':
106
            logger.info('Expiring route %s' %route.name)
107
            subtask(delete).delay(route, reason="EXPIRED")
108
        elif route.status != 'EXPIRED':
109
            route.check_sync()
110

  
111

  
83 112
#def delete(route):
84 113
#    
85 114
#    applier = PR.Applier(route_object=route)

Also available in: Unified diff