Commit 3342a545 authored by Lukas Burgey's avatar Lukas Burgey

Refactor minor details

parent 2ec58c45
......@@ -39,19 +39,6 @@ def questionnaire_default():
def credential_default():
return {}
# takes a list of states
# return '<state>' if all states are equal to '<state>'
# else it returns 'mixed'
def analyze_states(states):
_state = ''
for state in states:
if _state == '':
_state = state
elif _state != state:
return 'mixed'
return _state
# singleton for simple configs
# https://steelkiwi.com/blog/practical-application-singleton-design-pattern/
......@@ -529,9 +516,12 @@ class Service(models.Model):
# all group deployments have the same keys
# TODO check that assumption
deployment = user.deployments.filter(group=group)
if deployment.exists():
deployment.first().service_added(self)
try:
deployment = user.deployments.get(group=group)
deployment.service_added(self)
except Deployment.DoesNotExist:
LOGGER.error('Inconsistency in group deployment')
raise
class SSHPublicKey(models.Model):
......@@ -817,7 +807,22 @@ class DeploymentState(models.Model):
@property
def state(self):
return analyze_states(self.states)
if self.states:
_state = ''
for state in self.states:
if _state == '':
_state = state
elif _state != state:
return 'mixed'
return _state
# if we have no states we have nothing to do
return self.state_target
@property
def target_reached(self):
return self.state_target == self.state
@property
def service(self):
......@@ -831,10 +836,6 @@ class DeploymentState(models.Model):
def group(self):
return self.deployment.group
@property
def target_reached(self):
return self.state_target == self.state
# get a state for a user/service.
# if it does not exist it is created
@classmethod
......
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