1
+ import yaml
2
+ import sys
3
+
4
+ def generate_aggr_template (dict , path ):
5
+ """ Generate YAML template for aggregator deployment and save it in the given file
6
+ """
7
+ config = {
8
+ "apiVersion" : "v1" ,
9
+ "kind" : "Pod" ,
10
+ "metadata" : {
11
+ "name" : dict ["pod_name" ]
12
+ },
13
+ "spec" : {
14
+
15
+ "containers" : [{
16
+ "name" : "fedscale-aggr" ,
17
+ "image" : "fedscale/fedscale-aggr" ,
18
+ "imagePullPolicy" : "Always" ,
19
+ "ports" : [
20
+ {
21
+ "containerPort" : 30000
22
+ }
23
+ ],
24
+ "volumeMounts" : [{
25
+ "mountPath" : "FedScale/benchmark" ,
26
+ "name" : "benchmark" ,
27
+ "readOnly" : False
28
+ }
29
+ ]
30
+ }
31
+ ],
32
+ "volumes" : [{
33
+ "name" : "benchmark" ,
34
+ "hostPath" : {
35
+ # directory location on host, assume it exists on all nodes
36
+ "path" : dict ["data_path" ],
37
+ "type" : "Directory"
38
+ }
39
+ }]
40
+ }
41
+ }
42
+ with open (path , "w" ) as f :
43
+ f .write (yaml .dump (config , default_flow_style = False ))
44
+
45
+ # validate the yaml file in case weird things happen
46
+ with open (path , "r" ) as f :
47
+ try :
48
+ yaml .safe_load (f )
49
+ return config
50
+ except :
51
+ sys .exit ("Generated YAML is not valid, aborting..." )
52
+
53
+
54
+ def generate_exec_template (dict , path ):
55
+ """ Generate YAML template for executor deployment and save it in the given file
56
+ """
57
+ config = {
58
+ "apiVersion" : "v1" ,
59
+ "kind" : "Pod" ,
60
+ "metadata" : {
61
+ "name" : dict ["pod_name" ]
62
+ },
63
+ "spec" : {
64
+
65
+ "containers" : [{
66
+ "name" : "fedscale-exec" ,
67
+ "image" : "fedscale/fedscale-exec" ,
68
+ "imagePullPolicy" : "Always" ,
69
+ "ports" : [
70
+ {
71
+ "containerPort" : 32000
72
+ }
73
+ ],
74
+ "volumeMounts" : [{
75
+ "mountPath" : "FedScale/benchmark" ,
76
+ "name" : "benchmark" ,
77
+ "readOnly" : False
78
+ }
79
+ ]
80
+ }
81
+ ],
82
+ "volumes" : [{
83
+ "name" : "benchmark" ,
84
+ "hostPath" : {
85
+ # directory location on host, assume it exists on all nodes
86
+ "path" : dict ["data_path" ],
87
+ "type" : "Directory"
88
+ }
89
+ }]
90
+ }
91
+ }
92
+ with open (path , "w" ) as f :
93
+ f .write (yaml .dump (config , default_flow_style = False ))
94
+
95
+ # validate the yaml file in case weird things happen
96
+ with open (path , "r" ) as f :
97
+ try :
98
+ yaml .safe_load (f )
99
+ return config
100
+ except :
101
+ sys .exit ("Generated YAML is not valid, aborting..." )
102
+
103
+ # if __name__ == "__main__":
104
+ # generate_aggr_template({"pod_name": "fedscale-aggr-pod", "data_path": "/users/yilegu/benchmark"}, "generated_aggr.yaml")
105
+ # generate_exec_template({"pod_name": "fedscale-exec-pod", "data_path": "/users/yilegu/benchmark"}, "generated_exec.yaml")
0 commit comments