def create_configtx_file(config, dir, configtx_filename=CNFIGTX_FN): logger.info("Create configtx.yaml...") try: orderer_default = __create_orderer(config) orderer_org = __create_orderer_org(config) peers_org = __create_peers_org(config) application_default = __create_application(config) orderer_default['Organizations'] = orderer_org application_default['Organizations'] = peers_org orderer_profil = {} sample_consortium = {} consortiums = {} channel_profil = {} profiles = {} dic = {} orderer_profil['Orderer'] = orderer_default sample_consortium['Organizations'] = peers_org consortiums['SampleConsortium'] = sample_consortium orderer_profil['Consortiums'] = consortiums channel_profil['Consortium'] = "SampleConsortium" channel_profil['Application'] = application_default profiles['OrgsChannel'] = channel_profil profiles['OrgsOrdererGenesis'] = orderer_profil dic['Profiles'] = profiles dump_yaml_file(data=dic, file_path=dir + "/" + configtx_filename) logger.debug(json.dumps(dic, indent=4)) except Exception as e: logger.error(e) raise Exception("Create crypto-config.yaml failled!")
def create_docker_compose_file(ordererOrgs, peerOrgs, peer_image, orderer_image, ca_image, tls, dir, network="net", filename=DOCKERCOMPOSE_FN): try: logger.info("Create docker-compose.yaml...") services = [] for peerOrg in peerOrgs: caID = "ca_peer" + peerOrg.org_name #pk_name=caID.upper()+"_PK" cmd = ('cd {0}/crypto-config/peerOrganizations/{1}/ca/ && ls *_sk'. format(dir, peerOrg.domain)) pk_name = exec_cmd(cmd).replace('\n', '').replace('\r', '') services.append( __build_ca_service(caID=caID, peerOrg=peerOrg, ca_image=ca_image, tls=tls, pk_name=pk_name, port=peerOrg.ca.port, network=network)) for peer in peerOrg.peers: peerID = peer.hostname services.append( __build_peer_service(peerID=peerID, peerOrg=peerOrg, peer_image=peer_image, tls=tls, port_req=peer.request_port, port_evt=peer.event_port, network=network)) for ordererOrg in ordererOrgs: ordererID = ordererOrg.org_name.lower() + "." + ordererOrg.domain services.append( __build_orderer_service(ordererID=ordererID, ordererOrg=ordererOrg, orderer_image=orderer_image, peerOrgs=peerOrgs, tls=tls, port=ordererOrg.port, network=network)) dockerfile_dict = {'version': "2"} dockerfile_dict['networks'] = {network: None} dockerfile_dict['services'] = { service.container_name: service.to_dict() for service in services } dump_yaml_file(data=dockerfile_dict, file_path=dir + "/" + filename) #logger.debug(json.dumps(dockerfile_dict, indent=4)) #exec_cmd('cp {0}samples/1.0.4/docker-compose.yaml {1}/{2}'.format(my_path, dir, "docker-compose.yaml")) #exec_cmd('cp {0}samples/1.0.4/base.yaml {1}/{2}'.format(my_path, dir, "base.yaml")) except Exception as e: logger.error(e) raise Exception("create_docker_compose_file failled!")
def create_crypto_config_file(config, dir, cryptog_config_filename=CRYPTOCONFIG_FN): logger.info("Create crypto-config.yaml...") try: dic = {} orderer = {} ca = {} specs = [] peers = [] orderers = [] orderer['Domain'] = config.orderer_org.domain orderer['Name'] = "orderer" #config.orderer_org.org_name ca['Country'] = config.cert.country ca['Province'] = config.cert.province ca['Locality'] = config.cert.locality for o in config.orderer_org.orderers: specs.append({'Hostname': o.name}) orderer['Specs'] = specs orderer['CA'] = ca orderers.append(orderer) for peer_org in config.peer_orgs: peer = {} users = {} template = {} users['Count'] = peer_org.nb_users template['Count'] = peer_org.nb_peers peer['Domain'] = peer_org.domain peer['Name'] = peer_org.org_name peer['CA'] = ca peer['Users'] = users peer['Template'] = template peers.append(peer) dic['OrdererOrgs'] = orderers dic['PeerOrgs'] = peers dump_yaml_file(data=dic, file_path=dir + "/" + cryptog_config_filename) logger.debug(json.dumps(dic, indent=4)) return cryptog_config_filename except Exception as e: logger.error(e) raise Exception("Create crypto-config.yaml failled!")
def create_config_file(config, filename): logger.info("Create explorer config file...") try: dic = {} dic['host'] = EXPLORER_HOST dic['port'] = EXPLORER_PORT dic['channel'] = config.channel.name dic['keyValueStore'] = EXPLORER_LOCAL + "fabric-client-kvs" dic['eventWaitTime'] = "30000" mysql = {} mysql['host'] = EXPLORER_MSQL_HOST mysql['port'] = EXPLORER_MSQL_PORT mysql['database'] = EXPLORER_MSQL_DB mysql['username'] = EXPLORER_MSQL_LOGIN mysql['password'] = EXPLORER_MSQL_PWD dic['mysql'] = mysql for o in config.peer_orgs: org = {} org['name'] = "peer" + o.org_name org['mspid'] = o.mspid org['ca'] = o.ca.url for p in o.peers: peer = {} peer['request'] = p.request_url peer['events'] = p.event_url peer['server-hostname'] = p.hostname peer[ 'tls_cacerts'] = EXPLORER_LOCAL + o.domain + "/peer/" + p.name + "/ca.crt" org[p.name] = peer admin = {} admin['key'] = EXPLORER_LOCAL + o.domain + "/admin/keystore" admin['cert'] = EXPLORER_LOCAL + o.domain + "/admin/signcerts" org['admin'] = admin dic[o.org_name] = org with open(filename, 'w') as f: json.dump(dic, f, ensure_ascii=False, indent=4) logger.debug(json.dumps(dic, indent=4)) except Exception as e: logger.error(e) raise Exception("Create explorer config file failled!")
def create_connection_file(config, filename): for peer_org in config.peer_orgs: logger.info("Create composer config file...") try: dic ={} dic['name'] = 'profil'+peer_org.org_name dic['type'] = 'hlfv1' dic['mspID'] = peer_org.mspid dic['channel'] = config.channel.name dic['timeout'] = 300 peers=[] for p in peer_org.peers: peer = {} peer['requestURL']=p.request_url peer['eventURL']=p.event_url peer['cert']=COMPOSER_LOCAL+peer_org.domain+"/peer/"+p.name+"/ca.crt" peer['hostnameOverride']=p.hostname peers.append(peer) orderers=[] dic['peers']=peers for o in config.orderer_org.orderers: orderer = {} orderer['url']=o.url orderer['cert']=COMPOSER_LOCAL+config.orderer_org.domain+"/orderer/"+o.name+"/ca.crt" orderer['hostnameOverride']=o.hostname orderers.append(orderer) dic['orderers']=orderers ca = {} ca['url']=peer_org.ca.url ca['name']="ca-"+peer_org.org_name ca['cert']=COMPOSER_LOCAL+peer_org.domain+"/ca/ca.crt" ca['hostnameOverride']="ca."+peer_org.domain dic['ca']=ca with open(filename, 'w') as f: json.dump(dic, f, ensure_ascii=False, indent=4) logger.debug(json.dumps(dic, indent=4)) except Exception as e: logger.error(e) raise Exception("Create composer config file failled!")
def __init_folders(channel): logger.info("Initialize archives folders...") channel_dir = root_path+GENERATED+"/"+channel+"/" exec_cmd("rm -Rf {}".format(channel_dir)) exec_cmd("mkdir -p {}".format(channel_dir + LOCAL)) return channel_dir
def generate4composer(json_config): logger.info("Generate archive for composer...") generate_archives(json_config, "COMPOSER")
def generate4explorer(json_config): logger.info("Generate archive for explorer...") generate_archives(json_config, "EXPLORER")
def generate_dockerfiles(json_config): logger.info("Generate docker files...") generate_archives(json_config, "DOCKER")
def generate_channel_artifacts(json_config): logger.info("Generate channel artificats...") generate_archives(json_config, "CHANNEL")
def generate_crypto_material(json_config): logger.info("Generate crypto material...") generate_archives(json_config, "CRYPTO")
def generate_all_material(json_config): logger.info("Generate all material...") generate_archives(json_config)
def generate_configTX(path, channel_name=CHANNEL_NAME): logger.info("Generate configTX file...") channeltx_filename = channel_name + ".tx" cmd_channeltx = "cd " + path + " && " + root_path + CONFIGTXGEN + " -profile OrgsChannel -outputCreateChannelTx " + channeltx_filename + " -channelID " + channel_name exec_cmd(cmd_channeltx)
def generate_genesis_block(path): logger.info("Generate genesis block...") cmd_genesis_block = "cd " + path + " && " + root_path + CONFIGTXGEN + " -profile OrgsOrdererGenesis -outputBlock " + GENESISBLOCKNAME exec_cmd(cmd_genesis_block)
def generate_MSP(path, cryptoconfig_filename): logger.info("Generate MSP...") cmd_cryptogen = "cd " + path + " && " + root_path + CRYPTOGEN + " generate --config=" + path + "/" + cryptoconfig_filename + " --output=crypto-config" exec_cmd(cmd_cryptogen)