-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "[CE-62] Add network and network_config module"
- Loading branch information
Showing
13 changed files
with
143 additions
and
35 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
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
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import abc | ||
|
||
|
||
class BlockchainNetwork(object): | ||
""" | ||
BlockchainNetwork is an abstract class to represent a general model of a | ||
blockchain, such as a Hyperledger Fabric network. | ||
""" | ||
__metaclass__ = abc.ABCMeta | ||
|
||
@abc.abstractmethod | ||
def get_config(self): | ||
""" | ||
Get the configuration data for the network | ||
Returns: configuration dict struct | ||
""" | ||
return |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class BlockchainNetworkConfig(object): | ||
""" | ||
BlockchainNetworkConfig includes those configuration data for a network. | ||
""" | ||
|
||
def __init__(self, data=None, metadata=None): | ||
""" | ||
Init. | ||
Args: | ||
data: config data related to network. | ||
metadata: metadata is for cello usage. | ||
""" | ||
self.data = data or {} # include all config data we need for a network | ||
self.metadata = metadata or {} # metadata is for cello usage | ||
|
||
def get_data(self): | ||
""" | ||
Get the configuration data for the blockchain network | ||
Returns: data dict | ||
""" | ||
return self.data | ||
|
||
def get_metadata(self): | ||
""" | ||
Get the metadata | ||
Returns: metadata dict | ||
""" | ||
return self.metadata |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from common.blockchain_network import BlockchainNetwork | ||
from common.fabric_network_config import FabricNetworkConfig | ||
|
||
|
||
class FabricNetwork(BlockchainNetwork): | ||
""" | ||
FabricNetwork represents a Hyperledger Fabric network. | ||
""" | ||
|
||
def __init__(self, config=None): | ||
""" | ||
Args: | ||
config: configuration data of the fabric network | ||
""" | ||
self.config = config or FabricNetworkConfig() | ||
|
||
def get_config(self): | ||
""" | ||
Get the configuration data for the network | ||
Returns: configuration dict struct | ||
""" | ||
return self.config |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from common.blockchain_network_config import BlockchainNetworkConfig | ||
from common.utils import NETWORK_TYPES | ||
|
||
|
||
class FabricNetworkConfig(BlockchainNetworkConfig): | ||
""" | ||
FabricNetworkConfig includes those configuration data for a fabric network. | ||
""" | ||
|
||
def __init__(self, data=None, metadata=None): | ||
""" | ||
Init. | ||
Args: | ||
data: config data related to the fabric network. | ||
metadata: metadata is for cello usage. | ||
""" | ||
if not data: | ||
data = { # will be used in compose template as the network config | ||
'for_test': NETWORK_TYPES[0] | ||
} | ||
|
||
if not metadata: | ||
metadata = { # for cello usage | ||
'name': 'FABRIC_NETWORK_{}'.format('test'), # TODO: randomlize | ||
'type': NETWORK_TYPES[0], # network of the blockchain | ||
'worker_api': '', # which worker will handle this network | ||
'envs': {} # env variables to setup, before sending request | ||
# to worker. Can be used for compose template files | ||
} | ||
super(FabricNetworkConfig, self).__init__(data, metadata) | ||
|
||
def get_data(self): | ||
""" | ||
Get the configuration data | ||
Returns: data dict | ||
""" | ||
return self.data | ||
|
||
def get_metadata(self): | ||
""" | ||
Get the metadata | ||
Returns: metadata dict | ||
""" | ||
return self.metadata |
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
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
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
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
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
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