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(): ...@@ -23,9 +23,11 @@ def get_OC_vars():
23 vars.append(var) 23 vars.append(var)
24 return sorted(vars, key=alphanum_key) 24 return sorted(vars, key=alphanum_key)
25 25
26 -def get_nodes(vars, port=9876): 26 +def get_nodes(ips=None, port=9876):
27 node = lambda k: { 'id': k, 'ip': k, 'port': port } 27 node = lambda k: { 'id': k, 'ip': k, 'port': port }
28 - return [ node(environ[v]) for v in vars ] 28 + if not ips:
29 + ips = [ environ[v] for v in get_OC_vars() ]
30 + return [ node(v) for v in ips ]
29 31
30 def generate_base_partition(nodes): 32 def generate_base_partition(nodes):
31 return { 33 return {
...@@ -46,16 +48,16 @@ def generate_extended_partitions(nodes, k): ...@@ -46,16 +48,16 @@ def generate_extended_partitions(nodes, k):
46 return perms 48 return perms
47 49
48 if __name__ == '__main__': 50 if __name__ == '__main__':
49 - vars = get_OC_vars() 51 + nodes = get_nodes(sys.argv[1:])
50 - nodes = get_nodes(vars)
51 base_partition = generate_base_partition([v.get('id') for v in nodes]) 52 base_partition = generate_base_partition([v.get('id') for v in nodes])
52 extended_partitions = generate_extended_partitions([v.get('id') for v in nodes], 3) 53 extended_partitions = generate_extended_partitions([v.get('id') for v in nodes], 3)
53 partitions = [] 54 partitions = []
54 partitions.append(base_partition) 55 partitions.append(base_partition)
55 partitions.extend(extended_partitions) 56 partitions.extend(extended_partitions)
56 - name = 0 57 + m = hashlib.sha256()
57 for node in nodes: 58 for node in nodes:
58 - name = name ^ hash(node['ip']) 59 + m.update(node['ip'])
60 + name = int(m.hexdigest()[:8], base=16) # 32-bit int based on SHA256 digest
59 data = { 61 data = {
60 'name': name, 62 'name': name,
61 'nodes': nodes, 63 'nodes': nodes,
......