Implement automatic provisioning
This commit is contained in:
parent
3486f30f37
commit
766b530ace
|
@ -27,6 +27,7 @@ from core.views.manage.threshold.irc import (
|
||||||
ThresholdIRCAliases,
|
ThresholdIRCAliases,
|
||||||
ThresholdIRCAliasesEdit,
|
ThresholdIRCAliasesEdit,
|
||||||
ThresholdIRCNetworkActions,
|
ThresholdIRCNetworkActions,
|
||||||
|
ThresholdIRCNetworkActionsAuto,
|
||||||
ThresholdIRCNetworkActionsRelay,
|
ThresholdIRCNetworkActionsRelay,
|
||||||
ThresholdIRCNetworkChannels,
|
ThresholdIRCNetworkChannels,
|
||||||
ThresholdIRCNetworkInfo,
|
ThresholdIRCNetworkInfo,
|
||||||
|
@ -171,6 +172,11 @@ urlpatterns = [
|
||||||
ThresholdIRCNetworkActionsRelay.as_view(),
|
ThresholdIRCNetworkActionsRelay.as_view(),
|
||||||
name="threshold_irc_network_actions_add_relay",
|
name="threshold_irc_network_actions_add_relay",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"manage/threshold/irc/auto/<str:net>/",
|
||||||
|
ThresholdIRCNetworkActionsAuto.as_view(),
|
||||||
|
name="threshold_irc_network_actions_auto",
|
||||||
|
),
|
||||||
##
|
##
|
||||||
path("api/chans/", ThresholdChans.as_view(), name="chans"),
|
path("api/chans/", ThresholdChans.as_view(), name="chans"),
|
||||||
path("api/users/", ThresholdUsers.as_view(), name="users"),
|
path("api/users/", ThresholdUsers.as_view(), name="users"),
|
||||||
|
|
|
@ -111,3 +111,10 @@ def update_aliases(aliases):
|
||||||
payload = aliases
|
payload = aliases
|
||||||
deleted = threshold_request(url, payload, method="POST")
|
deleted = threshold_request(url, payload, method="POST")
|
||||||
return deleted
|
return deleted
|
||||||
|
|
||||||
|
|
||||||
|
def run_auto(net):
|
||||||
|
url = f"irc/auto/{net}"
|
||||||
|
payload = {}
|
||||||
|
deleted = threshold_request(url, payload, method="POST")
|
||||||
|
return deleted
|
||||||
|
|
|
@ -21,6 +21,10 @@
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
|
hx-post="{% url 'threshold_irc_network_actions_auto' net %}"
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#actions"
|
||||||
|
hx-swap="outerHTML"
|
||||||
class="button is-success">
|
class="button is-success">
|
||||||
<span class="icon-text">
|
<span class="icon-text">
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
|
|
|
@ -2,6 +2,7 @@ from django import template
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def nsep(lst):
|
def nsep(lst):
|
||||||
return "\n".join(lst)
|
return "\n".join(lst)
|
||||||
|
|
|
@ -287,6 +287,29 @@ class ThresholdIRCNetworkActions(SuperUserRequiredMixin, View):
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
|
|
||||||
|
class ThresholdIRCNetworkActionsAuto(SuperUserRequiredMixin, View):
|
||||||
|
template_name = "manage/threshold/irc/network/actions.html"
|
||||||
|
|
||||||
|
def post(self, request, net):
|
||||||
|
"""
|
||||||
|
Run network automation.
|
||||||
|
"""
|
||||||
|
ran = threshold.run_auto(net)
|
||||||
|
if ran["success"]:
|
||||||
|
message = f"Ran auto on network {net}"
|
||||||
|
message_class = "success"
|
||||||
|
else:
|
||||||
|
message = ran["reason"]
|
||||||
|
message_class = "danger"
|
||||||
|
|
||||||
|
context = {
|
||||||
|
"net": net,
|
||||||
|
"message": message,
|
||||||
|
"class": message_class,
|
||||||
|
}
|
||||||
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
|
|
||||||
class ThresholdIRCNetworkActionsRelay(SuperUserRequiredMixin, APIView):
|
class ThresholdIRCNetworkActionsRelay(SuperUserRequiredMixin, APIView):
|
||||||
template_name = "manage/threshold/irc/network/actions.html"
|
template_name = "manage/threshold/irc/network/actions.html"
|
||||||
parser_classes = [FormParser]
|
parser_classes = [FormParser]
|
||||||
|
|
Loading…
Reference in New Issue