add celery tasks
- add celery application code in gvaldap.celery - add osusers app to mimic the osusers code in the main gnuviechadmin code - add celery configuration settings to gvaldap.settings.base - add osusers.models.Group and osusers.models.User - add osusers.tasks.create_ldap_group and osusers.tasks.create_ldap_user - add billiard, kombu and pytz to requirements/base.txt
This commit is contained in:
parent
72f5d78c10
commit
1575725bcb
8 changed files with 110 additions and 0 deletions
21
gvaldap/gvaldap/celery.py
Normal file
21
gvaldap/gvaldap/celery.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from celery import Celery
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
|
||||||
|
'gvaldap.settings.production')
|
||||||
|
|
||||||
|
|
||||||
|
app = Celery('gvaldap')
|
||||||
|
|
||||||
|
app.config_from_object('django.conf:settings')
|
||||||
|
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(bind=True)
|
||||||
|
def debug_task(self):
|
||||||
|
print('Request: {0!r}'.format(self.request))
|
|
@ -217,6 +217,7 @@ DJANGO_APPS = (
|
||||||
# Apps specific for this project go here.
|
# Apps specific for this project go here.
|
||||||
LOCAL_APPS = (
|
LOCAL_APPS = (
|
||||||
'ldapentities',
|
'ldapentities',
|
||||||
|
'osusers',
|
||||||
)
|
)
|
||||||
|
|
||||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
||||||
|
@ -278,3 +279,12 @@ INSTALLED_APPS += (
|
||||||
# Don't need to use South when setting up a test database.
|
# Don't need to use South when setting up a test database.
|
||||||
SOUTH_TESTS_MIGRATE = False
|
SOUTH_TESTS_MIGRATE = False
|
||||||
########## END SOUTH CONFIGURATION
|
########## END SOUTH CONFIGURATION
|
||||||
|
|
||||||
|
|
||||||
|
########## CELERY CONFIGURATION
|
||||||
|
BROKER_URL = get_env_setting('GVALDAP_BROKER_URL')
|
||||||
|
CELERY_RESULT_BACKEND = 'amqp'
|
||||||
|
CELERY_RESULT_PERSISTENT = True
|
||||||
|
CELERY_TASK_RESULT_EXPIRES = None
|
||||||
|
CELERY_ACCEPT_CONTENT = ['pickle']
|
||||||
|
########## END CELERY CONFIGURATION
|
||||||
|
|
0
gvaldap/osusers/__init__.py
Normal file
0
gvaldap/osusers/__init__.py
Normal file
3
gvaldap/osusers/admin.py
Normal file
3
gvaldap/osusers/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
42
gvaldap/osusers/models.py
Normal file
42
gvaldap/osusers/models.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
from django.db import models
|
||||||
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
from model_utils.models import TimeStampedModel
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
|
class Group(TimeStampedModel, models.Model):
|
||||||
|
groupname = models.CharField(
|
||||||
|
_('Group name'), max_length=16, unique=True)
|
||||||
|
gid = models.PositiveSmallIntegerField(
|
||||||
|
_('Group ID'), unique=True, primary_key=True)
|
||||||
|
descr = models.TextField(_('Description'), blank=True)
|
||||||
|
passwd = models.CharField(
|
||||||
|
_('Group password'), max_length=128, blank=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('Group')
|
||||||
|
verbose_name_plural = _('Groups')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '{0} ({1})'.format(self.groupname, self.gid)
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
|
class User(TimeStampedModel, models.Model):
|
||||||
|
username = models.CharField(
|
||||||
|
_('User name'), max_length=64, unique=True)
|
||||||
|
uid = models.PositiveSmallIntegerField(
|
||||||
|
_('User ID'), unique=True, primary_key=True)
|
||||||
|
group = models.ForeignKey(Group, verbose_name=_('Group'))
|
||||||
|
gecos = models.CharField(_('Gecos field'), max_length=128, blank=True)
|
||||||
|
homedir = models.CharField(_('Home directory'), max_length=256)
|
||||||
|
shell = models.CharField(_('Login shell'), max_length=64)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('User')
|
||||||
|
verbose_name_plural = _('Users')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '{0} ({1})'.format(self.username, self.uid)
|
28
gvaldap/osusers/tasks.py
Normal file
28
gvaldap/osusers/tasks.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from celery import shared_task
|
||||||
|
from ldapentities.models import (
|
||||||
|
LdapGroup,
|
||||||
|
LdapUser,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def create_ldap_group(group):
|
||||||
|
ldapgroup = LdapGroup(gid=group.gid, name=group.groupname)
|
||||||
|
ldapgroup.save()
|
||||||
|
return ldapgroup.dn
|
||||||
|
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def create_ldap_user(user, password):
|
||||||
|
ldapuser = LdapUser(
|
||||||
|
uid=user.uid, group=user.group.gid, gecos=user.gecos,
|
||||||
|
home_directory=user.homedir, login_shell=user.shell,
|
||||||
|
username=user.username, common_name=user.username)
|
||||||
|
ldapuser.set_password(password)
|
||||||
|
ldapgroup = LdapGroup.objects.get(gid=ldapuser.group)
|
||||||
|
ldapgroup.members.append(ldapuser.username)
|
||||||
|
ldapgroup.save()
|
||||||
|
ldapuser.save()
|
||||||
|
return ldapuser.dn
|
3
gvaldap/osusers/tests.py
Normal file
3
gvaldap/osusers/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
|
@ -7,3 +7,6 @@ logutils==0.3.3
|
||||||
South==0.8.4
|
South==0.8.4
|
||||||
celery==3.1.11
|
celery==3.1.11
|
||||||
passlib==1.6.2
|
passlib==1.6.2
|
||||||
|
billiard==3.3.0.17
|
||||||
|
kombu==3.0.16
|
||||||
|
pytz==2014.3
|
||||||
|
|
Loading…
Reference in a new issue