-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from DanSheps/develop
Version bump for 4.2 and add Compliance module
- Loading branch information
Showing
11 changed files
with
192 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
import uuid | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.db import transaction | ||
from django.utils import timezone | ||
|
||
from netbox_config_backup.models import BackupJob | ||
from netbox_config_backup.utils.rq import can_backup | ||
from netbox_config_backup.jobs.backup import BackupRunner | ||
from netbox_config_backup.models import Backup | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('--time', dest='time', help="time") | ||
parser.add_argument('--device', dest='device', help="Device Name") | ||
|
||
def run_backup(self, backup=None): | ||
BackupRunner.enqueue(backup=backup, immediate=True) | ||
|
||
def handle(self, *args, **options): | ||
from netbox_config_backup.models import Backup | ||
if options['device']: | ||
print(f'Running:{options.get("device")}| ') | ||
print(f'Running backup for: {options.get("device")}') | ||
backup = Backup.objects.filter(device__name=options['device']).first() | ||
if not backup: | ||
backup = Backup.objects.filter(name=options['device']).first() | ||
if backup: | ||
self.run_backup(backup) | ||
else: | ||
raise Exception('Device not found') | ||
else: | ||
for backup in Backup.objects.all(): | ||
self.run_backup(backup) | ||
self.run_backup() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +0,0 @@ | ||
import logging | ||
|
||
from netbox.plugins import PluginTemplateExtension | ||
|
||
from netbox_config_backup.models import Backup, BackupJob, BackupCommitTreeChange | ||
from netbox_config_backup.tables import BackupsTable | ||
from netbox_config_backup.utils.backups import get_backup_tables | ||
from utilities.htmx import htmx_partial | ||
|
||
logger = logging.getLogger(f"netbox_config_backup") | ||
|
||
|
||
class DeviceBackups(PluginTemplateExtension): | ||
model = 'dcim.device' | ||
|
||
def full_width_page(self): | ||
request = self.context.get('request') | ||
def build_table(instance): | ||
bctc = BackupCommitTreeChange.objects.filter( | ||
backup=instance, | ||
file__isnull=False | ||
) | ||
table = BackupsTable(bctc, user=request.user) | ||
table.configure(request) | ||
|
||
return table | ||
|
||
device = self.context.get('object', None) | ||
devices = Backup.objects.filter(device=device) if device is not None else Backup.objects.none() | ||
if devices.count() > 0: | ||
instance = devices.first() | ||
table = build_table(instance) | ||
|
||
if htmx_partial(request): | ||
return self.render('htmx/table.html', extra_context={ | ||
'object': instance, | ||
'table': table, | ||
'preferences': {}, | ||
}) | ||
return self.render('netbox_config_backup/inc/backup_tables.html', extra_context={ | ||
'object': instance, | ||
'table': table, | ||
'preferences': request.user.config, | ||
}) | ||
|
||
return '' | ||
|
||
|
||
template_extensions = [DeviceBackups] | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
netbox_config_backup/templates/netbox_config_backup/compliance.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{% extends 'generic/object.html' %} | ||
{% load helpers %} | ||
|
||
{% block subtitle %} | ||
<div class="object-subtitle"> | ||
<span>{{ current.commit.time }}</span> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="row"> | ||
<div class="col col-md-12"> | ||
<div class="card"> | ||
<h5 class="card-header"> | ||
Configuration Compliance | ||
</h5> | ||
<div class="card-body"> | ||
<pre class="change-data">{% for line in diff %}{% spaceless %} | ||
{% if line == '+++' or line == '---' %} | ||
{% elif line|make_list|first == '@' %} | ||
<span style="background-color: #ffdb58; color: black;">{{line}}</span> | ||
{% elif line|make_list|first == '+' %} | ||
<span class="added"> {{line|make_list|slice:'1:'|join:''}}</span> | ||
{% elif line|make_list|first == '-' %} | ||
<span class="removed"> {{line|make_list|slice:'1:'|join:''}}</span> | ||
{% else %} | ||
<span>{{line}}</span> | ||
{% endif %} | ||
{% endspaceless %}{% endfor %}</pre> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.