Commit 3ef0bd43 by Bach Dániel

dashboard: add ssh key tasks

parent 9306e681
......@@ -29,9 +29,11 @@ from django.db.models import (
Model, ForeignKey, OneToOneField, CharField, IntegerField, TextField,
DateTimeField, permalink, BooleanField
)
from django.db.models.signals import post_save, pre_delete
from django.template.loader import render_to_string
from django.templatetags.static import static
from django.utils.translation import ugettext_lazy as _, override, ugettext
from django_sshkey.models import UserKey
from model_utils.models import TimeStampedModel
from model_utils.fields import StatusField
......@@ -39,6 +41,8 @@ from model_utils import Choices
from acl.models import AclBase
from vm.tasks.agent_tasks import add_keys, del_keys
logger = getLogger(__name__)
......@@ -224,3 +228,33 @@ if hasattr(settings, 'SAML_ORG_ID_ATTRIBUTE'):
else:
logger.debug("Do not register save_org_id to djangosaml2 pre_user_save")
def add_ssh_keys(sender, **kwargs):
from vm.models import Instance
userkey = kwargs.get('instance')
instances = Instance.get_objects_with_level(
'user', userkey.user).filter(status='RUNNING')
for i in instances:
logger.info('called add_keys(%s, %s)', i, userkey)
queue = i.get_remote_queue_name("agent")
add_keys.apply_async(args=(i.vm_name, [userkey.key]),
queue=queue)
def del_ssh_keys(sender, **kwargs):
from vm.models import Instance
userkey = kwargs.get('instance')
instances = Instance.get_objects_with_level(
'user', userkey.user).filter(status='RUNNING')
for i in instances:
logger.info('called del_keys(%s, %s)', i, userkey)
queue = i.get_remote_queue_name("agent")
del_keys.apply_async(args=(i.vm_name, [userkey.key]),
queue=queue)
post_save.connect(add_ssh_keys, sender=UserKey)
pre_delete.connect(del_ssh_keys, sender=UserKey)
......@@ -56,3 +56,18 @@ def start_access_server(vm):
@celery.task(name='agent.update')
def update(vm, data):
pass
@celery.task(name='agent.add_keys')
def add_keys(vm, keys):
pass
@celery.task(name='agent.del_keys')
def del_keys(vm, keys):
pass
@celery.task(name='agent.get_keys')
def get_keys(vm):
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment