Skip to content

Commit

Permalink
Merge 91c9a81 into 6a5ade3
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-napoleone committed Dec 4, 2018
2 parents 6a5ade3 + 91c9a81 commit 2b4e535
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 10 additions & 2 deletions tmn/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Configuration:

def __init__(self, name: str = None, net: str = None,
pkey: str = None, start: bool = False,
docker_url: str = None) -> None:
docker_url: str = None, api: bool = False) -> None:
self.networks = {}
self.services = {}
self.volumes = {}
Expand All @@ -34,6 +34,7 @@ def __init__(self, name: str = None, net: str = None,
self.client = docker.from_env()
else:
self.client = docker.DockerClient(base_url=docker_url)
self.api = 'True' if api else 'False'
try:
self.client.ping()
except Exception as e:
Expand All @@ -59,6 +60,7 @@ def _load(self) -> None:
self.id = resources.user.read('id')
self.name = resources.user.read('name')
self.net = resources.user.read('net')
self.api = resources.user.read('api')
#######################################################################
# this is a dirty fix for retro compatiblity #
# can be removed in some future version #
Expand Down Expand Up @@ -86,6 +88,7 @@ def _write(self) -> None:
resources.user.write('id', self.id)
resources.user.write('name', self.name)
resources.user.write('net', self.net)
resources.user.write('api', self.api)

def _compose(self) -> None:
self.networks['tmn'] = Network(
Expand All @@ -102,6 +105,11 @@ def _compose(self) -> None:
tag = 'testnet'
else:
tag = 'latest'
if self.api == 'True': # this is dirty, should be refactored
tomochain_ports = {'30303/udp': 30303, '30303/tcp': 30303,
8545: 8545, 8546: 8546}
else:
tomochain_ports = {'30303/udp': 30303, '30303/tcp': 30303}
self.services['metrics'] = Service(
name='{}_metrics'.format(self.name),
hostname='{}'.format(self.id),
Expand Down Expand Up @@ -130,7 +138,7 @@ def _compose(self) -> None:
'bind': '/tomochain', 'mode': 'rw'
}
},
ports={'30303/udp': 30303, '30303/tcp': 30303},
ports=tomochain_ports,
client=self.client
)
for container, variables in environments[self.net].items():
Expand Down
5 changes: 3 additions & 2 deletions tmn/tmn.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ def docs() -> None:
@click.option('--pkey', metavar='KEY', help=('Private key of the account your '
'masternode will collect rewards '
'on'))
def start(name: str, net: str, pkey: str) -> None:
@click.option('--api', is_flag=True)
def start(name: str, net: str, pkey: str, api: bool) -> None:
"Start the containers needed to run a masternode"
configuration = Configuration(name=name, net=net, pkey=pkey, start=True,
docker_url=docker_url)
docker_url=docker_url, api=api)
if configuration.force_recreate:
display.error_breaking_change()
sys.exit('\n')
Expand Down

0 comments on commit 2b4e535

Please sign in to comment.