-
Notifications
You must be signed in to change notification settings - Fork 1
/
crypto_config_generator.py
68 lines (56 loc) · 2.02 KB
/
crypto_config_generator.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
import yaml
import os
import copy
class CryptoConfig:
def __init__(self, orgs=1, ords=1):
self.no_of_peer_orgs = orgs
self.no_of_orderers = ords
self.orgs=[]
self.orders=[]
self.template = {
"OrdererOrgs": [],
"PeerOrgs": []
}
self.ordererTemplate ={
"Name": "Orderer",
"Domain": "example.com",
"EnableNodeOUs": True,
"Specs": []
}
self.peerOrgTemplate = {
"Name": "",
"Domain": "",
"EnableNodeOUs": True,
"Template": {
"Count": 2,
"SANS": [
"localhost"
]
},
"Users": {
"Count": 1
}
}
# path1 = os.getcwd()+'/network/'
directory = os.getcwd()+'/network/config/'
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print("Creation of the directory %s failed" % directory)
else:
print("Successfully created the directory %s " % directory)
def set_default_values(self):
print("Populate the YAML file with default values")
self.template["OrdererOrgs"].append(self.ordererTemplate)
for i in range(self.no_of_orderers):
self.template["OrdererOrgs"][0]["Specs"].append({"Hostname": "orderer" + str(i), "SANS": ["localhost","127.0.0.1"]})
for i in range(self.no_of_peer_orgs):
tmp = copy.deepcopy(self.peerOrgTemplate)
self.template["PeerOrgs"].append(tmp)
self.template["PeerOrgs"][i]["Name"] = "Org" + str(i+1)
self.template["PeerOrgs"][i]["Domain"] = "org" + str(i+1) + ".example.com"
with open('network/config/crypto-config.yaml', 'w') as f:
data = yaml.dump(self.template, f)
def add_org(self, name, domain, template_count):
print(10)