Commit 844200d8 authored by Lukas Burgey's avatar Lukas Burgey

Make service and vo deployment cooperate with each other

parent 2e2602ff
# pylint: disable=global-statement
import logging
from logging import getLogger
from json import dumps
from requests.auth import HTTPBasicAuth
from django.db import models
......@@ -10,7 +11,7 @@ from django_mysql.models import JSONField
import pika
from pika.exceptions import ConnectionClosed
LOGGER = logging.getLogger(__name__)
LOGGER = getLogger(__name__)
RABBITMQ_CONNECTION = None
......@@ -23,6 +24,14 @@ def exchanges_default():
]
def publish_to_user(user, obj):
from . import serializers
RabbitMQInstance.load().publish_to_user(
user,
dumps(serializers.UpdateSerializer(obj).data),
)
# singleton for simple configs
# https://steelkiwi.com/blog/practical-application-singleton-design-pattern/
class SingletonModel(models.Model):
......@@ -159,21 +168,6 @@ class RabbitMQInstance(SingletonModel):
msg,
)
def publish_by_service(self, service, msg):
self._publish(
'services',
service.name,
msg,
)
def publish_by_vo(self, vo, msg):
self._publish(
vo.broker_exchange,
vo.name,
msg,
)
def publish_to_user(self, user, msg):
self._publish(
'users',
......
This diff is collapsed.
......@@ -117,6 +117,7 @@ class VODeploymentSerializer(serializers.ModelSerializer):
class ServiceDeploymentSerializer(serializers.ModelSerializer):
states = DeploymentStateSerializer(many=True)
service = ServiceSerializer()
class Meta:
model = ServiceDeployment
fields = DEPLOYMENT_FIELDS + (
......@@ -132,41 +133,33 @@ class DeploymentSerializer(PolymorphicSerializer):
}
# contains properties which change less often
class UserSerializer(serializers.ModelSerializer):
vos = VOSerializer(many=True)
ssh_keys = SSHPublicKeySerializer(many=True)
class Meta:
model = User
fields = [
'id',
'profile_name',
'ssh_keys',
'userinfo',
'vos',
]
class UserStateSerializer(serializers.ModelSerializer):
vos = VOSerializer(many=True)
ssh_keys = SSHPublicKeySerializer(many=True)
deployments = DeploymentSerializer(many=True)
services = ServiceSerializer(many=True)
ssh_keys = SSHPublicKeySerializer(many=True)
states = DeploymentStateSerializer(many=True)
vos = VOSerializer(many=True)
class Meta:
model = User
fields = [
fields = (
'deployments',
'id',
'profile_name',
'services',
'ssh_keys',
'states',
'userinfo',
'vos',
]
)
class StateSerializer(serializers.Serializer):
error = serializers.CharField(allow_blank=True, required=False)
user = UserStateSerializer()
class UpdateSerializer(serializers.Serializer):
error = serializers.CharField(allow_blank=True, required=False)
deployment = DeploymentSerializer(required=False)
deployment_state = DeploymentStateSerializer(required=False)
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 to comment