v0.4.3 配合 vue前端

This commit is contained in:
何全
2019-06-21 17:26:19 +08:00
parent f134790dcb
commit d38df2138f
4 changed files with 51 additions and 10 deletions

View File

@@ -37,7 +37,13 @@ class EchoConsumer(WebsocketConsumer):
def connect(self):
# 创建channels group 命名为:用户名 (最好不要中文名字,这里会用名字 建立一个通道,通过这个通道进行通信)并使用channel_layer写入到redis
async_to_sync(self.channel_layer.group_add)(self.scope['user'].username, self.channel_name)
try:
async_to_sync(self.channel_layer.group_add)(self.scope['user'].username, self.channel_name)
except Exception as e:
# 这里是为了配合 seal-vue 使用,实际项目,请删除下面这一行
async_to_sync(self.channel_layer.group_add)("admin", self.channel_name)
# 可以在这里根据 用户 要访问的pod 进行 权限控制
path = self.scope['path'].split('/')
try:
@@ -59,4 +65,8 @@ class EchoConsumer(WebsocketConsumer):
self.send(text_data=event["text"])
def disconnect(self, close_code):
async_to_sync(self.channel_layer.group_discard)(self.scope['user'].username, self.channel_name)
try:
async_to_sync(self.channel_layer.group_discard)(self.scope['user'].username, self.channel_name)
except Exception as e:
# 这里是为了配合 seal-vue 使用,实际项目,请删除下面这一行
async_to_sync(self.channel_layer.group_discard)("admin", self.channel_name)

View File

@@ -18,6 +18,7 @@ class K8sApi(object):
aConfiguration.api_key = {"authorization": "Bearer " + token}
aApiClient = client.ApiClient(aConfiguration)
v1 = client.CoreV1Api(aApiClient)
return v1
def get_node_list(self):