-
-
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 #80 from DanSheps/develop-3.6
3.6 support
- Loading branch information
Showing
11 changed files
with
171 additions
and
90 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,17 +1,42 @@ | ||
import datetime | ||
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.tasks import backup_job | ||
from netbox_config_backup.utils import remove_queued | ||
from netbox_config_backup.utils.rq import can_backup | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('--time', help="time") | ||
parser.add_argument('device', help="Device Name") | ||
parser.add_argument('--time', dest='time', help="time") | ||
parser.add_argument('--device', dest='device', help="Device Name") | ||
|
||
def run_backup(self, backup): | ||
if can_backup(backup): | ||
backupjob = backup.jobs.filter(backup__device=backup.device).last() | ||
if backupjob is None: | ||
backupjob = BackupJob.objects.create( | ||
backup=backup, | ||
scheduled=timezone.now(), | ||
uuid=uuid.uuid4() | ||
) | ||
backup_job(backupjob.pk) | ||
remove_queued(backup) | ||
|
||
def handle(self, *args, **options): | ||
from netbox_config_backup.models import Backup, BackupJob | ||
from netbox_config_backup.models import Backup | ||
if options['device']: | ||
print(f'Running:{options.get("device")}| ') | ||
backup = Backup.objects.filter(device__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) | ||
|
||
backupjob = BackupJob.objects.filter(backup__device__name=options['device']).last() | ||
backup_job(backupjob.pk) |
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
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
Oops, something went wrong.