-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNcloudUtils.py
52 lines (39 loc) · 1.34 KB
/
NcloudUtils.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
from db import Mongo
from os import getenv
from helper import *
from requests import get
def getNcloudConfig(DB:Mongo):
data:dict = DB.get_doc({}, getenv('ADMIN_COLLECTION'))
if data == None:
return None
return {
"addall_inNewHosts": data.get('addall_inNewHosts'),
"autoStartSrvr": data.get('autoStartSrvr'),
"allowRegistration": data.get('allowRegistration'),
"pendingNewUser": data.get('pendingNewUser')
}
def getServers(DB:Mongo):
block:dict = DB.get_docs({}, getenv('SERVER_COLLECTION'))
NN = Nas(block)
return NN.getBlock()
def allAlive(DB:Mongo):
servers:dict = getServers(DB)
counter = 0
for server in servers:
try:
res = get(f'http://{server.get("address")}/init/')
if res.ok == False:
raise Exception
except Exception as e:
print(f'Error ocurred :: {server.get("address")} is not alive\t\t[{server.get("name")}]')
return False
return True
def isServerAlive(server:dict):
try:
res = get(f'http://{server.get("address")}/init/')
if res.ok == False:
raise Exception
except Exception as e:
print(f'Error ocurred :: {server.get("address")} is not alive\t\t[{server.get("name")}]')
return False
return True