This repository has been archived by the owner on Jul 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
manager.py
72 lines (55 loc) · 2.19 KB
/
manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3.7
# -*- coding: UTF-8 -*-
'''BlendNet Manager REST
Description: REST interface for Manager
Run: /srv/blender/blender -b -noaudio -P /srv/blendnet/manager.py
'''
import os, sys
sys.path.append(os.path.dirname(__file__))
from BlendNet import providers
# TODO: allow even basic config change - restart the http server if its configs changed
conf = {}
if os.path.exists('manager.json'):
with open('manager.json', 'r') as f:
import json
conf = json.load(f)
providers.loadProviders()
# Select the required provider, local by default
providers.selectProvider(conf.get('provider', 'local'))
from BlendNet import (
disable_buffering,
getVersion,
SimpleREST,
Server,
Manager,
)
class Processor(Server.Processor):
def __init__(self, conf, prefix = 'api/v1'):
super().__init__(Manager.Manager(conf), prefix)
@SimpleREST.get('resources')
def resources(self, req = None):
'''Returns the available resources'''
return {
'success': True,
'message': 'Resources got',
'data': self._e.resourcesGet(),
}
@SimpleREST.get('agent/*/log')
def agent_log(self, req, parts):
'''Returns the information about the task'''
agent = self._e.agentGet(parts[0])
if not agent:
return { 'success': False, 'message': 'Unable to find agent' }
data = agent.log()
if not data:
return { 'success': False, 'message': 'No data received from the agent' }
return { 'success': True, 'message': 'Got agent log', 'data': data }
SimpleREST.generateCert(conf.get('instance_name', 'blendnet-manager'), 'server')
httpd = SimpleREST.HTTPServer((conf.get('listen_host', ''), conf.get('listen_port', 8443)), __doc__.split('\n')[0], [Processor(conf)])
httpd.setTLS(conf.get('server_tls_key', None), conf.get('server_tls_cert', None))
httpd.setBasicAuth('%s:%s' % (conf.get('auth_user', None), conf.get('auth_password', None)))
# Upload CA back to the blendnet storage
if os.path.exists('ca.crt') and conf.get('storage_url'):
providers.uploadFileToStorage('ca.crt', conf['storage_url'], 'ca.crt')
print('BlendNet Manager v' + getVersion())
httpd.serve_forever()