Create job queue for remote backups
This commit is contained in:
@@ -1,9 +1,30 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from project_tools.api import register_tool
|
||||
from django.db import transaction, DatabaseError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from job_processor.models import JobQueue, JobType
|
||||
from job_processor.exceptions import JobQueuePushError
|
||||
from navigation.api import bind_links
|
||||
from project_tools.api import register_tool
|
||||
|
||||
from .links import backup_tool_link, restore_tool_link
|
||||
|
||||
# TODO: move to literals
|
||||
BACKUP_JOB_QUEUE_NAME = 'backups_queue'
|
||||
|
||||
|
||||
@transaction.commit_on_success
|
||||
def create_backups_job_queue():
|
||||
global backups_job_queue
|
||||
try:
|
||||
backups_job_queue, created = JobQueue.objects.get_or_create(name=BACKUP_JOB_QUEUE_NAME, defaults={'label': _('Backups'), 'unique_jobs': True})
|
||||
except DatabaseError:
|
||||
transaction.rollback()
|
||||
|
||||
|
||||
create_backups_job_queue()
|
||||
#backup_job_type = JobType('remote_backup', _(u'Remove backup'), do_backup)
|
||||
|
||||
register_tool(backup_tool_link)
|
||||
register_tool(restore_tool_link)
|
||||
|
||||
@@ -120,10 +120,14 @@ class AppBackup(object):
|
||||
|
||||
|
||||
class StorageModuleBase(object):
|
||||
#_registry = {}
|
||||
_registry = []
|
||||
|
||||
# Local modules depend on hardware on a node and execute in the Scheduler
|
||||
# of a particular node
|
||||
REALM_LOCAL = 'local'
|
||||
|
||||
# Remote modules can be execute by any node in a cluster and are placed
|
||||
# in the JobQueue
|
||||
REALM_REMOTE = 'remote'
|
||||
|
||||
REALM_CHOICES = (
|
||||
@@ -131,18 +135,23 @@ class StorageModuleBase(object):
|
||||
(REALM_REMOTE, _(u'remote')),
|
||||
)
|
||||
|
||||
# TODO: register subclasses of StorageModuleBase
|
||||
# do not register instances
|
||||
#def __new__(cls, *args, **kwargs):
|
||||
# print "NEW"
|
||||
|
||||
@classmethod
|
||||
def register(cls, klass):
|
||||
"""
|
||||
Register a subclass of StorageModuleBase to make it available to the
|
||||
UI
|
||||
"""
|
||||
cls._registry.append(klass)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
def is_local_realm(self):
|
||||
return self.realm == REALM_LOCAL
|
||||
|
||||
def is_remote_realm(self):
|
||||
return self.realm == REALM_REMOTE
|
||||
|
||||
def backup(self, data):
|
||||
raise NotImplemented
|
||||
|
||||
@@ -155,6 +164,7 @@ class StorageModuleBase(object):
|
||||
|
||||
class TestStorageModule(StorageModuleBase):
|
||||
label = _(u'Test storage module')
|
||||
realm = StorageModuleBase.REALM_LOCAL
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.backup_path = kwargs.pop('backup_path', None)
|
||||
@@ -170,5 +180,5 @@ class TestStorageModule(StorageModuleBase):
|
||||
print 'restore from path: %s' % self.restore_path
|
||||
return 'sample_data'
|
||||
|
||||
# TODO: get rid of register and try to register on subclassing
|
||||
|
||||
StorageModuleBase.register(TestStorageModule)
|
||||
|
||||
@@ -24,6 +24,7 @@ def backup_view(request):
|
||||
{'name': _(u'info'), 'attribute': 'info'},
|
||||
],
|
||||
}
|
||||
# TODO: move to test.py
|
||||
#ab = AppBackup.get_all()[0]
|
||||
#ab.backup(TestStorageModule(backup_path = '/tmp'))
|
||||
return render_to_response('generic_list.html', context,
|
||||
|
||||
Reference in New Issue
Block a user