agent: sync profile attributes from primary (#34210)

This commit is contained in:
Frédéric Péters 2020-03-09 20:11:42 +01:00
parent 0ca228fa96
commit 70a230090b
1 changed files with 15 additions and 0 deletions

View File

@ -7,6 +7,7 @@ from hobo.agent.common.management.commands import hobo_deploy
from hobo.deploy.signals import notify_agents
from hobo.environment.models import AVAILABLE_SERVICES, Hobo, Variable
from hobo.multitenant.middleware import TenantMiddleware, TenantNotFound
from hobo.profile.models import AttributeDefinition
class Command(hobo_deploy.Command):
@ -97,6 +98,20 @@ class Command(hobo_deploy.Command):
variable.value = me['slug']
variable.save()
# and reproduce profile settings from primary
if 'profile' in hobo_environment:
seen = []
for i, field in enumerate(hobo_environment['profile']['fields']):
attribute, created = AttributeDefinition.objects.get_or_create(
name=field['name'],
defaults={'label': field['label']})
for k, v in field.items():
setattr(attribute, k, v)
attribute.order = i + 1
attribute.save()
seen.append(attribute.name)
AttributeDefinition.objects.exclude(name__in=seen).delete()
if me.get('secondary'):
# on the primary hobo, notify other primary services, this will
# get authentic to know about secondary services