Beispiel #1
0
 def Apply(self):
     """
     Transition method for removing rules applied for the previous configuration of the router.
     :return:
     """
     regles_deprecated = Regles.objects.filter((Q(source=self) | Q(destination=self)) & Q(etat="Deprecated"))
     regles_production = Regles.objects.filter((Q(source=self) | Q(destination=self)) & Q(etat="Production")).values("regle")
     regles_invalides = regles_deprecated.exclude(Q(regle__in=regles_production))
     deployment = RulesDeployment()
     deployment.remove_rules(regles_invalides)
     regles_deprecated.delete()
Beispiel #2
0
 def Deploy(self):
     """
     Transition method for deploy a router in the topology, pushing all the rules necessary.
     :return:
     """
     if self.valid is True:
         manager = Manager()
         manager.create_rules(Switch.objects.all())
         deployment = RulesDeployment()
         deployment.send_rules(Switch.objects.all())
     else:
         raise Exception("Not a valid router.")
Beispiel #3
0
 def Prepare(self):
     """
     Transition method for moving the rules of the previous configuration into a special state,
     and applies rules for the new configuration.
     :return:
     """
     regles = Regles.objects.filter(Q(source=self) | Q(destination=self))
     for regle in regles:
         regle.ChangeRulesStatus()
         regle.save()
     manager = Manager()
     manager.create_rules(Switch.objects.all())
     deployment = RulesDeployment()
     deployment.send_rules(Switch.objects.all())
Beispiel #4
0
def pre_delete_hote(sender, **kwargs):
    """
    Clean-up all traces of the router in the Database.
    :param sender:
    :param kwargs:
    :return:
    """
    # Retrieve all flux where the deleted host is present
    flux_list = Flux.objects.filter(Q(hote_src=kwargs['instance']) | Q(hote_dst=kwargs['instance']))
    # Remove stats from these flux
    Stats.objects.filter(idflux__in=flux_list).delete()
    # delete flux
    flux_list.delete()

    # remove rules for designated host
    deployment = RulesDeployment()
    deployment.remove_host([kwargs['instance']])

    # Remove host from the BGP configuration
    render_conf_hosts(Hote.objects.exclude(idhote=kwargs['instance'].idhote))
Beispiel #5
0
 def form_valid(self, form):
     rules_deployment = RulesDeployment()
     context = rules_deployment.send_rules(Switch.objects.all())
     return render(self.request, "rules_success.html", context=context)