Skip to content

PEP8 cosmetic changes #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2da9eb9
PEP8 cosmetic changes
UkcaGreen Sep 26, 2019
4bde1b9
Update blockchain.py
UkcaGreen Oct 15, 2019
a29bb6a
refactoring for compact look
UkcaGreen Feb 22, 2020
cff7d0b
space adjustment
UkcaGreen Feb 22, 2020
9b6829f
adjustments
UkcaGreen Feb 22, 2020
4cf32f9
adjustments for compactness
UkcaGreen Feb 22, 2020
03359b1
cosmetic adjustments
UkcaGreen Feb 22, 2020
b49ffb2
cosmetic adjustments
UkcaGreen Feb 22, 2020
69be69c
cosmetic changes
UkcaGreen Feb 22, 2020
0781e9e
cosmetic changes
UkcaGreen Feb 22, 2020
d7c8280
cosmetic changes
UkcaGreen Feb 22, 2020
e04480a
cosmetic changes
UkcaGreen Feb 22, 2020
fac7c59
cosmetic changes
UkcaGreen Feb 22, 2020
1d6bdfd
cosmetic changes
UkcaGreen Feb 22, 2020
92c20b3
cosmetic changes
UkcaGreen Feb 22, 2020
ad92997
cosmetic changes
UkcaGreen Feb 23, 2020
4190565
cosmetic changes
UkcaGreen Feb 23, 2020
199336f
cosmetic changes
UkcaGreen Feb 23, 2020
b094f99
help messages are passed as variable
UkcaGreen Feb 23, 2020
7d52596
cosmetic changes
UkcaGreen Mar 1, 2020
8c26dd6
cosmetic changes
UkcaGreen Mar 1, 2020
c124a62
cosmetic changes
UkcaGreen Mar 1, 2020
1a31391
cosmetic changes
UkcaGreen Mar 1, 2020
52c2fc4
cosmetic changes
UkcaGreen Mar 1, 2020
538ecc0
cosmetic changes
UkcaGreen Mar 1, 2020
9ac519f
newline fix
UkcaGreen Mar 4, 2020
2d106c6
newline fix
UkcaGreen Mar 4, 2020
f71ef5b
ambigious variable name fix
UkcaGreen Mar 5, 2020
bb0f88b
unnecessary newline fix
UkcaGreen Mar 5, 2020
8b64cdb
cosmetic review
UkcaGreen Mar 5, 2020
e11f1d7
cosmetic review
UkcaGreen Mar 5, 2020
584184b
cosmetic changes
UkcaGreen Mar 9, 2020
d57f024
cosmetic changes
UkcaGreen Mar 9, 2020
e86633a
cosmetic changes
UkcaGreen Mar 9, 2020
da02b04
cosmetic changes
UkcaGreen Mar 11, 2020
234379c
Cosmetic Changes
UkcaGreen Mar 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions bal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@


27 changes: 13 additions & 14 deletions bal/balmn.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
from mininet.node import ( Host, CPULimitedHost )
from mininet.node import (Host, CPULimitedHost)
from mininet.util import specialClass
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
from mininet.topolib import TreeTopo
from bal.bcnode import ( POWNode, POSNode )
from bal.bcnode import (POWNode, POSNode)

HOSTDEF = 'proc'
HOSTS = { 'proc': Host,
'rt': specialClass( CPULimitedHost, defaults=dict( sched='rt' ) ),
'cfs': specialClass( CPULimitedHost, defaults=dict( sched='cfs' ) ),
'pow': POWNode,
'pos': POSNode}
HOSTS = {'proc': Host,
'rt': specialClass(CPULimitedHost, defaults=dict(sched='rt')),
'cfs': specialClass(CPULimitedHost, defaults=dict(sched='cfs')),
'pow': POWNode,
'pos': POSNode}

TOPODEF = 'none'
TOPOS = { 'minimal': lambda: SingleSwitchTopo( k=2 ),
'linear': LinearTopo,
'reversed': SingleSwitchReversedTopo,
'single': SingleSwitchTopo,
'none': None,
'tree': TreeTopo
}
TOPOS = {'minimal': lambda: SingleSwitchTopo(k=2),
'linear': LinearTopo,
'reversed': SingleSwitchReversedTopo,
'single': SingleSwitchTopo,
'none': None,
'tree': TreeTopo}
120 changes: 54 additions & 66 deletions bal/bcnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@

import os

class BCNode( CPULimitedHost):

class BCNode(CPULimitedHost):
"""A BCNode is a Node that is running (or has execed?) an
block[chain] application."""

def __init__( self, name, inNamespace=True,
server='', sargs='', sdir='/tmp/bcn',
client='', cargs='{command}', cdir=None,
ip="127.0.0.1", port='', socket='6000', **params ):
def __init__(self, name, inNamespace=True,
server='', sargs='', sdir='/tmp/bcn',
client='', cargs='{command}', cdir=None,
ip="127.0.0.1", port='', socket='6000', **params):
# Server params
self.server = server
self.sargs = sargs
Expand All @@ -31,42 +32,39 @@ def __init__( self, name, inNamespace=True,

self.ip = ip
self.port = port
self.socket= socket
CPULimitedHost.__init__( self, name, inNamespace=inNamespace,
ip=ip, **params )
self.socket = socket
CPULimitedHost.__init__(self, name, inNamespace=inNamespace,
ip=ip, **params)

def start( self, sim_path ):
def start(self, sim_path):
"""Start <bcnode> <args> on node.
Log to /tmp/bc_<name>.log"""
if self.server:
pathCheck( self.server )
cout = self.sdir + '/bc_' + self.name + '.log'
pathCheck(self.server)
cout = self.sdir + '/bc_' + self.name + '.log'
if self.sdir is not None:
try:
os.stat(self.sdir)
except:
except BaseException:
os.mkdir(self.sdir)
self.cmd( 'cd ' + self.sdir )
self.cmd('cd ' + self.sdir)
cmd = self.server
if self.sargs:
cmd += " " + self.sargs.format(name=self.name,
IP=self.IP(),
port=self.port,
cdir=self.cdir,
sdir=self.sdir,
socket=self.socket,
simulation_path = sim_path)
debug( cmd + ' 1>' + cout + ' 2>' + cout + ' &' )
self.cmd( cmd + ' 1>' + cout + ' 2>' + cout + ' &' )
cmd += " " + self.sargs.format(name=self.name, IP=self.IP(),
port=self.port, cdir=self.cdir,
sdir=self.sdir, socket=self.socket,
simulation_path=sim_path)
debug(cmd + ' 1>' + cout + ' 2>' + cout + ' &')
self.cmd(cmd + ' 1>' + cout + ' 2>' + cout + ' &')
self.execed = False

def stop( self, *args, **kwargs ):
def stop(self, *args, **kwargs):
"Stop node."
self.cmd( 'kill %' + self.server )
self.cmd( 'wait %' + self.server )
super( BCNode, self ).stop( *args, **kwargs )
self.cmd('kill %' + self.server)
self.cmd('wait %' + self.server)
super(BCNode, self).stop(*args, **kwargs)

def isAvailable( self ):
def isAvailable(self):
"Is executables available?"
cmd = 'which '
if self.server:
Expand All @@ -75,66 +73,56 @@ def isAvailable( self ):
cmd += self.client
return quietRun(cmd)


def call(self, command, silent= False, data=''):
def call(self, command, silent=False, data=''):
"""Call <client> <cargs> on node."""
if self.cdir is not None:
self.cmd( 'cd ' + self.cdir )
self.cmd('cd ' + self.cdir)
cmd = self.client
pathCheck( cmd )
pathCheck(cmd)
if data:
method = '''POST -H "Content-Type: application/json" -d '{data}' '''.format(data = data)
method = '''POST -H "Content-Type: application/json" -d '{data}' '''.format(data=data)
else:
method = "GET"

if self.cargs:
cmd += " " + self.cargs.format(command=command,
method=method,
name=self.name,
IP=self.IP(),
port=self.port,
cdir=self.cdir,
cmd += " " + self.cargs.format(command=command, method=method,
name=self.name, IP=self.IP(),
port=self.port, cdir=self.cdir,
sdir=self.sdir)
else:
cmd += " " + command
cmd += " " + command
if silent:
result = self.cmd( cmd )
result = self.cmd(cmd)
else:
result = self.cmdPrint( cmd )
result = self.cmdPrint(cmd)

debug("command: %s = %s" % (cmd, result))
return result


class POWNode(BCNode):
"""A POWNode is a BCNode that is running an POWBlockchain."""

def __init__( self, name, bcclass=None, inNamespace=True,
server='blockchain.py',
sargs='-p {port} -s {socket} -d 2 -k {sdir}/{IP}pow.pem -n {name} -sp {simulation_path}',
sdir='/tmp/bcn',
client='curl',
cargs="-s -X {method} http://{IP}:{port}/{command}",
cdir=None,
ip="127.0.0.1", port='5000', **params ):
def __init__(self, name, bcclass=None, inNamespace=True, server='blockchain.py',
sargs='-p {port} -s {socket} -d 2 -k {sdir}/{IP}pow.pem -n {name} -sp {simulation_path}',
sdir='/tmp/bcn', client='curl', cargs="-s -X {method} http://{IP}:{port}/{command}",
cdir=None, ip="127.0.0.1", port='5000', **params):

BCNode.__init__(self, name, inNamespace=inNamespace,
server=server, sargs=sargs, sdir=sdir,
client=client, cargs=cargs, cdir=cdir,
ip=ip, port=port, **params)

BCNode.__init__( self, name, inNamespace=inNamespace,
server=server, sargs=sargs, sdir=sdir,
client=client, cargs=cargs, cdir=cdir,
ip=ip, port=port, **params )

class POSNode(BCNode):
"""A POSNode is a BCNode that is running an POSBlockchain."""

def __init__( self, name, bcclass=None, inNamespace=True,
server='blockchain.py',
sargs='-p {port} -s {socket} -v pos -k {sdir}/{IP}pos.pem -n {name} -sp {simulation_path}',
sdir='/tmp/bcn',
client='curl',
cargs="-s -X {method} http://{IP}:{port}/{command}",
cdir=None,
ip="127.0.0.1", port='5000', socket='6000', **params ):

BCNode.__init__( self, name, inNamespace=inNamespace,
server=server, sargs=sargs, sdir=sdir,
client=client, cargs=cargs, cdir=cdir,
ip=ip, port=port, **params )
def __init__(self, name, bcclass=None, inNamespace=True, server='blockchain.py',
sargs='-p {port} -s {socket} -v pos -k {sdir}/{IP}pos.pem -n {name} -sp {simulation_path}',
sdir='/tmp/bcn', client='curl', cargs="-s -X {method} http://{IP}:{port}/{command}",
cdir=None, ip="127.0.0.1", port='5000', socket='6000', **params):

BCNode.__init__(self, name, inNamespace=inNamespace,
server=server, sargs=sargs, sdir=sdir,
client=client, cargs=cargs, cdir=cdir,
ip=ip, port=port, **params)
Loading