Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
portal
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
11
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
160c6664
authored
Apr 20, 2020
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement basic channels feature for testing
parent
37eea7f4
Pipeline
#1074
passed with stage
in 2 minutes 26 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
5 deletions
+29
-5
recircle/instance/models.py
+8
-2
status/consumers.py
+21
-3
No files found.
recircle/instance/models.py
View file @
160c6664
...
...
@@ -7,6 +7,9 @@ from image.models import Disk
from
interface_openstack.implementation.vm.instance
import
(
OSVirtualMachineManager
)
from
channels.layers
import
get_channel_layer
from
asgiref.sync
import
async_to_sync
import
logging
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -251,8 +254,11 @@ class Instance(BaseMachineDescriptor):
def
update_status
(
self
):
remote
=
self
.
get_remote_instance
()
self
.
status
=
remote
.
status
self
.
save
()
if
self
.
status
is
not
remote
.
status
:
self
.
status
=
remote
.
status
channels
=
get_channel_layer
()
async_to_sync
(
channels
.
group_send
)(
str
(
self
.
id
),
{
"type"
:
"status.status_changed"
})
self
.
save
()
@classmethod
def
generate_password
(
self
):
...
...
status/consumers.py
View file @
160c6664
# import json
#
from asgiref.sync import async_to_sync
from
asgiref.sync
import
async_to_sync
from
channels.generic.websocket
import
WebsocketConsumer
from
recircle.instance.models
import
Instance
import
logging
logger
=
logging
.
getLogger
(
__name__
)
class
StatusConsumer
(
WebsocketConsumer
):
def
connect
(
self
):
pass
instances
=
Instance
.
objects
.
all
()
for
inst
in
instances
:
async_to_sync
(
self
.
channel_layer
.
group_add
)(
str
(
inst
.
id
),
self
.
channel_name
)
def
disconnect
(
self
):
pass
instances
=
Instance
.
objects
.
all
()
for
inst
in
instances
:
async_to_sync
(
self
.
channel_layer
.
group_discard
)(
str
(
inst
.
id
),
self
.
channel_name
)
def
receive
(
self
,
text_message
):
pass
def
status_changed
(
self
,
event
):
logger
.
info
(
"Event received"
)
self
.
send
(
text_data
=
event
[
"status"
])
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