-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YoungHypo <haiboyang@smail.nju.edu.cn>
- Loading branch information
Showing
1 changed file
with
38 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,72 @@ | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
from subprocess import call | ||
from api.config import CELLO_HOME, FABRIC_TOOL, FABRIC_VERSION | ||
|
||
import subprocess | ||
import logging | ||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class ConfigTxGen: | ||
"""Class represents cryptotxgen.""" | ||
class CryptoGen: | ||
"""Class represents crypto-config tool.""" | ||
|
||
def __init__(self, network, filepath=CELLO_HOME, configtxgen=FABRIC_TOOL, version=FABRIC_VERSION): | ||
def __init__(self, name, filepath=CELLO_HOME, cryptogen=FABRIC_TOOL, version=FABRIC_VERSION): | ||
"""init CryptoGen | ||
param: | ||
network: network's name | ||
configtxgen: tool path | ||
name: organization's name | ||
cryptogen: tool path | ||
version: version | ||
filepath: cello's working directory | ||
return: | ||
""" | ||
self.network = network | ||
self.configtxgen = configtxgen + "/configtxgen" | ||
self.cryptogen = cryptogen + "/cryptogen" | ||
self.filepath = filepath | ||
self.version = version | ||
self.name = name | ||
|
||
def genesis(self, profile="", channelid="", outputblock="genesis.block"): | ||
"""generate gensis | ||
def generate(self, output="crypto-config", config="crypto-config.yaml"): | ||
"""Generate key material | ||
param: | ||
profile: profile | ||
channelid: channelid | ||
outputblock: outputblock | ||
output: The output directory in which to place artifacts | ||
config: The configuration template to use | ||
return: | ||
""" | ||
try: | ||
command = [ | ||
self.configtxgen, | ||
"-configPath", "{}/{}/".format(self.filepath, self.network), | ||
"-profile", "{}".format(profile), | ||
"-outputBlock", "{}/{}/{}".format(self.filepath, self.network, outputblock), | ||
"-channelID", "{}".format(channelid) | ||
self.cryptogen, | ||
"generate", | ||
"--output={}/{}/{}".format(self.filepath, self.name, output), | ||
"--config={}/{}/{}".format(self.filepath, self.name, config) | ||
] | ||
|
||
LOG.info(" ".join(command)) | ||
|
||
subprocess.run(command, check=True) | ||
|
||
except subprocess.CalledProcessError as e: | ||
err_msg = "configtxgen genesis fail! " | ||
raise Exception(err_msg+str(e)) | ||
call(command) | ||
|
||
except Exception as e: | ||
err_msg = "configtxgen genesis fail! " | ||
raise Exception(err_msg + str(e)) | ||
err_msg = "cryptogen generate fail for {}!".format(e) | ||
raise Exception(err_msg) | ||
|
||
def anchorpeer(self, profile, channelid, outputblock): | ||
"""set anchorpeer | ||
def extend(self, input="crypto-config", config="crypto-config.yaml"): | ||
"""Extend existing network | ||
param: | ||
profile: profile | ||
channelid: channelid | ||
outputblock: outputblock | ||
input: The input directory in which existing network place | ||
config: The configuration template to use | ||
return: | ||
""" | ||
pass | ||
try: | ||
command = [ | ||
self.cryptogen, | ||
"extend", | ||
"--input={}/{}/{}".format(self.filepath, self.name, input), | ||
"--config={}/{}/{}".format(self.filepath, self.name, config) | ||
] | ||
|
||
LOG.info(" ".join(command)) | ||
|
||
call(command) | ||
|
||
except Exception as e: | ||
err_msg = "cryptogen extend fail for {}!".format(e) | ||
raise Exception(err_msg) |