def get_context_data(self, **kwargs): context = super(GenerateAllSwitchView, self).get_context_data() switches = Switch.objects.all() manager = Manager() manager.create_rules(switches) rules = Regles.objects.values('regle') context["rules"] = rules return context
def generate_openflow_rules(modeladmin, request, queryset): """ Action for generating openflow rules on switch. :param modeladmin: :param request: :param queryset: :return: """ manager = Manager() manager.create_rules(queryset) modeladmin.message_user(request, "Les règles ont été mises à jour dans la base de données.") return redirect('rules_confirm')
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.")
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())
def form_valid(self, form): switches = form.get_selected() manager = Manager() manager.create_rules(switches) rules = Regles.objects.values('regle') return render(self.request, "switches_list.html", context={"rules": rules})