spug/spug_api/libs/channel.py

24 lines
573 B
Python
Raw Normal View History

2019-11-24 09:05:58 +00:00
from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync
import uuid
layer = get_channel_layer()
class Channel:
@staticmethod
def get_token():
return uuid.uuid4().hex
@staticmethod
def send_ssh_executor(hostname, port, username, command, token=None):
message = {
'type': 'exec',
'token': token,
'hostname': hostname,
'port': port,
'username': username,
'command': command
}
async_to_sync(layer.send)('ssh_exec', message)