diff --git a/src/agent/docker-rest-agent/server.py b/src/agent/docker-rest-agent/server.py index e06485ab4..9080e193d 100644 --- a/src/agent/docker-rest-agent/server.py +++ b/src/agent/docker-rest-agent/server.py @@ -46,7 +46,8 @@ def create_node(): port_map = ast.literal_eval(request.form.get("port_map")) volumes = [ '{}/fabric/{}:/etc/hyperledger/fabric'.format(storage_path, node_name), - '{}/production/{}:/var/hyperledger/production'.format(storage_path, node_name) + '{}/production/{}:/var/hyperledger/production'.format(storage_path, node_name), + '/var/run/docker.sock:/host/var/run/docker.sock' ] if request.form.get('type') == "peer": peer_envs = { diff --git a/src/api-engine/api/lib/peer/chaincode.py b/src/api-engine/api/lib/peer/chaincode.py index 917eddd32..518048d0f 100644 --- a/src/api-engine/api/lib/peer/chaincode.py +++ b/src/api-engine/api/lib/peer/chaincode.py @@ -6,7 +6,9 @@ import subprocess from api.lib.peer.command import Command from api.config import FABRIC_TOOL, FABRIC_CFG, FABRIC_VERSION +import logging +LOG = logging.getLogger(__name__) class ChainCode(Command): def __init__(self, version=FABRIC_VERSION, peer=FABRIC_TOOL, **kwargs): @@ -39,8 +41,13 @@ def lifecycle_install(self, cc_targz): :return: 0 means success. """ try: - res = os.system( - "{} lifecycle chaincode install {}".format(self.peer, cc_targz)) + command = [ + self.peer, + "lifecycle", "chaincode", "install", + cc_targz + ] + LOG.info(" ".join(command)) + res = os.system(" ".join(command)) res = res >> 8 except Exception as e: err_msg = "install chaincode failed for {}!".format(e) diff --git a/src/api-engine/api/routes/chaincode/views.py b/src/api-engine/api/routes/chaincode/views.py index bc2d2942a..e8c02a992 100644 --- a/src/api-engine/api/routes/chaincode/views.py +++ b/src/api-engine/api/routes/chaincode/views.py @@ -20,7 +20,7 @@ from api.lib.peer.chaincode import ChainCode as PeerChainCode from api.common.serializers import PageQuerySerializer -from api.utils.common import with_common_response +from api.utils.common import with_common_response, init_env_vars from api.exceptions import ResourceNotFound from api.routes.chaincode.serializers import ( @@ -33,7 +33,9 @@ from api.common import ok, err import threading import hashlib +import logging +LOG = logging.getLogger(__name__) class ChainCodeViewSet(viewsets.ViewSet): """Class represents Channel related operations.""" @@ -239,8 +241,8 @@ def install(self, request): if not qs.exists(): raise ResourceNotFound peer_node = qs.first() - envs = init_env_vars(peer_node, org) + envs = init_env_vars(peer_node, org) peer_channel_cli = PeerChainCode(**envs) res = peer_channel_cli.lifecycle_install(cc_targz) if res != 0: @@ -551,31 +553,3 @@ def query_committed(self, request): return Response( ok(chaincodes_commited), status=status.HTTP_200_OK ) - - -def init_env_vars(node, org): - """ - Initialize environment variables for peer channel CLI. - :param node: Node object - :param org: Organization object. - :return env: dict - """ - org_name = org.name - org_domain = org_name.split(".", 1)[1] - dir_certificate = "{}/{}/crypto-config/ordererOrganizations/{}".format( - CELLO_HOME, org_name, org_domain) - dir_node = "{}/{}/crypto-config/peerOrganizations".format( - CELLO_HOME, org_name) - - envs = { - "CORE_PEER_TLS_ENABLED": "true", - # "Org1.cello.comMSP" - "CORE_PEER_LOCALMSPID": "{}MSP".format(org_name.capitalize()), - "CORE_PEER_TLS_ROOTCERT_FILE": "{}/{}/peers/{}/tls/ca.crt".format(dir_node, org_name, node.name + "." + org_name), - "CORE_PEER_ADDRESS": "{}:{}".format( - node.name + "." + org_name, str(7051)), - "CORE_PEER_MSPCONFIGPATH": "{}/{}/users/Admin@{}/msp".format(dir_node, org_name, org_name), - "FABRIC_CFG_PATH": "{}/{}/peers/{}/".format(dir_node, org_name, node.name + "." + org_name), - "ORDERER_CA": "{}/msp/tlscacerts/tlsca.{}-cert.pem".format(dir_certificate, org_domain) - } - return envs diff --git a/src/api-engine/api/routes/channel/views.py b/src/api-engine/api/routes/channel/views.py index e7db44a9b..395fd61ed 100644 --- a/src/api-engine/api/routes/channel/views.py +++ b/src/api-engine/api/routes/channel/views.py @@ -18,7 +18,7 @@ from api.config import CELLO_HOME from api.common.serializers import PageQuerySerializer -from api.utils.common import with_common_response, parse_block_file, to_dict, json_filter, json_add_anchor_peer, json_create_envelope +from api.utils.common import with_common_response, parse_block_file, to_dict, json_filter, json_add_anchor_peer, json_create_envelope, init_env_vars from api.lib.configtxgen import ConfigTX, ConfigTxGen from api.lib.peer.channel import Channel as PeerChannel from api.lib.configtxlator.configtxlator import ConfigTxLator @@ -549,40 +549,3 @@ def peer_channel_update(name, org, anchor_peer, ordering_node, channel_artifacts orderer_url="{}.{}:{}".format( ordering_node.name, org.name.split(".", 1)[1], str(7050)), ) - - -def init_env_vars(node, org): - """ - Initialize environment variables for peer channel CLI. - :param node: Node object - :param org: Organization object. - :return env: dict - """ - org_name = org.name - org_domain = org_name.split(".", 1)[1] - dir_certificate = "{}/{}/crypto-config/ordererOrganizations/{}".format( - CELLO_HOME, org_name, org_domain) - dir_node = "{}/{}/crypto-config/peerOrganizations".format( - CELLO_HOME, org_name) - - envs = {} - - if(node.type == "orderer"): - envs = { - "CORE_PEER_TLS_ENABLED": "true", - "ORDERER_CA": "{}/orderers/{}/msp/tlscacerts/tlsca.{}-cert.pem".format(dir_certificate, node.name + "." + org_domain, org_domain), - "ORDERER_ADMIN_TLS_SIGN_CERT": "{}/orderers/{}/tls/server.crt".format(dir_certificate, node.name + "." + org_domain), - "ORDERER_ADMIN_TLS_PRIVATE_KEY": "{}/orderers/{}/tls/server.key".format(dir_certificate, node.name + "." + org_domain) - } - elif(node.type == "peer"): - envs = { - "CORE_PEER_TLS_ENABLED": "true", - "CORE_PEER_LOCALMSPID": "{}MSP".format(org_name.split(".")[0].capitalize()), - "CORE_PEER_TLS_ROOTCERT_FILE": "{}/{}/peers/{}/tls/ca.crt".format(dir_node, org_name, node.name + "." + org_name), - "CORE_PEER_MSPCONFIGPATH": "{}/{}/users/Admin@{}/msp".format(dir_node, org_name, org_name), - "CORE_PEER_ADDRESS": "{}:{}".format( - node.name + "." + org_name, str(7051)), - "FABRIC_CFG_PATH": "{}/{}/peers/{}/".format(dir_node, org_name, node.name + "." + org_name) - } - - return envs diff --git a/src/api-engine/api/utils/common.py b/src/api-engine/api/utils/common.py index 8829d3ea8..6d0ddd89e 100644 --- a/src/api-engine/api/utils/common.py +++ b/src/api-engine/api/utils/common.py @@ -13,6 +13,7 @@ import uuid from zipfile import ZipFile from json import loads +from api.config import CELLO_HOME import json import logging @@ -261,4 +262,40 @@ def json_create_envelope(input, output, channel): except Exception as e: LOG.error("Failed to create config update envelope: {}".format(str(e))) - raise \ No newline at end of file + raise + +def init_env_vars(node, org): + """ + Initialize environment variables for peer channel CLI. + :param node: Node object + :param org: Organization object. + :return env: dict + """ + org_name = org.name + org_domain = org_name.split(".", 1)[1] + dir_certificate = "{}/{}/crypto-config/ordererOrganizations/{}".format( + CELLO_HOME, org_name, org_domain) + dir_node = "{}/{}/crypto-config/peerOrganizations".format( + CELLO_HOME, org_name) + + envs = {} + + if(node.type == "orderer"): + envs = { + "CORE_PEER_TLS_ENABLED": "true", + "ORDERER_CA": "{}/orderers/{}/msp/tlscacerts/tlsca.{}-cert.pem".format(dir_certificate, node.name + "." + org_domain, org_domain), + "ORDERER_ADMIN_TLS_SIGN_CERT": "{}/orderers/{}/tls/server.crt".format(dir_certificate, node.name + "." + org_domain), + "ORDERER_ADMIN_TLS_PRIVATE_KEY": "{}/orderers/{}/tls/server.key".format(dir_certificate, node.name + "." + org_domain) + } + elif(node.type == "peer"): + envs = { + "CORE_PEER_TLS_ENABLED": "true", + "CORE_PEER_LOCALMSPID": "{}MSP".format(org_name.split(".")[0].capitalize()), + "CORE_PEER_TLS_ROOTCERT_FILE": "{}/{}/peers/{}/tls/ca.crt".format(dir_node, org_name, node.name + "." + org_name), + "CORE_PEER_MSPCONFIGPATH": "{}/{}/users/Admin@{}/msp".format(dir_node, org_name, org_name), + "CORE_PEER_ADDRESS": "{}:{}".format( + node.name + "." + org_name, str(7051)), + "FABRIC_CFG_PATH": "{}/{}/peers/{}/".format(dir_node, org_name, node.name + "." + org_name) + } + + return envs \ No newline at end of file