Brian O'Connor
Committed by Ray Milkey

Updating onos-gen-partitions to take IPs via CLI args

Also, moving to SHA256 hash for onos-gen-partitions

Change-Id: Id2a56401cebf75345660059e16144426d4ae89c3
......@@ -23,9 +23,11 @@ def get_OC_vars():
vars.append(var)
return sorted(vars, key=alphanum_key)
def get_nodes(vars, port=9876):
def get_nodes(ips=None, port=9876):
node = lambda k: { 'id': k, 'ip': k, 'port': port }
return [ node(environ[v]) for v in vars ]
if not ips:
ips = [ environ[v] for v in get_OC_vars() ]
return [ node(v) for v in ips ]
def generate_base_partition(nodes):
return {
......@@ -46,16 +48,16 @@ def generate_extended_partitions(nodes, k):
return perms
if __name__ == '__main__':
vars = get_OC_vars()
nodes = get_nodes(vars)
nodes = get_nodes(sys.argv[1:])
base_partition = generate_base_partition([v.get('id') for v in nodes])
extended_partitions = generate_extended_partitions([v.get('id') for v in nodes], 3)
partitions = []
partitions.append(base_partition)
partitions.extend(extended_partitions)
name = 0
m = hashlib.sha256()
for node in nodes:
name = name ^ hash(node['ip'])
m.update(node['ip'])
name = int(m.hexdigest()[:8], base=16) # 32-bit int based on SHA256 digest
data = {
'name': name,
'nodes': nodes,
......