Skip to content

Commit 297b495

Browse files
committed
update cryptogen.py
Signed-off-by: YoungHypo <[email protected]>
1 parent 289a7e0 commit 297b495

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed
Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,72 @@
11
#
22
# SPDX-License-Identifier: Apache-2.0
33
#
4+
from subprocess import call
45
from api.config import CELLO_HOME, FABRIC_TOOL, FABRIC_VERSION
56

6-
import subprocess
77
import logging
88
LOG = logging.getLogger(__name__)
99

1010

11-
class ConfigTxGen:
12-
"""Class represents cryptotxgen."""
11+
class CryptoGen:
12+
"""Class represents crypto-config tool."""
1313

14-
def __init__(self, network, filepath=CELLO_HOME, configtxgen=FABRIC_TOOL, version=FABRIC_VERSION):
14+
def __init__(self, name, filepath=CELLO_HOME, cryptogen=FABRIC_TOOL, version=FABRIC_VERSION):
1515
"""init CryptoGen
1616
param:
17-
network: network's name
18-
configtxgen: tool path
17+
name: organization's name
18+
cryptogen: tool path
1919
version: version
2020
filepath: cello's working directory
2121
return:
2222
"""
23-
self.network = network
24-
self.configtxgen = configtxgen + "/configtxgen"
23+
self.cryptogen = cryptogen + "/cryptogen"
2524
self.filepath = filepath
2625
self.version = version
26+
self.name = name
2727

28-
def genesis(self, profile="", channelid="", outputblock="genesis.block"):
29-
"""generate gensis
28+
def generate(self, output="crypto-config", config="crypto-config.yaml"):
29+
"""Generate key material
3030
param:
31-
profile: profile
32-
channelid: channelid
33-
outputblock: outputblock
31+
output: The output directory in which to place artifacts
32+
config: The configuration template to use
3433
return:
3534
"""
3635
try:
3736
command = [
38-
self.configtxgen,
39-
"-configPath", "{}/{}/".format(self.filepath, self.network),
40-
"-profile", "{}".format(profile),
41-
"-outputBlock", "{}/{}/{}".format(self.filepath, self.network, outputblock),
42-
"-channelID", "{}".format(channelid)
37+
self.cryptogen,
38+
"generate",
39+
"--output={}/{}/{}".format(self.filepath, self.name, output),
40+
"--config={}/{}/{}".format(self.filepath, self.name, config)
4341
]
4442

4543
LOG.info(" ".join(command))
4644

47-
subprocess.run(command, check=True)
48-
49-
except subprocess.CalledProcessError as e:
50-
err_msg = "configtxgen genesis fail! "
51-
raise Exception(err_msg+str(e))
45+
call(command)
5246

5347
except Exception as e:
54-
err_msg = "configtxgen genesis fail! "
55-
raise Exception(err_msg + str(e))
48+
err_msg = "cryptogen generate fail for {}!".format(e)
49+
raise Exception(err_msg)
5650

57-
def anchorpeer(self, profile, channelid, outputblock):
58-
"""set anchorpeer
51+
def extend(self, input="crypto-config", config="crypto-config.yaml"):
52+
"""Extend existing network
5953
param:
60-
profile: profile
61-
channelid: channelid
62-
outputblock: outputblock
54+
input: The input directory in which existing network place
55+
config: The configuration template to use
6356
return:
6457
"""
65-
pass
58+
try:
59+
command = [
60+
self.cryptogen,
61+
"extend",
62+
"--input={}/{}/{}".format(self.filepath, self.name, input),
63+
"--config={}/{}/{}".format(self.filepath, self.name, config)
64+
]
65+
66+
LOG.info(" ".join(command))
67+
68+
call(command)
69+
70+
except Exception as e:
71+
err_msg = "cryptogen extend fail for {}!".format(e)
72+
raise Exception(err_msg)

0 commit comments

Comments
 (0)