-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·102 lines (91 loc) · 2.58 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python3
##################################### IMPORT ###############################################
import sys
sys.path.append('./iptables')
import time
import argparse
import command
import service
import apply as app
import proba
##################################### PARSE ###############################################
def parseCliOptions():
parser = argparse.ArgumentParser()
parser.add_argument( '--command', #imp
dest = 'command',
type = str,
default = 'ls',
help = 'command to the get status output',
)
parser.add_argument( '--cycle',#imp
dest = 'cycle',
type = int,
default = 1,
help = 'cycle time in seconds',
)
parser.add_argument( '--alpha', #imp
dest = 'alpha',
type = float,
default = .8,
help = 'The importance of the location in scheduling',
)
parser.add_argument( '--LoadBalancing', #imp
dest = 'LB',
type = str,
default = '1-best',
help = 'The function that will decide how probability should be divided over the pods',
)
parser.add_argument( '--K', #imp
dest = 'K',
type = int,
default = -1,
help = 'number of best pods',
)
parser.add_argument( '--serfoff', #imp
dest = 'serfoff',
action = 'store_true',
help = 'use serf for latency calculation or use ping',
)
parser.add_argument( '--Delay', #imp
dest = 'Delay',
type = float,
default = 0,
help = 'counting for the enduser time',
)
parser.add_argument( '--LocalRtt', #imp
dest = 'local',
type = float,
default = 0.3,
help = 'local node rtt time, to count the time needed to access the pod',
)
parser.add_argument( '--Beta', #imp
dest = 'Beta',
type = float,
default = 1,
help = 'Beta for the probability function (positive)',
)
options = parser.parse_args()
return options.__dict__
##################################### MAIN ###############################################
def GetOptions():
options = parseCliOptions()
return options
def Run(options):
BestList = []
svcl = []
command.DeleteAllRules()
svcl = service.GetSvcs()
service.PrintSvcl(svcl)
for sv in svcl:
print(sv.name)
BestList.append(app.best(sv,options))
while True:
print("sleeping")
time.sleep(options['cycle'])
print("wakeup")
svcl,BestList = service.Check(svcl,BestList,options)
app.PrintBestList(BestList)
if __name__ == "__main__":
options = parseCliOptions()
#command.DeleteAllRules()
Run(options)