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
580739c0
Commit
580739c0
authored
Dec 08, 2017
by
Lukas Burgey
Browse files
Change the sending of deployment changes
parent
70836be3
Changes
2
Hide whitespace changes
Inline
Side-by-side
django_backend/backend/clientapi/models.py
View file @
580739c0
from
django.dispatch
import
receiver
from
django.db.models.signals
import
post_save
from
..
import
models
from
.serializers
import
DeploymentSerializer
import
pika
...
...
@@ -11,7 +10,7 @@ class Deployments:
pass
@
receiver
(
post_sav
e
,
sender
=
models
.
Deployment
)
@
receiver
(
models
.
deployment_chang
e
,
sender
=
models
.
Deployment
)
def
publish_deployment
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
instance
is
None
:
return
...
...
@@ -27,14 +26,11 @@ def publish_deployment(sender, instance=None, created=False, **kwargs):
message
=
json
.
dumps
(
DeploymentSerializer
(
instance
).
data
)
# we only use the service as routing key
routing_keys
=
[
'service.'
+
instance
.
service
.
name
]
routing_key
=
'service.'
+
instance
.
service
.
name
channel
.
basic_publish
(
exchange
=
exchange_name
,
routing_key
=
routing_key
,
body
=
message
)
for
routing_key
in
routing_keys
:
channel
.
basic_publish
(
exchange
=
exchange_name
,
routing_key
=
routing_key
,
body
=
message
)
print
(
" [x] Sent %r:%r"
%
(
routing_key
,
message
))
print
(
" [x] Sent %r:%r"
%
(
routing_key
,
message
))
connection
.
close
()
django_backend/backend/models.py
View file @
580739c0
from
django.contrib.auth.models
import
AbstractUser
,
Group
from
django.db
import
models
from
django.conf
import
settings
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
,
Signal
from
rest_framework.authtoken.models
import
Token
from
django.db.models.signals
import
post_save
from
datetime
import
datetime
...
...
@@ -9,6 +9,8 @@ from datetime import datetime
import
requests
from
requests.auth
import
HTTPBasicAuth
deployment_change
=
Signal
(
providing_args
=
[
'instance'
])
class
User
(
AbstractUser
):
TYPE_CHOICES
=
(
...
...
@@ -234,6 +236,7 @@ class Deployment(models.Model):
if
key
in
self
.
ssh_keys_to_withdraw
.
all
():
self
.
ssh_keys_to_withdraw
.
remove
(
key
)
self
.
save
()
self
.
send_change
()
def
withdraw_key
(
self
,
key
):
# key state: -> (4)
...
...
@@ -242,6 +245,7 @@ class Deployment(models.Model):
# keys which are to be withdrawn by the clients
self
.
ssh_keys_to_withdraw
.
add
(
key
)
self
.
save
()
self
.
send_change
()
def
client_got_deployment
(
self
):
# the client has withdrawn the keys so we can empty the list
...
...
@@ -249,5 +253,14 @@ class Deployment(models.Model):
# TODO: does the deletion of the ssh_keys actually occur?
self
.
save
()
def
send_change
(
self
):
deployment_change
.
send
(
sender
=
self
.
__class__
,
instance
=
self
)
def
__str__
(
self
):
return
'{}@{}'
.
format
(
self
.
user
,
self
.
service
)
@
receiver
(
post_save
,
sender
=
Deployment
)
def
publish_deployment_creation
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
instance
.
send_change
()
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