Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalBackend
Commits
3342a545
Commit
3342a545
authored
Jul 23, 2018
by
Lukas Burgey
Browse files
Refactor minor details
parent
2ec58c45
Changes
1
Hide whitespace changes
Inline
Side-by-side
django_backend/backend/models.py
View file @
3342a545
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment