mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
14438 script job mapping
This commit is contained in:
parent
6930e441ae
commit
5981fc958d
@ -19,7 +19,7 @@ def update_scripts(apps, schema_editor):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# update all jobs associated with this module/name to point to the new script obj
|
# update all jobs associated with this module/name to point to the new script obj
|
||||||
module.jobs.filter(name=name).update(object_type=ct, object_id=obj.id)
|
module.jobs.filter(name=script).update(object_type=ct, object_id=obj.id)
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -50,11 +50,6 @@ class Script(EventRulesMixin, JobsMixin, models.Model):
|
|||||||
def python_class(self):
|
def python_class(self):
|
||||||
return self.module.get_module_scripts.get(self.name)
|
return self.module.get_module_scripts.get(self.name)
|
||||||
|
|
||||||
def get_jobs(self):
|
|
||||||
return self.module.jobs.filter(
|
|
||||||
name=self.name
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ScriptModuleManager(models.Manager.from_queryset(RestrictedQuerySet)):
|
class ScriptModuleManager(models.Manager.from_queryset(RestrictedQuerySet)):
|
||||||
|
|
||||||
|
@ -1209,7 +1209,7 @@ class ScriptListView(ContentTypePermissionRequiredMixin, View):
|
|||||||
return 'extras.view_script'
|
return 'extras.view_script'
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
script_modules = ScriptModule.objects.restrict(request.user)
|
script_modules = ScriptModule.objects.restrict(request.user).prefetch_related('jobs')
|
||||||
|
|
||||||
return render(request, 'extras/script_list.html', {
|
return render(request, 'extras/script_list.html', {
|
||||||
'model': ScriptModule,
|
'model': ScriptModule,
|
||||||
@ -1229,7 +1229,7 @@ class ScriptView(ContentTypePermissionRequiredMixin, View):
|
|||||||
def get(self, request, pk):
|
def get(self, request, pk):
|
||||||
script = Script.objects.get(pk=pk)
|
script = Script.objects.get(pk=pk)
|
||||||
script_class = script.python_class()
|
script_class = script.python_class()
|
||||||
jobs = script.get_jobs()
|
jobs = script.jobs.all()
|
||||||
form = script_class.as_form(initial=normalize_querydict(request.GET))
|
form = script_class.as_form(initial=normalize_querydict(request.GET))
|
||||||
|
|
||||||
return render(request, 'extras/script.html', {
|
return render(request, 'extras/script.html', {
|
||||||
@ -1246,7 +1246,7 @@ class ScriptView(ContentTypePermissionRequiredMixin, View):
|
|||||||
|
|
||||||
script = Script.objects.get(pk=pk)
|
script = Script.objects.get(pk=pk)
|
||||||
script_class = script.python_class()
|
script_class = script.python_class()
|
||||||
jobs = script.get_jobs()
|
jobs = script.jobs.all()
|
||||||
form = script_class.as_form(request.POST, request.FILES)
|
form = script_class.as_form(request.POST, request.FILES)
|
||||||
|
|
||||||
# Allow execution only if RQ worker process is running
|
# Allow execution only if RQ worker process is running
|
||||||
@ -1256,7 +1256,7 @@ class ScriptView(ContentTypePermissionRequiredMixin, View):
|
|||||||
elif form.is_valid():
|
elif form.is_valid():
|
||||||
job = Job.enqueue(
|
job = Job.enqueue(
|
||||||
run_script,
|
run_script,
|
||||||
instance=script.module,
|
instance=script,
|
||||||
name=script_class.class_name,
|
name=script_class.class_name,
|
||||||
user=request.user,
|
user=request.user,
|
||||||
schedule_at=form.cleaned_data.pop('_schedule_at'),
|
schedule_at=form.cleaned_data.pop('_schedule_at'),
|
||||||
@ -1286,7 +1286,7 @@ class ScriptSourceView(ContentTypePermissionRequiredMixin, View):
|
|||||||
def get(self, request, pk):
|
def get(self, request, pk):
|
||||||
script = Script.objects.get(pk=pk)
|
script = Script.objects.get(pk=pk)
|
||||||
script_class = script.python_class()
|
script_class = script.python_class()
|
||||||
jobs = script.get_jobs()
|
jobs = script.jobs.all()
|
||||||
|
|
||||||
return render(request, 'extras/script/source.html', {
|
return render(request, 'extras/script/source.html', {
|
||||||
'job_count': jobs.count(),
|
'job_count': jobs.count(),
|
||||||
@ -1305,7 +1305,7 @@ class ScriptJobsView(ContentTypePermissionRequiredMixin, View):
|
|||||||
def get(self, request, pk):
|
def get(self, request, pk):
|
||||||
script = Script.objects.get(pk=pk)
|
script = Script.objects.get(pk=pk)
|
||||||
script_class = script.python_class()
|
script_class = script.python_class()
|
||||||
jobs = script.get_jobs()
|
jobs = script.jobs.all()
|
||||||
|
|
||||||
jobs_table = JobTable(
|
jobs_table = JobTable(
|
||||||
data=jobs,
|
data=jobs,
|
||||||
|
@ -52,31 +52,29 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% with jobs=module.get_latest_jobs %}
|
{% for script in module.scripts.all %}
|
||||||
{% for script in module.scripts.all %}
|
<tr>
|
||||||
<tr>
|
<td>
|
||||||
<td>
|
<a href="{% url 'extras:script' script.id %}" name="script.{{ script.name }}">{{ script.python_class.name }}</a>
|
||||||
<a href="{% url 'extras:script' script.id %}" name="script.{{ script.name }}">{{ script.python_class.name }}</a>
|
</td>
|
||||||
</td>
|
<td>
|
||||||
<td>
|
{{ script.python_class.Meta.description|markdown|placeholder }}
|
||||||
{{ script.python_class.Meta.description|markdown|placeholder }}
|
</td>
|
||||||
</td>
|
{% with last_result=script.get_latest_jobs|get_key:script.name %}
|
||||||
{% with last_result=jobs|get_key:script.python_class.class_name %}
|
{% if last_result %}
|
||||||
{% if last_result %}
|
<td>
|
||||||
<td>
|
<a href="{% url 'extras:script_result' job_pk=last_result.pk %}">{{ last_result.created|annotated_date }}</a>
|
||||||
<a href="{% url 'extras:script_result' job_pk=last_result.pk %}">{{ last_result.created|annotated_date }}</a>
|
</td>
|
||||||
</td>
|
<td class="text-end">
|
||||||
<td class="text-end">
|
{% badge last_result.get_status_display last_result.get_status_color %}
|
||||||
{% badge last_result.get_status_display last_result.get_status_color %}
|
</td>
|
||||||
</td>
|
{% else %}
|
||||||
{% else %}
|
<td class="text-muted">{% trans "Never" %}</td>
|
||||||
<td class="text-muted">{% trans "Never" %}</td>
|
<td class="text-end">{{ ''|placeholder }}</td>
|
||||||
<td class="text-end">{{ ''|placeholder }}</td>
|
{% endif %}
|
||||||
{% endif %}
|
|
||||||
{% endwith %}
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endwith %}
|
||||||
{% endwith %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
Reference in New Issue
Block a user